[Xfce4-commits] <xfwm4:master> Keep pointer position relative to the window being moved (bug #8629), Add "tile_on_move" option (bug #6648), Restore original window positios after an XRandR resize (bug #6589)

Olivier Fourdan noreply at xfce.org
Sat Apr 7 17:10:02 CEST 2012


Updating branch refs/heads/master
         to 1d2753376664e4fe3b3a16c35a83f065f1408c2a (commit)
       from e296502edd7c3678100cab1928f71a802d151c4b (commit)

commit 1d2753376664e4fe3b3a16c35a83f065f1408c2a
Author: Olivier Fourdan <fourdan at xfce.org>
Date:   Sat Apr 7 17:10:15 2012 +0200

    Keep pointer position relative to the window being moved (bug #8629),
    Add "tile_on_move" option (bug #6648),
    Restore original window positios after an XRandR resize (bug #6589)

 src/client.c     |   27 ++++++++++++++++--
 src/client.h     |    4 ++-
 src/moveresize.c |   80 ++++++++++++++++++++++++++++++++---------------------
 3 files changed, 75 insertions(+), 36 deletions(-)

diff --git a/src/client.c b/src/client.c
index 6c2e0aa..fb3665c 100644
--- a/src/client.c
+++ b/src/client.c
@@ -840,10 +840,14 @@ clientMoveResizeWindow (Client *c, XWindowChanges * wc, unsigned long mask)
     flags = CFG_REQUEST;
     if (mask & (CWX | CWY | CWWidth | CWHeight))
     {
+        /* Clear any previously saved pos flag from screen resize */
+        FLAG_UNSET (c->xfwm_flags, XFWM_FLAG_SAVED_POS);
+
         if (FLAG_TEST (c->flags, CLIENT_FLAG_MAXIMIZED))
         {
             clientRemoveMaximizeFlag (c);
         }
+
         flags |= CFG_REQUEST | CFG_CONSTRAINED;
     }
     if ((mask & (CWWidth | CWHeight)) && !(mask & (CWX | CWY)))
@@ -1741,7 +1745,11 @@ clientFrame (DisplayInfo *display_info, Window w, gboolean recapture)
        initially maximized or fullscreen windows being placed offscreen
        once de-maximized
      */
-    clientSaveSizePos (c);
+    c->old_x = c->x;
+    c->old_y = c->y;
+    c->old_width = c->width;
+    c->old_height = c->height;
+
     c->fullscreen_old_x = c->x;
     c->fullscreen_old_y = c->y;
     c->fullscreen_old_width = c->width;
@@ -3552,9 +3560,22 @@ clientScreenResize(ScreenInfo *screen_info, gboolean fully_visible)
             {
                 configure_flags |= CFG_KEEP_VISIBLE;
             }
+            if (FLAG_TEST (c->xfwm_flags, XFWM_FLAG_SAVED_POS))
+            {
+                wc.x = c->saved_x;
+                wc.y = c->saved_y;
+            }
+            else
+            {
+                FLAG_SET (c->xfwm_flags, XFWM_FLAG_SAVED_POS);
+
+                c->saved_x = c->x;
+                c->saved_y = c->y;
+
+                wc.x = c->x;
+                wc.y = c->y;
+            }
 
-            wc.x = c->x;
-            wc.y = c->y;
             clientConfigure (c, &wc, CWX | CWY, configure_flags);
         }
     }
diff --git a/src/client.h b/src/client.h
index a6355cf..e8bc4e3 100644
--- a/src/client.h
+++ b/src/client.h
@@ -135,7 +135,7 @@
 #define XFWM_FLAG_DRAW_ACTIVE           (1L<<17)
 #define XFWM_FLAG_SEEN_ACTIVE           (1L<<18)
 #define XFWM_FLAG_FIRST_MAP             (1L<<19)
-/* Unused slot                          ........ */
+#define XFWM_FLAG_SAVED_POS             (1L<<20)
 #define XFWM_FLAG_MOVING_RESIZING       (1L<<21)
 #define XFWM_FLAG_NEEDS_REDRAW          (1L<<22)
 #define XFWM_FLAG_OPACITY_LOCKED        (1L<<23)
@@ -286,6 +286,8 @@ struct _Client
     gint gravity;
     guint win_workspace;
     unsigned int ignore_unmap;
+    gint saved_x;
+    gint saved_y;
     gint old_x;
     gint old_y;
     gint old_width;
diff --git a/src/moveresize.c b/src/moveresize.c
index 33cdb54..d476d2c 100644
--- a/src/moveresize.c
+++ b/src/moveresize.c
@@ -71,6 +71,7 @@ struct _MoveResizeData
     gint cancel_w, cancel_h;
     guint cancel_workspace;
     gint mx, my;
+    gint px, py; /* pointer relative position */
     gint ox, oy;
     gint ow, oh;
     gint oldw, oldh;
@@ -179,40 +180,40 @@ clientSetHandle(MoveResizeData *passdata, int handle)
     switch (handle)
     {
         case CORNER_BOTTOM_LEFT:
-            px = frameX(c) + frameLeft(c) / 2;
-            py = frameY(c) + frameHeight(c) - frameBottom(c) / 2;
+            px = frameX (c) + frameLeft(c) / 2;
+            py = frameY (c) + frameHeight (c) - frameBottom(c) / 2;
             break;
         case CORNER_BOTTOM_RIGHT:
-            px = frameX(c) + frameWidth(c) - frameRight(c) / 2;
-            py = frameY(c) + frameHeight(c) - frameBottom(c) / 2;
+            px = frameX (c) + frameWidth (c) - frameRight(c) / 2;
+            py = frameY (c) + frameHeight (c) - frameBottom(c) / 2;
             break;
         case CORNER_TOP_LEFT:
-            px = frameX(c) + frameLeft(c) / 2;
-            py = frameY(c);
+            px = frameX (c) + frameLeft(c) / 2;
+            py = frameY (c);
             break;
         case CORNER_TOP_RIGHT:
-            px = frameX(c) + frameWidth(c) - frameRight(c) / 2;
-            py = frameY(c);
+            px = frameX (c) + frameWidth (c) - frameRight(c) / 2;
+            py = frameY (c);
             break;
         case CORNER_COUNT + SIDE_LEFT:
-            px = frameX(c) + frameLeft(c) / 2;
-            py = frameY(c) + frameHeight(c) / 2;
+            px = frameX (c) + frameLeft(c) / 2;
+            py = frameY (c) + frameHeight (c) / 2;
             break;
         case CORNER_COUNT + SIDE_RIGHT:
-            px = frameX(c) + frameWidth(c) - frameRight(c) / 2;
-            py = frameY(c) + frameHeight(c) / 2;
+            px = frameX (c) + frameWidth (c) - frameRight(c) / 2;
+            py = frameY (c) + frameHeight (c) / 2;
             break;
         case CORNER_COUNT + SIDE_TOP:
-            px = frameX(c) + frameWidth(c) / 2;
-            py = frameY(c);
+            px = frameX (c) + frameWidth (c) / 2;
+            py = frameY (c);
             break;
         case CORNER_COUNT + SIDE_BOTTOM:
-            px = frameX(c) + frameWidth(c) / 2;
-            py = frameY(c) + frameHeight(c) - frameBottom(c) / 2;
+            px = frameX (c) + frameWidth (c) / 2;
+            py = frameY (c) + frameHeight (c) - frameBottom(c) / 2;
             break;
         default:
-            px = frameX(c) + frameWidth(c) / 2;
-            py = frameY(c) + frameHeight(c) / 2;
+            px = frameX (c) + frameWidth (c) / 2;
+            py = frameY (c) + frameHeight (c) / 2;
             break;
     }
 
@@ -221,6 +222,8 @@ clientSetHandle(MoveResizeData *passdata, int handle)
     passdata->handle = handle;
     passdata->mx = px;
     passdata->my = py;
+    passdata->px = passdata->mx - frameX (c);
+    passdata->py = passdata->my - frameY (c);
     passdata->ox = c->x;
     passdata->oy = c->y;
     passdata->ow = c->width;
@@ -947,23 +950,33 @@ clientMoveEventFilter (XEvent * xevent, gpointer data)
                 (ABS (xevent->xmotion.y_root - passdata->my) > 15))
             {
                 /* to keep the distance from the edges of the window proportional. */
-                double xratio = .5;
+                double xratio, yratio;
 
-                if (FLAG_TEST(c->flags, CLIENT_FLAG_MAXIMIZED_HORIZ))
+                xratio = (xevent->xmotion.x_root - frameX (c)) / (double) frameWidth (c);
+                yratio = (xevent->xmotion.y_root - frameY (c)) / (double) frameHeight (c);
+
+                if (FLAG_TEST_ALL(c->flags, CLIENT_FLAG_MAXIMIZED))
                 {
-                    xratio = (xevent->xmotion.x_root - c->x) / (double)c->width;
-                    if (FLAG_TEST(c->flags, CLIENT_FLAG_MAXIMIZED_VERT))
-                    {
-                       toggled_maximize = TRUE;
-                    }
+                    toggled_maximize = TRUE;
                 }
                 if (clientToggleMaximized (c, c->flags & CLIENT_FLAG_MAXIMIZED, FALSE))
                 {
                     passdata->move_resized = TRUE;
+
                     passdata->ox = c->x;
-                    passdata->mx = CLAMP(c->x + c->width * xratio, c->x, c->x + c->width);
+                    passdata->mx =  frameX (c) + passdata->px;
+                    if ((passdata->mx <  frameX (c)) || (passdata->mx >  frameX (c) + frameWidth (c)))
+                    {
+                        passdata->mx = CLAMP(frameX (c) + frameWidth (c) * xratio, frameX (c), frameX (c) + frameWidth (c));
+                    }
+
                     passdata->oy = c->y;
-                    passdata->my = c->y - frameTop(c) / 2;
+                    passdata->my = frameY (c) + passdata->py;
+                    if ((passdata->my < frameY (c)) || (passdata->my > frameY (c) + frameHeight (c)))
+                    {
+                        passdata->my = CLAMP(frameY (c) + frameHeight (c) * yratio, frameY (c), frameY (c) + frameHeight (c));
+                    }
+
                     configure_flags = CFG_FORCE_REDRAW;
                 }
             }
@@ -986,11 +999,6 @@ clientMoveEventFilter (XEvent * xevent, gpointer data)
                 configure_flags = CFG_FORCE_REDRAW;
                 toggled_maximize = FALSE;
                 passdata->move_resized = TRUE;
-                /*
-                   Update "passdata->my" to the current value to
-                   allow "restore on move" to keep working next time
-                 */
-                passdata->my = c->y - frameTop(c) / 2;
             }
         }
         else if (!clientMoveTile (c, (XMotionEvent *) xevent))
