i3 - improved tiling WM


Improve drag_pointer error handling

Patch status: merged

Patch by Tony Crisci

Long description:

Log errors generated by failed pointer grabs and ungrab the pointer
after failed keyboard grabs.

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

b/src/floating.c

15
@@ -682,6 +682,8 @@ drag_result_t drag_pointer(Con *con, const xcb_button_press_event_t *event, xcb_
16
     /* Grab the pointer */
17
     xcb_grab_pointer_cookie_t cookie;
18
     xcb_grab_pointer_reply_t *reply;
19
+    xcb_generic_error_t *error;
20
+
21
     cookie = xcb_grab_pointer(conn,
22
         false,               /* get all pointer events specified by the following mask */
23
         root,                /* grab the root window */
24
@@ -692,8 +694,9 @@ drag_result_t drag_pointer(Con *con, const xcb_button_press_event_t *event, xcb_
25
         xcursor,             /* possibly display a special cursor */
26
         XCB_CURRENT_TIME);
27
 
28
-    if ((reply = xcb_grab_pointer_reply(conn, cookie, NULL)) == NULL) {
29
-        ELOG("Could not grab pointer\n");
30
+    if ((reply = xcb_grab_pointer_reply(conn, cookie, &error)) == NULL) {
31
+        ELOG("Could not grab pointer (error_code = %d)\n", error->error_code);
32
+        free(error);
33
         return DRAG_ABORT;
34
     }
35
 
36
@@ -711,8 +714,10 @@ drag_result_t drag_pointer(Con *con, const xcb_button_press_event_t *event, xcb_
37
             XCB_GRAB_MODE_ASYNC /* keyboard mode */
38
             );
39
 
40
-    if ((keyb_reply = xcb_grab_keyboard_reply(conn, keyb_cookie, NULL)) == NULL) {
41
-        ELOG("Could not grab keyboard\n");
42
+    if ((keyb_reply = xcb_grab_keyboard_reply(conn, keyb_cookie, &error)) == NULL) {
43
+        ELOG("Could not grab keyboard (error_code = %d)\n", error->error_code);
44
+        free(error);
45
+        xcb_ungrab_pointer(conn, XCB_CURRENT_TIME);
46
         return DRAG_ABORT;
47
     }
48