sites

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

dwm-clkanywhere-20260122-a9aa0d8.diff (4244B)


      1 From ce289911cbbb48ce3900e434ac4d1f5a3fa35400 Mon Sep 17 00:00:00 2001
      2 From: jameel-sawafta <jameelhsawafta@gmail.com>
      3 Date: Thu, 22 Jan 2026 15:47:37 +0200
      4 Subject: [PATCH] dwm: add ClkAnywhere and viewnext/viewprev for cyclic tag
      5  navigation
      6 
      7 ---
      8  config.def.h |  8 +++++++-
      9  dwm.c        | 35 ++++++++++++++++++++++++++++++++---
     10  2 files changed, 39 insertions(+), 4 deletions(-)
     11 
     12 diff --git a/config.def.h b/config.def.h
     13 index 81c3fc0..8c850be 100644
     14 --- a/config.def.h
     15 +++ b/config.def.h
     16 @@ -1,5 +1,9 @@
     17  /* See LICENSE file for copyright and license details. */
     18  
     19 +/* mouse buttons */
     20 +#define Button8 8
     21 +#define Button9 9
     22 +
     23  /* appearance */
     24  static const unsigned int borderpx  = 1;        /* border pixel of windows */
     25  static const unsigned int snap      = 32;       /* snap pixel */
     26 @@ -99,7 +103,7 @@ static const Key keys[] = {
     27  };
     28  
     29  /* button definitions */
     30 -/* click can be ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, or ClkRootWin */
     31 +/* click can be ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, ClkRootWin, or ClkAnywhere */
     32  static const Button buttons[] = {
     33  	/* click                event mask      button          function        argument */
     34  	{ ClkLtSymbol,          0,              Button1,        setlayout,      {0} },
     35 @@ -113,5 +117,7 @@ static const Button buttons[] = {
     36  	{ ClkTagBar,            0,              Button3,        toggleview,     {0} },
     37  	{ ClkTagBar,            MODKEY,         Button1,        tag,            {0} },
     38  	{ ClkTagBar,            MODKEY,         Button3,        toggletag,      {0} },
     39 +	{ ClkAnywhere,          MODKEY,         Button9,        viewnext,       {0} },
     40 +	{ ClkAnywhere,          MODKEY,         Button8,        viewprev,       {0} },
     41  };
     42  
     43 diff --git a/dwm.c b/dwm.c
     44 index 53b393e..3ed105f 100644
     45 --- a/dwm.c
     46 +++ b/dwm.c
     47 @@ -64,7 +64,7 @@ enum { NetSupported, NetWMName, NetWMState, NetWMCheck,
     48         NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */
     49  enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms */
     50  enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
     51 -       ClkClientWin, ClkRootWin, ClkLast }; /* clicks */
     52 +       ClkClientWin, ClkRootWin, ClkAnywhere, ClkLast }; /* clicks */
     53  
     54  typedef union {
     55  	int i;
     56 @@ -226,6 +226,8 @@ static void updatetitle(Client *c);
     57  static void updatewindowtype(Client *c);
     58  static void updatewmhints(Client *c);
     59  static void view(const Arg *arg);
     60 +static void viewnext(const Arg *arg);
     61 +static void viewprev(const Arg *arg);
     62  static Client *wintoclient(Window w);
     63  static Monitor *wintomon(Window w);
     64  static int xerror(Display *dpy, XErrorEvent *ee);
     65 @@ -451,7 +453,8 @@ buttonpress(XEvent *e)
     66  		click = ClkClientWin;
     67  	}
     68  	for (i = 0; i < LENGTH(buttons); i++)
     69 -		if (click == buttons[i].click && buttons[i].func && buttons[i].button == ev->button
     70 +		if ((click == buttons[i].click || buttons[i].click == ClkAnywhere)
     71 +		&& buttons[i].func && buttons[i].button == ev->button
     72  		&& CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state))
     73  			buttons[i].func(click == ClkTagBar && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg);
     74  }
     75 @@ -940,7 +943,7 @@ grabbuttons(Client *c, int focused)
     76  			XGrabButton(dpy, AnyButton, AnyModifier, c->win, False,
     77  				BUTTONMASK, GrabModeSync, GrabModeSync, None, None);
     78  		for (i = 0; i < LENGTH(buttons); i++)
     79 -			if (buttons[i].click == ClkClientWin)
     80 +			if (buttons[i].click == ClkClientWin || buttons[i].click == ClkAnywhere)
     81  				for (j = 0; j < LENGTH(modifiers); j++)
     82  					XGrabButton(dpy, buttons[i].button,
     83  						buttons[i].mask | modifiers[j],
     84 @@ -2062,6 +2065,32 @@ view(const Arg *arg)
     85  	arrange(selmon);
     86  }
     87  
     88 +void
     89 +viewnext(const Arg *arg)
     90 +{
     91 +	unsigned int i;
     92 +	unsigned int curtag = selmon->tagset[selmon->seltags] & TAGMASK;
     93 +
     94 +	for (i = 0; i < LENGTH(tags) && !(curtag & (1 << i)); i++);
     95 +	i = (i + 1) % LENGTH(tags);
     96 +
     97 +	Arg a = {.ui = 1 << i};
     98 +	view(&a);
     99 +}
    100 +
    101 +void
    102 +viewprev(const Arg *arg)
    103 +{
    104 +	unsigned int i;
    105 +	unsigned int curtag = selmon->tagset[selmon->seltags] & TAGMASK;
    106 +
    107 +	for (i = 0; i < LENGTH(tags) && !(curtag & (1 << i)); i++);
    108 +	i = (i == 0) ? LENGTH(tags) - 1 : i - 1;
    109 +
    110 +	Arg a = {.ui = 1 << i};
    111 +	view(&a);
    112 +}
    113 +
    114  Client *
    115  wintoclient(Window w)
    116  {
    117 -- 
    118 2.52.0
    119