From cfac43ecdfe8c1d928475af937ac0df982f1bd0c Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Fri, 31 Oct 2008 19:22:24 +0100 Subject: [PATCH] event: regrab keys on keyboard mapping change (FS#365) Signed-off-by: Julien Danjou --- event.c | 21 +++++++++++++++++++++ keybinding.c | 2 +- keybinding.h | 1 + 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/event.c b/event.c index 36bc6541..8dc9cf57 100644 --- a/event.c +++ b/event.c @@ -697,6 +697,9 @@ event_handle_mappingnotify(void *data, if(ev->request == XCB_MAPPING_MODIFIER || ev->request == XCB_MAPPING_KEYBOARD) { + int nscreen = xcb_setup_roots_length(xcb_get_setup(connection)); + int phys_screen = 0; + /* Send the request to get the NumLock, ShiftLock and CapsLock masks */ xmapping_cookie = xcb_get_modifier_mapping_unchecked(globalconf.connection); @@ -708,6 +711,24 @@ event_handle_mappingnotify(void *data, xutil_lock_mask_get(globalconf.connection, xmapping_cookie, globalconf.keysyms, &globalconf.numlockmask, &globalconf.shiftlockmask, &globalconf.capslockmask); + + do + { + xcb_screen_t *s = xutil_screen_get(globalconf.connection, phys_screen); + /* yes XCB_BUTTON_MASK_ANY is also for grab_key even if it's look + * weird */ + xcb_ungrab_key(connection, XCB_GRAB_ANY, s->root, XCB_BUTTON_MASK_ANY); + phys_screen++; + } while(phys_screen < nscreen); + + /* regrab everything */ + keybinding_array_t *arr = &globalconf.keys.by_sym; + for(int i = 0; i < arr->len; i++) + window_root_grabkey(arr->tab[i]); + + arr = &globalconf.keys.by_code; + for(int i = 0; i < arr->len; i++) + window_root_grabkey(arr->tab[i]); } return 0; diff --git a/keybinding.c b/keybinding.c index f6fba0f9..d17018d4 100644 --- a/keybinding.c +++ b/keybinding.c @@ -70,7 +70,7 @@ keybinding_cmp(const keybinding_t *k1, const keybinding_t *k2) /** Grab key on the root windows. * \param k The keybinding. */ -static void +void window_root_grabkey(keybinding_t *k) { int phys_screen = 0; diff --git a/keybinding.h b/keybinding.h index 78422c57..c34cc644 100644 --- a/keybinding.h +++ b/keybinding.h @@ -44,5 +44,6 @@ ARRAY_TYPE(keybinding_t *, keybinding) keybinding_t *keybinding_find(const xcb_key_press_event_t *); xcb_keysym_t key_getkeysym(xcb_keycode_t, uint16_t); +void window_root_grabkey(keybinding_t *); #endif