easy_click resize modification (patch incl.)

Tim Smith tim at desert.net
Tue Apr 19 07:57:56 CEST 2005


Hi!  I just made a patch to xfwm4 that changes how Alt+Button3
(easy_click) works; it now resizes in a single dimension
(horizontal/vertical) if you're not in the corner of the window.  How
would I best go about submitting it to the project and getting it into
the main xfwm4 version?

I'm attaching the diff to this message.  Feel free to comment on style,
etc. - I tried to follow the same code style, but I'm not familiar with
glib and friends so there may be some helper functions I should be
using, etc.

Thanks!

Tim
-- 
If you're not part of the solution, you're part of the precipitate.
-------------- next part --------------
diff -ru xfwm4-4.2.1/src/client.c xfwm4-4.2.1-patched/src/client.c
--- xfwm4-4.2.1/src/client.c	Tue Mar 15 09:11:55 2005
+++ xfwm4-4.2.1-patched/src/client.c	Sun Apr 17 01:26:19 2005
@@ -619,7 +619,8 @@
         maxy = c->size->max_aspect.y;
 
         if ((minx * h1 > miny * w1) &&
-            (miny) && (corner == 4 + SIDE_BOTTOM))
+            (miny) &&
+            ((corner == 4 + SIDE_TOP) || (corner == 4 + SIDE_BOTTOM)))
         {
             /* Change width to match */
             delta = MAKE_MULT (minx * h1 /  miny - w1, xinc);
@@ -3215,6 +3216,7 @@
     int cx, cy, disp_x, disp_y, disp_max_x, disp_max_y;
     int frame_x, frame_y, frame_height, frame_width;
     int frame_top, frame_left, frame_right, frame_bottom;
+    int move_top, move_bottom, move_left, move_right;
     GdkRectangle rect;
     gint monitor_nbr;
 
@@ -3236,6 +3238,23 @@
     cx = frame_x + (frame_width / 2);
     cy = frame_y + (frame_height / 2);
 
+    move_top = ((passdata->corner == CORNER_TOP_RIGHT)
+            || (passdata->corner == CORNER_TOP_LEFT)
+            || (passdata->corner == 4 + SIDE_TOP)) ?
+        1 : 0;
+    move_bottom = ((passdata->corner == CORNER_BOTTOM_RIGHT)
+            || (passdata->corner == CORNER_BOTTOM_LEFT)
+            || (passdata->corner == 4 + SIDE_BOTTOM)) ?
+        1 : 0;
+    move_right = ((passdata->corner == CORNER_TOP_RIGHT)
+            || (passdata->corner == CORNER_BOTTOM_RIGHT)
+            || (passdata->corner == 4 + SIDE_RIGHT)) ?
+        1 : 0;
+    move_left = ((passdata->corner == CORNER_TOP_LEFT)
+            || (passdata->corner == CORNER_BOTTOM_LEFT)
+            || (passdata->corner == 4 + SIDE_LEFT)) ?
+        1 : 0;
+
     monitor_nbr = find_monitor_at_point (screen_info->gscr, cx, cy);
     gdk_screen_get_monitor_geometry (screen_info->gscr, monitor_nbr, &rect);
 
@@ -3385,28 +3404,21 @@
         prev_width = c->width;
         prev_height = c->height;
 
-        if ((passdata->corner == CORNER_TOP_LEFT)
-            || (passdata->corner == CORNER_BOTTOM_LEFT)
-            || (passdata->corner == 4 + SIDE_LEFT))
+        if (move_left)
         {
             c->width = passdata->ox - (xevent->xmotion.x_root - passdata->mx);
         }
-        else if ((passdata->corner == CORNER_BOTTOM_RIGHT)
-            || (passdata->corner == CORNER_TOP_RIGHT)
-            || (passdata->corner == 4 + SIDE_RIGHT))
+        else if (move_right)
         {
             c->width = passdata->ox + (xevent->xmotion.x_root - passdata->mx);
         }
         if (!FLAG_TEST (c->flags, CLIENT_FLAG_SHADED))
         {
-            if ((passdata->corner == CORNER_TOP_LEFT)
-                || (passdata->corner == CORNER_TOP_RIGHT))
+            if (move_top)
             {
                 c->height = passdata->oy - (xevent->xmotion.y_root - passdata->my);
             }
-            else if ((passdata->corner == CORNER_BOTTOM_RIGHT)
-                || (passdata->corner == CORNER_BOTTOM_LEFT)
-                || (passdata->corner == 4 + SIDE_BOTTOM))
+            else if (move_bottom)
             {
                 c->height = passdata->oy + (xevent->xmotion.y_root - passdata->my);
             }
@@ -3414,39 +3426,30 @@
         clientConstrainRatio (c, c->width, c->height, passdata->corner);
 
         clientSetWidth (c, c->width);
-        if ((passdata->corner == CORNER_TOP_LEFT)
-            || (passdata->corner == CORNER_BOTTOM_LEFT)
-            || (passdata->corner == 4 + SIDE_LEFT))
+        if (move_left)
         {
             c->x = c->x - (c->width - passdata->oldw);
             frame_x = frameX (c);
         }
-        if (((passdata->corner == CORNER_TOP_LEFT)
-             || (passdata->corner == CORNER_TOP_RIGHT))
-            && !clientCkeckTitle (c))
+        if (move_top && !clientCkeckTitle (c))
         {
             c->x = prev_x;
             c->width = prev_width;
         }
 
         clientSetHeight (c, c->height);
-        if (!FLAG_TEST (c->flags, CLIENT_FLAG_SHADED)
-            && (passdata->corner == CORNER_TOP_LEFT
-                || passdata->corner == CORNER_TOP_RIGHT))
+        if (!FLAG_TEST (c->flags, CLIENT_FLAG_SHADED) && move_top)
         {
             c->y = c->y - (c->height - passdata->oldh);
             frame_y = frameY (c);
         }
-        if (((passdata->corner == CORNER_TOP_LEFT)
-             || (passdata->corner == CORNER_TOP_RIGHT))
-            && !clientCkeckTitle (c))
+        if (move_top && !clientCkeckTitle (c))
         {
             c->y = prev_y;
             c->height = prev_height;
         }
 
-        if ((passdata->corner == CORNER_TOP_LEFT)
-            || (passdata->corner == CORNER_TOP_RIGHT))
+        if (move_top)
         {
             if ((c->y > disp_max_y - CLIENT_MIN_VISIBLE)
                 || (c->y > gdk_screen_get_height (screen_info->gscr)
@@ -3456,9 +3459,7 @@
                 c->height = prev_height;
             }
         }
-        else if ((passdata->corner == CORNER_BOTTOM_LEFT)
-            || (passdata->corner == CORNER_BOTTOM_RIGHT)
-            || (passdata->corner == 4 + SIDE_BOTTOM))
+        else if (move_bottom)
         {
             if ((c->y + c->height < disp_y + CLIENT_MIN_VISIBLE)
                 || (c->y + c->height < screen_info->margins [TOP] + CLIENT_MIN_VISIBLE))
@@ -3466,9 +3467,7 @@
                 c->height = prev_height;
             }
         }
-        if ((passdata->corner == CORNER_TOP_LEFT)
-            || (passdata->corner == CORNER_BOTTOM_LEFT)
-            || (passdata->corner == 4 + SIDE_LEFT))
+        if (move_left)
         {
             if ((c->x > disp_max_x - CLIENT_MIN_VISIBLE)
                 || (c->x > gdk_screen_get_width (screen_info->gscr)
@@ -3478,9 +3477,7 @@
                 c->width = prev_width;
             }
         }
-        else if ((passdata->corner == CORNER_TOP_RIGHT)
-            || (passdata->corner == CORNER_BOTTOM_RIGHT)
-            || (passdata->corner == 4 + SIDE_RIGHT))
+        else if (move_right)
         {
             if ((c->x + c->width < disp_x + CLIENT_MIN_VISIBLE)
                 || (c->x + c->width < screen_info->margins [LEFT] + CLIENT_MIN_VISIBLE))
@@ -3561,7 +3558,6 @@
     passdata.c = c;
     passdata.ox = c->width;
     passdata.oy = c->height;
-    passdata.corner = CORNER_BOTTOM_RIGHT;
     passdata.use_keys = FALSE;
     passdata.grab = FALSE;
     passdata.corner = corner;
diff -ru xfwm4-4.2.1/src/display.c xfwm4-4.2.1-patched/src/display.c
--- xfwm4-4.2.1/src/display.c	Thu Dec 16 08:16:55 2004
+++ xfwm4-4.2.1-patched/src/display.c	Sun Apr 17 01:01:02 2005
@@ -197,6 +197,8 @@
         XCreateFontCursor (display->dpy, XC_left_side);
     display->resize_cursor[4 + SIDE_RIGHT] = 
         XCreateFontCursor (display->dpy, XC_right_side);
+    display->resize_cursor[4 + SIDE_TOP] = 
+        XCreateFontCursor (display->dpy, XC_top_side);
     display->resize_cursor[4 + SIDE_BOTTOM] = 
         XCreateFontCursor (display->dpy, XC_bottom_side);
 
@@ -268,7 +270,7 @@
 myDisplayGetCursorResize (DisplayInfo *display, guint index)
 {
     g_return_val_if_fail (display, None);
-    g_return_val_if_fail (index < 7, None);
+    g_return_val_if_fail (index < 8, None);
 
     return display->resize_cursor [index];
 }
diff -ru xfwm4-4.2.1/src/display.h xfwm4-4.2.1-patched/src/display.h
--- xfwm4-4.2.1/src/display.h	Thu Dec 16 08:16:55 2004
+++ xfwm4-4.2.1-patched/src/display.h	Sun Apr 17 01:02:46 2005
@@ -52,6 +52,7 @@
 #define SIDE_LEFT                                               0
 #define SIDE_RIGHT                                              1
 #define SIDE_BOTTOM                                             2
+#define SIDE_TOP                                                3
 
 #define ANY                                                     0
 #define WINDOW                                                  1
@@ -166,7 +167,7 @@
     Cursor busy_cursor;
     Cursor move_cursor;
     Cursor root_cursor;
-    Cursor resize_cursor[7];
+    Cursor resize_cursor[8];
     
     Atom atoms[NB_ATOMS];
 
diff -ru xfwm4-4.2.1/src/events.c xfwm4-4.2.1-patched/src/events.c
--- xfwm4-4.2.1/src/events.c	Sun Feb 13 10:29:37 2005
+++ xfwm4-4.2.1-patched/src/events.c	Sun Apr 17 17:05:01 2005
@@ -858,22 +858,76 @@
         }
         else if ((ev->button == Button3) && (state == AltMask) && (screen_info->params->easy_click))
         {
-            if ((ev->x < c->width / 2) && (ev->y < c->height / 2))
+            int part, x_corner_pixels, y_corner_pixels, x_distance, y_distance;
+
+#define MAXIMUM_OF(a, b) ((a) > (b) ? (a) : (b))
+            /* Corner is 1/3 of the side */
+#define CORNER_PIXELS(length) MAXIMUM_OF((length) / 3, 50)
+            x_corner_pixels = CORNER_PIXELS(c->width);
+            y_corner_pixels = CORNER_PIXELS(c->height);
+#undef CORNER_PIXELS
+#undef MAXIMUM_OF
+
+            /* Distance from event to edge of client window */
+            x_distance = c->width / 2 - abs(c->width / 2 - ev->x);
+            y_distance = c->height / 2 - abs(c->height / 2 - ev->y);
+
+            if (x_distance < x_corner_pixels && y_distance < y_corner_pixels)
             {
-                edgeButton (c, CORNER_TOP_LEFT, ev);
-            }
-            else if ((ev->x < c->width / 2) && (ev->y > c->height / 2))
-            {
-                edgeButton (c, CORNER_BOTTOM_LEFT, ev);
-            }
-            else if ((ev->x > c->width / 2) && (ev->y < c->height / 2))
-            {
-                edgeButton (c, CORNER_TOP_RIGHT, ev);
+                /* In a corner */
+                if (ev->x < c->width / 2)
+                {
+                    if (ev->y < c->height / 2)
+                    {
+                        part = CORNER_TOP_LEFT;
+                    }
+                    else
+                    {
+                        part = CORNER_BOTTOM_LEFT;
+                    }
+                }
+                else
+                {
+                    if (ev->y < c->height / 2)
+                    {
+                        part = CORNER_TOP_RIGHT;
+                    }
+                    else
+                    {
+                        part = CORNER_BOTTOM_RIGHT;
+                    }
+                }
             }
             else
             {
-                edgeButton (c, CORNER_BOTTOM_RIGHT, ev);
+                /* Not a corner - some side */
+                if (x_distance / x_corner_pixels < y_distance / y_corner_pixels)
+                {
+                    /* Left or right side */
+                    if (ev->x < c->width / 2)
+                    {
+                        part = 4 + SIDE_LEFT;
+                    }
+                    else
+                    {
+                        part = 4 + SIDE_RIGHT;
+                    }
+                }
+                else
+                {
+                    /* Top or bottom side */
+                    if (ev->y < c->height / 2)
+                    {
+                        part = 4 + SIDE_TOP;
+                    }
+                    else
+                    {
+                        part = 4 + SIDE_BOTTOM;
+                    }
+                }
             }
+
+            edgeButton (c, part, ev);
         }
         else if (WIN_IS_BUTTON (win))
         {


More information about the Xfce4-dev mailing list