From 5663175d5743668857aed60aa7b11cdb1bb2c65d Mon Sep 17 00:00:00 2001 From: Patrick Louis Date: Fri, 2 Oct 2020 11:35:03 +0300 Subject: [PATCH] Refresh keyboard mapping uppon MappingNotify event When dynamically switching between layout the keys that are grabbed need to also be refreshed. This is a fix similar to venam/2bwm@148d832 fixes dylanaraps#100 --- sowm.c | 12 ++++++++++++ sowm.h | 1 + 2 files changed, 13 insertions(+) diff --git a/sowm.c b/sowm.c index b4a39dd..96f8340 100644 --- a/sowm.c +++ b/sowm.c @@ -24,6 +24,7 @@ static void (*events[LASTEvent])(XEvent *e) = { [ConfigureRequest] = configure_request, [KeyPress] = key_press, [MapRequest] = map_request, + [MappingNotify] = mapping_notify, [DestroyNotify] = notify_destroy, [EnterNotify] = notify_enter, [MotionNotify] = notify_motion @@ -221,6 +222,15 @@ void map_request(XEvent *e) { win_focus(list->prev); } +void mapping_notify(XEvent *e) { + XMappingEvent *ev = &e->xmapping; + + if (ev->request == MappingKeyboard || ev->request == MappingModifier) { + XRefreshKeyboardMapping(ev); + input_grab(root); + } +} + void run(const Arg arg) { if (fork()) return; if (d) close(ConnectionNumber(d)); @@ -240,6 +250,8 @@ void input_grab(Window root) { == XKeysymToKeycode(d, 0xff7f)) numlock = (1 << i); + XUngrabKey(d, AnyKey, AnyModifier, root); + for (i = 0; i < sizeof(keys)/sizeof(*keys); i++) if ((code = XKeysymToKeycode(d, keys[i].keysym))) for (j = 0; j < sizeof(modifiers)/sizeof(*modifiers); j++) diff --git a/sowm.h b/sowm.h index 455ed93..b059f06 100644 --- a/sowm.h +++ b/sowm.h @@ -39,6 +39,7 @@ void configure_request(XEvent *e); void input_grab(Window root); void key_press(XEvent *e); void map_request(XEvent *e); +void mapping_notify(XEvent *e); void notify_destroy(XEvent *e); void notify_enter(XEvent *e); void notify_motion(XEvent *e);