Snap pointer to resize bar on drag resize
Patch status: merged
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/351/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 |
@@ -102,8 +102,6 @@ bool resize_find_tiling_participants(Con **current, Con **other, direction_t dir |
51 |
int resize_graphical_handler(Con *first, Con *second, orientation_t orientation, const xcb_button_press_event_t *event) { |
52 |
DLOG("resize handler\n"); |
53 |
|
54 |
- uint32_t new_position; |
55 |
- |
56 |
/* TODO: previously, we were getting a rect containing all screens. why? */ |
57 |
Con *output = con_get_output(first); |
58 |
DLOG("x = %d, width = %d\n", output->rect.x, output->rect.width); |
59 |
@@ -122,19 +120,29 @@ int resize_graphical_handler(Con *first, Con *second, orientation_t orientation, |
60 |
xcb_window_t grabwin = create_window(conn, output->rect, XCB_COPY_FROM_PARENT, XCB_COPY_FROM_PARENT, |
61 |
XCB_WINDOW_CLASS_INPUT_ONLY, XCURSOR_CURSOR_POINTER, true, mask, values); |
62 |
|
63 |
+ /* Keep track of the coordinate orthogonal to motion so we can determine |
64 |
+ * the length of the resize afterward. */ |
65 |
+ uint32_t initial_position, new_position; |
66 |
+ |
67 |
+ /* Configure the resizebar and snap the pointer. The resizebar runs along |
68 |
+ * the rect of the second con and follows the motion of the pointer. */ |
69 |
Rect helprect; |
70 |
if (orientation == HORIZ) { |
71 |
- helprect.x = event->root_x; |
72 |
+ helprect.x = second->rect.x; |
73 |
helprect.y = output->rect.y; |
74 |
helprect.width = 2; |
75 |
helprect.height = output->rect.height; |
76 |
- new_position = event->root_x; |
77 |
+ initial_position = second->rect.x; |
78 |
+ xcb_warp_pointer(conn, XCB_NONE, event->root, 0, 0, 0, 0, |
79 |
+ second->rect.x, event->root_y); |
80 |
} else { |
81 |
helprect.x = output->rect.x; |
82 |
- helprect.y = event->root_y; |
83 |
+ helprect.y = second->rect.y; |
84 |
helprect.width = output->rect.width; |
85 |
helprect.height = 2; |
86 |
- new_position = event->root_y; |
87 |
+ initial_position = second->rect.y; |
88 |
+ xcb_warp_pointer(conn, XCB_NONE, event->root, 0, 0, 0, 0, |
89 |
+ event->root_x, second->rect.y); |
90 |
} |
91 |
|
92 |
mask = XCB_CW_BACK_PIXEL; |
93 |
@@ -152,8 +160,12 @@ int resize_graphical_handler(Con *first, Con *second, orientation_t orientation, |
94 |
|
95 |
xcb_flush(conn); |
96 |
|
97 |
+ /* `new_position' will be updated by the `resize_callback'. */ |
98 |
+ new_position = initial_position; |
99 |
+ |
100 |
const struct callback_params params = { orientation, output, helpwin, &new_position }; |
101 |
|
102 |
+ /* `drag_pointer' blocks until the drag is completed. */ |
103 |
drag_result_t drag_result = drag_pointer(NULL, event, grabwin, BORDER_TOP, 0, resize_callback, ¶ms); |
104 |
|
105 |
xcb_destroy_window(conn, helpwin); |
106 |
@@ -164,10 +176,7 @@ int resize_graphical_handler(Con *first, Con *second, orientation_t orientation, |
107 |
if (drag_result == DRAG_REVERT) |
108 |
return 0; |
109 |
|
110 |
- int pixels; |
111 |
- if (orientation == HORIZ) |
112 |
- pixels = (new_position - event->root_x); |
113 |
- else pixels = (new_position - event->root_y); |
114 |
+ int pixels = (new_position - initial_position); |
115 |
|
116 |
DLOG("Done, pixels = %d\n", pixels); |
117 |
|