sites

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

dwm-ifroot-6.6.diff (2343B)


      1 From 7100c2c92ea694d3146517f7913e6b9a8c054788 Mon Sep 17 00:00:00 2001
      2 From: Noah Osterholz <osterholznoah@gmail.com>
      3 Date: Wed, 8 Oct 2025 16:17:12 +0200
      4 Subject: [PATCH] Adding the ifroot function to be able to assign one keymap to
      5  two functions depending on wether a client or the root window is focused.
      6 
      7 ---
      8  config.def.h |  2 +-
      9  dwm.c        | 19 +++++++++++++++++++
     10  2 files changed, 20 insertions(+), 1 deletion(-)
     11 
     12 diff --git a/config.def.h b/config.def.h
     13 index 81c3fc0..afc21ec 100644
     14 --- a/config.def.h
     15 +++ b/config.def.h
     16 @@ -74,7 +74,7 @@ static const Key keys[] = {
     17  	{ MODKEY,                       XK_l,      setmfact,       {.f = +0.05} },
     18  	{ MODKEY,                       XK_Return, zoom,           {0} },
     19  	{ MODKEY,                       XK_Tab,    view,           {0} },
     20 -	{ MODKEY|ShiftMask,             XK_c,      killclient,     {0} },
     21 +	{ MODKEY|ShiftMask,             XK_c,      ifroot,         {.v = &(TwoFuncPtr){quit, killclient, {0}, {0} } } },
     22  	{ MODKEY,                       XK_t,      setlayout,      {.v = &layouts[0]} },
     23  	{ MODKEY,                       XK_f,      setlayout,      {.v = &layouts[1]} },
     24  	{ MODKEY,                       XK_m,      setlayout,      {.v = &layouts[2]} },
     25 diff --git a/dwm.c b/dwm.c
     26 index 4f345ee..b144e90 100644
     27 --- a/dwm.c
     28 +++ b/dwm.c
     29 @@ -140,6 +140,13 @@ typedef struct {
     30  	int monitor;
     31  } Rule;
     32  
     33 +typedef struct {
     34 +	void (*func1)(const Arg *arg);
     35 +	void (*func2)(const Arg *arg);
     36 +	const Arg arg1;
     37 +	const Arg arg2;
     38 +} TwoFuncPtr;
     39 +
     40  /* function declarations */
     41  static void applyrules(Client *c);
     42  static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact);
     43 @@ -174,6 +181,7 @@ static long getstate(Window w);
     44  static int gettextprop(Window w, Atom atom, char *text, unsigned int size);
     45  static void grabbuttons(Client *c, int focused);
     46  static void grabkeys(void);
     47 +static void ifroot(const Arg *arg);
     48  static void incnmaster(const Arg *arg);
     49  static void keypress(XEvent *e);
     50  static void killclient(const Arg *arg);
     51 @@ -976,6 +984,17 @@ grabkeys(void)
     52  	}
     53  }
     54  
     55 +void
     56 +ifroot(const Arg *arg)
     57 +{
     58 +	TwoFuncPtr *funcs = (TwoFuncPtr*)arg->v;
     59 +	if (!selmon->sel) { /*no client -> root window*/
     60 +		funcs->func1(&(funcs->arg1));
     61 +		return;
     62 +	} /*client window*/
     63 +	funcs->func2(&(funcs->arg2));
     64 +}
     65 +
     66  void
     67  incnmaster(const Arg *arg)
     68  {
     69 -- 
     70 2.51.0
     71