dwm-keychain-20200729-053e3a2.diff 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. From e6c2d5fdc6010a22d6cd74485cb0b3e74467d0da Mon Sep 17 00:00:00 2001
  2. From: braunbearded <braunbearded1@gmail.com>
  3. Date: Wed, 29 Jul 2020 18:37:47 +0200
  4. Subject: [PATCH 1/4] chain key bindings
  5. ---
  6. dwm.c | 34 +++++++++++++++++++++++++++++-----
  7. 1 file changed, 29 insertions(+), 5 deletions(-)
  8. diff --git a/dwm.c b/dwm.c
  9. index 9fd0286..7298c5e 100644
  10. --- a/dwm.c
  11. +++ b/dwm.c
  12. @@ -101,6 +101,7 @@ struct Client {
  13. typedef struct {
  14. unsigned int mod;
  15. + KeySym chain;
  16. KeySym keysym;
  17. void (*func)(const Arg *);
  18. const Arg arg;
  19. @@ -268,6 +269,7 @@ static Display *dpy;
  20. static Drw *drw;
  21. static Monitor *mons, *selmon;
  22. static Window root, wmcheckwin;
  23. +static KeySym keychain = -1;
  24. /* configuration, allows nested code to access above variables */
  25. #include "config.h"
  26. @@ -954,13 +956,18 @@ grabkeys(void)
  27. unsigned int i, j;
  28. unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask };
  29. KeyCode code;
  30. + KeyCode chain;
  31. XUngrabKey(dpy, AnyKey, AnyModifier, root);
  32. for (i = 0; i < LENGTH(keys); i++)
  33. - if ((code = XKeysymToKeycode(dpy, keys[i].keysym)))
  34. + if ((code = XKeysymToKeycode(dpy, keys[i].keysym))) {
  35. + if (keys[i].chain != -1 &&
  36. + ((chain = XKeysymToKeycode(dpy, keys[i].chain))))
  37. + code = chain;
  38. for (j = 0; j < LENGTH(modifiers); j++)
  39. XGrabKey(dpy, code, keys[i].mod | modifiers[j], root,
  40. True, GrabModeAsync, GrabModeAsync);
  41. + }
  42. }
  43. }
  44. @@ -989,14 +996,31 @@ keypress(XEvent *e)
  45. unsigned int i;
  46. KeySym keysym;
  47. XKeyEvent *ev;
  48. + int current = 0;
  49. ev = &e->xkey;
  50. keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
  51. - for (i = 0; i < LENGTH(keys); i++)
  52. - if (keysym == keys[i].keysym
  53. - && CLEANMASK(keys[i].mod) == CLEANMASK(ev->state)
  54. - && keys[i].func)
  55. + for (i = 0; i < LENGTH(keys); i++) {
  56. + if (keysym == keys[i].keysym && keys[i].chain == -1
  57. + && CLEANMASK(keys[i].mod) == CLEANMASK(ev->state)
  58. + && keys[i].func)
  59. + keys[i].func(&(keys[i].arg));
  60. + else if (keysym == keys[i].chain && keychain == -1
  61. + && CLEANMASK(keys[i].mod) == CLEANMASK(ev->state)
  62. + && keys[i].func) {
  63. + current = 1;
  64. + keychain = keysym;
  65. + XGrabKey(dpy, AnyKey, AnyModifier, root, True, GrabModeAsync,
  66. + GrabModeAsync);
  67. + } else if (!current && keysym == keys[i].keysym
  68. + && keys[i].chain == keychain
  69. + && keys[i].func)
  70. keys[i].func(&(keys[i].arg));
  71. + }
  72. + if (!current) {
  73. + keychain = -1;
  74. + grabkeys();
  75. + }
  76. }
  77. void
  78. --
  79. 2.28.0
  80. From ad3d15cf7df3286d35728afef823c3163898e2db Mon Sep 17 00:00:00 2001
  81. From: braunbearded <braunbearded1@gmail.com>
  82. Date: Wed, 29 Jul 2020 18:38:15 +0200
  83. Subject: [PATCH 2/4] update default bindings
  84. ---
  85. config.def.h | 80 +++++++++++++++++++++++++++-------------------------
  86. 1 file changed, 41 insertions(+), 39 deletions(-)
  87. diff --git a/config.def.h b/config.def.h
  88. index 1c0b587..c7cab16 100644
  89. --- a/config.def.h
  90. +++ b/config.def.h
  91. @@ -45,11 +45,11 @@ static const Layout layouts[] = {
  92. /* key definitions */
  93. #define MODKEY Mod1Mask
  94. -#define TAGKEYS(KEY,TAG) \
  95. - { MODKEY, KEY, view, {.ui = 1 << TAG} }, \
  96. - { MODKEY|ControlMask, KEY, toggleview, {.ui = 1 << TAG} }, \
  97. - { MODKEY|ShiftMask, KEY, tag, {.ui = 1 << TAG} }, \
  98. - { MODKEY|ControlMask|ShiftMask, KEY, toggletag, {.ui = 1 << TAG} },
  99. +#define TAGKEYS(CHAIN,KEY,TAG) \
  100. + { MODKEY, CHAIN, KEY, view, {.ui = 1 << TAG} }, \
  101. + { MODKEY|ControlMask, CHAIN, KEY, toggleview, {.ui = 1 << TAG} }, \
  102. + { MODKEY|ShiftMask, CHAIN, KEY, tag, {.ui = 1 << TAG} }, \
  103. + { MODKEY|ControlMask|ShiftMask, CHAIN, KEY, toggletag, {.ui = 1 << TAG} },
  104. /* helper for spawning shell commands in the pre dwm-5.0 fashion */
  105. #define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }
  106. @@ -60,40 +60,42 @@ static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont,
  107. static const char *termcmd[] = { "st", NULL };
  108. static Key keys[] = {
  109. - /* modifier key function argument */
  110. - { MODKEY, XK_p, spawn, {.v = dmenucmd } },
  111. - { MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } },
  112. - { MODKEY, XK_b, togglebar, {0} },
  113. - { MODKEY, XK_j, focusstack, {.i = +1 } },
  114. - { MODKEY, XK_k, focusstack, {.i = -1 } },
  115. - { MODKEY, XK_i, incnmaster, {.i = +1 } },
  116. - { MODKEY, XK_d, incnmaster, {.i = -1 } },
  117. - { MODKEY, XK_h, setmfact, {.f = -0.05} },
  118. - { MODKEY, XK_l, setmfact, {.f = +0.05} },
  119. - { MODKEY, XK_Return, zoom, {0} },
  120. - { MODKEY, XK_Tab, view, {0} },
  121. - { MODKEY|ShiftMask, XK_c, killclient, {0} },
  122. - { MODKEY, XK_t, setlayout, {.v = &layouts[0]} },
  123. - { MODKEY, XK_f, setlayout, {.v = &layouts[1]} },
  124. - { MODKEY, XK_m, setlayout, {.v = &layouts[2]} },
  125. - { MODKEY, XK_space, setlayout, {0} },
  126. - { MODKEY|ShiftMask, XK_space, togglefloating, {0} },
  127. - { MODKEY, XK_0, view, {.ui = ~0 } },
  128. - { MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } },
  129. - { MODKEY, XK_comma, focusmon, {.i = -1 } },
  130. - { MODKEY, XK_period, focusmon, {.i = +1 } },
  131. - { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } },
  132. - { MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } },
  133. - TAGKEYS( XK_1, 0)
  134. - TAGKEYS( XK_2, 1)
  135. - TAGKEYS( XK_3, 2)
  136. - TAGKEYS( XK_4, 3)
  137. - TAGKEYS( XK_5, 4)
  138. - TAGKEYS( XK_6, 5)
  139. - TAGKEYS( XK_7, 6)
  140. - TAGKEYS( XK_8, 7)
  141. - TAGKEYS( XK_9, 8)
  142. - { MODKEY|ShiftMask, XK_q, quit, {0} },
  143. + /* modifier chain key key function argument */
  144. + { MODKEY, -1, XK_p, spawn, {.v = dmenucmd } },
  145. + { MODKEY|ShiftMask, -1, XK_Return, spawn, {.v = termcmd } },
  146. + { MODKEY, -1, XK_b, togglebar, {0} },
  147. + { MODKEY, -1, XK_j, focusstack, {.i = +1 } },
  148. + { MODKEY, -1, XK_k, focusstack, {.i = -1 } },
  149. + { MODKEY, -1, XK_i, incnmaster, {.i = +1 } },
  150. + { MODKEY, -1, XK_d, incnmaster, {.i = -1 } },
  151. + { MODKEY, -1, XK_h, setmfact, {.f = -0.05} },
  152. + { MODKEY, -1, XK_l, setmfact, {.f = +0.05} },
  153. + { MODKEY, -1, XK_Return, zoom, {0} },
  154. + { MODKEY, -1, XK_Tab, view, {0} },
  155. + { MODKEY|ShiftMask, -1, XK_c, killclient, {0} },
  156. + { MODKEY, -1, XK_t, setlayout, {.v = &layouts[0]} },
  157. + { MODKEY, -1, XK_f, setlayout, {.v = &layouts[1]} },
  158. + { MODKEY, -1, XK_m, setlayout, {.v = &layouts[2]} },
  159. + { MODKEY, -1, XK_space, setlayout, {0} },
  160. + { MODKEY|ShiftMask, -1, XK_space, togglefloating, {0} },
  161. + { MODKEY, -1, XK_0, view, {.ui = ~0 } },
  162. + { MODKEY|ShiftMask, -1, XK_0, tag, {.ui = ~0 } },
  163. + { MODKEY, -1, XK_comma, focusmon, {.i = -1 } },
  164. + { MODKEY, -1, XK_period, focusmon, {.i = +1 } },
  165. + { MODKEY|ShiftMask, -1, XK_comma, tagmon, {.i = -1 } },
  166. + { MODKEY|ShiftMask, -1, XK_period, tagmon, {.i = +1 } },
  167. + TAGKEYS( -1, XK_1, 0)
  168. + TAGKEYS( -1, XK_2, 1)
  169. + TAGKEYS( -1, XK_3, 2)
  170. + TAGKEYS( -1, XK_4, 3)
  171. + TAGKEYS( -1, XK_5, 4)
  172. + TAGKEYS( -1, XK_6, 5)
  173. + TAGKEYS( -1, XK_7, 6)
  174. + TAGKEYS( -1, XK_8, 7)
  175. + TAGKEYS( -1, XK_9, 8)
  176. + { MODKEY|ShiftMask, -1, XK_q, quit, {0} },
  177. + { MODKEY, XK_a, XK_d, spawn, {.v = dmenucmd } },
  178. + { MODKEY, XK_a, XK_t, spawn, {.v = termcmd } },
  179. };
  180. /* button definitions */
  181. --
  182. 2.28.0
  183. From e9f3eec82010fd6083dc57f058902a1aab2d14ea Mon Sep 17 00:00:00 2001
  184. From: braunbearded <braunbearded1@gmail.com>
  185. Date: Wed, 29 Jul 2020 19:07:07 +0200
  186. Subject: [PATCH 3/4] fix bug for mod key ignore
  187. ---
  188. dwm.c | 1 +
  189. 1 file changed, 1 insertion(+)
  190. diff --git a/dwm.c b/dwm.c
  191. index 7298c5e..aee56d4 100644
  192. --- a/dwm.c
  193. +++ b/dwm.c
  194. @@ -1013,6 +1013,7 @@ keypress(XEvent *e)
  195. XGrabKey(dpy, AnyKey, AnyModifier, root, True, GrabModeAsync,
  196. GrabModeAsync);
  197. } else if (!current && keysym == keys[i].keysym
  198. + && keychain != -1
  199. && keys[i].chain == keychain
  200. && keys[i].func)
  201. keys[i].func(&(keys[i].arg));
  202. --
  203. 2.28.0
  204. From 053e3a2b2ff87805a15f3fe2f82a7d8bf0ab9b7a Mon Sep 17 00:00:00 2001
  205. From: braunbearded <braunbearded1@gmail.com>
  206. Date: Wed, 29 Jul 2020 21:25:23 +0200
  207. Subject: [PATCH 4/4] listen for all keys inkl modifier after prefix
  208. ---
  209. dwm.c | 8 +++++---
  210. 1 file changed, 5 insertions(+), 3 deletions(-)
  211. diff --git a/dwm.c b/dwm.c
  212. index aee56d4..dea8f6a 100644
  213. --- a/dwm.c
  214. +++ b/dwm.c
  215. @@ -993,10 +993,11 @@ isuniquegeom(XineramaScreenInfo *unique, size_t n, XineramaScreenInfo *info)
  216. void
  217. keypress(XEvent *e)
  218. {
  219. - unsigned int i;
  220. + unsigned int i, j;
  221. KeySym keysym;
  222. XKeyEvent *ev;
  223. int current = 0;
  224. + unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask };
  225. ev = &e->xkey;
  226. keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
  227. @@ -1010,8 +1011,9 @@ keypress(XEvent *e)
  228. && keys[i].func) {
  229. current = 1;
  230. keychain = keysym;
  231. - XGrabKey(dpy, AnyKey, AnyModifier, root, True, GrabModeAsync,
  232. - GrabModeAsync);
  233. + for (j = 0; j < LENGTH(modifiers); j++)
  234. + XGrabKey(dpy, AnyKey, 0 | modifiers[j], root,
  235. + True, GrabModeAsync, GrabModeAsync);
  236. } else if (!current && keysym == keys[i].keysym
  237. && keychain != -1
  238. && keys[i].chain == keychain
  239. --
  240. 2.28.0