From 954e60b735eb4084654d6473124d79cfa134a20b Mon Sep 17 00:00:00 2001 From: bakkeby Date: Wed, 18 Jan 2023 21:58:32 +0100 Subject: [PATCH] Adding proposed view history patch ref. #327 --- README.md | 7 +++++++ dwm.c | 23 +++++++++++++++++++++++ patches.def.h | 10 ++++++++++ 3 files changed, 40 insertions(+) diff --git a/README.md b/README.md index 24b0d6a..34a5f2b 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,8 @@ Browsing patches? There is a [map of patches](https://coggle.it/diagram/X9IiSSM6 ### Changelog: +2023-01-18 - Added the view history patch + 2022-10-08 - Added the alt-tab patch 2022-08-12 - Added the nametag patch @@ -802,6 +804,11 @@ Browsing patches? There is a [map of patches](https://coggle.it/diagram/X9IiSSM6 - adds configurable gaps between windows differentiating between outer, inner, horizontal and vertical gaps + - viewhistory + - adds a tag change history that is longer than the default current and previous tag + - `MOD`+Tab (`view(0)`) can be pressed multiple times to go further back to earlier tag + selections + - [viewontag](https://dwm.suckless.org/patches/viewontag/) - follow a window to the tag it is being moved to diff --git a/dwm.c b/dwm.c index bb6c169..91e0f2a 100644 --- a/dwm.c +++ b/dwm.c @@ -76,6 +76,7 @@ #define Button8 8 #define Button9 9 #define NUMTAGS 9 +#define NUMVIEWHIST NUMTAGS #define BARRULES 20 #if TAB_PATCH #define MAXTABS 50 @@ -487,7 +488,11 @@ struct Monitor { #endif // SETBORDERPX_PATCH unsigned int seltags; unsigned int sellt; + #if VIEW_HISTORY_PATCH + unsigned int tagset[NUMVIEWHIST]; + #else unsigned int tagset[2]; + #endif // VIEW_HISTORY_PATCH int showbar; #if TAB_PATCH int showtab; @@ -1595,7 +1600,12 @@ createmon(void) m = ecalloc(1, sizeof(Monitor)); #if !EMPTYVIEW_PATCH + #if VIEW_HISTORY_PATCH + for (i = 0; i < LENGTH(m->tagset); i++) + m->tagset[i] = 1; + #else m->tagset[0] = m->tagset[1] = 1; + #endif // VIEW_HISTORY_PATCH #endif // EMPTYVIEW_PATCH m->mfact = mfact; m->nmaster = nmaster; @@ -4905,7 +4915,20 @@ view(const Arg *arg) #if BAR_TAGPREVIEW_PATCH tagpreviewswitchtag(); #endif // BAR_TAGPREVIEW_PATCH + #if VIEW_HISTORY_PATCH + if (!arg->ui) { + selmon->seltags += 1; + if (selmon->seltags == LENGTH(selmon->tagset)) + selmon->seltags = 0; + } else { + if (selmon->seltags == 0) + selmon->seltags = LENGTH(selmon->tagset) - 1; + else + selmon->seltags -= 1; + } + #else selmon->seltags ^= 1; /* toggle sel tagset */ + #endif // VIEW_HISTORY_PATCH if (arg->ui & TAGMASK) selmon->tagset[selmon->seltags] = arg->ui & TAGMASK; #if PERTAG_PATCH diff --git a/patches.def.h b/patches.def.h index 1429aa0..43178e2 100644 --- a/patches.def.h +++ b/patches.def.h @@ -1311,6 +1311,16 @@ */ #define VANITYGAPS_MONOCLE_PATCH 0 +/* By default MOD+Tab will take the user back to the previous tag only. If the user keeps + * using MOD+Tab then the view will switch back and forth between the current and previous tag. + * This patch allows dwm to keep a longer history of previous tag changes such that MOD+Tab can + * be pressed multiple times to go further back to earlier tag selections. + * + * The number of history elements is defined by the NUMVIEWHIST macro in dwm.c and defaults to + * the number of tags in the system. + */ +#define VIEW_HISTORY_PATCH 0 + /* Follow a window to the tag it is being moved to. * https://dwm.suckless.org/patches/viewontag/ */