Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Xresources shortcuts #122

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion config.def.h
Original file line number Diff line number Diff line change
Expand Up @@ -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} },
Expand All @@ -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" } },
};

/*
Expand Down
2 changes: 2 additions & 0 deletions st.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
10 changes: 9 additions & 1 deletion x.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ typedef struct {
uint mod;
KeySym keysym;
void (*func)(const Arg *);
const Arg arg;
Arg arg;
} Shortcut;

typedef struct {
Expand Down Expand Up @@ -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);
Expand Down
67 changes: 66 additions & 1 deletion xst.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down