From 8cad102fd59463e8a2238845399dcaa1f759508c Mon Sep 17 00:00:00 2001 From: Ben Collerson Date: Tue, 2 Jan 2024 10:33:59 +1000 Subject: [PATCH 1/2] chainkeys --- config.def.h | 62 ++++++++++++++++++++++++++-------------------------- dwl.c | 22 ++++++++++++++++++- 2 files changed, 52 insertions(+), 32 deletions(-) diff --git a/config.def.h b/config.def.h index 9009517..f4b7b2a 100644 --- a/config.def.h +++ b/config.def.h @@ -105,10 +105,10 @@ static const enum libinput_config_tap_button_map button_map = LIBINPUT_CONFIG_TA #define MODKEY WLR_MODIFIER_ALT #define TAGKEYS(KEY,SKEY,TAG) \ - { MODKEY, KEY, view, {.ui = 1 << TAG} }, \ - { MODKEY|WLR_MODIFIER_CTRL, KEY, toggleview, {.ui = 1 << TAG} }, \ - { MODKEY|WLR_MODIFIER_SHIFT, SKEY, tag, {.ui = 1 << TAG} }, \ - { MODKEY|WLR_MODIFIER_CTRL|WLR_MODIFIER_SHIFT,SKEY,toggletag, {.ui = 1 << TAG} } + { MODKEY, -1, KEY, view, {.ui = 1 << TAG} }, \ + { MODKEY|WLR_MODIFIER_CTRL, -1, KEY, toggleview, {.ui = 1 << TAG} }, \ + { MODKEY|WLR_MODIFIER_SHIFT, -1, SKEY, tag, {.ui = 1 << TAG} }, \ + { MODKEY|WLR_MODIFIER_CTRL|WLR_MODIFIER_SHIFT,-1,SKEY,toggletag, {.ui = 1 << TAG} } /* helper for spawning shell commands in the pre dwm-5.0 fashion */ #define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } } @@ -119,30 +119,30 @@ static const char *menucmd[] = { "bemenu-run", NULL }; static const Key keys[] = { /* Note that Shift changes certain key codes: c -> C, 2 -> at, etc. */ - /* modifier key function argument */ - { MODKEY, XKB_KEY_p, spawn, {.v = menucmd} }, - { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_Return, spawn, {.v = termcmd} }, - { MODKEY, XKB_KEY_j, focusstack, {.i = +1} }, - { MODKEY, XKB_KEY_k, focusstack, {.i = -1} }, - { MODKEY, XKB_KEY_i, incnmaster, {.i = +1} }, - { MODKEY, XKB_KEY_d, incnmaster, {.i = -1} }, - { MODKEY, XKB_KEY_h, setmfact, {.f = -0.05f} }, - { MODKEY, XKB_KEY_l, setmfact, {.f = +0.05f} }, - { MODKEY, XKB_KEY_Return, zoom, {0} }, - { MODKEY, XKB_KEY_Tab, view, {0} }, - { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_C, killclient, {0} }, - { MODKEY, XKB_KEY_t, setlayout, {.v = &layouts[0]} }, - { MODKEY, XKB_KEY_f, setlayout, {.v = &layouts[1]} }, - { MODKEY, XKB_KEY_m, setlayout, {.v = &layouts[2]} }, - { MODKEY, XKB_KEY_space, setlayout, {0} }, - { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_space, togglefloating, {0} }, - { MODKEY, XKB_KEY_e, togglefullscreen, {0} }, - { MODKEY, XKB_KEY_0, view, {.ui = ~0} }, - { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_parenright, tag, {.ui = ~0} }, - { MODKEY, XKB_KEY_comma, focusmon, {.i = WLR_DIRECTION_LEFT} }, - { MODKEY, XKB_KEY_period, focusmon, {.i = WLR_DIRECTION_RIGHT} }, - { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_less, tagmon, {.i = WLR_DIRECTION_LEFT} }, - { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_greater, tagmon, {.i = WLR_DIRECTION_RIGHT} }, + /* modifier chain, key function argument */ + { MODKEY, -1, XKB_KEY_p, spawn, {.v = menucmd} }, + { MODKEY|WLR_MODIFIER_SHIFT, -1, XKB_KEY_Return, spawn, {.v = termcmd} }, + { MODKEY, -1, XKB_KEY_j, focusstack, {.i = +1} }, + { MODKEY, -1, XKB_KEY_k, focusstack, {.i = -1} }, + { MODKEY, -1, XKB_KEY_i, incnmaster, {.i = +1} }, + { MODKEY, -1, XKB_KEY_d, incnmaster, {.i = -1} }, + { MODKEY, -1, XKB_KEY_h, setmfact, {.f = -0.05} }, + { MODKEY, -1, XKB_KEY_l, setmfact, {.f = +0.05} }, + { MODKEY, -1, XKB_KEY_Return, zoom, {0} }, + { MODKEY, -1, XKB_KEY_Tab, view, {0} }, + { MODKEY|WLR_MODIFIER_SHIFT, -1, XKB_KEY_C, killclient, {0} }, + { MODKEY, -1, XKB_KEY_t, setlayout, {.v = &layouts[0]} }, + { MODKEY, -1, XKB_KEY_f, setlayout, {.v = &layouts[1]} }, + { MODKEY, -1, XKB_KEY_m, setlayout, {.v = &layouts[2]} }, + { MODKEY, -1, XKB_KEY_space, setlayout, {0} }, + { MODKEY|WLR_MODIFIER_SHIFT, -1, XKB_KEY_space, togglefloating, {0} }, + { MODKEY, -1, XKB_KEY_e, togglefullscreen, {0} }, + { MODKEY, -1, XKB_KEY_0, view, {.ui = ~0} }, + { MODKEY|WLR_MODIFIER_SHIFT, -1, XKB_KEY_parenright, tag, {.ui = ~0} }, + { MODKEY, -1, XKB_KEY_comma, focusmon, {.i = WLR_DIRECTION_LEFT} }, + { MODKEY, -1, XKB_KEY_period, focusmon, {.i = WLR_DIRECTION_RIGHT} }, + { MODKEY|WLR_MODIFIER_SHIFT, -1, XKB_KEY_less, tagmon, {.i = WLR_DIRECTION_LEFT} }, + { MODKEY|WLR_MODIFIER_SHIFT, -1, XKB_KEY_greater, tagmon, {.i = WLR_DIRECTION_RIGHT} }, TAGKEYS( XKB_KEY_1, XKB_KEY_exclam, 0), TAGKEYS( XKB_KEY_2, XKB_KEY_at, 1), TAGKEYS( XKB_KEY_3, XKB_KEY_numbersign, 2), @@ -152,14 +152,14 @@ static const Key keys[] = { TAGKEYS( XKB_KEY_7, XKB_KEY_ampersand, 6), TAGKEYS( XKB_KEY_8, XKB_KEY_asterisk, 7), TAGKEYS( XKB_KEY_9, XKB_KEY_parenleft, 8), - { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_Q, quit, {0} }, + { MODKEY|WLR_MODIFIER_SHIFT, -1, XKB_KEY_Q, quit, {0} }, /* Ctrl-Alt-Backspace and Ctrl-Alt-Fx used to be handled by X server */ - { WLR_MODIFIER_CTRL|WLR_MODIFIER_ALT,XKB_KEY_Terminate_Server, quit, {0} }, + { WLR_MODIFIER_CTRL|WLR_MODIFIER_ALT,-1,XKB_KEY_Terminate_Server, quit, {0} }, /* Ctrl-Alt-Fx is used to switch to another VT, if you don't know what a VT is * do not remove them. */ -#define CHVT(n) { WLR_MODIFIER_CTRL|WLR_MODIFIER_ALT,XKB_KEY_XF86Switch_VT_##n, chvt, {.ui = (n)} } +#define CHVT(n) { WLR_MODIFIER_CTRL|WLR_MODIFIER_ALT,-1,XKB_KEY_XF86Switch_VT_##n, chvt, {.ui = (n)} } CHVT(1), CHVT(2), CHVT(3), CHVT(4), CHVT(5), CHVT(6), CHVT(7), CHVT(8), CHVT(9), CHVT(10), CHVT(11), CHVT(12), }; diff --git a/dwl.c b/dwl.c index f25ac2f..8ffad73 100644 --- a/dwl.c +++ b/dwl.c @@ -139,6 +139,7 @@ typedef struct { typedef struct { uint32_t mod; + xkb_keysym_t chain; xkb_keysym_t keysym; void (*func)(const Arg *); const Arg arg; @@ -338,6 +339,7 @@ static const char broken[] = "broken"; static pid_t child_pid = -1; static int locked; static void *exclusive_focus; +static xkb_keysym_t chainkey = -1; static struct wl_display *dpy; static struct wlr_backend *backend; static struct wlr_scene *scene; @@ -1363,10 +1365,28 @@ keybinding(uint32_t mods, xkb_keysym_t sym) const Key *k; for (k = keys; k < END(keys); k++) { if (CLEANMASK(mods) == CLEANMASK(k->mod) - && sym == k->keysym && k->func) { + && sym == k->keysym + && chainkey == -1 + && k->chain == -1 + && k->func) { k->func(&k->arg); return 1; } + else if (sym == k->keysym + && chainkey != -1 + && k->chain == chainkey + && k->func) { + k->func(&k->arg); + chainkey = -1; + return 1; + } + else if (CLEANMASK(mods) == CLEANMASK(k->mod) + && k->chain == sym + && chainkey == -1 + && k->func) { + chainkey = sym; + return 1; + } } return 0; } -- 2.43.0 From 0b11cce166dc0daabe305622d593532407a178ed Mon Sep 17 00:00:00 2001 From: Ben Collerson Date: Tue, 2 Jan 2024 10:33:59 +1000 Subject: [PATCH 2/2] fix types - signed ints should be signed. --- config.def.h | 4 ++-- dwl.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/config.def.h b/config.def.h index f4b7b2a..ac70906 100644 --- a/config.def.h +++ b/config.def.h @@ -126,8 +126,8 @@ static const Key keys[] = { { MODKEY, -1, XKB_KEY_k, focusstack, {.i = -1} }, { MODKEY, -1, XKB_KEY_i, incnmaster, {.i = +1} }, { MODKEY, -1, XKB_KEY_d, incnmaster, {.i = -1} }, - { MODKEY, -1, XKB_KEY_h, setmfact, {.f = -0.05} }, - { MODKEY, -1, XKB_KEY_l, setmfact, {.f = +0.05} }, + { MODKEY, -1, XKB_KEY_h, setmfact, {.f = -0.05f} }, + { MODKEY, -1, XKB_KEY_l, setmfact, {.f = +0.05f} }, { MODKEY, -1, XKB_KEY_Return, zoom, {0} }, { MODKEY, -1, XKB_KEY_Tab, view, {0} }, { MODKEY|WLR_MODIFIER_SHIFT, -1, XKB_KEY_C, killclient, {0} }, diff --git a/dwl.c b/dwl.c index 8ffad73..cbb9cbf 100644 --- a/dwl.c +++ b/dwl.c @@ -139,7 +139,7 @@ typedef struct { typedef struct { uint32_t mod; - xkb_keysym_t chain; + int chain; xkb_keysym_t keysym; void (*func)(const Arg *); const Arg arg; @@ -339,7 +339,7 @@ static const char broken[] = "broken"; static pid_t child_pid = -1; static int locked; static void *exclusive_focus; -static xkb_keysym_t chainkey = -1; +static int chainkey = -1; static struct wl_display *dpy; static struct wlr_backend *backend; static struct wlr_scene *scene; @@ -1381,7 +1381,7 @@ keybinding(uint32_t mods, xkb_keysym_t sym) return 1; } else if (CLEANMASK(mods) == CLEANMASK(k->mod) - && k->chain == sym + && k->chain == (int)sym && chainkey == -1 && k->func) { chainkey = sym; -- 2.43.0