dwm-keycodes-20230319-a38a8b3.diff - sites - public wiki contents of suckless.org
(HTM) git clone git://git.suckless.org/sites
(DIR) Log
(DIR) Files
(DIR) Refs
---
dwm-keycodes-20230319-a38a8b3.diff (7476B)
---
1 From a38a8b3310bd6fb4bb1371a5cad486ac280f773d Mon Sep 17 00:00:00 2001
2 From: Quentin Rameau <quinq@fifth.space>
3 Date: Tue, 10 Apr 2018 13:26:33 +0200
4 Subject: [PATCH] Use keycode for keyboard input instead of keysyms
5
6 ---
7 config.def.h | 68 ++++++++++++++++++++++++++--------------------------
8 dwm.c | 30 +++++++----------------
9 2 files changed, 42 insertions(+), 56 deletions(-)
10
11 diff --git a/config.def.h b/config.def.h
12 index 9efa774..b8ed024 100644
13 --- a/config.def.h
14 +++ b/config.def.h
15 @@ -61,40 +61,40 @@ static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont,
16 static const char *termcmd[] = { "st", NULL };
17
18 static const Key keys[] = {
19 - /* modifier key function argument */
20 - { MODKEY, XK_p, spawn, {.v = dmenucmd } },
21 - { MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } },
22 - { MODKEY, XK_b, togglebar, {0} },
23 - { MODKEY, XK_j, focusstack, {.i = +1 } },
24 - { MODKEY, XK_k, focusstack, {.i = -1 } },
25 - { MODKEY, XK_i, incnmaster, {.i = +1 } },
26 - { MODKEY, XK_d, incnmaster, {.i = -1 } },
27 - { MODKEY, XK_h, setmfact, {.f = -0.05} },
28 - { MODKEY, XK_l, setmfact, {.f = +0.05} },
29 - { MODKEY, XK_Return, zoom, {0} },
30 - { MODKEY, XK_Tab, view, {0} },
31 - { MODKEY|ShiftMask, XK_c, killclient, {0} },
32 - { MODKEY, XK_t, setlayout, {.v = &layouts[0]} },
33 - { MODKEY, XK_f, setlayout, {.v = &layouts[1]} },
34 - { MODKEY, XK_m, setlayout, {.v = &layouts[2]} },
35 - { MODKEY, XK_space, setlayout, {0} },
36 - { MODKEY|ShiftMask, XK_space, togglefloating, {0} },
37 - { MODKEY, XK_0, view, {.ui = ~0 } },
38 - { MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } },
39 - { MODKEY, XK_comma, focusmon, {.i = -1 } },
40 - { MODKEY, XK_period, focusmon, {.i = +1 } },
41 - { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } },
42 - { MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } },
43 - TAGKEYS( XK_1, 0)
44 - TAGKEYS( XK_2, 1)
45 - TAGKEYS( XK_3, 2)
46 - TAGKEYS( XK_4, 3)
47 - TAGKEYS( XK_5, 4)
48 - TAGKEYS( XK_6, 5)
49 - TAGKEYS( XK_7, 6)
50 - TAGKEYS( XK_8, 7)
51 - TAGKEYS( XK_9, 8)
52 - { MODKEY|ShiftMask, XK_q, quit, {0} },
53 + /* modifier key function argument */
54 + { MODKEY, 33, spawn, {.v = dmenucmd } }, // p
55 + { MODKEY|ShiftMask, 36, spawn, {.v = termcmd } }, // Return
56 + { MODKEY, 56, togglebar, {0} }, // b
57 + { MODKEY, 44, focusstack, {.i = +1 } }, // j
58 + { MODKEY, 45, focusstack, {.i = -1 } }, // k
59 + { MODKEY, 31, incnmaster, {.i = +1 } }, // i
60 + { MODKEY, 40, incnmaster, {.i = -1 } }, // d
61 + { MODKEY, 43, setmfact, {.f = -0.05} }, // h
62 + { MODKEY, 46, setmfact, {.f = +0.05} }, // l
63 + { MODKEY, 36, zoom, {0} }, // Return
64 + { MODKEY, 23, view, {0} }, // Tab
65 + { MODKEY|ShiftMask, 54, killclient, {0} }, // c
66 + { MODKEY, 28, setlayout, {.v = &layouts[0]} }, // t
67 + { MODKEY, 41, setlayout, {.v = &layouts[1]} }, // f
68 + { MODKEY, 58, setlayout, {.v = &layouts[2]} }, // m
69 + { MODKEY, 65, setlayout, {0} }, // space
70 + { MODKEY|ShiftMask, 65, togglefloating, {0} }, // space
71 + { MODKEY, 19, view, {.ui = ~0 } }, // 0
72 + { MODKEY|ShiftMask, 19, tag, {.ui = ~0 } }, // 0
73 + { MODKEY, 59, focusmon, {.i = -1 } }, // comma
74 + { MODKEY, 60, focusmon, {.i = +1 } }, // period
75 + { MODKEY|ShiftMask, 59, tagmon, {.i = -1 } }, // comma
76 + { MODKEY|ShiftMask, 60, tagmon, {.i = +1 } }, // period
77 + TAGKEYS( 10, 0) // 1
78 + TAGKEYS( 11, 1) // 2
79 + TAGKEYS( 12, 2) // 3
80 + TAGKEYS( 13, 3) // 4
81 + TAGKEYS( 14, 4) // 5
82 + TAGKEYS( 15, 5) // 6
83 + TAGKEYS( 16, 6) // 7
84 + TAGKEYS( 17, 7) // 8
85 + TAGKEYS( 18, 8) // 9
86 + { MODKEY|ShiftMask, 24, quit, {0} }, // q
87 };
88
89 /* button definitions */
90 diff --git a/dwm.c b/dwm.c
91 index c2bd871..f710729 100644
92 --- a/dwm.c
93 +++ b/dwm.c
94 @@ -31,7 +31,6 @@
95 #include <sys/types.h>
96 #include <sys/wait.h>
97 #include <X11/cursorfont.h>
98 -#include <X11/keysym.h>
99 #include <X11/Xatom.h>
100 #include <X11/Xlib.h>
101 #include <X11/Xproto.h>
102 @@ -101,7 +100,7 @@ struct Client {
103
104 typedef struct {
105 unsigned int mod;
106 - KeySym keysym;
107 + KeyCode keycode;
108 void (*func)(const Arg *);
109 const Arg arg;
110 } Key;
111 @@ -954,26 +953,15 @@ grabkeys(void)
112 {
113 updatenumlockmask();
114 {
115 - unsigned int i, j, k;
116 + unsigned int i, j;
117 unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask };
118 - int start, end, skip;
119 - KeySym *syms;
120
121 XUngrabKey(dpy, AnyKey, AnyModifier, root);
122 - XDisplayKeycodes(dpy, &start, &end);
123 - syms = XGetKeyboardMapping(dpy, start, end - start + 1, &skip);
124 - if (!syms)
125 - return;
126 - for (k = start; k <= end; k++)
127 - for (i = 0; i < LENGTH(keys); i++)
128 - /* skip modifier codes, we do that ourselves */
129 - if (keys[i].keysym == syms[(k - start) * skip])
130 - for (j = 0; j < LENGTH(modifiers); j++)
131 - XGrabKey(dpy, k,
132 - keys[i].mod | modifiers[j],
133 - root, True,
134 - GrabModeAsync, GrabModeAsync);
135 - XFree(syms);
136 + for (i = 0; i < LENGTH(keys); i++)
137 + for (j = 0; j < LENGTH(modifiers); j++)
138 + XGrabKey(dpy, keys[i].keycode,
139 + keys[i].mod | modifiers[j], root,
140 + True, GrabModeAsync, GrabModeAsync);
141 }
142 }
143
144 @@ -1000,13 +988,11 @@ void
145 keypress(XEvent *e)
146 {
147 unsigned int i;
148 - KeySym keysym;
149 XKeyEvent *ev;
150
151 ev = &e->xkey;
152 - keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
153 for (i = 0; i < LENGTH(keys); i++)
154 - if (keysym == keys[i].keysym
155 + if (ev->keycode == keys[i].keycode
156 && CLEANMASK(keys[i].mod) == CLEANMASK(ev->state)
157 && keys[i].func)
158 keys[i].func(&(keys[i].arg));
159 --
160 2.40.0
161