From 80059c6dae8de4962b14f08bd75f1c773e37a78d Mon Sep 17 00:00:00 2001 From: Mark Tiefenbruck Date: Fri, 15 Aug 2008 04:02:14 -0700 Subject: move size hints to a struct --- src/CurrentWindowCmd.cc | 4 +- src/WinClient.cc | 153 ++++++++++++++++++++++++------------------------ src/WinClient.hh | 28 +++++++-- src/Window.cc | 26 ++++---- 4 files changed, 116 insertions(+), 95 deletions(-) diff --git a/src/CurrentWindowCmd.cc b/src/CurrentWindowCmd.cc index 9253058..65c5711 100644 --- a/src/CurrentWindowCmd.cc +++ b/src/CurrentWindowCmd.cc @@ -391,10 +391,10 @@ ResizeCmd::ResizeCmd(const int step_size_x, const int step_size_y) : void ResizeCmd::real_execute() { int w = std::max(static_cast(fbwindow().width() + - m_step_size_x * fbwindow().winClient().width_inc), + m_step_size_x * fbwindow().winClient().widthInc()), fbwindow().frame().titlebarHeight() * 2 + 10); int h = std::max(static_cast(fbwindow().height() + - m_step_size_y * fbwindow().winClient().height_inc), + m_step_size_y * fbwindow().winClient().heightInc()), fbwindow().frame().titlebarHeight() + 10); fbwindow().resize(w, h); } diff --git a/src/WinClient.cc b/src/WinClient.cc index a7e689f..9aac38d 100644 --- a/src/WinClient.cc +++ b/src/WinClient.cc @@ -67,12 +67,6 @@ WinClient::WinClient(Window win, BScreen &screen, FluxboxWindow *fbwin): transient_for(0), window_group(0), x(0), y(0), old_bw(0), - min_width(1), min_height(1), - max_width(0), max_height(0), - width_inc(1), height_inc(1), - min_aspect_x(0), min_aspect_y(0), - max_aspect_x(0), max_aspect_y(0), - base_width(1), base_height(1), initial_state(0), normal_hint_flags(0), wm_hint_flags(0), @@ -87,6 +81,15 @@ WinClient::WinClient(Window win, BScreen &screen, FluxboxWindow *fbwin): m_window_type(Focusable::TYPE_NORMAL), m_mwm_hint(0), m_strut(0) { + + m_size_hints.min_width = m_size_hints.min_height = + m_size_hints.width_inc = m_size_hints.height_inc = + m_size_hints.base_width = m_size_hints.base_height = 1; + + m_size_hints.max_width = m_size_hints.max_height = + m_size_hints.min_aspect_x = m_size_hints.min_aspect_y = + m_size_hints.max_aspect_x = m_size_hints.max_aspect_y = 0; + updateWMProtocols(); updateMWMHints(); updateWMHints(); @@ -469,65 +472,65 @@ void WinClient::updateWMNormalHints() { long icccm_mask; XSizeHints sizehint; if (! XGetWMNormalHints(display(), window(), &sizehint, &icccm_mask)) { - min_width = min_height = - base_width = base_height = - width_inc = height_inc = 1; - max_width = 0; // unbounded - max_height = 0; - min_aspect_x = min_aspect_y = - max_aspect_x = max_aspect_y = 0; + m_size_hints.min_width = m_size_hints.min_height = + m_size_hints.base_width = m_size_hints.base_height = + m_size_hints.width_inc = m_size_hints.height_inc = 1; + m_size_hints.max_width = 0; // unbounded + m_size_hints.max_height = 0; + m_size_hints.min_aspect_x = m_size_hints.min_aspect_y = + m_size_hints.max_aspect_x = m_size_hints.max_aspect_y = 0; m_win_gravity = NorthWestGravity; } else { normal_hint_flags = sizehint.flags; if (sizehint.flags & PMinSize) { - min_width = sizehint.min_width; - min_height = sizehint.min_height; + m_size_hints.min_width = sizehint.min_width; + m_size_hints.min_height = sizehint.min_height; if (!(sizehint.flags & PBaseSize)) { - base_width = min_width; - base_height = min_height; + m_size_hints.base_width = m_size_hints.min_width; + m_size_hints.base_height = m_size_hints.min_height; } } else { - min_width = min_height = 1; - base_width = base_height = 0; + m_size_hints.min_width = m_size_hints.min_height = 1; + m_size_hints.base_width = m_size_hints.base_height = 0; } if (sizehint.flags & PBaseSize) { - base_width = sizehint.base_width; - base_height = sizehint.base_height; + m_size_hints.base_width = sizehint.base_width; + m_size_hints.base_height = sizehint.base_height; if (!(sizehint.flags & PMinSize)) { - min_width = base_width; - min_height = base_height; + m_size_hints.min_width = m_size_hints.base_width; + m_size_hints.min_height = m_size_hints.base_height; } } // default set in PMinSize if (sizehint.flags & PMaxSize) { - max_width = sizehint.max_width; - max_height = sizehint.max_height; + m_size_hints.max_width = sizehint.max_width; + m_size_hints.max_height = sizehint.max_height; } else { - max_width = 0; // unbounded - max_height = 0; + m_size_hints.max_width = 0; // unbounded + m_size_hints.max_height = 0; } if (sizehint.flags & PResizeInc) { - width_inc = sizehint.width_inc; - height_inc = sizehint.height_inc; + m_size_hints.width_inc = sizehint.width_inc; + m_size_hints.height_inc = sizehint.height_inc; } else - width_inc = height_inc = 1; + m_size_hints.width_inc = m_size_hints.height_inc = 1; - if (width_inc == 0) - width_inc = 1; - if (height_inc == 0) - height_inc = 1; + if (m_size_hints.width_inc == 0) + m_size_hints.width_inc = 1; + if (m_size_hints.height_inc == 0) + m_size_hints.height_inc = 1; if (sizehint.flags & PAspect) { - min_aspect_x = sizehint.min_aspect.x; - min_aspect_y = sizehint.min_aspect.y; - max_aspect_x = sizehint.max_aspect.x; - max_aspect_y = sizehint.max_aspect.y; + m_size_hints.min_aspect_x = sizehint.min_aspect.x; + m_size_hints.min_aspect_y = sizehint.min_aspect.y; + m_size_hints.max_aspect_x = sizehint.max_aspect.x; + m_size_hints.max_aspect_y = sizehint.max_aspect.y; } else - min_aspect_x = min_aspect_y = - max_aspect_x = max_aspect_y = 0; + m_size_hints.min_aspect_x = m_size_hints.min_aspect_y = + m_size_hints.max_aspect_x = m_size_hints.max_aspect_y = 0; if (sizehint.flags & PWinGravity) m_win_gravity = sizehint.win_gravity; @@ -725,29 +728,29 @@ void WinClient::applySizeHints(int &width, int &height, int i = width, j = height; // Check minimum size - if (width < 0 || width < static_cast(min_width)) - width = min_width; + if (width < 0 || width < static_cast(m_size_hints.min_width)) + width = m_size_hints.min_width; - if (height < 0 || height < static_cast(min_height)) - height = min_height; + if (height < 0 || height < static_cast(m_size_hints.min_height)) + height = m_size_hints.min_height; // Check maximum size - if (max_width > 0 && width > static_cast(max_width)) - width = max_width; + if (m_size_hints.max_width > 0 && width > static_cast(m_size_hints.max_width)) + width = m_size_hints.max_width; - if (max_height > 0 && height > static_cast(max_height)) - height = max_height; + if (m_size_hints.max_height > 0 && height > static_cast(m_size_hints.max_height)) + height = m_size_hints.max_height; // we apply aspect ratios before incrementals // Too difficult to exactly satisfy both incremental+aspect // in most situations // (they really shouldn't happen at the same time anyway). - /* aspect ratios are applied exclusive to the base_width + /* aspect ratios are applied exclusive to the m_size_hints.base_width * - * min_aspect_x width max_aspect_x + * m_size_hints.min_aspect_x width m_size_hints.max_aspect_x * ------------ < ------- < ------------ - * min_aspect_y height max_aspect_y + * m_size_hints.min_aspect_y height m_size_hints.max_aspect_y * * beware of integer maximum (so I'll use doubles instead and divide) * @@ -764,16 +767,16 @@ void WinClient::applySizeHints(int &width, int &height, * is used in that case. */ - if (min_aspect_y > 0 && max_aspect_y > 0 && - (height - base_height) > 0) { - double widthd = static_cast(width - base_width); - double heightd = static_cast(height - base_height); + if (m_size_hints.min_aspect_y > 0 && m_size_hints.max_aspect_y > 0 && + (height - m_size_hints.base_height) > 0) { + double widthd = static_cast(width - m_size_hints.base_width); + double heightd = static_cast(height - m_size_hints.base_height); - double min = static_cast(min_aspect_x) / - static_cast(min_aspect_y); + double min = static_cast(m_size_hints.min_aspect_x) / + static_cast(m_size_hints.min_aspect_y); - double max = static_cast(max_aspect_x) / - static_cast(max_aspect_y); + double max = static_cast(m_size_hints.max_aspect_x) / + static_cast(m_size_hints.max_aspect_y); double actual = widthd / heightd; @@ -794,23 +797,23 @@ void WinClient::applySizeHints(int &width, int &height, } if (changed) { - width = static_cast(widthd) + base_width; - height = static_cast(heightd) + base_height; + width = static_cast(widthd) + m_size_hints.base_width; + height = static_cast(heightd) + m_size_hints.base_height; } } } // enforce incremental size limits, wrt base size // only calculate this if we really need to - i = (width - static_cast(base_width)) / - static_cast(width_inc); - width = i*static_cast(width_inc) + - static_cast(base_width); + i = (width - static_cast(m_size_hints.base_width)) / + static_cast(m_size_hints.width_inc); + width = i*static_cast(m_size_hints.width_inc) + + static_cast(m_size_hints.base_width); - j = (height - static_cast(base_height)) / - static_cast(height_inc); - height = j*static_cast(height_inc) + - static_cast(base_height); + j = (height - static_cast(m_size_hints.base_height)) / + static_cast(m_size_hints.height_inc); + height = j*static_cast(m_size_hints.height_inc) + + static_cast(m_size_hints.base_height); if (display_width) *display_width = i; @@ -821,24 +824,24 @@ void WinClient::applySizeHints(int &width, int &height, // check if the given width and height satisfy the size hints bool WinClient::checkSizeHints(unsigned int width, unsigned int height) { - if (width < min_width || height < min_height) + if (width < m_size_hints.min_width || height < m_size_hints.min_height) return false; - if (width > max_width || height > max_height) + if (width > m_size_hints.max_width || height > m_size_hints.max_height) return false; - if ((width - base_width) % width_inc != 0) + if ((width - m_size_hints.base_width) % m_size_hints.width_inc != 0) return false; - if ((height - base_height) % height_inc != 0) + if ((height - m_size_hints.base_height) % m_size_hints.height_inc != 0) return false; double ratio = (double)width / (double)height; - if (min_aspect_y > 0 && (double)min_aspect_x / (double)min_aspect_y > ratio) + if (m_size_hints.min_aspect_y > 0 && (double)m_size_hints.min_aspect_x / (double)m_size_hints.min_aspect_y > ratio) return false; - if (max_aspect_y > 0 && (double)max_aspect_x / (double)max_aspect_y < ratio) + if (m_size_hints.max_aspect_y > 0 && (double)m_size_hints.max_aspect_x / (double)m_size_hints.max_aspect_y < ratio) return false; return true; diff --git a/src/WinClient.hh b/src/WinClient.hh index 51d5077..51d3b3e 100644 --- a/src/WinClient.hh +++ b/src/WinClient.hh @@ -43,6 +43,21 @@ public: unsigned long decorations; // Motif wm decorations } MwmHints; + typedef struct SizeHints { + unsigned int min_width; + unsigned int max_width; + unsigned int min_height; + unsigned int max_height; + unsigned int width_inc; + unsigned int height_inc; + unsigned int min_aspect_x; + unsigned int max_aspect_x; + unsigned int min_aspect_y; + unsigned int max_aspect_y; + unsigned int base_width; + unsigned int base_height; + } SizeHints; + WinClient(Window win, BScreen &screen, FluxboxWindow *fbwin = 0); ~WinClient(); @@ -129,8 +144,12 @@ public: const MwmHints *getMwmHint() const { return m_mwm_hint; } - unsigned int maxWidth() const { return max_width; } - unsigned int maxHeight() const { return max_height; } + unsigned int minWidth() const { return m_size_hints.min_width; } + unsigned int minHeight() const { return m_size_hints.min_height; } + unsigned int maxWidth() const { return m_size_hints.max_width; } + unsigned int maxHeight() const { return m_size_hints.max_height; } + unsigned int widthInc() const { return m_size_hints.width_inc; } + unsigned int heightInc() const { return m_size_hints.height_inc; } static const int PropMwmHintsElements = 3; @@ -145,10 +164,6 @@ public: int x, y, old_bw; - unsigned int - min_width, min_height, max_width, max_height, width_inc, height_inc, - min_aspect_x, min_aspect_y, max_aspect_x, max_aspect_y, - base_width, base_height; unsigned long initial_state, normal_hint_flags, wm_hint_flags; private: @@ -172,6 +187,7 @@ private: Focusable::WindowType m_window_type; MwmHints *m_mwm_hint; + SizeHints m_size_hints; Strut *m_strut; // map transient_for X window to winclient transient diff --git a/src/Window.cc b/src/Window.cc index 0c5ae0f..651b995 100644 --- a/src/Window.cc +++ b/src/Window.cc @@ -472,8 +472,9 @@ void FluxboxWindow::init() { if ((m_client->normal_hint_flags & PMinSize) && (m_client->normal_hint_flags & PMaxSize) && - m_client->max_width != 0 && m_client->max_width <= m_client->min_width && - m_client->max_height != 0 && m_client->max_height <= m_client->min_height) { + m_client->maxWidth() != 0 && m_client->maxHeight() != 0 && + m_client->maxWidth() <= m_client->minWidth() && + m_client->maxHeight() <= m_client->minHeight()) { decorations.maximize = decorations.handle = functions.resize = functions.maximize = false; decorations.tab = false; //no tab for this window @@ -2391,19 +2392,20 @@ void FluxboxWindow::propertyNotifyEvent(WinClient &client, Atom atom) { #ifdef DEBUG cerr<<"XA_WM_NORMAL_HINTS("<