Introduction
Introduction Statistics Contact Development Disclaimer Help
dwm-keychord-6.4.diff - sites - public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log
Files
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?= <[email protected]>
3 Date: Wed, 19 Jul 2023 14:17:39 +0200
4 Subject: [PATCH] Update dwm-keychord patch to comply with the changes in…
5 from version 6.2 to version 6.4. Namely changes in the grabkey function…
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 …
23 - { MODKEY|ControlMask, KEY, toggleview, {.ui …
24 - { MODKEY|ShiftMask, KEY, tag, {.ui …
25 - { MODKEY|ControlMask|ShiftMask, KEY, toggletag, {.ui …
26 +#define TAGKEYS(KEY,TAG) …
27 + &((Keychord){1, {{MODKEY, KEY}}, …
28 + &((Keychord){1, {{MODKEY|ControlMask, KEY}}, …
29 + &((Keychord){1, {{MODKEY|ShiftMask, KEY}}, …
30 + &((Keychord){1, {{MODKEY|ControlMask|ShiftMask, KEY}}, …
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 dmenu…
35 static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", d…
36 static const char *termcmd[] = { "st", NULL };
37
38 -static const Key keys[] = {
39 - /* modifier key function argu…
40 - { MODKEY, XK_p, spawn, {.v …
41 - { MODKEY|ShiftMask, XK_Return, spawn, {.v …
42 - { MODKEY, XK_b, togglebar, {0} …
43 - { MODKEY, XK_j, focusstack, {.i …
44 - { MODKEY, XK_k, focusstack, {.i …
45 - { MODKEY, XK_i, incnmaster, {.i …
46 - { MODKEY, XK_d, incnmaster, {.i …
47 - { MODKEY, XK_h, setmfact, {.f …
48 - { MODKEY, XK_l, setmfact, {.f …
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 …
53 - { MODKEY, XK_f, setlayout, {.v …
54 - { MODKEY, XK_m, setlayout, {.v …
55 - { MODKEY, XK_space, setlayout, {0} …
56 - { MODKEY|ShiftMask, XK_space, togglefloating, {0} …
57 - { MODKEY, XK_0, view, {.ui…
58 - { MODKEY|ShiftMask, XK_0, tag, {.ui…
59 - { MODKEY, XK_comma, focusmon, {.i …
60 - { MODKEY, XK_period, focusmon, {.i …
61 - { MODKEY|ShiftMask, XK_comma, tagmon, {.i …
62 - { MODKEY|ShiftMask, XK_period, tagmon, {.i …
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}}, …
76 + &((Keychord){1, {{MODKEY|ShiftMask, XK_Return}}, …
77 + &((Keychord){2, {{MODKEY, XK_e}, {MODKEY, XK_e}}, …
78 + &((Keychord){1, {{MODKEY, XK_b}}, …
79 + &((Keychord){1, {{MODKEY, XK_j}}, …
80 + &((Keychord){1, {{MODKEY, XK_k}}, …
81 + &((Keychord){1, {{MODKEY, XK_i}}, …
82 + &((Keychord){1, {{MODKEY, XK_d}}, …
83 + &((Keychord){1, {{MODKEY, XK_h}}, …
84 + &((Keychord){1, {{MODKEY, XK_l}}, …
85 + &((Keychord){1, {{MODKEY, XK_Return}}, …
86 + &((Keychord){1, {{MODKEY, XK_Tab}}, …
87 + &((Keychord){1, {{MODKEY|ShiftMask, XK_c}}, …
88 + &((Keychord){1, {{MODKEY, XK_t}}, …
89 + &((Keychord){1, {{MODKEY, XK_f}}, …
90 + &((Keychord){1, {{MODKEY, XK_m}}, …
91 + &((Keychord){1, {{MODKEY, XK_space}}, …
92 + &((Keychord){1, {{MODKEY|ShiftMask, XK_space}}, …
93 + &((Keychord){1, {{MODKEY, XK_0}}, …
94 + &((Keychord){1, {{MODKEY|ShiftMask, XK_0}}, …
95 + &((Keychord){1, {{MODKEY, XK_comma}}, …
96 + &((Keychord){1, {{MODKEY, XK_period}}, …
97 + &((Keychord){1, {{MODKEY|ShiftMask, XK_comma}}, …
98 + &((Keychord){1, {{MODKEY|ShiftMask, XK_period}}, …
99 + &((Keychord){1, {{MODKEY|ShiftMask, XK_q}}, …
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, …
148 int start, end, skip;
149 KeySym *syms;
150 @@ -964,15 +971,18 @@ grabkeys(void)
151 syms = XGetKeyboardMapping(dpy, start, end - start + 1,…
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 ours…
159 - if (keys[i].keysym == syms[(k - start) …
160 - for (j = 0; j < LENGTH(modifier…
161 + if (keychords[i]->keys[currentkey].keys…
162 + for (c = 0; c < LENGTH(modifier…
163 XGrabKey(dpy, k,
164 - keys[i].mod | …
165 + keychords[i]->…
166 root, True,
167 GrabModeAsync,…
168 + if(currentkey > 0)
169 + XGrabKey(dpy, XKeysymToKeycode(dpy, XK_Escape),…
170 XFree(syms);
171 }
172 }
173 @@ -999,17 +1009,51 @@ isuniquegeom(XineramaScreenInfo *unique, size_t n…
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].ke…
205 + && CLEANMASK((*(rpointer + i))->keys[currentkey]…
206 + && (*(rpointer + i))->func){
207 + if((*(rpointer + i))->n == currentkey +1){
208 + (*(rpointer + i))->func(&((*(rpoint…
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
You are viewing proxied material from suckless.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.