@@ -1099,6 +1107,8 @@ clientMove (Client * c, XEvent * ev)
         passdata.button = ev->xbutton.button;
         passdata.mx = ev->xbutton.x_root;
         passdata.my = ev->xbutton.y_root;
+        passdata.px = passdata.mx - frameX (c);
+        passdata.py = passdata.my - frameY (c);
     }
     else
     {
@@ -1142,6 +1152,9 @@ clientMove (Client * c, XEvent * ev)
      */
     placeSidewalks(screen_info, FALSE);
 
+    /* Clear any previously saved pos flag from screen resize */
+    FLAG_UNSET (c->xfwm_flags, XFWM_FLAG_SAVED_POS);
+
     FLAG_SET (c->xfwm_flags, XFWM_FLAG_MOVING_RESIZING);
     TRACE ("entering move loop");
     eventFilterPush (display_info->xfilter, clientMoveEventFilter, &passdata);
@@ -1706,6 +1719,9 @@ clientResize (Client * c, int handle, XEvent * ev)
         clientSetOpacity (c, c->opacity, OPACITY_RESIZE, OPACITY_RESIZE);
     }
 
+    /* Clear any previously saved pos flag from screen resize */
+    FLAG_UNSET (c->xfwm_flags, XFWM_FLAG_SAVED_POS);
+
     FLAG_SET (c->xfwm_flags, XFWM_FLAG_MOVING_RESIZING);
     TRACE ("entering resize loop");
     eventFilterPush (display_info->xfilter, clientResizeEventFilter, &passdata);


More information about the Xfce4-commits mailing list