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
This commit is contained in:
Patrick Louis 2020-10-02 11:35:03 +03:00
parent 95596f43aa
commit 5663175d57
2 changed files with 13 additions and 0 deletions

12
sowm.c
View File

@ -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++)

1
sowm.h
View File

@ -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);