dwm-grab-all-keycodes-6.2.diff - sites - public wiki contents of suckless.org | |
git clone git://git.suckless.org/sites | |
Log | |
Files | |
Refs | |
--- | |
dwm-grab-all-keycodes-6.2.diff (1859B) | |
--- | |
1 From f64e5ddc9bc47dd3bca79a1eac214525ba005caf Mon Sep 17 00:00:00 2001 | |
2 From: Alexander Courtis <[email protected]> | |
3 Date: Sat, 15 Feb 2020 14:23:26 +1100 | |
4 Subject: [PATCH] Grab all keycodes that map to keys.keysym | |
5 | |
6 There may be multiple keycodes that map to a keys.keysym. One such scena… | |
7 | |
8 When grabbing keys, we now scan all X keycode mappings and look for matc… | |
9 | |
10 Changing keymaps via xkb or other means will not cause the keys to be "r… | |
11 | |
12 --- | |
13 dwm.c | 26 ++++++++++++++++++++------ | |
14 1 file changed, 20 insertions(+), 6 deletions(-) | |
15 | |
16 diff --git a/dwm.c b/dwm.c | |
17 index cc4fce7..04f6220 100644 | |
18 --- a/dwm.c | |
19 +++ b/dwm.c | |
20 @@ -1104,14 +1104,28 @@ grabkeys(void) | |
21 { | |
22 unsigned int i, j; | |
23 unsigned int modifiers[] = { 0, LockMask, numlockmask, … | |
24 - KeyCode code; | |
25 + int kc, kcmin, kcmax, kcper; | |
26 + KeySym keysym, *keysyms; | |
27 | |
28 XUngrabKey(dpy, AnyKey, AnyModifier, root); | |
29 - for (i = 0; i < LENGTH(keys); i++) | |
30 - if ((code = XKeysymToKeycode(dpy, keys[i].keysy… | |
31 - for (j = 0; j < LENGTH(modifiers); j++) | |
32 - XGrabKey(dpy, code, keys[i].mod… | |
33 - True, GrabModeAsync, Gr… | |
34 + | |
35 + /* retrieve all the keycode -> keysym mappings */ | |
36 + XDisplayKeycodes(dpy, &kcmin, &kcmax); | |
37 + keysyms = XGetKeyboardMapping(dpy, kcmin, kcmax - kcmin… | |
38 + | |
39 + /* only look at the first keysym for each keycode as we… | |
40 + for (kc = kcmin; kc <= kcmax; kc++) { | |
41 + keysym = keysyms[(kc - kcmin) * kcper]; | |
42 + for (i = 0; i < LENGTH(keys); i++) { | |
43 + if (keys[i].keysym == keysym) { | |
44 + for (j = 0; j < LENGTH(modifier… | |
45 + XGrabKey(dpy, kc, keys[… | |
46 + } | |
47 + } | |
48 + } | |
49 + } | |
50 + | |
51 + XFree(keysyms); | |
52 } | |
53 } | |
54 | |
55 -- | |
56 2.25.0 | |
57 |