From e39b8f558d852bfd9deef2e4cacdacad681859db Mon Sep 17 00:00:00 2001 From: Joe Date: Fri, 27 Dec 2024 11:43:14 +0100 Subject: how fcking great --- config.def.h | 6 +++--- dwm.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 3 deletions(-) diff --git a/config.def.h b/config.def.h index 07ea5ec..ced1d3c 100644 --- a/config.def.h +++ b/config.def.h @@ -144,7 +144,7 @@ static const Layout layouts[] = { static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */ static const char *term_cmd[] = { "alacritty", NULL }; static const char *hardflip_cmd[] = { "alacritty", "-e", "hf", NULL }; -static const char *dmenucmd[] = { "dmenu_run", "-i", "-m", "0", NULL }; +static const char *dmenucmd[] = { "dmenu_run", "-i", NULL }; static const char *dmapps_cmd[] = { "/home/r_bousset/.local/bin/dmapps", NULL }; static const char *dmpc_cmd[] = { "/home/r_bousset/.local/bin/dmpc", NULL }; static const char *dmbookm_cmd[] = { "/home/r_bousset/.local/bin/dmbookm", NULL }; @@ -213,8 +213,8 @@ static const Key keys[] = { { MODKEY|ControlMask, XK_F9, spawn, {.v = dmkill_cmd } }, { MODKEY|ControlMask, XK_F10, spawn, {.v = dmscrot_cmd } }, { MODKEY|ControlMask, XK_F11, spawn, {.v = dmsearch_cmd } }, - { MODKEY|ControlMask, XK_F12, spawn, {.v = dmlog_cmd } }, - { MODKEY|ControlMask, XK_BackSpace, spawn, {.v = dmlog_cmd } }, + { MODKEY|ControlMask, XK_F12, dmenuspawn, {.v = dmlog_cmd } }, + { MODKEY|ControlMask, XK_BackSpace, dmenuspawn, {.v = dmlog_cmd } }, { MODKEY, XK_BackSpace, spawn, {.v = dmpc_cmd } }, { MODKEY|ControlMask, XK_p, spawn, {.v = dmpass_cmd } }, { MODKEY|ControlMask|ShiftMask, XK_p, spawn, {.v = dmpass_full_cmd } }, diff --git a/dwm.c b/dwm.c index ec5910d..c3c7d12 100644 --- a/dwm.c +++ b/dwm.c @@ -206,6 +206,7 @@ static void destroynotify(XEvent *e); static void detach(Client *c); static void detachstack(Client *c); static Monitor *dirtomon(int dir); +static void dmenuspawn(const Arg *arg); static void drawbar(Monitor *m); static void drawbars(void); static int drawstatusbar(Monitor *m, int bh, char* text); @@ -2661,6 +2662,64 @@ sigterm(int unused) quit(&a); } +void +dmenuspawn(const Arg *arg) +{ + unsigned int focused_tag; + int i, j; + struct sigaction sa; + char **cmd; + + cmd = malloc(8 * sizeof(char*)); + if (!cmd) + return; + + for (i = 0; i < 8 && ((char**)arg->v)[i] != NULL; i++) { + cmd[i] = strdup(((char**)arg->v)[i]); + if (!cmd[i]) { + for (j = 0; j < i; j++) { + free(cmd[j]); + } + free(cmd); + return; + } + } + focused_tag = selmon->tagset[selmon->seltags]; + for (j = 0; j < LENGTH(tags); j++) { + if (focused_tag & (1 << (j - 1))) { + break; + } + } + cmd[i] = strdup(tagsel[j - 1][1]); + if (!cmd[i]) { + for (j = 0; j < i; j++) { + free(cmd[j]); + } + free(cmd); + return; + } + cmd[i + 1] = NULL; + if (arg->v == dmenucmd) + dmenumon[0] = '0' + selmon->num; + if (fork() == 0) { + if (dpy) + close(ConnectionNumber(dpy)); + setsid(); + + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + sa.sa_handler = SIG_DFL; + sigaction(SIGCHLD, &sa, NULL); + + execvp(((char **)cmd)[0], (char **)cmd); + die("dwm: execvp '%s' failed:", ((char **)cmd)[0]); + } + for (i = 0; cmd[i] != NULL; i++) { + free(cmd[i]); + } + free(cmd); +} + void spawn(const Arg *arg) { -- cgit v1.2.3