diff --git a/config.def.h b/config.def.h index 5d3a7e8..31fc2eb 100644 --- a/config.def.h +++ b/config.def.h @@ -59,11 +59,11 @@ static const Layout layouts[] = { /* key definitions */ #define MODKEY Mod4Mask -#define TAGKEYS(KEY,TAG) \ - { MODKEY, KEY, view, {.ui = 1 << TAG} }, \ - { MODKEY|ControlMask, KEY, toggleview, {.ui = 1 << TAG} }, \ - { MODKEY|ShiftMask, KEY, tag, {.ui = 1 << TAG} }, \ - { MODKEY|ControlMask|ShiftMask, KEY, toggletag, {.ui = 1 << TAG} }, +#define TAGKEYS(KEY,TAG) \ + &((Keychord){1, {{MODKEY, KEY}}, view, {.ui = 1 << TAG} }), \ + &((Keychord){1, {{MODKEY|ControlMask, KEY}}, toggleview, {.ui = 1 << TAG} }), \ + &((Keychord){1, {{MODKEY|ShiftMask, KEY}}, tag, {.ui = 1 << TAG} }), \ + &((Keychord){1, {{MODKEY|ControlMask|ShiftMask, KEY}}, 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 } } @@ -81,75 +81,76 @@ static const char *themecmd[] = { "lupan-set-theme", "toggle", NULL }; #include "exitdwm.c" #include "movestack.c" -static const Key keys[] = { - /* modifier key function argument */ - { MODKEY, XK_p, spawndmenu, {0} }, - { MODKEY, XK_u, shiftview, { .i = +1 } }, - { MODKEY|ShiftMask, XK_u, shifttag, { .i = +1 } }, - { MODKEY|ShiftMask, XK_y, shifttag, { .i = -1 } }, - { MODKEY, XK_y, shiftview, { .i = -1 } }, - { MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } }, - { MODKEY, XK_b, togglebar, {0} }, - { MODKEY, XK_j, focusstackvis, {.i = +1 } }, - { MODKEY, XK_k, focusstackvis, {.i = -1 } }, - { MODKEY|ControlMask, XK_j, focusstackhid, {.i = +1 } }, - { MODKEY|ControlMask, XK_k, focusstackhid, {.i = -1 } }, - { MODKEY, XK_i, incnmaster, {.i = +1 } }, - { MODKEY, XK_d, incnmaster, {.i = -1 } }, - { MODKEY, XK_h, setmfact, {.f = -0.05} }, - { MODKEY|ShiftMask, XK_h, shiftboth, { .i = -1 } }, - { MODKEY|ControlMask, XK_h, shiftswaptags, { .i = -1 } }, - { MODKEY|ControlMask, XK_l, shiftswaptags, { .i = +1 } }, - { MODKEY|ShiftMask, XK_l, shiftboth, { .i = +1 } }, - { MODKEY, XK_l, setmfact, {.f = +0.05} }, - { MODKEY|ShiftMask, XK_j, movestack, {.i = +1 } }, - { MODKEY|ShiftMask, XK_k, movestack, {.i = -1 } }, - { MODKEY, XK_Return, zoom, {0} }, - { MODKEY, XK_Tab, view, {0} }, - { MODKEY, XK_w, goback, {0} }, - { MODKEY|ShiftMask, XK_c, killclient, {0} }, - { MODKEY, XK_t, setlayout, {.v = &layouts[0]} }, - { MODKEY, XK_f, setlayout, {.v = &layouts[1]} }, - { MODKEY, XK_m, setlayout, {.v = &layouts[2]} }, - { MODKEY, XK_g, setlayout, {.v = &layouts[3]} }, - { MODKEY, XK_space, setlayout, {0} }, - { MODKEY|ShiftMask, XK_space, togglefloating, {0} }, - { MODKEY, XK_0, view, {.ui = ~0 } }, - { MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } }, - { MODKEY, XK_comma, focusmon, {.i = -1 } }, - { MODKEY, XK_period, focusmon, {.i = +1 } }, - { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } }, - { MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } }, - { MODKEY, XK_s, show, {0} }, - { MODKEY|ShiftMask, XK_s, showall, {0} }, - { MODKEY|ControlMask, XK_s, hide, {0} }, - TAGKEYS( XK_1, 0) - TAGKEYS( XK_2, 1) - TAGKEYS( XK_3, 2) - TAGKEYS( XK_4, 3) - TAGKEYS( XK_5, 4) - TAGKEYS( XK_6, 5) - TAGKEYS( XK_7, 6) - TAGKEYS( XK_8, 7) - TAGKEYS( XK_9, 8) - { ControlMask, XK_1, focusbynum, {.i = 0} }, - { ControlMask, XK_2, focusbynum, {.i = 1} }, - { ControlMask, XK_3, focusbynum, {.i = 2} }, - { ControlMask, XK_4, focusbynum, {.i = 3} }, - { ControlMask, XK_5, focusbynum, {.i = 4} }, - { ControlMask, XK_6, focusbynum, {.i = 5} }, - { ControlMask, XK_7, focusbynum, {.i = 6} }, - { ControlMask, XK_8, focusbynum, {.i = 7} }, - { ControlMask, XK_9, focusbynum, {.i = 8} }, - { MODKEY|ShiftMask, XK_q, quit, {0} }, - { MODKEY|ControlMask|ShiftMask, XK_q, quit, {1} }, - { MODKEY|ShiftMask, XK_e, exitdwm, {0} }, - { MODKEY, XK_o, winview, {0} }, - { MODKEY, XK_a, gridall, {} }, - { MODKEY, XK_r, winviewmono, {} }, - { MODKEY|ControlMask|ShiftMask, XK_s, spawn, {.v = suspendcmd } }, - { MODKEY|ControlMask|ShiftMask, XK_l, spawn, {.v = lockcmd } }, - { MODKEY|ControlMask|ShiftMask, XK_t, spawn, {.v = themecmd } }, +static Keychord *keychords[] = { + /* Keys function argument */ + &((Keychord){1, {{MODKEY, XK_p}}, spawndmenu, {0} }), + &((Keychord){1, {{MODKEY, XK_u}}, shiftview, { .i = +1 } }), + &((Keychord){1, {{MODKEY|ShiftMask, XK_u}}, shifttag, { .i = +1 } }), + &((Keychord){1, {{MODKEY|ShiftMask, XK_y}}, shifttag, { .i = -1 } }), + &((Keychord){1, {{MODKEY, XK_y}}, shiftview, { .i = -1 } }), + &((Keychord){1, {{MODKEY|ShiftMask, XK_Return}}, spawn, {.v = termcmd } }), + &((Keychord){2, {{MODKEY, XK_e}, {MODKEY, XK_e}}, spawn, {.v = termcmd } }), + &((Keychord){1, {{MODKEY, XK_b}}, togglebar, {0} }), + &((Keychord){1, {{MODKEY, XK_j}}, focusstackvis, {.i = +1 } }), + &((Keychord){1, {{MODKEY, XK_k}}, focusstackvis, {.i = -1 } }), + &((Keychord){1, {{MODKEY|ControlMask, XK_j}}, focusstackhid, {.i = +1 } }), + &((Keychord){1, {{MODKEY|ControlMask, XK_k}}, focusstackhid, {.i = -1 } }), + &((Keychord){1, {{MODKEY, XK_i}}, incnmaster, {.i = +1 } }), + &((Keychord){1, {{MODKEY, XK_d}}, incnmaster, {.i = -1 } }), + &((Keychord){1, {{MODKEY, XK_h}}, setmfact, {.f = -0.05} }), + &((Keychord){1, {{MODKEY|ShiftMask, XK_h}}, shiftboth, {.i = -1} }), + &((Keychord){1, {{MODKEY|ControlMask, XK_h}}, shiftswaptags, {.i = -1} }), + &((Keychord){1, {{MODKEY, XK_l}}, setmfact, {.f = +0.05} }), + &((Keychord){1, {{MODKEY|ControlMask, XK_l}}, shiftswaptags, { .i = +1 } }), + &((Keychord){1, {{MODKEY|ShiftMask, XK_l}}, shiftboth, { .i = +1 } }), + &((Keychord){1, {{MODKEY|ShiftMask, XK_j}}, movestack, {.i = +1 } }), + &((Keychord){1, {{MODKEY|ShiftMask, XK_k}}, movestack, {.i = -1 } }), + &((Keychord){1, {{MODKEY, XK_Return}}, zoom, {0} }), + &((Keychord){1, {{MODKEY, XK_Tab}}, view, {0} }), + &((Keychord){1, {{MODKEY, XK_w}}, goback, {0} }), + &((Keychord){1, {{MODKEY|ShiftMask, XK_c}}, killclient, {0} }), + &((Keychord){1, {{MODKEY, XK_t}}, setlayout, {.v = &layouts[0]} }), + &((Keychord){1, {{MODKEY, XK_f}}, setlayout, {.v = &layouts[1]} }), + &((Keychord){1, {{MODKEY, XK_m}}, setlayout, {.v = &layouts[2]} }), + &((Keychord){1, {{MODKEY, XK_g}}, setlayout, {.v = &layouts[3]} }), + &((Keychord){1, {{MODKEY, XK_space}}, setlayout, {0} }), + &((Keychord){1, {{MODKEY|ShiftMask, XK_space}}, togglefloating, {0} }), + &((Keychord){1, {{MODKEY, XK_0}}, view, {.ui = ~0 } }), + &((Keychord){1, {{MODKEY|ShiftMask, XK_0}}, tag, {.ui = ~0 } }), + &((Keychord){1, {{MODKEY, XK_comma}}, focusmon, {.i = -1 } }), + &((Keychord){1, {{MODKEY, XK_period}}, focusmon, {.i = +1 } }), + &((Keychord){1, {{MODKEY|ShiftMask, XK_comma}}, tagmon, {.i = -1 } }), + &((Keychord){1, {{MODKEY|ShiftMask, XK_period}}, tagmon, {.i = +1 } }), + &((Keychord){1, {{MODKEY, XK_s}}, show, {0} }), + &((Keychord){1, {{MODKEY|ShiftMask, XK_s}}, showall, {0} }), + &((Keychord){1, {{MODKEY|ControlMask, XK_s}}, hide, {0} }), + &((Keychord){1, {{MODKEY|ShiftMask, XK_q}}, quit, {0} }), + &((Keychord){1, {{MODKEY|ControlMask|ShiftMask, XK_q}}, quit, {1} }), + &((Keychord){1, {{MODKEY|ShiftMask, XK_e}}, exitdwm, {0} }), + &((Keychord){1, {{MODKEY, XK_o}}, winview, {0} }), + &((Keychord){1, {{MODKEY, XK_a}}, gridall, {0} }), + &((Keychord){1, {{MODKEY, XK_r}}, winviewmono, {0} }), + &((Keychord){1, {{MODKEY|ControlMask|ShiftMask, XK_s}}, spawn, {.v = suspendcmd } }), + &((Keychord){1, {{MODKEY|ControlMask|ShiftMask, XK_l}}, spawn, {.v = lockcmd } }), + &((Keychord){1, {{MODKEY|ControlMask|ShiftMask, XK_t}}, spawn, {.v = themecmd } }), + TAGKEYS( XK_1, 0) + TAGKEYS( XK_2, 1) + TAGKEYS( XK_3, 2) + TAGKEYS( XK_4, 3) + TAGKEYS( XK_5, 4) + TAGKEYS( XK_6, 5) + TAGKEYS( XK_7, 6) + TAGKEYS( XK_8, 7) + TAGKEYS( XK_9, 8) + &((Keychord){1, {{ ControlMask, XK_1}}, focusbynum, {.i = 0} }), + &((Keychord){1, {{ ControlMask, XK_2}}, focusbynum, {.i = 1} }), + &((Keychord){1, {{ ControlMask, XK_3}}, focusbynum, {.i = 2} }), + &((Keychord){1, {{ ControlMask, XK_4}}, focusbynum, {.i = 3} }), + &((Keychord){1, {{ ControlMask, XK_5}}, focusbynum, {.i = 4} }), + &((Keychord){1, {{ ControlMask, XK_6}}, focusbynum, {.i = 5} }), + &((Keychord){1, {{ ControlMask, XK_7}}, focusbynum, {.i = 6} }), + &((Keychord){1, {{ ControlMask, XK_8}}, focusbynum, {.i = 7} }), + &((Keychord){1, {{ ControlMask, XK_9}}, focusbynum, {.i = 8} }), }; /* button definitions */ diff --git a/config.h b/config.h index f8da20d..31fc2eb 100644 --- a/config.h +++ b/config.h @@ -7,8 +7,8 @@ static const unsigned int gappx = 2; /* gaps between windows */ static const unsigned int snap = 32; /* snap pixel */ static const int showbar = 1; /* 0 means no bar */ static const int topbar = 1; /* 0 means bottom bar */ -static const char *fonts[] = { "monospace:size=11" }; -static const char dmenufont[] = "monospace:size=11"; +static const char *fonts[] = { "monospace:size=10" }; +static const char dmenufont[] = "monospace:size=10"; static const char col_gray1[] = "#222222"; static const char col_gray2[] = "#444444"; static const char col_gray3[] = "#bbbbbb"; @@ -59,99 +59,98 @@ static const Layout layouts[] = { /* key definitions */ #define MODKEY Mod4Mask -#define TAGKEYS(KEY,TAG) \ - { MODKEY, KEY, view, {.ui = 1 << TAG} }, \ - { MODKEY|ControlMask, KEY, toggleview, {.ui = 1 << TAG} }, \ - { MODKEY|ShiftMask, KEY, tag, {.ui = 1 << TAG} }, \ - { MODKEY|ControlMask|ShiftMask, KEY, toggletag, {.ui = 1 << TAG} }, +#define TAGKEYS(KEY,TAG) \ + &((Keychord){1, {{MODKEY, KEY}}, view, {.ui = 1 << TAG} }), \ + &((Keychord){1, {{MODKEY|ControlMask, KEY}}, toggleview, {.ui = 1 << TAG} }), \ + &((Keychord){1, {{MODKEY|ShiftMask, KEY}}, tag, {.ui = 1 << TAG} }), \ + &((Keychord){1, {{MODKEY|ControlMask|ShiftMask, KEY}}, 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 } } /* commands */ -static char dmenumon[2] = "0"; /* component of dmenu{dark,light}, manipulated in spawndmenu() */ +static char dmenumon[8] = "0"; /* component of dmenu{dark,light}, manipulated in spawndmenu() */ static const char *dmenudark[] = { "dmenu_run", "-l", "10", "-m", dmenumon, "-i", "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL }; static const char *dmenulight[] = { "dmenu_run", "-l", "10", "-m", dmenumon, "-i", "-fn", dmenufont, "-nb", col_gray3, "-nf", col_gray1, "-sb", col_cyan, "-sf", col_gray4, NULL }; -static const char *termcmd[] = { "alacritty", NULL }; +static const char *termcmd[] = { "st", NULL }; static const char *lockcmd[] = { "slock", NULL }; static const char *suspendcmd[] = { "systemctl", "suspend", NULL }; static const char *themecmd[] = { "lupan-set-theme", "toggle", NULL }; -static const char *changeresulutioncmd[] = { "change-resolution", NULL }; #include "shift-tools.c" #include "exitdwm.c" #include "movestack.c" -static const Key keys[] = { - /* modifier key function argument */ - { MODKEY, XK_p, spawndmenu, {0} }, - { MODKEY, XK_u, shiftview, { .i = +1 } }, - { MODKEY|ShiftMask, XK_u, shifttag, { .i = +1 } }, - { MODKEY|ShiftMask, XK_y, shifttag, { .i = -1 } }, - { MODKEY, XK_y, shiftview, { .i = -1 } }, - { MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } }, - { MODKEY, XK_b, togglebar, {0} }, - { MODKEY, XK_j, focusstackvis, {.i = +1 } }, - { MODKEY, XK_k, focusstackvis, {.i = -1 } }, - { MODKEY|ControlMask, XK_j, focusstackhid, {.i = +1 } }, - { MODKEY|ControlMask, XK_k, focusstackhid, {.i = -1 } }, - { MODKEY, XK_i, incnmaster, {.i = +1 } }, - { MODKEY, XK_d, incnmaster, {.i = -1 } }, - { MODKEY, XK_h, setmfact, {.f = -0.05} }, - { MODKEY|ShiftMask, XK_h, shiftboth, { .i = -1 } }, - { MODKEY|ControlMask, XK_h, shiftswaptags, { .i = -1 } }, - { MODKEY|ControlMask, XK_l, shiftswaptags, { .i = +1 } }, - { MODKEY|ShiftMask, XK_l, shiftboth, { .i = +1 } }, - { MODKEY, XK_l, setmfact, {.f = +0.05} }, - { MODKEY|ShiftMask, XK_j, movestack, {.i = +1 } }, - { MODKEY|ShiftMask, XK_k, movestack, {.i = -1 } }, - { MODKEY, XK_Return, zoom, {0} }, - { MODKEY, XK_Tab, view, {0} }, - { MODKEY, XK_w, goback, {0} }, - { MODKEY|ShiftMask, XK_c, killclient, {0} }, - { MODKEY, XK_t, setlayout, {.v = &layouts[0]} }, - { MODKEY, XK_f, setlayout, {.v = &layouts[1]} }, - { MODKEY, XK_m, setlayout, {.v = &layouts[2]} }, - { MODKEY, XK_g, setlayout, {.v = &layouts[3]} }, - { MODKEY, XK_space, setlayout, {0} }, - { MODKEY|ShiftMask, XK_space, togglefloating, {0} }, - { MODKEY, XK_0, view, {.ui = ~0 } }, - { MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } }, - { MODKEY, XK_comma, focusmon, {.i = -1 } }, - { MODKEY, XK_period, focusmon, {.i = +1 } }, - { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } }, - { MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } }, - { MODKEY, XK_s, show, {0} }, - { MODKEY|ShiftMask, XK_s, showall, {0} }, - { MODKEY|ControlMask, XK_s, hide, {0} }, - TAGKEYS( XK_1, 0) - TAGKEYS( XK_2, 1) - TAGKEYS( XK_3, 2) - TAGKEYS( XK_4, 3) - TAGKEYS( XK_5, 4) - TAGKEYS( XK_6, 5) - TAGKEYS( XK_7, 6) - TAGKEYS( XK_8, 7) - TAGKEYS( XK_9, 8) - { ControlMask, XK_1, focusbynum, {.i = 0} }, - { ControlMask, XK_2, focusbynum, {.i = 1} }, - { ControlMask, XK_3, focusbynum, {.i = 2} }, - { ControlMask, XK_4, focusbynum, {.i = 3} }, - { ControlMask, XK_5, focusbynum, {.i = 4} }, - { ControlMask, XK_6, focusbynum, {.i = 5} }, - { ControlMask, XK_7, focusbynum, {.i = 6} }, - { ControlMask, XK_8, focusbynum, {.i = 7} }, - { ControlMask, XK_9, focusbynum, {.i = 8} }, - { MODKEY|ShiftMask, XK_q, quit, {0} }, - { MODKEY|ControlMask|ShiftMask, XK_q, quit, {1} }, - { MODKEY|ShiftMask, XK_e, exitdwm, {0} }, - { MODKEY, XK_o, winview, {0} }, - { MODKEY, XK_a, gridall, {} }, - { MODKEY, XK_r, winviewmono, {} }, - { MODKEY, XK_n, spawn, {.v = changeresulutioncmd } }, - { MODKEY|ControlMask|ShiftMask, XK_s, spawn, {.v = suspendcmd } }, - { MODKEY|ControlMask|ShiftMask, XK_l, spawn, {.v = lockcmd } }, - { MODKEY|ControlMask|ShiftMask, XK_t, spawn, {.v = themecmd } }, +static Keychord *keychords[] = { + /* Keys function argument */ + &((Keychord){1, {{MODKEY, XK_p}}, spawndmenu, {0} }), + &((Keychord){1, {{MODKEY, XK_u}}, shiftview, { .i = +1 } }), + &((Keychord){1, {{MODKEY|ShiftMask, XK_u}}, shifttag, { .i = +1 } }), + &((Keychord){1, {{MODKEY|ShiftMask, XK_y}}, shifttag, { .i = -1 } }), + &((Keychord){1, {{MODKEY, XK_y}}, shiftview, { .i = -1 } }), + &((Keychord){1, {{MODKEY|ShiftMask, XK_Return}}, spawn, {.v = termcmd } }), + &((Keychord){2, {{MODKEY, XK_e}, {MODKEY, XK_e}}, spawn, {.v = termcmd } }), + &((Keychord){1, {{MODKEY, XK_b}}, togglebar, {0} }), + &((Keychord){1, {{MODKEY, XK_j}}, focusstackvis, {.i = +1 } }), + &((Keychord){1, {{MODKEY, XK_k}}, focusstackvis, {.i = -1 } }), + &((Keychord){1, {{MODKEY|ControlMask, XK_j}}, focusstackhid, {.i = +1 } }), + &((Keychord){1, {{MODKEY|ControlMask, XK_k}}, focusstackhid, {.i = -1 } }), + &((Keychord){1, {{MODKEY, XK_i}}, incnmaster, {.i = +1 } }), + &((Keychord){1, {{MODKEY, XK_d}}, incnmaster, {.i = -1 } }), + &((Keychord){1, {{MODKEY, XK_h}}, setmfact, {.f = -0.05} }), + &((Keychord){1, {{MODKEY|ShiftMask, XK_h}}, shiftboth, {.i = -1} }), + &((Keychord){1, {{MODKEY|ControlMask, XK_h}}, shiftswaptags, {.i = -1} }), + &((Keychord){1, {{MODKEY, XK_l}}, setmfact, {.f = +0.05} }), + &((Keychord){1, {{MODKEY|ControlMask, XK_l}}, shiftswaptags, { .i = +1 } }), + &((Keychord){1, {{MODKEY|ShiftMask, XK_l}}, shiftboth, { .i = +1 } }), + &((Keychord){1, {{MODKEY|ShiftMask, XK_j}}, movestack, {.i = +1 } }), + &((Keychord){1, {{MODKEY|ShiftMask, XK_k}}, movestack, {.i = -1 } }), + &((Keychord){1, {{MODKEY, XK_Return}}, zoom, {0} }), + &((Keychord){1, {{MODKEY, XK_Tab}}, view, {0} }), + &((Keychord){1, {{MODKEY, XK_w}}, goback, {0} }), + &((Keychord){1, {{MODKEY|ShiftMask, XK_c}}, killclient, {0} }), + &((Keychord){1, {{MODKEY, XK_t}}, setlayout, {.v = &layouts[0]} }), + &((Keychord){1, {{MODKEY, XK_f}}, setlayout, {.v = &layouts[1]} }), + &((Keychord){1, {{MODKEY, XK_m}}, setlayout, {.v = &layouts[2]} }), + &((Keychord){1, {{MODKEY, XK_g}}, setlayout, {.v = &layouts[3]} }), + &((Keychord){1, {{MODKEY, XK_space}}, setlayout, {0} }), + &((Keychord){1, {{MODKEY|ShiftMask, XK_space}}, togglefloating, {0} }), + &((Keychord){1, {{MODKEY, XK_0}}, view, {.ui = ~0 } }), + &((Keychord){1, {{MODKEY|ShiftMask, XK_0}}, tag, {.ui = ~0 } }), + &((Keychord){1, {{MODKEY, XK_comma}}, focusmon, {.i = -1 } }), + &((Keychord){1, {{MODKEY, XK_period}}, focusmon, {.i = +1 } }), + &((Keychord){1, {{MODKEY|ShiftMask, XK_comma}}, tagmon, {.i = -1 } }), + &((Keychord){1, {{MODKEY|ShiftMask, XK_period}}, tagmon, {.i = +1 } }), + &((Keychord){1, {{MODKEY, XK_s}}, show, {0} }), + &((Keychord){1, {{MODKEY|ShiftMask, XK_s}}, showall, {0} }), + &((Keychord){1, {{MODKEY|ControlMask, XK_s}}, hide, {0} }), + &((Keychord){1, {{MODKEY|ShiftMask, XK_q}}, quit, {0} }), + &((Keychord){1, {{MODKEY|ControlMask|ShiftMask, XK_q}}, quit, {1} }), + &((Keychord){1, {{MODKEY|ShiftMask, XK_e}}, exitdwm, {0} }), + &((Keychord){1, {{MODKEY, XK_o}}, winview, {0} }), + &((Keychord){1, {{MODKEY, XK_a}}, gridall, {0} }), + &((Keychord){1, {{MODKEY, XK_r}}, winviewmono, {0} }), + &((Keychord){1, {{MODKEY|ControlMask|ShiftMask, XK_s}}, spawn, {.v = suspendcmd } }), + &((Keychord){1, {{MODKEY|ControlMask|ShiftMask, XK_l}}, spawn, {.v = lockcmd } }), + &((Keychord){1, {{MODKEY|ControlMask|ShiftMask, XK_t}}, spawn, {.v = themecmd } }), + TAGKEYS( XK_1, 0) + TAGKEYS( XK_2, 1) + TAGKEYS( XK_3, 2) + TAGKEYS( XK_4, 3) + TAGKEYS( XK_5, 4) + TAGKEYS( XK_6, 5) + TAGKEYS( XK_7, 6) + TAGKEYS( XK_8, 7) + TAGKEYS( XK_9, 8) + &((Keychord){1, {{ ControlMask, XK_1}}, focusbynum, {.i = 0} }), + &((Keychord){1, {{ ControlMask, XK_2}}, focusbynum, {.i = 1} }), + &((Keychord){1, {{ ControlMask, XK_3}}, focusbynum, {.i = 2} }), + &((Keychord){1, {{ ControlMask, XK_4}}, focusbynum, {.i = 3} }), + &((Keychord){1, {{ ControlMask, XK_5}}, focusbynum, {.i = 4} }), + &((Keychord){1, {{ ControlMask, XK_6}}, focusbynum, {.i = 5} }), + &((Keychord){1, {{ ControlMask, XK_7}}, focusbynum, {.i = 6} }), + &((Keychord){1, {{ ControlMask, XK_8}}, focusbynum, {.i = 7} }), + &((Keychord){1, {{ ControlMask, XK_9}}, focusbynum, {.i = 8} }), }; /* button definitions */ diff --git a/dwm.c b/dwm.c index 23a1b4a..8d7528a 100644 --- a/dwm.c +++ b/dwm.c @@ -102,9 +102,14 @@ struct Client { typedef struct { unsigned int mod; KeySym keysym; +} Key; + +typedef struct { + unsigned int n; + const Key keys[5]; void (*func)(const Arg *); const Arg arg; -} Key; +} Keychord; typedef struct { const char *symbol; @@ -294,6 +299,7 @@ static Monitor *mons, *selmon, *prevmon; static Window root, wmcheckwin; static const char **dmenucmd; static int colormodechanged; +unsigned int currentkey = 0; /* configuration, allows nested code to access above variables */ #include "config.h" @@ -1088,7 +1094,8 @@ grabkeys(void) { updatenumlockmask(); { - unsigned int i, j, k; + /* unsigned int i, j, k; */ + unsigned int i, c, k; unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask }; int start, end, skip; KeySym *syms; @@ -1098,15 +1105,18 @@ grabkeys(void) syms = XGetKeyboardMapping(dpy, start, end - start + 1, &skip); if (!syms) return; + for (k = start; k <= end; k++) - for (i = 0; i < LENGTH(keys); i++) + for (i = 0; i < LENGTH(keychords); i++) /* skip modifier codes, we do that ourselves */ - if (keys[i].keysym == syms[(k - start) * skip]) - for (j = 0; j < LENGTH(modifiers); j++) + if (keychords[i]->keys[currentkey].keysym == syms[(k - start) * skip]) + for (c = 0; c < LENGTH(modifiers); c++) XGrabKey(dpy, k, - keys[i].mod | modifiers[j], + keychords[i]->keys[currentkey].mod | modifiers[c], root, True, GrabModeAsync, GrabModeAsync); + if(currentkey > 0) + XGrabKey(dpy, XKeysymToKeycode(dpy, XK_Escape), AnyModifier, root, True, GrabModeAsync, GrabModeAsync); XFree(syms); } } @@ -1163,17 +1173,58 @@ isuniquegeom(XineramaScreenInfo *unique, size_t n, XineramaScreenInfo *info) void keypress(XEvent *e) { - unsigned int i; + /* unsigned int i; */ + XEvent event = *e; + unsigned int ran = 0; KeySym keysym; XKeyEvent *ev; - ev = &e->xkey; - keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0); - for (i = 0; i < LENGTH(keys); i++) - if (keysym == keys[i].keysym - && CLEANMASK(keys[i].mod) == CLEANMASK(ev->state) - && keys[i].func) - keys[i].func(&(keys[i].arg)); + Keychord *arr1[sizeof(keychords) / sizeof(Keychord*)]; + Keychord *arr2[sizeof(keychords) / sizeof(Keychord*)]; + memcpy(arr1, keychords, sizeof(keychords)); + Keychord **rpointer = arr1; + Keychord **wpointer = arr2; + + size_t r = sizeof(keychords)/ sizeof(Keychord*); + + while(1){ + ev = &event.xkey; + keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0); + size_t w = 0; + for (int i = 0; i < r; i++){ + if(keysym == (*(rpointer + i))->keys[currentkey].keysym + && CLEANMASK((*(rpointer + i))->keys[currentkey].mod) == CLEANMASK(ev->state) + && (*(rpointer + i))->func){ + if((*(rpointer + i))->n == currentkey +1){ + (*(rpointer + i))->func(&((*(rpointer + i))->arg)); + ran = 1; + }else{ + *(wpointer + w) = *(rpointer + i); + w++; + } + } + } + currentkey++; + if(w == 0 || ran == 1) + break; + grabkeys(); + /* Events arriving mid-chord must be dispatched, not dropped: + * discarding a ButtonPress that activated the GrabModeSync grab + * from grabbuttons() freezes pointer and keyboard permanently, + * since only buttonpress()'s XAllowEvents can release it. */ + while (running && !XNextEvent(dpy, &event)) { + if (event.type == KeyPress) + break; + if (handler[event.type]) + handler[event.type](&event); /* call handler */ + } + r = w; + Keychord **holder = rpointer; + rpointer = wpointer; + wpointer = holder; + } + currentkey = 0; + grabkeys(); } void