dwm: Added the ifroot patch. - sites - public wiki contents of suckless.org
 (HTM) git clone git://git.suckless.org/sites
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
 (DIR) commit 06394d148d8346aad2e68fb971d1bcb9549f8d2d
 (DIR) parent 1975317cd073ab5fa02d8639bbc6e8333e785bff
 (HTM) Author: Noah Osterholz <osterholznoah@gmail.com>
       Date:   Wed,  8 Oct 2025 16:30:59 +0200
       
       dwm: Added the ifroot patch.
       
       Added a patch to dwm which makes it possible to assign two functions to one
       keymap.
       
       Diffstat:
         A dwm.suckless.org/patches/ifroot/dw… |      71 +++++++++++++++++++++++++++++++
         A dwm.suckless.org/patches/ifroot/in… |      16 ++++++++++++++++
       
       2 files changed, 87 insertions(+), 0 deletions(-)
       ---
 (DIR) diff --git a/dwm.suckless.org/patches/ifroot/dwm-ifroot-6.6.diff b/dwm.suckless.org/patches/ifroot/dwm-ifroot-6.6.diff
       @@ -0,0 +1,71 @@
       +From 7100c2c92ea694d3146517f7913e6b9a8c054788 Mon Sep 17 00:00:00 2001
       +From: Noah Osterholz <osterholznoah@gmail.com>
       +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
       +
 (DIR) diff --git a/dwm.suckless.org/patches/ifroot/index.md b/dwm.suckless.org/patches/ifroot/index.md
       @@ -0,0 +1,16 @@
       +ifroot
       +=============
       +
       +Description
       +-----------
       +Adds the ifroot function which can assign two functions to one keybind.
       +The first function passed to ifroot will be invoked if no client is focused, the second if there is one.
       +It is mainly intended to be used for using the same keybinding to close windows and quit dwm or open the power menu.
       +
       +Download
       +--------
       +* [dwm-ifroot-6.6.diff](dwm-ifroot-6.6.diff)
       +
       +Authors
       +-------
       +* Noah Osterholz - <osterholznoah@gmail.com>