i3 - improved tiling WM


Snap pointer to resize bar on drag resize

Patch status: superseded

Patch by Tony Crisci

Long description:

When the user initiates a drag resize, draw the resize bar on the border
of the two involved containers and snap the pointer.

This solution produces cleaner code than the former approach where the
caller obfuscated the click coordinates of the event. This may confuse
someone expecting a true button press event.

Fixes an issue where the resize cursor is not shown when the resize bar
is clicked until the user begins to drag the mouse.

Fixes an issue where focus is not properly updated after the drag is
complete when `focus_follows_mouse' option is set, leaving the pointer
in an unfocused window in some cases.

Fixes an issue where the resize bar may jump a few pixels when the mouse
is first moved.

(Thanks to pbos for suggesting this fix and providing an example
implementation)

To apply this patch, use:
curl http://cr.i3wm.org/patch/350/raw.patch | git am

b/src/click.c

33
@@ -62,12 +62,7 @@ static bool tiling_resize_for_border(Con *con, border_t border, xcb_button_press
34
         second = tmp;
35
     }
36
 
37
-    /* We modify the X/Y position in the event so that the divider line is at
38
-     * the actual position of the border, not at the position of the click. */
39
     const orientation_t orientation = ((border == BORDER_LEFT || border == BORDER_RIGHT) ? HORIZ : VERT);
40
-    if (orientation == HORIZ)
41
-        event->root_x = second->rect.x;
42
-    else event->root_y = second->rect.y;
43
 
44
     resize_graphical_handler(first, second, orientation, event);
45
 

b/src/resize.c

50
@@ -122,19 +122,24 @@ int resize_graphical_handler(Con *first, Con *second, orientation_t orientation,
51
     xcb_window_t grabwin = create_window(conn, output->rect, XCB_COPY_FROM_PARENT, XCB_COPY_FROM_PARENT,
52
             XCB_WINDOW_CLASS_INPUT_ONLY, XCURSOR_CURSOR_POINTER, true, mask, values);
53
 
54
+    /* configure the resizebar position and snap the pointer */
55
     Rect helprect;
56
     if (orientation == HORIZ) {
57
-        helprect.x = event->root_x;
58
+        helprect.x = second->rect.x;
59
         helprect.y = output->rect.y;
60
         helprect.width = 2;
61
         helprect.height = output->rect.height;
62
-        new_position = event->root_x;
63
+        new_position = second->rect.x;
64
+        xcb_warp_pointer(conn, XCB_NONE, event->root, 0, 0, 0, 0,
65
+                second->rect.x, event->root_y);
66
     } else {
67
         helprect.x = output->rect.x;
68
-        helprect.y = event->root_y;
69
+        helprect.y = second->rect.y;
70
         helprect.width = output->rect.width;
71
         helprect.height = 2;
72
-        new_position = event->root_y;
73
+        new_position = second->rect.y;
74
+        xcb_warp_pointer(conn, XCB_NONE, event->root, 0, 0, 0, 0,
75
+                event->root_x, second->rect.y);
76
     }
77
 
78
     mask = XCB_CW_BACK_PIXEL;