Skip to content

Commit ae67378

Browse files
Bagellllbakkeby
andauthored
Tag-Sync patch (for syncing tags across all monitors) (#219)
* Tag-Sync patch * Major compatibility updates * SWITCHTAG/TAGSYNC compatibility * tagsync: refactoring Co-authored-by: bakkeby <[email protected]>
1 parent 8f986a4 commit ae67378

File tree

10 files changed

+135
-109
lines changed

10 files changed

+135
-109
lines changed

config.def.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,6 @@ static const char dmenufont[] = "monospace:size=10";
133133

134134
static char c000000[] = "#000000"; // placeholder value
135135

136-
#if BAR_FLEXWINTITLE_PATCH
137-
#endif // BAR_FLEXWINTITLE_PATCH
138136
static char normfgcolor[] = "#bbbbbb";
139137
static char normbgcolor[] = "#222222";
140138
static char normbordercolor[] = "#444444";

dwm.c

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -923,8 +923,14 @@ applyrules(Client *c)
923923
view(&((Arg) { .ui = newtagset }));
924924
#endif // PERTAG_PATCH
925925
} else {
926+
#if TAGSYNC_PATCH
927+
for (m = mons; m; m = m->next)
928+
m->tagset[m->seltags] = newtagset;
929+
arrange(NULL);
930+
#else
926931
c->mon->tagset[c->mon->seltags] = newtagset;
927932
arrange(c->mon);
933+
#endif // TAGSYNC_PATCH
928934
}
929935
}
930936
}
@@ -4052,7 +4058,11 @@ toggletag(const Arg *arg)
40524058
void
40534059
toggleview(const Arg *arg)
40544060
{
4055-
unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK);
4061+
unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK);;
4062+
#if TAGSYNC_PATCH
4063+
Monitor *origselmon = selmon;
4064+
for (selmon = mons; selmon; selmon = selmon->next) {
4065+
#endif // TAGSYNC_PATCH
40564066
#if PERTAG_PATCH
40574067
int i;
40584068
#endif // PERTAG_PATCH
@@ -4123,11 +4133,25 @@ toggleview(const Arg *arg)
41234133
togglebar(NULL);
41244134
#endif // PERTAGBAR_PATCH
41254135
#endif // PERTAG_PATCH
4136+
#if !TAGSYNC_PATCH
41264137
focus(NULL);
41274138
arrange(selmon);
4139+
#endif // TAGSYNC_PATCH
41284140
#if !EMPTYVIEW_PATCH
41294141
}
41304142
#endif // EMPTYVIEW_PATCH
4143+
#if TAGSYNC_PATCH
4144+
}
4145+
selmon = origselmon;
4146+
#if !EMPTYVIEW_PATCH
4147+
if (newtagset) {
4148+
#endif // EMPTYVIEW_PATCH
4149+
focus(NULL);
4150+
arrange(NULL);
4151+
#if !EMPTYVIEW_PATCH
4152+
}
4153+
#endif // EMPTYVIEW_PATCH
4154+
#endif // TAGSYNC_PATCH
41314155
#if BAR_EWMHTAGS_PATCH
41324156
updatecurrentdesktop();
41334157
#endif // BAR_EWMHTAGS_PATCH
@@ -4685,6 +4709,10 @@ updatewmhints(Client *c)
46854709
void
46864710
view(const Arg *arg)
46874711
{
4712+
#if TAGSYNC_PATCH
4713+
Monitor *origselmon = selmon;
4714+
for (selmon = mons; selmon; selmon = selmon->next) {
4715+
#endif // TAGSYNC_PATCH
46884716
#if EMPTYVIEW_PATCH
46894717
if (arg->ui && (arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
46904718
#else
@@ -4699,18 +4727,20 @@ view(const Arg *arg)
46994727
selmon->seltags ^= 1; /* toggle sel tagset */
47004728
#if PERTAG_PATCH
47014729
pertagview(arg);
4702-
#if SWAPFOCUS_PATCH
4703-
Client *unmodified = selmon->pertag->prevclient[selmon->pertag->curtag];
4704-
#endif // SWAPFOCUS_PATCH
47054730
#else
47064731
if (arg->ui & TAGMASK)
47074732
selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
47084733
#endif // PERTAG_PATCH
4734+
#if TAGSYNC_PATCH
4735+
}
4736+
selmon = origselmon;
4737+
#endif // TAGSYNC_PATCH
47094738
focus(NULL);
4710-
#if SWAPFOCUS_PATCH && PERTAG_PATCH
4711-
selmon->pertag->prevclient[selmon->pertag->curtag] = unmodified;
4712-
#endif // SWAPFOCUS_PATCH
4739+
#if TAGSYNC_PATCH
4740+
arrange(NULL);
4741+
#else
47134742
arrange(selmon);
4743+
#endif // TAGSYNC_PATCH
47144744
#if BAR_EWMHTAGS_PATCH
47154745
updatecurrentdesktop();
47164746
#endif // BAR_EWMHTAGS_PATCH

patch/bar_ewmhtags.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,3 @@ updatecurrentdesktop(void)
5050
long data[] = { i };
5151
XChangeProperty(dpy, root, netatom[NetCurrentDesktop], XA_CARDINAL, 32, PropModeReplace, (unsigned char *)data, 1);
5252
}
53-

patch/combo.c

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,10 @@ combotag(const Arg *arg)
3030
void
3131
comboview(const Arg *arg)
3232
{
33-
unsigned newtags = arg->ui & TAGMASK;
3433
if (combo) {
35-
selmon->tagset[selmon->seltags] |= newtags;
34+
view(&((Arg) { .ui = selmon->tagset[selmon->seltags] | (arg->ui & TAGMASK) }));
3635
} else {
37-
selmon->seltags ^= 1; /*toggle tagset*/
3836
combo = 1;
39-
if (newtags) {
40-
#if PERTAG_PATCH
41-
pertagview(&((Arg) { .ui = newtags }));
42-
#else
43-
selmon->tagset[selmon->seltags] = newtags;
44-
#endif // PERTAG_PATCH
45-
}
37+
view(arg);
4638
}
47-
focus(NULL);
48-
arrange(selmon);
4939
}
50-

patch/distributetags.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,31 @@
11
void
22
distributetags(const Arg *arg)
33
{
4+
Client *c;
45
unsigned int ui = 1;
56
int i = 0;
6-
for (Client *c = selmon->clients; c; c = c->next) {
7+
8+
#if TAGSYNC_PATCH
9+
Monitor *origselmon = selmon;
10+
for (selmon = mons; selmon; selmon = selmon->next) {
11+
#endif // TAGSYNC_PATCH
12+
13+
for (c = selmon->clients; c; c = c->next) {
714
if (HIDDEN(c))
815
continue;
916
if (!(c->tags & TAGMASK))
1017
continue;
1118
c->tags = (ui << i) & TAGMASK;
1219
i = (i + 1) % NUMTAGS;
1320
}
21+
22+
#if TAGSYNC_PATCH
23+
}
24+
selmon = origselmon;
25+
focus(NULL);
26+
arrange(NULL);
27+
#else
1428
focus(NULL);
1529
arrange(selmon);
30+
#endif // TAGSYNC_PATCH
1631
}
17-

patch/focusadjacenttag.c

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,7 @@ viewtoleft(const Arg *arg)
2727
{
2828
if (__builtin_popcount(selmon->tagset[selmon->seltags] & TAGMASK) == 1
2929
&& selmon->tagset[selmon->seltags] > 1) {
30-
selmon->seltags ^= 1; /* toggle sel tagset */
31-
#if PERTAG_PATCH
32-
pertagview(&((Arg) { .ui = selmon->tagset[selmon->seltags ^ 1] >> 1 }));
33-
#else
34-
selmon->tagset[selmon->seltags] = selmon->tagset[selmon->seltags ^ 1] >> 1;
35-
#endif // pertagview
36-
focus(NULL);
37-
arrange(selmon);
38-
#if BAR_EWMHTAGS_PATCH
39-
updatecurrentdesktop();
40-
#endif // BAR_EWMHTAGS_PATCH
30+
view(&((Arg) { .ui = selmon->tagset[selmon->seltags] >> 1 }));
4131
}
4232
}
4333

@@ -46,17 +36,7 @@ viewtoright(const Arg *arg)
4636
{
4737
if (__builtin_popcount(selmon->tagset[selmon->seltags] & TAGMASK) == 1
4838
&& selmon->tagset[selmon->seltags] & (TAGMASK >> 1)) {
49-
selmon->seltags ^= 1; /* toggle sel tagset */
50-
#if PERTAG_PATCH
51-
pertagview(&((Arg) { .ui = selmon->tagset[selmon->seltags ^ 1] << 1 }));
52-
#else
53-
selmon->tagset[selmon->seltags] = selmon->tagset[selmon->seltags ^ 1] << 1;
54-
#endif // pertagview
55-
focus(NULL);
56-
arrange(selmon);
57-
#if BAR_EWMHTAGS_PATCH
58-
updatecurrentdesktop();
59-
#endif // BAR_EWMHTAGS_PATCH
39+
view(&((Arg) { .ui = selmon->tagset[selmon->seltags] << 1 }));
6040
}
6141
}
6242

@@ -67,17 +47,7 @@ tagandviewtoleft(const Arg *arg)
6747
&& __builtin_popcount(selmon->tagset[selmon->seltags] & TAGMASK) == 1
6848
&& selmon->tagset[selmon->seltags] > 1) {
6949
selmon->sel->tags >>= 1;
70-
selmon->seltags ^= 1; /* toggle sel tagset */
71-
#if PERTAG_PATCH
72-
pertagview(&((Arg) { .ui = selmon->tagset[selmon->seltags ^ 1] >> 1 }));
73-
#else
74-
selmon->tagset[selmon->seltags] = selmon->tagset[selmon->seltags ^ 1] >> 1;
75-
#endif // pertagview
76-
focus(selmon->sel);
77-
arrange(selmon);
78-
#if BAR_EWMHTAGS_PATCH
79-
updatecurrentdesktop();
80-
#endif // BAR_EWMHTAGS_PATCH
50+
view(&((Arg) { .ui = selmon->tagset[selmon->seltags] >> 1 }));
8151
}
8252
}
8353

@@ -88,17 +58,6 @@ tagandviewtoright(const Arg *arg)
8858
&& __builtin_popcount(selmon->tagset[selmon->seltags] & TAGMASK) == 1
8959
&& selmon->tagset[selmon->seltags] & (TAGMASK >> 1)) {
9060
selmon->sel->tags <<= 1;
91-
selmon->seltags ^= 1; /* toggle sel tagset */
92-
#if PERTAG_PATCH
93-
pertagview(&((Arg) { .ui = selmon->tagset[selmon->seltags ^ 1] << 1 }));
94-
#else
95-
selmon->tagset[selmon->seltags] = selmon->tagset[selmon->seltags ^ 1] << 1;
96-
#endif // pertagview
97-
focus(selmon->sel);
98-
arrange(selmon);
99-
#if BAR_EWMHTAGS_PATCH
100-
updatecurrentdesktop();
101-
#endif // BAR_EWMHTAGS_PATCH
61+
view(&((Arg) { .ui = selmon->tagset[selmon->seltags] << 1 }));
10262
}
10363
}
104-

