diff --git a/config.def.h b/config.def.h index 061ad66..5dc6bb4 100644 --- a/config.def.h +++ b/config.def.h @@ -84,6 +84,10 @@ static const Key keys[] = { { MODKEY, XK_period, focusmon, {.i = +1 } }, { MODKEY|ShiftMask, XK_comma, 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_2, 1) TAGKEYS( XK_3, 2) diff --git a/config.h b/config.h index b46e538..14d67e2 100644 --- a/config.h +++ b/config.h @@ -63,41 +63,45 @@ static const char *browsercmd[] = { "qutebrowser", NULL }; static const char *termcmd[] = { "kitty", NULL }; static Key keys[] = { - /* modifier key function argument */ - { MODKEY, XK_p, spawn, {.v = dmenucmd } }, - { MODKEY, XK_q, spawn, {.v = browsercmd } }, - { MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } }, - { MODKEY, XK_b, togglebar, {0} }, - { MODKEY, XK_j, focusstack, {.i = +1 } }, - { MODKEY, XK_k, focusstack, {.i = -1 } }, - { MODKEY, XK_i, incnmaster, {.i = +1 } }, - { MODKEY, XK_d, incnmaster, {.i = -1 } }, - { MODKEY, XK_h, setmfact, {.f = -0.02} }, - { MODKEY, XK_l, setmfact, {.f = +0.02} }, - { MODKEY, XK_Return, zoom, {0} }, - { MODKEY, XK_Tab, view, {0} }, - { MODKEY, XK_w, killclient, {0} }, - { MODKEY, XK_t, setlayout, {.v = &layouts[0]} }, - { MODKEY, XK_f, setlayout, {.v = &layouts[1]} }, - { MODKEY, XK_m, setlayout, {.v = &layouts[2]} }, - { MODKEY, XK_space, setlayout, {0} }, - { MODKEY|ShiftMask, XK_space, togglefloating, {0} }, - { MODKEY, XK_0, view, {.ui = ~0 } }, - { MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } }, - { MODKEY, XK_comma, focusmon, {.i = -1 } }, - { MODKEY, XK_period, focusmon, {.i = +1 } }, - { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } }, - { MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } }, - TAGKEYS( XK_1, 0) - TAGKEYS( XK_2, 1) - TAGKEYS( XK_3, 2) - TAGKEYS( XK_4, 3) - TAGKEYS( XK_5, 4) - TAGKEYS( XK_6, 5) - TAGKEYS( XK_7, 6) - TAGKEYS( XK_8, 7) - TAGKEYS( XK_9, 8) - { MODKEY|ShiftMask, XK_grave, quit, {0} }, + /* modifier key function argument */ + { MODKEY, XK_p, spawn, {.v = dmenucmd } }, + { MODKEY, XK_q, spawn, {.v = browsercmd } }, + { MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } }, + { MODKEY, XK_b, togglebar, {0} }, + { MODKEY, XK_j, focusstack, {.i = +1 } }, + { MODKEY, XK_k, focusstack, {.i = -1 } }, + { MODKEY, XK_i, incnmaster, {.i = +1 } }, + { MODKEY, XK_d, incnmaster, {.i = -1 } }, + { MODKEY, XK_h, setmfact, {.f = -0.02} }, + { MODKEY, XK_l, setmfact, {.f = +0.02} }, + { MODKEY, XK_Return, zoom, {0} }, + { MODKEY, XK_Tab, view, {0} }, + { MODKEY, XK_w, killclient, {0} }, + { MODKEY, XK_t, setlayout, {.v = &layouts[0]} }, + { MODKEY, XK_f, setlayout, {.v = &layouts[1]} }, + { MODKEY, XK_m, setlayout, {.v = &layouts[2]} }, + { MODKEY, XK_space, setlayout, {0} }, + { MODKEY|ShiftMask, XK_space, togglefloating, {0} }, + { MODKEY, XK_0, view, {.ui = ~0 } }, + { MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } }, + { MODKEY, XK_comma, focusmon, {.i = -1 } }, + { MODKEY, XK_period, focusmon, {.i = +1 } }, + { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } }, + { MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } }, + { MODKEY, XK_bracketright, viewnext, {0} }, + { MODKEY, XK_bracketleft, viewprev, {0} }, + { MODKEY|ShiftMask, XK_bracketright, tagtonext, {0} }, + { MODKEY|ShiftMask, XK_bracketleft, tagtoprev, {0} }, + TAGKEYS( XK_1, 0) + TAGKEYS( XK_2, 1) + TAGKEYS( XK_3, 2) + TAGKEYS( XK_4, 3) + TAGKEYS( XK_5, 4) + TAGKEYS( XK_6, 5) + TAGKEYS( XK_7, 6) + TAGKEYS( XK_8, 7) + TAGKEYS( XK_9, 8) + { MODKEY|ShiftMask, XK_grave, quit, {0} }, }; /* button definitions */ diff --git a/dwm.c b/dwm.c index e5efb6a..f078ffa 100644 --- a/dwm.c +++ b/dwm.c @@ -184,8 +184,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); @@ -209,6 +211,8 @@ static void sigchld(int unused); static void spawn(const Arg *arg); 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); @@ -228,6 +232,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 int xerror(Display *dpy, XErrorEvent *ee); @@ -1193,6 +1199,13 @@ movemouse(const Arg *arg) } } +unsigned int +nexttag(void) +{ + unsigned int seltag = selmon->tagset[selmon->seltags]; + return seltag == (1 << (LENGTH(tags) - 1)) ? 1 : seltag << 1; +} + Client * nexttiled(Client *c) { @@ -1209,6 +1222,13 @@ pop(Client *c) arrange(c->mon); } +unsigned int +prevtag(void) +{ + unsigned int seltag = selmon->tagset[selmon->seltags]; + return seltag == 1 ? (1 << (LENGTH(tags) - 1)) : seltag >> 1; +} + void propertynotify(XEvent *e) { @@ -1666,6 +1686,32 @@ tagmon(const Arg *arg) sendmon(selmon->sel, dirtomon(arg->i)); } +void +tagtonext(const Arg *arg) +{ + unsigned int tmp; + + if (selmon->sel == NULL) + return; + + tmp = nexttag(); + tag(&(const Arg){.ui = tmp }); + view(&(const Arg){.ui = tmp }); +} + +void +tagtoprev(const Arg *arg) +{ + unsigned int tmp; + + if (selmon->sel == NULL) + return; + + tmp = prevtag(); + tag(&(const Arg){.ui = tmp }); + view(&(const Arg){.ui = tmp }); +} + void tile(Monitor *m) { @@ -2044,6 +2090,18 @@ view(const Arg *arg) arrange(selmon); } +void +viewnext(const Arg *arg) +{ + view(&(const Arg){.ui = nexttag()}); +} + +void +viewprev(const Arg *arg) +{ + view(&(const Arg){.ui = prevtag()}); +} + Client * wintoclient(Window w) { diff --git a/patches/dwm-adjacenttag-6.2.diff b/patches/dwm-adjacenttag-6.2.diff new file mode 100644 index 0000000..6121f65 --- /dev/null +++ b/patches/dwm-adjacenttag-6.2.diff @@ -0,0 +1,126 @@ +diff -up a/config.def.h b/config.def.h +--- a/config.def.h 2021-10-02 13:57:18.011307099 +0100 ++++ b/config.def.h 2021-10-02 13:58:07.812080253 +0100 +@@ -84,6 +84,10 @@ static Key keys[] = { + { MODKEY, XK_period, focusmon, {.i = +1 } }, + { MODKEY|ShiftMask, XK_comma, 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_2, 1) + TAGKEYS( XK_3, 2) +diff -up a/dwm.c b/dwm.c +--- a/dwm.c 2021-10-02 13:57:18.011307099 +0100 ++++ b/dwm.c 2021-10-02 14:21:17.063622953 +0100 +@@ -183,8 +183,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 *); ++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); +@@ -208,6 +210,8 @@ static void sigchld(int unused); + static void spawn(const Arg *arg); + 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 *); + static void togglebar(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 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 int xerror(Display *dpy, XErrorEvent *ee); +@@ -1192,6 +1198,13 @@ movemouse(const Arg *arg) + } + } + ++unsigned int ++nexttag(void) ++{ ++ unsigned int seltag = selmon->tagset[selmon->seltags]; ++ return seltag == (1 << (LENGTH(tags) - 1)) ? 1 : seltag << 1; ++} ++ + Client * + nexttiled(Client *c) + { +@@ -1208,6 +1221,13 @@ pop(Client *c) + arrange(c->mon); + } + ++unsigned int ++prevtag(void) ++{ ++ unsigned int seltag = selmon->tagset[selmon->seltags]; ++ return seltag == 1 ? (1 << (LENGTH(tags) - 1)) : seltag >> 1; ++} ++ + void + propertynotify(XEvent *e) + { +@@ -1671,6 +1691,32 @@ tagmon(const Arg *arg) + } + + void ++tagtonext(const Arg *arg) ++{ ++ unsigned int tmp; ++ ++ if (selmon->sel == NULL) ++ return; ++ ++ tmp = nexttag(); ++ tag(&(const Arg){.ui = tmp }); ++ view(&(const Arg){.ui = tmp }); ++} ++ ++void ++tagtoprev(const Arg *arg) ++{ ++ unsigned int tmp; ++ ++ if (selmon->sel == NULL) ++ return; ++ ++ tmp = prevtag(); ++ tag(&(const Arg){.ui = tmp }); ++ view(&(const Arg){.ui = tmp }); ++} ++ ++void + tile(Monitor *m) + { + unsigned int i, n, h, mw, my, ty; +@@ -2044,6 +2090,18 @@ view(const Arg *arg) + arrange(selmon); + } + ++void ++viewnext(const Arg *arg) ++{ ++ view(&(const Arg){.ui = nexttag()}); ++} ++ ++void ++viewprev(const Arg *arg) ++{ ++ view(&(const Arg){.ui = prevtag()}); ++} ++ + Client * + wintoclient(Window w) + {