From 162b8b56b94020b93fdb6d7ad606e2c10d499c3a Mon Sep 17 00:00:00 2001 From: neeasade Date: Sun, 5 Jul 2020 18:31:12 -0500 Subject: [PATCH 1/3] initial outline for xresources binding --- config.def.h | 3 +++ x.c | 7 ++++++ xst.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 77 insertions(+), 1 deletion(-) diff --git a/config.def.h b/config.def.h index 905b542..f1873e7 100644 --- a/config.def.h +++ b/config.def.h @@ -30,6 +30,9 @@ static unsigned int borderless = 0; /* allow infelicity between the weights: */ unsigned int max_bold_weight_infelicity = 20; +/* xresources shortcuts -- 100 picked arbitrarily */ +static Shortcut xres_shortcuts[100]; + static unsigned int borderpx = 2; /* diff --git a/x.c b/x.c index c527e54..7a928f2 100644 --- a/x.c +++ b/x.c @@ -1859,6 +1859,13 @@ kpress(XEvent *ev) } } + for (bp = xres_shortcuts; bp < xres_shortcuts + LEN(xres_shortcuts); bp++) { + if (ksym == bp->keysym && match(bp->mod, e->state)) { + 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 761f8a8..256009c 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); @@ -98,6 +99,71 @@ xrdb_load(void) XRESOURCE_LOAD_FLOAT("cwscale", cwscale); XRESOURCE_LOAD_FLOAT("chscale", chscale); + + /* note: unsure on speed here, rather than iterating each time, + might be worth it to query like a `st.enable_keybinds` or something + */ + + /* + 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[] = { + "bind_alt", + "bind_shift", + "bind_shift_alt", + "bind_ctrl_alt", + "bind_ctrl_shift", + }; + + const int bind_masks[] = { + 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); + + if(XrmGetResource(xrdb, loadValue, loadValue, &type, &ret)) + { + printf("foundshortcut: %s\n", loadValue); + printf("value: %s\n", ret.addr); + + /* todo: Shortcut instance -> xresarray */ + struct Shortcut bind; + + bind->mod = bind_masks[i]; + bind->keysym = letter; + bind->func = externalpipe; + bind->arg = (Arg){.v = "notify-send a"}; + /* {.i = 0}, */ + + xres_shortcuts[xres_shortcut_index++] = + /* mask keysym function argument */ + bind; + + } + } + + if (ret.addr != NULL && !strncmp("String", type, 64)) + colorname[i] = ret.addr; + } } XFlush(dpy); } From 581177e0c2eff3d5eb4eed2cd58eef26abf7a3af Mon Sep 17 00:00:00 2001 From: neeasade Date: Thu, 9 Jul 2020 13:49:45 -0500 Subject: [PATCH 2/3] iterate keybinds -- almost there --- config.def.h | 1 - x.c | 2 +- xst.c | 42 ++++++++++++++++++++---------------------- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/config.def.h b/config.def.h index 34a8d23..15074af 100644 --- a/config.def.h +++ b/config.def.h @@ -249,7 +249,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/x.c b/x.c index c49a3b4..3f3759f 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 { diff --git a/xst.c b/xst.c index 526efaf..5c25c8f 100644 --- a/xst.c +++ b/xst.c @@ -106,10 +106,6 @@ xrdb_load(void) XRESOURCE_LOAD_INTEGER("boxdraw_bold", boxdraw_bold); XRESOURCE_LOAD_INTEGER("boxdraw_braille", boxdraw_braille); - /* note: unsure on speed here, rather than iterating each time, - might be worth it to query like a `st.enable_keybinds` or something - */ - /* st.bind_alt_{a-z} st.bind_shift_{a-z} @@ -119,15 +115,15 @@ xrdb_load(void) all with optional suffix `_withcontent`, for */ - const char* bind_types[] = { - "bind_alt", - "bind_shift", - "bind_shift_alt", - "bind_ctrl_alt", - "bind_ctrl_shift", + const char* bind_types[5] = { + "alt", + "shift", + "shift_alt", + "ctrl_alt", + "ctrl_shift", }; - const int bind_masks[] = { + const int bind_masks[5] = { Mod1Mask, ShiftMask, (Mod1Mask|ShiftMask), @@ -145,25 +141,27 @@ xrdb_load(void) { 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("foundshortcut: %s\n", loadValue); + printf("found shortcut: %s\n", loadValue); printf("value: %s\n", ret.addr); - /* todo: Shortcut instance -> xresarray */ - struct Shortcut bind; + /* static char *command[] = { "/bin/sh", "-c", "notify-send heyy" }; */ + char *command[3] = { "/bin/sh", "-c", ret.addr}; - bind->mod = bind_masks[i]; - bind->keysym = letter; - bind->func = externalpipe; - bind->arg = (Arg){.v = "notify-send a"}; - /* {.i = 0}, */ + Arg bindarg = {.v = command}; - xres_shortcuts[xres_shortcut_index++] = - /* mask keysym function argument */ - bind; + /* Shortcut bind; */ + Shortcut bind = { + .mod = bind_masks[i], + .keysym = letter, + .func = externalpipe, + .arg = bindarg, + }; + xres_shortcuts[xres_shortcut_index++] = bind; } } From b39a910d2301c925d2b66fd70bb8586ad631da32 Mon Sep 17 00:00:00 2001 From: neeasade Date: Thu, 19 Nov 2020 16:42:59 -0600 Subject: [PATCH 3/3] keybinds update (logging) --- config.def.h | 8 +++++--- st.c | 2 ++ x.c | 1 + xst.c | 15 ++++++++------- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/config.def.h b/config.def.h index e706b61..04c85bc 100644 --- a/config.def.h +++ b/config.def.h @@ -32,9 +32,6 @@ static unsigned int borderless = 0; /* allow infelicity between the weights: */ unsigned int max_bold_weight_infelicity = 20; -/* xresources shortcuts -- 100 picked arbitrarily */ -static Shortcut xres_shortcuts[100]; - static unsigned int borderpx = 2; /* @@ -239,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} }, 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 79ec83a..0fe4032 100644 --- a/x.c +++ b/x.c @@ -1933,6 +1933,7 @@ 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; } diff --git a/xst.c b/xst.c index 5a445db..6b86266 100644 --- a/xst.c +++ b/xst.c @@ -150,25 +150,26 @@ xrdb_load(void) printf("found shortcut: %s\n", loadValue); printf("value: %s\n", ret.addr); - /* static char *command[] = { "/bin/sh", "-c", "notify-send heyy" }; */ - char *command[3] = { "/bin/sh", "-c", ret.addr}; + /* char *command[5] = { "/bin/sh", "-c", ret.addr, "externalpipe", NULL }; */ - Arg bindarg = {.v = command}; + /* 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 = bindarg, */ + .arg = {.v = (char *[]){ "/bin/sh", "-c", ret.addr, "externalpipe", NULL }} + /* .arg = {.v = command}, */ }; xres_shortcuts[xres_shortcut_index++] = bind; } } - - if (ret.addr != NULL && !strncmp("String", type, 64)) - colorname[i] = ret.addr; } } XFlush(dpy);