You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
patches/dwm/dwm-switchtag-6.3.diff

134 lines
4.0 KiB
Diff

From 163533a11c3fed615ca4644ac9e279bc3a2ed5ed Mon Sep 17 00:00:00 2001
From: Bakkeby <bakkeby@gmail.com>
Date: Mon, 10 Jan 2022 13:45:08 +0100
Subject: [PATCH] Adding switchtag option for rules allowing auto-moving
dedicated tags for specific applications
dwm allow you to set application specific rules so that you can have your browser, for example,
start up on tag 9 optionally on a given monitor.
When you open your browser it is then automatically moved to the configured tag, but you have
to manually enable the tag to see the newly opened application.
This patch adds an extra configuration option for individual rules where:
- 0 is default behaviour
- 1 automatically moves you to the tag of the newly opened application and
- 2 enables the tag of the newly opened application in addition to your existing enabled tags
- 3 as 1, but closing that window reverts the view back to what it was previously (*)
- 4 as 2, but closing that window reverts the view back to what it was previously (*)
(*) except if the client has been moved between tags or to another monitor
---
config.def.h | 6 +++---
dwm.c | 30 +++++++++++++++++++++++++++++-
2 files changed, 32 insertions(+), 4 deletions(-)
diff --git a/config.def.h b/config.def.h
index a2ac963..9287921 100644
--- a/config.def.h
+++ b/config.def.h
@@ -26,9 +26,9 @@ static const Rule rules[] = {
* WM_CLASS(STRING) = instance, class
* WM_NAME(STRING) = title
*/
- /* class instance title tags mask isfloating monitor */
- { "Gimp", NULL, NULL, 0, 1, -1 },
- { "Firefox", NULL, NULL, 1 << 8, 0, -1 },
+ /* class instance title tags mask switchtag isfloating monitor */
+ { "Gimp", NULL, NULL, 0, 1, 1, -1 },
+ { "Firefox", NULL, NULL, 1 << 8, 1, 0, -1 },
};
/* layout(s) */
diff --git a/dwm.c b/dwm.c
index a96f33c..216836f 100644
--- a/dwm.c
+++ b/dwm.c
@@ -92,6 +92,7 @@ struct Client {
int basew, baseh, incw, inch, maxw, maxh, minw, minh;
int bw, oldbw;
unsigned int tags;
+ unsigned int switchtag;
int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen;
Client *next;
Client *snext;
@@ -137,6 +138,7 @@ typedef struct {
const char *instance;
const char *title;
unsigned int tags;
+ int switchtag;
int isfloating;
int monitor;
} Rule;
@@ -280,7 +282,7 @@ void
applyrules(Client *c)
{
const char *class, *instance;
- unsigned int i;
+ unsigned int i, newtagset;
const Rule *r;
Monitor *m;
XClassHint ch = { NULL, NULL };
@@ -303,6 +305,25 @@ applyrules(Client *c)
for (m = mons; m && m->num != r->monitor; m = m->next);
if (m)
c->mon = m;
+
+ if (r->switchtag) {
+ selmon = c->mon;
+ if (r->switchtag == 2 || r->switchtag == 4)
+ newtagset = c->mon->tagset[c->mon->seltags] ^ c->tags;
+ else
+ newtagset = c->tags;
+
+ if (newtagset && !(c->tags & c->mon->tagset[c->mon->seltags])) {
+ if (r->switchtag == 3 || r->switchtag == 4)
+ c->switchtag = c->mon->tagset[c->mon->seltags];
+ if (r->switchtag == 1 || r->switchtag == 3)
+ view(&((Arg) { .ui = newtagset }));
+ else {
+ c->mon->tagset[c->mon->seltags] = newtagset;
+ arrange(c->mon);
+ }
+ }
+ }
}
}
if (ch.res_class)
@@ -1425,6 +1446,8 @@ sendmon(Client *c, Monitor *m)
attachstack(c);
focus(NULL);
arrange(NULL);
+ if (c->switchtag)
+ c->switchtag = 0;
}
void
@@ -1661,6 +1684,8 @@ tag(const Arg *arg)
{
if (selmon->sel && arg->ui & TAGMASK) {
selmon->sel->tags = arg->ui & TAGMASK;
+ if (selmon->sel->switchtag)
+ selmon->sel->switchtag = 0;
focus(NULL);
arrange(selmon);
}
@@ -1769,6 +1794,7 @@ void
unmanage(Client *c, int destroyed)
{
Monitor *m = c->mon;
+ unsigned int switchtag = c->switchtag;
XWindowChanges wc;
detach(c);
@@ -1788,6 +1814,8 @@ unmanage(Client *c, int destroyed)
focus(NULL);
updateclientlist();
arrange(m);
+ if (switchtag)
+ view(&((Arg) { .ui = switchtag }));
}
void
--
2.19.1