[wiki] [sites] [dwm][patch][graballkeycodes] added graballkeycodes for 6.2 || Alexander Courtis

From: <git_AT_suckless.org>
Date: Thu, 31 Dec 2020 01:44:30 +0100

commit 52429b8282ae3f2bfd0647e6cc550cd253dab726
Author: Alexander Courtis <alex_AT_courtis.org>
Date: Thu Dec 31 11:44:27 2020 +1100

    [dwm][patch][graballkeycodes] added graballkeycodes for 6.2

diff --git a/dwm.suckless.org/patches/graballkeycodes/dwm-grab-all-keycodes-6.2.diff b/dwm.suckless.org/patches/graballkeycodes/dwm-grab-all-keycodes-6.2.diff
new file mode 100644
index 00000000..e303b920
--- /dev/null
+++ b/dwm.suckless.org/patches/graballkeycodes/dwm-grab-all-keycodes-6.2.diff
_AT_@ -0,0 +1,57 @@
+From f64e5ddc9bc47dd3bca79a1eac214525ba005caf Mon Sep 17 00:00:00 2001
+From: Alexander Courtis <acourtis_AT_atlassian.com>
+Date: Sat, 15 Feb 2020 14:23:26 +1100
+Subject: [PATCH] Grab all keycodes that map to keys.keysym
+
+There may be multiple keycodes that map to a keys.keysym. One such scenario is using xkb to remap a key: `caps:escape`
+
+When grabbing keys, we now scan all X keycode mappings and look for match.
+
+Changing keymaps via xkb or other means will not cause the keys to be "re-grabbed". This existing behaviour is desirable.
+
+---
+ dwm.c | 26 ++++++++++++++++++++------
+ 1 file changed, 20 insertions(+), 6 deletions(-)
+
+diff --git a/dwm.c b/dwm.c
+index cc4fce7..04f6220 100644
+--- a/dwm.c
++++ b/dwm.c
+_AT_@ -1104,14 +1104,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);
+ }
+ }
+
+--
+2.25.0
+
diff --git a/dwm.suckless.org/patches/graballkeycodes/index.md b/dwm.suckless.org/patches/graballkeycodes/index.md
new file mode 100644
index 00000000..754f1cc3
--- /dev/null
+++ b/dwm.suckless.org/patches/graballkeycodes/index.md
_AT_@ -0,0 +1,22 @@
+graballkeycodes
+===============
+
+Description
+-----------
+
+Grab all keycodes that map to keys.keysym
+
+There may be multiple keycodes that map to a keys.keysym. One such scenario is using xkb to remap a key: `caps:escape`
+
+When grabbing keys, we now scan all X keycode mappings and look for match.
+
+Changing keymaps via xkb or other means will not cause the keys to be "re-grabbed". This existing behaviour is desirable.
+
+Download
+--------
+* [dwm-grab-all-keycodes-6.2.diff](dwm-grab-all-keycodes-6.2.diff) (20201231)
+
+Author
+------
+* Alexander Courtis
+
Received on Thu Dec 31 2020 - 01:44:30 CET

This archive was generated by hypermail 2.3.0 : Thu Dec 31 2020 - 01:48:50 CET