sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

commit dad1a50b00c4f435f8e94f8dd5fa903482106df4
parent 50cf550daa43729ec15b46e66d896fe73b24bf42
Author: Noah Osterholz <osterholznoah@gmail.com>
Date:   Fri,  6 Mar 2026 12:54:27 +0100

[dwm][patches][conditional & ifroot] Adding and marking obsolete

Added the conditional patch for conditionals in keymaps and
marked my other patch ifroot as obsolete as it is fully included
in conditional without sacrificing simplicity.

Diffstat:
Adwm.suckless.org/patches/conditional/dwm-conditional-6.8.diff | 88+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Adwm.suckless.org/patches/conditional/index.md | 17+++++++++++++++++
Mdwm.suckless.org/patches/ifroot/index.md | 1+
3 files changed, 106 insertions(+), 0 deletions(-)

diff --git a/dwm.suckless.org/patches/conditional/dwm-conditional-6.8.diff b/dwm.suckless.org/patches/conditional/dwm-conditional-6.8.diff @@ -0,0 +1,88 @@ +From e8b312c6e3035560a14789db1a7d47410b62a710 Mon Sep 17 00:00:00 2001 +From: Noah Osterholz <osterholznoah@gmail.com> +Date: Fri, 6 Mar 2026 11:32:03 +0100 +Subject: [PATCH] Adding conditional keybinding support. + +This patch adds the conditional function to change the behaviour +of a keymap depending on the return value of another function. +--- + config.def.h | 9 ++++++++- + dwm.c | 21 +++++++++++++++++++++ + 2 files changed, 29 insertions(+), 1 deletion(-) + +diff --git a/config.def.h b/config.def.h +index 81c3fc0..c1112c9 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -61,6 +61,13 @@ static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() + static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL }; + static const char *termcmd[] = { "st", NULL }; + ++/* condition functions */ ++static int ++isrootwindow(void) ++{ ++ return (selmon->sel == NULL); /* selmon->sel == NULL -> root window focused */ ++} ++ + static const Key keys[] = { + /* modifier key function argument */ + { MODKEY, XK_p, spawn, {.v = dmenucmd } }, +@@ -74,7 +81,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, conditional, {.v = &(CondFuncPtr){isrootwindow, 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 0a67103..a2dc2f1 100644 +--- a/dwm.c ++++ b/dwm.c +@@ -140,6 +140,14 @@ typedef struct { + int monitor; + } Rule; + ++typedef struct { ++ int (*condition)(void); ++ void (*func_true)(const Arg *arg); ++ void (*func_false)(const Arg *arg); ++ const Arg arg_true; ++ const Arg arg_false; ++} CondFuncPtr; ++ + /* function declarations */ + static void applyrules(Client *c); + static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact); +@@ -152,6 +160,7 @@ static void checkotherwm(void); + static void cleanup(void); + static void cleanupmon(Monitor *mon); + static void clientmessage(XEvent *e); ++static void conditional(const Arg *arg); + static void configure(Client *c); + static void configurenotify(XEvent *e); + static void configurerequest(XEvent *e); +@@ -977,6 +986,18 @@ grabkeys(void) + } + } + ++void ++conditional(const Arg *arg) ++{ ++ CondFuncPtr *conditional = (CondFuncPtr*)arg->v; ++ if (conditional->condition() && conditional->func_true != NULL) { ++ conditional->func_true(&(conditional->arg_true)); ++ return; ++ } else if (conditional->func_false != NULL) { ++ conditional->func_false(&(conditional->arg_false)); ++ } ++} ++ + void + incnmaster(const Arg *arg) + { +-- +2.53.0 + diff --git a/dwm.suckless.org/patches/conditional/index.md b/dwm.suckless.org/patches/conditional/index.md @@ -0,0 +1,17 @@ +ifroot +====== + +Description +----------- +Adds the `conditional` function to modify the behavior of keybindings based on a condition encoded as a function. +`conditional` takes three function pointers, namely `condition`, `func_true`, and `func_false`, along with arguments for the last two. +`func_true` is invoked when `conditional` returns true, otherwise `func_false` is invoked. +`NULL` can be passed as `func_true` or `func_false` and acts as a no-op. + +Download +-------- +* [dwm-conditional-6.8.diff](dwm-conditional-6.8.diff) + +Authors +------- +* Noah Osterholz - <osterholznoah@gmail.com> diff --git a/dwm.suckless.org/patches/ifroot/index.md b/dwm.suckless.org/patches/ifroot/index.md @@ -7,6 +7,7 @@ Adds the `ifroot` function, which allows assigning two actions to a single keybi The first action is executed when no client is focused, and the second when a client is focused. This is mainly intended for using the same keybinding to close windows, quit dwm, or open the power menu. +This patch is obsolete, use `conditional` instead. Download --------