From 6d42d1cf5ed7d4ae6b3941727bf17cb6b48defd4 Mon Sep 17 00:00:00 2001
From: fluxgen <fluxgen>
Date: Sun, 19 Feb 2006 12:50:01 +0000
Subject: Added center resize. Resizes all corners at the same time.

---
 src/Screen.hh          |  1 +
 src/ScreenResources.cc |  4 ++++
 src/Window.cc          | 55 +++++++++++++++++++++++++++++++++++++-------------
 src/Window.hh          |  3 ++-
 4 files changed, 48 insertions(+), 15 deletions(-)

diff --git a/src/Screen.hh b/src/Screen.hh
index 4f91d9c..7954456 100644
--- a/src/Screen.hh
+++ b/src/Screen.hh
@@ -90,6 +90,7 @@ public:
     enum ResizeModel { 
         BOTTOMRESIZE = 0, 
         QUADRANTRESIZE, 
+        CENTERRESIZE,
         DEFAULTRESIZE = BOTTOMRESIZE };
 
 
diff --git a/src/ScreenResources.cc b/src/ScreenResources.cc
index f26a376..7a58914 100644
--- a/src/ScreenResources.cc
+++ b/src/ScreenResources.cc
@@ -58,6 +58,8 @@ std::string FbTk::Resource<BScreen::ResizeModel>::getString() const {
         return std::string("Quadrant");
     case BScreen::BOTTOMRESIZE:
         return std::string("Bottom");
+    case BScreen::CENTERRESIZE:
+        return std::string("Center");
     }
 
     return std::string("Default");
@@ -70,6 +72,8 @@ setFromString(char const *strval) {
         m_value = BScreen::BOTTOMRESIZE;
     } else if (strcasecmp(strval, "Quadrant") == 0) {
         m_value = BScreen::QUADRANTRESIZE;
+    } else if (strcasecmp(strval, "Center") == 0) {
+        m_value = BScreen::CENTERRESIZE;
     } else 
         m_value = BScreen::DEFAULTRESIZE;
 }
diff --git a/src/Window.cc b/src/Window.cc
index a3b20f9..e6db450 100644
--- a/src/Window.cc
+++ b/src/Window.cc
@@ -2814,9 +2814,12 @@ void FluxboxWindow::motionNotifyEvent(XMotionEvent &me) {
               m_resize_corner = RIGHTBOTTOM;
           else if (me.window == frame().gripLeft())
               m_resize_corner = LEFTBOTTOM;
-          else if (screen().getResizeModel() != BScreen::QUADRANTRESIZE)
-              m_resize_corner = RIGHTBOTTOM;
-          else if (me.x < cx)
+          else if (screen().getResizeModel() != BScreen::QUADRANTRESIZE) {
+              if (screen().getResizeModel() == BScreen::CENTERRESIZE)
+                  m_resize_corner = ALLCORNERS;
+              else
+                  m_resize_corner = RIGHTBOTTOM;              
+          } else if (me.x < cx)
               m_resize_corner = (me.y < cy) ? LEFTTOP : LEFTBOTTOM;
           else
               m_resize_corner = (me.y < cy) ? RIGHTTOP : RIGHTBOTTOM;
@@ -2835,21 +2838,45 @@ void FluxboxWindow::motionNotifyEvent(XMotionEvent &me) {
 
             int dx = me.x - m_button_grab_x;
             int dy = me.y - m_button_grab_y;
-
-            if (m_resize_corner == LEFTTOP || m_resize_corner == RIGHTTOP) {
+            switch (m_resize_corner) {
+            case LEFTTOP:
+                 m_last_resize_w = frame().width() - dx;
+                 m_last_resize_x = frame().x() + dx;
+                 // no break, use code below too
+            case RIGHTTOP:
                 m_last_resize_h = frame().height() - dy;
                 m_last_resize_y = frame().y() + dy;
-            } else {
-                m_last_resize_h = frame().height() + dy;
-            }
-
-            if (m_resize_corner == LEFTTOP || m_resize_corner == LEFTBOTTOM) {
+                break;
+            case LEFTBOTTOM:
                  m_last_resize_w = frame().width() - dx;
                  m_last_resize_x = frame().x() + dx;
-            } else {
-                 m_last_resize_w = frame().width() + dx;
-            }
+                 break;
+            case ALLCORNERS:
+                // dx or dy must be at least 2
+                if (abs(dx) >= 2 || abs(dy) >= 2) {
+                    // take max and make it even
+                    int diff = 2 * (max(dx, dy) / 2);
+
+                    m_last_resize_h =  frame().height() + diff;
+                        
+                    m_last_resize_w = frame().width() + diff;
+                    m_last_resize_x = frame().x() - diff/2;
+                    m_last_resize_y = frame().y() - diff/2;
+                }
+                break;
+            };
 
+            // if not on top or all corner then move bottom
+            
+            if (!(m_resize_corner == LEFTTOP || m_resize_corner == RIGHTTOP ||
+                  m_resize_corner == ALLCORNERS))
+                m_last_resize_h = frame().height() + dy;
+
+            // if not top or left bottom or all corners then move right side
+            if (!(m_resize_corner == LEFTTOP || m_resize_corner == LEFTBOTTOM ||
+                  m_resize_corner == ALLCORNERS))
+                m_last_resize_w = frame().width() + dx;
+            
             fixsize(&gx, &gy);
 
             if (old_resize_x != m_last_resize_x ||
@@ -3692,7 +3719,7 @@ void FluxboxWindow::fixsize(int *user_w, int *user_h) {
     // move X if necessary
     if (m_resize_corner == LEFTTOP || m_resize_corner == LEFTBOTTOM) {
         m_last_resize_x = frame().x() + frame().width() - m_last_resize_w;
-    }
+    } 
 
     if (m_resize_corner == LEFTTOP || m_resize_corner == RIGHTTOP) {
         m_last_resize_y = frame().y() + frame().height() - m_last_resize_h;
diff --git a/src/Window.hh b/src/Window.hh
index 87a78af..7c59371 100644
--- a/src/Window.hh
+++ b/src/Window.hh
@@ -137,7 +137,8 @@ public:
         LEFTTOP,
         LEFTBOTTOM,
         RIGHTBOTTOM,
-        RIGHTTOP
+        RIGHTTOP,
+        ALLCORNERS
     };
 
     typedef struct _blackbox_hints {
-- 
cgit v0.11.2