From: Ingo Bürk Date: Wed, 11 Nov 2015 19:21:26 +0000 (+0100) Subject: Extract function to grab buttons when managing a window. X-Git-Tag: 4.12~103^2~1 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=66882bf445970588c6c7a6a2c2e08a38ad0b9536;p=i3%2Fi3 Extract function to grab buttons when managing a window. We refactor the button grabbing into a function to allow the next patch both to - conditionally grab different sets of buttons - grab the buttons again when reloading the config. relates to #2049 --- diff --git a/include/xcb.h b/include/xcb.h index 2c87a19c..27d8986f 100644 --- a/include/xcb.h +++ b/include/xcb.h @@ -160,3 +160,9 @@ void xcb_add_property_atom(xcb_connection_t *conn, xcb_window_t window, xcb_atom * */ void xcb_remove_property_atom(xcb_connection_t *conn, xcb_window_t window, xcb_atom_t property, xcb_atom_t atom); + +/** + * Grab the specified buttons on a window when managing it. + * + */ +void xcb_grab_buttons(xcb_connection_t *conn, xcb_window_t window, uint8_t* buttons); diff --git a/src/manage.c b/src/manage.c index 0dec2844..033d55e1 100644 --- a/src/manage.c +++ b/src/manage.c @@ -168,12 +168,7 @@ void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cooki cwindow->id = window; cwindow->depth = get_visual_depth(attr->visual); - /* We need to grab buttons 1-3 for click-to-focus and buttons 1-5 - * to allow for mouse bindings using --whole-window to work correctly. */ - xcb_grab_button(conn, false, window, XCB_EVENT_MASK_BUTTON_PRESS, - XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, root, XCB_NONE, - XCB_BUTTON_INDEX_ANY, - XCB_BUTTON_MASK_ANY /* don’t filter for any modifiers */); + xcb_grab_buttons(conn, window, (uint8_t[]) {XCB_BUTTON_INDEX_ANY}); /* update as much information as possible so far (some replies may be NULL) */ window_update_class(cwindow, xcb_get_property_reply(conn, class_cookie, NULL), true); diff --git a/src/xcb.c b/src/xcb.c index f98115f5..cafc29ca 100644 --- a/src/xcb.c +++ b/src/xcb.c @@ -319,3 +319,14 @@ release_grab: FREE(reply); xcb_ungrab_server(conn); } + +/* + * Grab the specified buttons on a window when managing it. + * + */ +void xcb_grab_buttons(xcb_connection_t *conn, xcb_window_t window, uint8_t* buttons) { + for (int i = 0; i < sizeof(buttons) / sizeof(uint8_t); i++) { + xcb_grab_button(conn, false, window, XCB_EVENT_MASK_BUTTON_PRESS, XCB_GRAB_MODE_SYNC, + XCB_GRAB_MODE_ASYNC, root, XCB_NONE, buttons[i], XCB_BUTTON_MASK_ANY); + } +}