dwm-rotatetags-6.2.diff (2448B)
1 From 7600ab7f23e732062ce5ff34a42ca0f1ce019702 Mon Sep 17 00:00:00 2001 2 From: Sam <tritoke@protonmail.com> 3 Date: Fri, 23 Jul 2021 18:38:03 +0100 4 Subject: [PATCH] Created rotatetags function, and keybinds. 5 6 - Added rotatetags function which rotates the tagset left / right the 7 given number of tags, including wrapping round the ends if necessary. 8 9 - Added keybinds for MOD + left and right arrows, moving the tagset left / 10 right respectively. 11 --- 12 config.def.h | 2 ++ 13 dwm.c | 28 ++++++++++++++++++++++++++++ 14 2 files changed, 30 insertions(+) 15 16 diff --git a/config.def.h b/config.def.h 17 index 1c0b587..2992431 100644 18 --- a/config.def.h 19 +++ b/config.def.h 20 @@ -84,6 +84,8 @@ static Key keys[] = { 21 { MODKEY, XK_period, focusmon, {.i = +1 } }, 22 { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } }, 23 { MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } }, 24 + { MODKEY, XK_Left, rotatetags, {.i = -1 } }, 25 + { MODKEY, XK_Right, rotatetags, {.i = +1 } }, 26 TAGKEYS( XK_1, 0) 27 TAGKEYS( XK_2, 1) 28 TAGKEYS( XK_3, 2) 29 diff --git a/dwm.c b/dwm.c 30 index 4465af1..768166e 100644 31 --- a/dwm.c 32 +++ b/dwm.c 33 @@ -192,6 +192,7 @@ static void resize(Client *c, int x, int y, int w, int h, int interact); 34 static void resizeclient(Client *c, int x, int y, int w, int h); 35 static void resizemouse(const Arg *arg); 36 static void restack(Monitor *m); 37 +static void rotatetags(const Arg *arg); 38 static void run(void); 39 static void scan(void); 40 static int sendevent(Client *c, Atom proto); 41 @@ -1369,6 +1370,33 @@ restack(Monitor *m) 42 while (XCheckMaskEvent(dpy, EnterWindowMask, &ev)); 43 } 44 45 +void 46 +rotatetags(const Arg *arg) 47 +{ 48 + const int rot = abs(arg->i); 49 + const unsigned int tagset = selmon->tagset[selmon->seltags]; 50 + unsigned int newtagset; 51 + 52 + /* check the direction of the shift */ 53 + if (arg->i < 0) { 54 + /* shift tags right */ 55 + newtagset = (tagset >> rot) | (tagset << (LENGTH(tags) - rot)); 56 + } else { 57 + /* shift tags left */ 58 + newtagset = (tagset << rot) | (tagset >> (LENGTH(tags) - rot)); 59 + } 60 + 61 + /* mask the tag bits */ 62 + newtagset &= TAGMASK; 63 + 64 + if (newtagset) { 65 + selmon->tagset[selmon->seltags] = newtagset; 66 + focus(NULL); 67 + arrange(selmon); 68 + } 69 +} 70 + 71 + 72 void 73 run(void) 74 { 75 -- 76 2.32.0 77