applied adjacenttag-spikvacant patch

This commit is contained in:
celso 2023-07-17 18:58:46 -03:00
parent 6dc040b178
commit f8dbf4fcb8
2 changed files with 97 additions and 0 deletions

View File

@ -85,6 +85,10 @@ static const Key keys[] = {
{ MODKEY, XK_period, focusmon, {.i = +1 } }, { MODKEY, XK_period, focusmon, {.i = +1 } },
{ MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } }, { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } },
{ MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } }, { MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } },
{ MODKEY, XK_Right, viewnext, {0} },
{ MODKEY, XK_Left, viewprev, {0} },
{ MODKEY|ShiftMask, XK_Right, tagtonext, {0} },
{ MODKEY|ShiftMask, XK_Left, tagtoprev, {0} },
TAGKEYS( XK_1, 0) TAGKEYS( XK_1, 0)
TAGKEYS( XK_2, 1) TAGKEYS( XK_2, 1)
TAGKEYS( XK_3, 2) TAGKEYS( XK_3, 2)

93
dwm.c
View File

@ -184,8 +184,10 @@ static void maprequest(XEvent *e);
static void monocle(Monitor *m); static void monocle(Monitor *m);
static void motionnotify(XEvent *e); static void motionnotify(XEvent *e);
static void movemouse(const Arg *arg); static void movemouse(const Arg *arg);
static unsigned int nexttag(void);
static Client *nexttiled(Client *c); static Client *nexttiled(Client *c);
static void pop(Client *c); static void pop(Client *c);
static unsigned int prevtag(void);
static void propertynotify(XEvent *e); static void propertynotify(XEvent *e);
static void quit(const Arg *arg); static void quit(const Arg *arg);
static Monitor *recttomon(int x, int y, int w, int h); static Monitor *recttomon(int x, int y, int w, int h);
@ -208,6 +210,8 @@ static void showhide(Client *c);
static void spawn(const Arg *arg); static void spawn(const Arg *arg);
static void tag(const Arg *arg); static void tag(const Arg *arg);
static void tagmon(const Arg *arg); static void tagmon(const Arg *arg);
static void tagtonext(const Arg *arg);
static void tagtoprev(const Arg *arg);
static void tile(Monitor *m); static void tile(Monitor *m);
static void togglebar(const Arg *arg); static void togglebar(const Arg *arg);
static void togglefloating(const Arg *arg); static void togglefloating(const Arg *arg);
@ -227,6 +231,8 @@ static void updatetitle(Client *c);
static void updatewindowtype(Client *c); static void updatewindowtype(Client *c);
static void updatewmhints(Client *c); static void updatewmhints(Client *c);
static void view(const Arg *arg); static void view(const Arg *arg);
static void viewnext(const Arg *arg);
static void viewprev(const Arg *arg);
static Client *wintoclient(Window w); static Client *wintoclient(Window w);
static Monitor *wintomon(Window w); static Monitor *wintomon(Window w);
static int xerror(Display *dpy, XErrorEvent *ee); static int xerror(Display *dpy, XErrorEvent *ee);
@ -1207,6 +1213,29 @@ movemouse(const Arg *arg)
} }
} }
unsigned int
nexttag(void)
{
unsigned int seltag = selmon->tagset[selmon->seltags];
unsigned int usedtags = 0;
Client *c = selmon->clients;
if (!c)
return seltag;
/* skip vacant tags */
do {
usedtags |= c->tags;
c = c->next;
} while (c);
do {
seltag = seltag == (1 << (LENGTH(tags) - 1)) ? 1 : seltag << 1;
} while (!(seltag & usedtags));
return seltag;
}
Client * Client *
nexttiled(Client *c) nexttiled(Client *c)
{ {
@ -1223,6 +1252,28 @@ pop(Client *c)
arrange(c->mon); arrange(c->mon);
} }
unsigned int
prevtag(void)
{
unsigned int seltag = selmon->tagset[selmon->seltags];
unsigned int usedtags = 0;
Client *c = selmon->clients;
if (!c)
return seltag;
/* skip vacant tags */
do {
usedtags |= c->tags;
c = c->next;
} while (c);
do {
seltag = seltag == 1 ? (1 << (LENGTH(tags) - 1)) : seltag >> 1;
} while (!(seltag & usedtags));
return seltag;
}
void void
propertynotify(XEvent *e) propertynotify(XEvent *e)
{ {
@ -1689,6 +1740,36 @@ tagmon(const Arg *arg)
sendmon(selmon->sel, dirtomon(arg->i)); sendmon(selmon->sel, dirtomon(arg->i));
} }
void
tagtonext(const Arg *arg)
{
unsigned int tmp;
if (selmon->sel == NULL)
return;
if ((tmp = nexttag()) == selmon->tagset[selmon->seltags])
return;
tag(&(const Arg){.ui = tmp });
view(&(const Arg){.ui = tmp });
}
void
tagtoprev(const Arg *arg)
{
unsigned int tmp;
if (selmon->sel == NULL)
return;
if ((tmp = prevtag()) == selmon->tagset[selmon->seltags])
return;
tag(&(const Arg){.ui = tmp });
view(&(const Arg){.ui = tmp });
}
void void
tile(Monitor *m) tile(Monitor *m)
{ {
@ -2067,6 +2148,18 @@ view(const Arg *arg)
arrange(selmon); arrange(selmon);
} }
void
viewnext(const Arg *arg)
{
view(&(const Arg){.ui = nexttag()});
}
void
viewprev(const Arg *arg)
{
view(&(const Arg){.ui = prevtag()});
}
Client * Client *
wintoclient(Window w) wintoclient(Window w)
{ {