patch/reorganizetags.c

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,42 @@
11
void
22
reorganizetags(const Arg *arg)
33
{
4-
Client *c;
5-
unsigned int occ, unocc, i;
6-
unsigned int tagdest[NUMTAGS];
4+
Client *c;
5+
unsigned int occ, unocc, i;
6+
unsigned int tagdest[NUMTAGS];
77

8-
occ = 0;
9-
for (c = selmon->clients; c; c = c->next)
10-
occ |= (1 << (ffs(c->tags)-1));
11-
unocc = 0;
12-
for (i = 0; i < NUMTAGS; ++i) {
13-
while (unocc < i && (occ & (1 << unocc)))
14-
unocc++;
15-
if (occ & (1 << i)) {
16-
tagdest[i] = unocc;
17-
occ &= ~(1 << i);
18-
occ |= 1 << unocc;
19-
}
20-
}
8+
#if TAGSYNC_PATCH
9+
Monitor *origselmon = selmon;
10+
for (selmon = mons; selmon; selmon = selmon->next) {
11+
#endif // TAGSYNC_PATCH
2112

22-
for (c = selmon->clients; c; c = c->next)
23-
c->tags = 1 << tagdest[ffs(c->tags)-1];
24-
if (selmon->sel)
25-
selmon->tagset[selmon->seltags] = selmon->sel->tags;
26-
arrange(selmon);
27-
}
13+
occ = 0;
14+
for (c = selmon->clients; c; c = c->next)
15+
occ |= (1 << (ffs(c->tags)-1));
16+
unocc = 0;
17+
for (i = 0; i < NUMTAGS; ++i) {
18+
while (unocc < i && (occ & (1 << unocc)))
19+
unocc++;
20+
if (occ & (1 << i)) {
21+
tagdest[i] = unocc;
22+
occ &= ~(1 << i);
23+
occ |= 1 << unocc;
24+
}
25+
}
26+
27+
for (c = selmon->clients; c; c = c->next)
28+
c->tags = 1 << tagdest[ffs(c->tags)-1];
29+
#if TAGSYNC_PATCH
30+
}
31+
selmon = origselmon;
32+
#endif // TAGSYNC_PATCH
2833

