From c2001a841f99eb24dd671c7c039264a515776ea7 Mon Sep 17 00:00:00 2001
From: Tomas Janousek <tomi@nomi.cz>
Date: Mon, 19 Mar 2007 09:48:26 +0100
Subject: [PATCH] Move the fit-into-area and sizehint code from maximize to moveResize.

Use it in ArrangeWindows.
---
 src/Window.cc       |   58 +++++++++++++++++++++++++++++++-------------------
 src/Window.hh       |   11 ++++++++-
 src/WorkspaceCmd.cc |   14 ++---------
 3 files changed, 49 insertions(+), 34 deletions(-)

From aa3dcd61b807e5904cadc576e6190b9e62013200 Mon Sep 17 00:00:00 2001
From: Tomas Janousek <tomi@nomi.cz>
Date: Thu, 12 Apr 2007 14:51:42 +0200
Subject: [PATCH] ArrangeWindows should follow the MaxIgnoreIncrement setting

---
 src/WorkspaceCmd.cc |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

--- a/src/Window.cc
+++ b/src/Window.cc
@@ -1247,7 +1247,7 @@ void FluxboxWindow::resize(unsigned int width, unsigned int height) {
 // send_event is just an override
 void FluxboxWindow::moveResize(int new_x, int new_y,
                                unsigned int new_width, unsigned int new_height,
-                               bool send_event) {
+                               bool send_event, int fit) {
 
     // magic to detect if moved during initialisation
     if (!m_initialized)
@@ -1255,6 +1255,33 @@ void FluxboxWindow::moveResize(int new_x, int new_y,
 
     send_event = send_event || frame().x() != new_x || frame().y() != new_y;
 
+    if (fit & MAX_VERT) {
+        new_height -= 2 * frame().window().borderWidth();
+        if (!screen().getMaxOverTabs()) {
+            new_y += yOffset();
+            new_height -= heightOffset();
+        }
+    }
+    if (fit & MAX_HORZ) {
+        new_width -= 2 * frame().window().borderWidth();
+        if (!screen().getMaxOverTabs()) {
+            new_x += xOffset();
+            new_width -= widthOffset();
+        }
+    }
+    if (fit & FIT_SIZEHINTS) {
+        m_last_resize_x = new_x; m_last_resize_y = new_y;
+        m_last_resize_w = new_width; m_last_resize_h = new_height;
+
+        ResizeDirection old_resize_corner = m_resize_corner;
+        m_resize_corner = NOCORNER;
+        fixsize(0, 0, (maximized ? true : false));
+        m_resize_corner = old_resize_corner;
+
+        new_x = m_last_resize_x; new_y = m_last_resize_y;
+        new_width = m_last_resize_w; new_height = m_last_resize_h;
+    }
+
     if ((new_width != frame().width() || new_height != frame().height()) &&
         isResizable() && !isShaded()) {
 
@@ -1678,6 +1705,7 @@ void FluxboxWindow::maximize(int type) {
         new_h = frame().height();
 
     int orig_max = maximized;
+    int fit = MAX_NONE;
 
     // These evaluate whether we need to TOGGLE the value for that field
     // Why? If maximize is only set to zero outside this,
@@ -1701,11 +1729,8 @@ void FluxboxWindow::maximize(int type) {
             m_old_pos_y  = new_y;
             m_old_height = new_h;
             new_y = screen().maxTop(head);
-            new_h = screen().maxBottom(head) - new_y - 2*frame().window().borderWidth();
-            if (!screen().getMaxOverTabs()) {
-                new_y += yOffset();
-                new_h -= heightOffset();
-            }
+            new_h = screen().maxBottom(head) - new_y;
+            fit |= MAX_VERT;
         }
         maximized ^= MAX_VERT;
     }
@@ -1721,33 +1746,22 @@ void FluxboxWindow::maximize(int type) {
             m_old_pos_x = new_x;
             m_old_width = new_w;
             new_x = screen().maxLeft(head);
-            new_w = screen().maxRight(head) - new_x - 2*frame().window().borderWidth();
-            if (!screen().getMaxOverTabs()) {
-                new_x += xOffset();
-                new_w -= widthOffset();
-            }
+            new_w = screen().maxRight(head) - new_x;
+            fit |= MAX_HORZ;
         }
         maximized ^= MAX_HORZ;
     }
 
     // ensure we apply the sizehints here, otherwise some
     // apps (eg xterm) end up a little bit .. crappy (visually)
-    m_last_resize_x = new_x;
-    m_last_resize_y = new_y;
-    m_last_resize_w = new_w;
-    m_last_resize_h = new_h;
 
     // frankly, that xterm bug was pretty obscure, and it's really annoying not
     // being able to maximize my terminals, so we make an option
     // but we do fix size hints when restoring the window to normal size
-    if (!screen().getMaxIgnoreIncrement() || !maximized) {
-        ResizeDirection old_resize_corner = m_resize_corner;
-        m_resize_corner = NOCORNER;
-        fixsize(0, 0, (maximized ? true : false));
-        m_resize_corner = old_resize_corner;
-    }
+    if (!screen().getMaxIgnoreIncrement() || !maximized)
+        fit |= FIT_SIZEHINTS;
 
-    moveResize(m_last_resize_x, m_last_resize_y, m_last_resize_w, m_last_resize_h);
+    moveResize(new_x, new_y, new_w, new_h, false, fit);
 
     // notify listeners that we changed state
     stateSig().notify();
--- a/src/Window.hh
+++ b/src/Window.hh
@@ -116,6 +116,14 @@ public:
         MAX_VERT = 2, ///< maximize vertical
         MAX_FULL = 3  ///< maximize full
     };
+
+    /**
+     * Additional flags for moveResize
+     */
+    enum MoveResizeFit {
+        FIT_SIZEHINTS = 4 ///< apply size hints
+    };
+
     /**
        This enumeration represents individual decoration
        attributes, they can be OR-d together to get a mask.
@@ -308,7 +316,8 @@ public:
     /// resize frame to width, height
     void resize(unsigned int width, unsigned int height);
     /// move and resize frame to pox x,y and size width, height
-    void moveResize(int x, int y, unsigned int width, unsigned int height, bool send_event = false);
+    void moveResize(int x, int y, unsigned int width, unsigned int height,
+            bool send_event = false, int fit = MAX_NONE);
     /// move to pos x,y and resize client window to size width, height
     void moveResizeForClient(int x, int y, unsigned int width, unsigned int height, int gravity = ForgetGravity, unsigned int client_bw = 0);
     /**
diff -u b/src/WorkspaceCmd.cc b/src/WorkspaceCmd.cc
--- b/src/WorkspaceCmd.cc
+++ b/src/WorkspaceCmd.cc
@@ -256,17 +256,10 @@
                 }
             }
 
-            if (normal_windows.size() > 1) {
-                (*closest)->moveResize(x_offs + (*closest)->xOffset(),
-			y_offs + (*closest)->yOffset(),
-			cal_width - (*closest)->widthOffset(),
-			cal_height - (*closest)->heightOffset());
-            } else { // the last window gets everything that is left.
-                (*closest)->moveResize(x_offs + (*closest)->xOffset(),
-			y_offs + (*closest)->yOffset(),
-			screen->maxRight(head) - x_offs - (*closest)->widthOffset(),
-			cal_height - (*closest)->heightOffset());
-            }
+            (*closest)->moveResize(x_offs, y_offs,
+                    normal_windows.size() > 1 ? cal_width : screen->maxRight(head) - x_offs,
+                    cal_height, false, FluxboxWindow::MAX_FULL |
+                    (screen->getMaxIgnoreIncrement() ? 0 : FluxboxWindow::FIT_SIZEHINTS));
 
             normal_windows.erase(closest);
 
