From 7100c2c92ea694d3146517f7913e6b9a8c054788 Mon Sep 17 00:00:00 2001 From: Noah Osterholz Date: Wed, 8 Oct 2025 16:17:12 +0200 Subject: [PATCH] Adding the ifroot function to be able to assign one keymap to two functions depending on wether a client or the root window is focused. --- config.def.h | 2 +- dwm.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/config.def.h b/config.def.h index 81c3fc0..afc21ec 100644 --- a/config.def.h +++ b/config.def.h @@ -74,7 +74,7 @@ static const Key keys[] = { { MODKEY, XK_l, setmfact, {.f = +0.05} }, { MODKEY, XK_Return, zoom, {0} }, { MODKEY, XK_Tab, view, {0} }, - { MODKEY|ShiftMask, XK_c, killclient, {0} }, + { MODKEY|ShiftMask, XK_c, ifroot, {.v = &(TwoFuncPtr){quit, killclient, {0}, {0} } } }, { MODKEY, XK_t, setlayout, {.v = &layouts[0]} }, { MODKEY, XK_f, setlayout, {.v = &layouts[1]} }, { MODKEY, XK_m, setlayout, {.v = &layouts[2]} }, diff --git a/dwm.c b/dwm.c index 4f345ee..b144e90 100644 --- a/dwm.c +++ b/dwm.c @@ -140,6 +140,13 @@ typedef struct { int monitor; } Rule; +typedef struct { + void (*func1)(const Arg *arg); + void (*func2)(const Arg *arg); + const Arg arg1; + const Arg arg2; +} TwoFuncPtr; + /* function declarations */ static void applyrules(Client *c); static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact); @@ -174,6 +181,7 @@ static long getstate(Window w); static int gettextprop(Window w, Atom atom, char *text, unsigned int size); static void grabbuttons(Client *c, int focused); static void grabkeys(void); +static void ifroot(const Arg *arg); static void incnmaster(const Arg *arg); static void keypress(XEvent *e); static void killclient(const Arg *arg); @@ -976,6 +984,17 @@ grabkeys(void) } } +void +ifroot(const Arg *arg) +{ + TwoFuncPtr *funcs = (TwoFuncPtr*)arg->v; + if (!selmon->sel) { /*no client -> root window*/ + funcs->func1(&(funcs->arg1)); + return; + } /*client window*/ + funcs->func2(&(funcs->arg2)); +} + void incnmaster(const Arg *arg) { -- 2.51.0