34+
if (selmon->sel)
35+
view(&((Arg) { .ui = selmon->sel->tags }));
36+
else
37+
#if TAGSYNC_PATCH
38+
arrange(NULL);
39+
#else
40+
arrange(selmon);
41+
#endif // TAGSYNC_PATCH
42+
}

patch/shiftviewclients.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ shiftviewclients(const Arg *arg)
55
Client *c;
66
unsigned int tagmask = 0;
77

8-
for (c = selmon->clients; c; c = c->next)
8+
#if TAGSYNC_PATCH
9+
Monitor *origselmon = selmon;
10+
for (selmon = mons; selmon; selmon = selmon->next)
11+
#endif // TAGSYNC_PATCH
12+
for (c = selmon->clients; c; c = c->next) {
913
#if SCRATCHPADS_PATCH
1014
if (!(c->tags & SPTAGMASK))
1115
tagmask = tagmask | c->tags;
@@ -15,28 +19,33 @@ shiftviewclients(const Arg *arg)
1519
#else
1620
tagmask = tagmask | c->tags;
1721
#endif // SCRATCHPADS_PATCH
22+
}
23+
#if TAGSYNC_PATCH
24+
selmon = origselmon;
25+
#endif // TAGSYNC_PATCH
1826

1927
#if SCRATCHPADS_PATCH
2028
shifted.ui = selmon->tagset[selmon->seltags] & ~SPTAGMASK;
2129
#else
2230
shifted.ui = selmon->tagset[selmon->seltags];
2331
#endif // SCRATCHPADS_PATCH
24-
if (arg->i > 0) // left circular shift
32+
if (arg->i > 0) { // left circular shift
2533
do {
2634
shifted.ui = (shifted.ui << arg->i)
2735
| (shifted.ui >> (NUMTAGS - arg->i));
2836
#if SCRATCHPADS_PATCH
2937
shifted.ui &= ~SPTAGMASK;
3038
#endif // SCRATCHPADS_PATCH
3139
} while (tagmask && !(shifted.ui & tagmask));
32-
else // right circular shift
40+
} else { // right circular shift
3341
do {
3442
shifted.ui = (shifted.ui >> (- arg->i)
3543
| shifted.ui << (NUMTAGS + arg->i));
3644
#if SCRATCHPADS_PATCH
3745
shifted.ui &= ~SPTAGMASK;
3846
#endif // SCRATCHPADS_PATCH
3947
} while (tagmask && !(shifted.ui & tagmask));
48+
}
4049

