From dd9c4443eb4e92a7087747f7987baf5feaa47b0a Mon Sep 17 00:00:00 2001 From: Saumit Dinesan Date: Fri, 7 Oct 2022 05:53:05 +0530 Subject: Applied adjacenttag-skipvacant patch --- dwm.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) (limited to 'dwm.c') diff --git a/dwm.c b/dwm.c index 6fc164f..72f3e89 100644 --- a/dwm.c +++ b/dwm.c @@ -235,8 +235,10 @@ static void maprequest(XEvent *e); static void monocle(Monitor *m); static void motionnotify(XEvent *e); static void movemouse(const Arg *arg); +static unsigned int nexttag(void); static Client *nexttiled(Client *c); static void pop(Client *c); +static unsigned int prevtag(void); static void propertynotify(XEvent *e); static void quit(const Arg *arg); static Monitor *recttomon(int x, int y, int w, int h); @@ -267,6 +269,8 @@ static void spawn(const Arg *arg); static Monitor *systraytomon(Monitor *m); static void tag(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 togglebar(const Arg *arg); static void togglefloating(const Arg *arg); @@ -290,6 +294,8 @@ static void updatetitle(Client *c); static void updatewindowtype(Client *c); static void updatewmhints(Client *c); static void view(const Arg *arg); +static void viewnext(const Arg *arg); +static void viewprev(const Arg *arg); static Client *wintoclient(Window w); static Monitor *wintomon(Window w); static Client *wintosystrayicon(Window w); @@ -1480,6 +1486,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 * nexttiled(Client *c) { @@ -1496,6 +1525,28 @@ pop(Client *c) 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 propertynotify(XEvent *e) { @@ -2046,6 +2097,36 @@ tagmon(const Arg *arg) 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 tile(Monitor *m) { @@ -2733,6 +2814,18 @@ swallowingclient(Window w) return NULL; } +void +viewnext(const Arg *arg) +{ + view(&(const Arg){.ui = nexttag()}); +} + +void +viewprev(const Arg *arg) +{ + view(&(const Arg){.ui = prevtag()}); +} + Client * wintoclient(Window w) { -- cgit v1.2.3