switchtag: adding more control over when views switch back to what they were previously

pull/19/head
bakkeby 4 years ago
parent a5640756dd
commit 007979adfc

@ -1,4 +1,4 @@
From 7a591391e5e1b9740ab71f69e3875c120240322e Mon Sep 17 00:00:00 2001
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
@ -12,10 +12,14 @@ 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 | 14 ++++++++++++++
2 files changed, 17 insertions(+), 3 deletions(-)
dwm.c | 30 +++++++++++++++++++++++++++++-
2 files changed, 32 insertions(+), 4 deletions(-)
diff --git a/config.def.h b/config.def.h
index 1c0b587..4ea7156 100644
@ -35,10 +39,18 @@ index 1c0b587..4ea7156 100644
/* layout(s) */
diff --git a/dwm.c b/dwm.c
index 4465af1..9e727fc 100644
index 4465af1..c7d1025 100644
--- a/dwm.c
+++ b/dwm.c
@@ -137,6 +137,7 @@ typedef struct {
@@ -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;
@ -46,26 +58,76 @@ index 4465af1..9e727fc 100644
int isfloating;
int monitor;
} Rule;
@@ -302,6 +303,19 @@ applyrules(Client *c)
@@ -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) {
+ unsigned int newtagset;
+ if (r->switchtag == 2)
+ 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->mon->tagset[c->mon->seltags] = newtagset;
+ arrange(c->mon);
+ 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

Loading…
Cancel
Save