diff --git a/config.def.h b/config.def.h index 125d2e3..04c85bc 100644 --- a/config.def.h +++ b/config.def.h @@ -236,6 +236,11 @@ static MouseShortcut mshortcuts[] = { #define MODKEY Mod1Mask #define TERMMOD (ControlMask|ShiftMask) +/* xresources shortcuts -- 100 picked arbitrarily */ +static Shortcut xres_shortcuts[100]; + +/* static char* xres_shortcuts_commands[100][5] = {}; */ + static Shortcut shortcuts[] = { /* mask keysym function argument */ { XK_ANY_MOD, XK_Break, sendbreak, {.i = 0} }, @@ -252,7 +257,6 @@ static Shortcut shortcuts[] = { { TERMMOD, XK_Num_Lock, numlock, {.i = 0} }, { ShiftMask, XK_Page_Up, kscrollup, {.i = -1} }, { ShiftMask, XK_Page_Down, kscrolldown, {.i = -1} }, - { MODKEY, 'u', externalpipe, {.v = "xurls | eval dmenu $(dmenu_options) | xargs -r $BROWSER" } }, }; /* diff --git a/st.c b/st.c index df79b53..96aaf91 100644 --- a/st.c +++ b/st.c @@ -2031,6 +2031,8 @@ externalpipe(const Arg *arg) dup2(to[0], STDIN_FILENO); close(to[0]); close(to[1]); + + printf("I'm being called! %s ?\n", ((char **)arg->v)[0]); execvp(((char **)arg->v)[0], (char **)arg->v); fprintf(stderr, "st: execvp %s\n", ((char **)arg->v)[0]); perror("failed"); diff --git a/x.c b/x.c index 4dcb168..0fe4032 100644 --- a/x.c +++ b/x.c @@ -26,7 +26,7 @@ typedef struct { uint mod; KeySym keysym; void (*func)(const Arg *); - const Arg arg; + Arg arg; } Shortcut; typedef struct { @@ -1931,6 +1931,14 @@ kpress(XEvent *ev) } } + for (bp = xres_shortcuts; bp < xres_shortcuts + LEN(xres_shortcuts); bp++) { + if (ksym == bp->keysym && match(bp->mod, e->state)) { + printf("hit!\n"); + bp->func(&(bp->arg)); + return; + } + } + /* 2. custom keys from config.h */ if ((customkey = kmap(ksym, e->state))) { ttywrite(customkey, strlen(customkey), 1); diff --git a/xst.c b/xst.c index 277e874..6b86266 100644 --- a/xst.c +++ b/xst.c @@ -44,7 +44,8 @@ xrdb_load(void) /* handling colors here without macros to do via loop. */ int i = 0; - char loadValue[12] = ""; + /* this value is also used for keybinds */ + char loadValue[100] = ""; for (i = 0; i < 256; i++) { sprintf(loadValue, "%s%d", "st.color", i); @@ -106,6 +107,70 @@ xrdb_load(void) XRESOURCE_LOAD_INTEGER("boxdraw_braille", boxdraw_braille); XRESOURCE_LOAD_INTEGER("depth", opt_depth); + + /* + st.bind_alt_{a-z} + st.bind_shift_{a-z} + st.bind_shift_alt_{a-z} + st.bind_ctrl_alt_{a-z} + st.bind_ctrl_shift_{a-z} + all with optional suffix `_withcontent`, for + */ + + const char* bind_types[5] = { + "alt", + "shift", + "shift_alt", + "ctrl_alt", + "ctrl_shift", + }; + + const int bind_masks[5] = { + Mod1Mask, + ShiftMask, + (Mod1Mask|ShiftMask), + (ControlMask|Mod1Mask), + (ControlMask|ShiftMask), + }; + + + /* int i = 0; */ + int xres_shortcut_index = 0; + int j = 0; + for (i = 0; i < 5; i++) + { + for (j = 0; j < 26; j++) + { + char letter = 'a' + j; + sprintf(loadValue, "st.kb_%s_%c", bind_types[i], letter); + /* printf("checking: %s\n", loadValue); */ + + if(XrmGetResource(xrdb, loadValue, loadValue, &type, &ret)) + { + printf("found shortcut: %s\n", loadValue); + printf("value: %s\n", ret.addr); + + /* char *command[5] = { "/bin/sh", "-c", ret.addr, "externalpipe", NULL }; */ + + /* xres_shortcuts_commands[xres_shortcut_index] = command; */ + /* { "/bin/sh", "-c", ret.addr, "externalpipe", NULL }; */ + /* Arg bindarg = {.v = command}; */ + /* Arg bindarg = {.v = xres_shortcuts_commands[xres_shortcut_index]}; */ + + /* Shortcut bind; */ + Shortcut bind = { + .mod = bind_masks[i], + .keysym = letter, + .func = externalpipe, + /* .arg = bindarg, */ + .arg = {.v = (char *[]){ "/bin/sh", "-c", ret.addr, "externalpipe", NULL }} + /* .arg = {.v = command}, */ + }; + + xres_shortcuts[xres_shortcut_index++] = bind; + } + } + } } XFlush(dpy); }