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.2.diff

134 lines
4.0 KiB
Diff

From d4e831126db7e64b55daf24b770a47f04416e2ca Mon Sep 17 00:00:00 2001
From: bakkeby <bakkeby@gmail.com>
Date: Tue, 7 Apr 2020 12:01:30 +0200
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 1c0b587..4ea7156 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 4465af1..c7d1025 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;
@@ -279,7 +281,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 };
@@ -302,6 +304,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)
@@ -1421,6 +1442,8 @@ sendmon(Client *c, Monitor *m)
attachstack(c);
focus(NULL);
arrange(NULL);
+ if (c->switchtag)
+ c->switchtag = 0;
}
void
@@ -1657,6 +1680,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);
}
@@ -1763,6 +1788,7 @@ void
unmanage(Client *c, int destroyed)
{
Monitor *m = c->mon;
+ unsigned int switchtag = c->switchtag;
XWindowChanges wc;
detach(c);
@@ -1782,6 +1808,8 @@ unmanage(Client *c, int destroyed)
focus(NULL);
updateclientlist();
arrange(m);
+ if (switchtag)
+ view(&((Arg) { .ui = switchtag }));
}
void
--
2.19.1