diff options
author | tsxv478 <atvx717@infraredcombat.xyz> | 2025-03-14 20:00:02 +0300 |
---|---|---|
committer | tsxv478 <atvx717@infraredcombat.xyz> | 2025-03-14 20:00:02 +0300 |
commit | 6f57b704e7fc8c6b0b74f34a7e150e920d0b65f4 (patch) | |
tree | 664d6c5ef67df35d3335a177625c2450b3d62e34 | |
parent | b16f49712d2760b2025a334940b7ba2de96efe72 (diff) |
-rw-r--r-- | dwm.c | 26 |
1 files changed, 20 insertions, 6 deletions
@@ -1205,14 +1205,28 @@ grabkeys(void) { unsigned int i, j; unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask }; - KeyCode code; + int kc, kcmin, kcmax, kcper; + KeySym keysym, *keysyms; XUngrabKey(dpy, AnyKey, AnyModifier, root); - for (i = 0; i < LENGTH(keys); i++) - if ((code = XKeysymToKeycode(dpy, keys[i].keysym))) - for (j = 0; j < LENGTH(modifiers); j++) - XGrabKey(dpy, code, keys[i].mod | modifiers[j], root, - True, GrabModeAsync, GrabModeAsync); + + /* retrieve all the keycode -> keysym mappings */ + XDisplayKeycodes(dpy, &kcmin, &kcmax); + keysyms = XGetKeyboardMapping(dpy, kcmin, kcmax - kcmin + 1, &kcper); + + /* only look at the first keysym for each keycode as we handle shifted states */ + for (kc = kcmin; kc <= kcmax; kc++) { + keysym = keysyms[(kc - kcmin) * kcper]; + for (i = 0; i < LENGTH(keys); i++) { + if (keys[i].keysym == keysym) { + for (j = 0; j < LENGTH(modifiers); j++) { + XGrabKey(dpy, kc, keys[i].mod | modifiers[j], root, True, GrabModeAsync, GrabModeAsync); + } + } + } + } + + XFree(keysyms); } } |