From b32d1a9585badc90c433b6c2d925a34b7c4e0b0d Mon Sep 17 00:00:00 2001 From: Tomas Janousek Date: Fri, 16 Mar 2007 10:17:38 +0100 Subject: [PATCH] Fix maximization of size-hinted windows The applySizeHints function uses the closest point to line formula to calculate the new w/h. This results in a friendly behaviour while resizing size-hinted windows, but when maximizing it results in windows partly off the screen, which is of course not desirable. This patch makes it use another formula in the case of maximization. --- src/WinClient.cc | 17 ++++++++++++++--- src/WinClient.hh | 3 ++- src/Window.cc | 6 +++--- src/Window.hh | 2 +- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/WinClient.cc b/src/WinClient.cc index 458ac01..bb8a25c 100644 --- a/src/WinClient.cc +++ b/src/WinClient.cc @@ -772,7 +772,8 @@ void closestPointToLine(double &ret_x, double &ret_y, * See ICCCM section 4.1.2.3 */ void WinClient::applySizeHints(int &width, int &height, - int *display_width, int *display_height) { + int *display_width, int *display_height, + bool maximizing) { int i = width, j = height; @@ -810,6 +811,10 @@ void WinClient::applySizeHints(int &width, int &height, * Consider that the aspect ratio is a line, and the current * w/h is a point, so we're just using the formula for * shortest distance from a point to a line! + * + * When maximizing, we must not increase any of the sizes, because we + * would end up with the window partly off a screen, so a simpler formula + * is used in that case. */ if (min_aspect_y > 0 && max_aspect_y > 0 && @@ -829,10 +834,16 @@ void WinClient::applySizeHints(int &width, int &height, bool changed = false; if (actual < min) { changed = true; - closestPointToLine(widthd, heightd, widthd, heightd, min); + if (maximizing) + heightd = widthd / min; + else + closestPointToLine(widthd, heightd, widthd, heightd, min); } else if (actual > max) { changed = true; - closestPointToLine(widthd, heightd, widthd, heightd, max); + if (maximizing) + widthd = heightd * max; + else + closestPointToLine(widthd, heightd, widthd, heightd, max); } if (changed) { diff --git a/src/WinClient.hh b/src/WinClient.hh index 541c985..cbe5c1a 100644 --- a/src/WinClient.hh +++ b/src/WinClient.hh @@ -91,7 +91,8 @@ public: * to the user when resizing. * We use pointers for display_* since they are optional. */ - void applySizeHints(int &width, int &height, int *display_width = 0, int *display_height = 0); + void applySizeHints(int &width, int &height, int *display_width = 0, + int *display_height = 0, bool maximizing = false); void setGroupLeftWindow(Window win); diff --git a/src/Window.cc b/src/Window.cc index e471d6e..8e6b887 100644 --- a/src/Window.cc +++ b/src/Window.cc @@ -1711,7 +1711,7 @@ void FluxboxWindow::maximize(int type) { ResizeDirection old_resize_corner = m_resize_corner; m_resize_corner = NOCORNER; - fixsize(); + fixsize(0, 0, true); m_resize_corner = old_resize_corner; moveResize(m_last_resize_x, m_last_resize_y, m_last_resize_w, m_last_resize_h); @@ -3779,7 +3779,7 @@ void FluxboxWindow::changeBlackboxHints(const BlackboxHints &net) { } -void FluxboxWindow::fixsize(int *user_w, int *user_h) { +void FluxboxWindow::fixsize(int *user_w, int *user_h, bool maximizing) { int titlebar_height = (decorations.titlebar ? frame().titlebar().height() + frame().titlebar().borderWidth() : 0); @@ -3795,7 +3795,7 @@ void FluxboxWindow::fixsize(int *user_w, int *user_h) { // dy = new height (w/o decorations), similarly int dh = m_last_resize_h - decoration_height; - m_client->applySizeHints(dw, dh, user_w, user_h); + m_client->applySizeHints(dw, dh, user_w, user_h, maximizing); // update last resize m_last_resize_w = dw; diff --git a/src/Window.hh b/src/Window.hh index 1e55fb5..3206fdd 100644 --- a/src/Window.hh +++ b/src/Window.hh @@ -472,7 +472,7 @@ private: // modifies left and top if snap is necessary void doSnapping(int &left, int &top); // user_w/h return the values that should be shown to the user - void fixsize(int *user_w = 0, int *user_h = 0); + void fixsize(int *user_w = 0, int *user_h = 0, bool maximizing = false); void moveResizeClient(WinClient &client, int x, int y, unsigned int width, unsigned int height); /// sends configurenotify to all clients void sendConfigureNotify(bool send_to_netizens = true); -- 1.4.4.4