4150
view(&shifted);
4251
}

patch/swaptags.c

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,31 @@
11
void
22
swaptags(const Arg *arg)
33
{
4-
unsigned int newtag = arg->ui & TAGMASK;
5-
unsigned int curtag = selmon->tagset[selmon->seltags];
4+
Client *c;
5+
unsigned int newtag = arg->ui & TAGMASK;
6+
unsigned int curtag = selmon->tagset[selmon->seltags];
67

7-
if (newtag == curtag || !curtag || (curtag & (curtag-1)))
8-
return;
8+
if (newtag == curtag || !curtag || (curtag & (curtag-1)))
9+
return;
910

10-
for (Client *c = selmon->clients; c != NULL; c = c->next) {
11-
if ((c->tags & newtag) || (c->tags & curtag))
12-
c->tags ^= curtag ^ newtag;
11+
#if TAGSYNC_PATCH
12+
Monitor *origselmon = selmon;
13+
for (selmon = mons; selmon; selmon = selmon->next) {
14+
#endif // TAGSYNC_PATCH
1315

14-
if (!c->tags)
15-
c->tags = newtag;
16-
}
16+
for (c = selmon->clients; c != NULL; c = c->next) {
17+
if ((c->tags & newtag) || (c->tags & curtag))
18+
c->tags ^= curtag ^ newtag;
1719

18-
selmon->tagset[selmon->seltags] = newtag;
20+
if (!c->tags)
21+
c->tags = newtag;
22+
}
1923

20-
focus(NULL);
21-
arrange(selmon);
24+
#if TAGSYNC_PATCH
25+
}
26+
selmon = origselmon;
27+
#endif // TAGSYNC_PATCH
28+
29+
view(&((Arg) { .ui = newtag }));
2230
}
2331

0 commit comments

Comments
 (0)