dwm-keychord-6.4.diff - sites - public wiki contents of suckless.org
(HTM) git clone git://git.suckless.org/sites
(DIR) Log
(DIR) Files
(DIR) Refs
---
dwm-keychord-6.4.diff (12025B)
---
1 From cb7ea178ac8e60cf123b333af64df8228762f669 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Aaron=20Z=C3=BCger?= <contact@azureorange.xyz>
3 Date: Wed, 19 Jul 2023 14:17:39 +0200
4 Subject: [PATCH] Update dwm-keychord patch to comply with the changes in dwm
5 from version 6.2 to version 6.4. Namely changes in the grabkey function to
6 match the newer implementation of said function.
7
8 ---
9 config.def.h | 81 ++++++++++++++++++++++++++--------------------------
10 dwm.c | 72 +++++++++++++++++++++++++++++++++++++---------
11 2 files changed, 99 insertions(+), 54 deletions(-)
12
13 diff --git a/config.def.h b/config.def.h
14 index 9efa774..49f0558 100644
15 --- a/config.def.h
16 +++ b/config.def.h
17 @@ -46,11 +46,11 @@ static const Layout layouts[] = {
18
19 /* key definitions */
20 #define MODKEY Mod1Mask
21 -#define TAGKEYS(KEY,TAG) \
22 - { MODKEY, KEY, view, {.ui = 1 << TAG} }, \
23 - { MODKEY|ControlMask, KEY, toggleview, {.ui = 1 << TAG} }, \
24 - { MODKEY|ShiftMask, KEY, tag, {.ui = 1 << TAG} }, \
25 - { MODKEY|ControlMask|ShiftMask, KEY, toggletag, {.ui = 1 << TAG} },
26 +#define TAGKEYS(KEY,TAG) \
27 + &((Keychord){1, {{MODKEY, KEY}}, view, {.ui = 1 << TAG} }), \
28 + &((Keychord){1, {{MODKEY|ControlMask, KEY}}, toggleview, {.ui = 1 << TAG} }), \
29 + &((Keychord){1, {{MODKEY|ShiftMask, KEY}}, tag, {.ui = 1 << TAG} }), \
30 + &((Keychord){1, {{MODKEY|ControlMask|ShiftMask, KEY}}, toggletag, {.ui = 1 << TAG} }),
31
32 /* helper for spawning shell commands in the pre dwm-5.0 fashion */
33 #define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }
34 @@ -60,41 +60,42 @@ static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn()
35 static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
36 static const char *termcmd[] = { "st", NULL };
37
38 -static const Key keys[] = {
39 - /* modifier key function argument */
40 - { MODKEY, XK_p, spawn, {.v = dmenucmd } },
41 - { MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } },
42 - { MODKEY, XK_b, togglebar, {0} },
43 - { MODKEY, XK_j, focusstack, {.i = +1 } },
44 - { MODKEY, XK_k, focusstack, {.i = -1 } },
45 - { MODKEY, XK_i, incnmaster, {.i = +1 } },
46 - { MODKEY, XK_d, incnmaster, {.i = -1 } },
47 - { MODKEY, XK_h, setmfact, {.f = -0.05} },
48 - { MODKEY, XK_l, setmfact, {.f = +0.05} },
49 - { MODKEY, XK_Return, zoom, {0} },
50 - { MODKEY, XK_Tab, view, {0} },
51 - { MODKEY|ShiftMask, XK_c, killclient, {0} },
52 - { MODKEY, XK_t, setlayout, {.v = &layouts[0]} },
53 - { MODKEY, XK_f, setlayout, {.v = &layouts[1]} },
54 - { MODKEY, XK_m, setlayout, {.v = &layouts[2]} },
55 - { MODKEY, XK_space, setlayout, {0} },
56 - { MODKEY|ShiftMask, XK_space, togglefloating, {0} },
57 - { MODKEY, XK_0, view, {.ui = ~0 } },
58 - { MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } },
59 - { MODKEY, XK_comma, focusmon, {.i = -1 } },
60 - { MODKEY, XK_period, focusmon, {.i = +1 } },
61 - { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } },
62 - { MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } },
63 - TAGKEYS( XK_1, 0)
64 - TAGKEYS( XK_2, 1)
65 - TAGKEYS( XK_3, 2)
66 - TAGKEYS( XK_4, 3)
67 - TAGKEYS( XK_5, 4)
68 - TAGKEYS( XK_6, 5)
69 - TAGKEYS( XK_7, 6)
70 - TAGKEYS( XK_8, 7)
71 - TAGKEYS( XK_9, 8)
72 - { MODKEY|ShiftMask, XK_q, quit, {0} },
73 +static Keychord *keychords[] = {
74 + /* Keys function argument */
75 + &((Keychord){1, {{MODKEY, XK_p}}, spawn, {.v = dmenucmd } }),
76 + &((Keychord){1, {{MODKEY|ShiftMask, XK_Return}}, spawn, {.v = termcmd } }),
77 + &((Keychord){2, {{MODKEY, XK_e}, {MODKEY, XK_e}}, spawn, {.v = termcmd } }),
78 + &((Keychord){1, {{MODKEY, XK_b}}, togglebar, {0} }),
79 + &((Keychord){1, {{MODKEY, XK_j}}, focusstack, {.i = +1 } }),
80 + &((Keychord){1, {{MODKEY, XK_k}}, focusstack, {.i = -1 } }),
81 + &((Keychord){1, {{MODKEY, XK_i}}, incnmaster, {.i = +1 } }),
82 + &((Keychord){1, {{MODKEY, XK_d}}, incnmaster, {.i = -1 } }),
83 + &((Keychord){1, {{MODKEY, XK_h}}, setmfact, {.f = -0.05} }),
84 + &((Keychord){1, {{MODKEY, XK_l}}, setmfact, {.f = +0.05} }),
85 + &((Keychord){1, {{MODKEY, XK_Return}}, zoom, {0} }),
86 + &((Keychord){1, {{MODKEY, XK_Tab}}, view, {0} }),
87 + &((Keychord){1, {{MODKEY|ShiftMask, XK_c}}, killclient, {0} }),
88 + &((Keychord){1, {{MODKEY, XK_t}}, setlayout, {.v = &layouts[0]} }),
89 + &((Keychord){1, {{MODKEY, XK_f}}, setlayout, {.v = &layouts[1]} }),
90 + &((Keychord){1, {{MODKEY, XK_m}}, setlayout, {.v = &layouts[2]} }),
91 + &((Keychord){1, {{MODKEY, XK_space}}, setlayout, {0} }),
92 + &((Keychord){1, {{MODKEY|ShiftMask, XK_space}}, togglefloating, {0} }),
93 + &((Keychord){1, {{MODKEY, XK_0}}, view, {.ui = ~0 } }),
94 + &((Keychord){1, {{MODKEY|ShiftMask, XK_0}}, tag, {.ui = ~0 } }),
95 + &((Keychord){1, {{MODKEY, XK_comma}}, focusmon, {.i = -1 } }),
96 + &((Keychord){1, {{MODKEY, XK_period}}, focusmon, {.i = +1 } }),
97 + &((Keychord){1, {{MODKEY|ShiftMask, XK_comma}}, tagmon, {.i = -1 } }),
98 + &((Keychord){1, {{MODKEY|ShiftMask, XK_period}}, tagmon, {.i = +1 } }),
99 + &((Keychord){1, {{MODKEY|ShiftMask, XK_q}}, quit, {0} }),
100 + TAGKEYS( XK_1, 0)
101 + TAGKEYS( XK_2, 1)
102 + TAGKEYS( XK_3, 2)
103 + TAGKEYS( XK_4, 3)
104 + TAGKEYS( XK_5, 4)
105 + TAGKEYS( XK_6, 5)
106 + TAGKEYS( XK_7, 6)
107 + TAGKEYS( XK_8, 7)
108 + TAGKEYS( XK_9, 8)
109 };
110
111 /* button definitions */
112 diff --git a/dwm.c b/dwm.c
113 index f1d86b2..e4885a4 100644
114 --- a/dwm.c
115 +++ b/dwm.c
116 @@ -102,9 +102,14 @@ struct Client {
117 typedef struct {
118 unsigned int mod;
119 KeySym keysym;
120 +} Key;
121 +
122 +typedef struct {
123 + unsigned int n;
124 + const Key keys[5];
125 void (*func)(const Arg *);
126 const Arg arg;
127 -} Key;
128 +} Keychord;
129
130 typedef struct {
131 const char *symbol;
132 @@ -267,6 +272,7 @@ static Display *dpy;
133 static Drw *drw;
134 static Monitor *mons, *selmon;
135 static Window root, wmcheckwin;
136 +unsigned int currentkey = 0;
137
138 /* configuration, allows nested code to access above variables */
139 #include "config.h"
140 @@ -954,7 +960,8 @@ grabkeys(void)
141 {
142 updatenumlockmask();
143 {
144 - unsigned int i, j, k;
145 + /* unsigned int i, j, k; */
146 + unsigned int i, c, k;
147 unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask };
148 int start, end, skip;
149 KeySym *syms;
150 @@ -964,15 +971,18 @@ grabkeys(void)
151 syms = XGetKeyboardMapping(dpy, start, end - start + 1, &skip);
152 if (!syms)
153 return;
154 +
155 for (k = start; k <= end; k++)
156 - for (i = 0; i < LENGTH(keys); i++)
157 + for (i = 0; i < LENGTH(keychords); i++)
158 /* skip modifier codes, we do that ourselves */
159 - if (keys[i].keysym == syms[(k - start) * skip])
160 - for (j = 0; j < LENGTH(modifiers); j++)
161 + if (keychords[i]->keys[currentkey].keysym == syms[(k - start) * skip])
162 + for (c = 0; c < LENGTH(modifiers); c++)
163 XGrabKey(dpy, k,
164 - keys[i].mod | modifiers[j],
165 + keychords[i]->keys[currentkey].mod | modifiers[c],
166 root, True,
167 GrabModeAsync, GrabModeAsync);
168 + if(currentkey > 0)
169 + XGrabKey(dpy, XKeysymToKeycode(dpy, XK_Escape), AnyModifier, root, True, GrabModeAsync, GrabModeAsync);
170 XFree(syms);
171 }
172 }
173 @@ -999,17 +1009,51 @@ isuniquegeom(XineramaScreenInfo *unique, size_t n, XineramaScreenInfo *info)
174 void
175 keypress(XEvent *e)
176 {
177 - unsigned int i;
178 + /* unsigned int i; */
179 + XEvent event = *e;
180 + unsigned int ran = 0;
181 KeySym keysym;
182 XKeyEvent *ev;
183
184 - ev = &e->xkey;
185 - keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
186 - for (i = 0; i < LENGTH(keys); i++)
187 - if (keysym == keys[i].keysym
188 - && CLEANMASK(keys[i].mod) == CLEANMASK(ev->state)
189 - && keys[i].func)
190 - keys[i].func(&(keys[i].arg));
191 + Keychord *arr1[sizeof(keychords) / sizeof(Keychord*)];
192 + Keychord *arr2[sizeof(keychords) / sizeof(Keychord*)];
193 + memcpy(arr1, keychords, sizeof(keychords));
194 + Keychord **rpointer = arr1;
195 + Keychord **wpointer = arr2;
196 +
197 + size_t r = sizeof(keychords)/ sizeof(Keychord*);
198 +
199 + while(1){
200 + ev = &event.xkey;
201 + keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
202 + size_t w = 0;
203 + for (int i = 0; i < r; i++){
204 + if(keysym == (*(rpointer + i))->keys[currentkey].keysym
205 + && CLEANMASK((*(rpointer + i))->keys[currentkey].mod) == CLEANMASK(ev->state)
206 + && (*(rpointer + i))->func){
207 + if((*(rpointer + i))->n == currentkey +1){
208 + (*(rpointer + i))->func(&((*(rpointer + i))->arg));
209 + ran = 1;
210 + }else{
211 + *(wpointer + w) = *(rpointer + i);
212 + w++;
213 + }
214 + }
215 + }
216 + currentkey++;
217 + if(w == 0 || ran == 1)
218 + break;
219 + grabkeys();
220 + while (running && !XNextEvent(dpy, &event) && !ran)
221 + if(event.type == KeyPress)
222 + break;
223 + r = w;
224 + Keychord **holder = rpointer;
225 + rpointer = wpointer;
226 + wpointer = holder;
227 + }
228 + currentkey = 0;
229 + grabkeys();
230 }
231
232 void
233 --
234 2.41.0
235