sites

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

dwm-adjacenttag-skipvacant-6.2.diff (4025B)


      1 diff -up a/config.def.h b/config.def.h
      2 --- a/config.def.h	2021-10-02 14:22:28.034782413 +0100
      3 +++ b/config.def.h	2021-10-02 14:22:28.044723532 +0100
      4 @@ -84,6 +84,10 @@ static Key keys[] = {
      5  	{ MODKEY,                       XK_period, focusmon,       {.i = +1 } },
      6  	{ MODKEY|ShiftMask,             XK_comma,  tagmon,         {.i = -1 } },
      7  	{ MODKEY|ShiftMask,             XK_period, tagmon,         {.i = +1 } },
      8 +	{ MODKEY,                       XK_Right,  viewnext,       {0} },
      9 +	{ MODKEY,                       XK_Left,   viewprev,       {0} },
     10 +	{ MODKEY|ShiftMask,             XK_Right,  tagtonext,      {0} },
     11 +	{ MODKEY|ShiftMask,             XK_Left,   tagtoprev,      {0} },
     12  	TAGKEYS(                        XK_1,                      0)
     13  	TAGKEYS(                        XK_2,                      1)
     14  	TAGKEYS(                        XK_3,                      2)
     15 diff -up a/dwm.c b/dwm.c
     16 --- a/dwm.c	2021-10-02 14:22:28.034782413 +0100
     17 +++ b/dwm.c	2021-10-02 14:27:54.599845767 +0100
     18 @@ -183,8 +183,10 @@ static void maprequest(XEvent *e);
     19  static void monocle(Monitor *m);
     20  static void motionnotify(XEvent *e);
     21  static void movemouse(const Arg *arg);
     22 +static unsigned int nexttag(void);
     23  static Client *nexttiled(Client *c);
     24  static void pop(Client *);
     25 +static unsigned int prevtag(void);
     26  static void propertynotify(XEvent *e);
     27  static void quit(const Arg *arg);
     28  static Monitor *recttomon(int x, int y, int w, int h);
     29 @@ -208,6 +210,8 @@ static void sigchld(int unused);
     30  static void spawn(const Arg *arg);
     31  static void tag(const Arg *arg);
     32  static void tagmon(const Arg *arg);
     33 +static void tagtonext(const Arg *arg);
     34 +static void tagtoprev(const Arg *arg);
     35  static void tile(Monitor *);
     36  static void togglebar(const Arg *arg);
     37  static void togglefloating(const Arg *arg);
     38 @@ -227,6 +231,8 @@ static void updatetitle(Client *c);
     39  static void updatewindowtype(Client *c);
     40  static void updatewmhints(Client *c);
     41  static void view(const Arg *arg);
     42 +static void viewnext(const Arg *arg);
     43 +static void viewprev(const Arg *arg);
     44  static Client *wintoclient(Window w);
     45  static Monitor *wintomon(Window w);
     46  static int xerror(Display *dpy, XErrorEvent *ee);
     47 @@ -1192,6 +1198,29 @@ movemouse(const Arg *arg)
     48  	}
     49  }
     50  
     51 +unsigned int
     52 +nexttag(void)
     53 +{
     54 +	unsigned int seltag = selmon->tagset[selmon->seltags];
     55 +	unsigned int usedtags = 0;
     56 +	Client *c = selmon->clients;
     57 +
     58 +	if (!c)
     59 +		return seltag;
     60 +
     61 +	/* skip vacant tags */
     62 +	do {
     63 +		usedtags |= c->tags;
     64 +		c = c->next;
     65 +	} while (c);
     66 +
     67 +	do {
     68 +		seltag = seltag == (1 << (LENGTH(tags) - 1)) ? 1 : seltag << 1;
     69 +	} while (!(seltag & usedtags));
     70 +
     71 +	return seltag;
     72 +}
     73 +
     74  Client *
     75  nexttiled(Client *c)
     76  {
     77 @@ -1208,6 +1237,28 @@ pop(Client *c)
     78  	arrange(c->mon);
     79  }
     80  
     81 +unsigned int
     82 +prevtag(void)
     83 +{
     84 +	unsigned int seltag = selmon->tagset[selmon->seltags];
     85 +	unsigned int usedtags = 0;
     86 +	Client *c = selmon->clients;
     87 +	if (!c)
     88 +		return seltag;
     89 +
     90 +	/* skip vacant tags */
     91 +	do {
     92 +		usedtags |= c->tags;
     93 +		c = c->next;
     94 +	} while (c);
     95 +
     96 +	do {
     97 +		seltag = seltag == 1 ? (1 << (LENGTH(tags) - 1)) : seltag >> 1;
     98 +	} while (!(seltag & usedtags));
     99 +
    100 +	return seltag;
    101 +}
    102 +
    103  void
    104  propertynotify(XEvent *e)
    105  {
    106 @@ -1671,6 +1722,36 @@ tagmon(const Arg *arg)
    107  }
    108  
    109  void
    110 +tagtonext(const Arg *arg)
    111 +{
    112 +	unsigned int tmp;
    113 +
    114 +	if (selmon->sel == NULL)
    115 +		return;
    116 +
    117 +	if ((tmp = nexttag()) == selmon->tagset[selmon->seltags])
    118 +		return;
    119 +
    120 +	tag(&(const Arg){.ui = tmp });
    121 +	view(&(const Arg){.ui = tmp });
    122 +}
    123 +
    124 +void
    125 +tagtoprev(const Arg *arg)
    126 +{
    127 +	unsigned int tmp;
    128 +
    129 +	if (selmon->sel == NULL)
    130 +		return;
    131 +
    132 +	if ((tmp = prevtag()) == selmon->tagset[selmon->seltags])
    133 +		return;
    134 +
    135 +	tag(&(const Arg){.ui = tmp });
    136 +	view(&(const Arg){.ui = tmp });
    137 +}
    138 +
    139 +void
    140  tile(Monitor *m)
    141  {
    142  	unsigned int i, n, h, mw, my, ty;
    143 @@ -2044,6 +2125,18 @@ view(const Arg *arg)
    144  	arrange(selmon);
    145  }
    146  
    147 +void
    148 +viewnext(const Arg *arg)
    149 +{
    150 +	view(&(const Arg){.ui = nexttag()});
    151 +}
    152 +
    153 +void
    154 +viewprev(const Arg *arg)
    155 +{
    156 +	view(&(const Arg){.ui = prevtag()});
    157 +}
    158 + 
    159  Client *
    160  wintoclient(Window w)
    161  {