Skip to content

Tag-Sync patch (for syncing tags across all monitors) #219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions config.def.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ static const char dmenufont[] = "monospace:size=10";

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

#if BAR_FLEXWINTITLE_PATCH
#endif // BAR_FLEXWINTITLE_PATCH
static char normfgcolor[] = "#bbbbbb";
static char normbgcolor[] = "#222222";
static char normbordercolor[] = "#444444";
Expand Down
44 changes: 37 additions & 7 deletions dwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -911,8 +911,14 @@ applyrules(Client *c)
view(&((Arg) { .ui = newtagset }));
#endif // PERTAG_PATCH
} else {
#if TAGSYNC_PATCH
for (m = mons; m; m = m->next)
m->tagset[m->seltags] = newtagset;
arrange(NULL);
#else
c->mon->tagset[c->mon->seltags] = newtagset;
arrange(c->mon);
#endif // TAGSYNC_PATCH
}
}
}
Expand Down Expand Up @@ -4040,7 +4046,11 @@ toggletag(const Arg *arg)
void
toggleview(const Arg *arg)
{
unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK);
unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK);;
#if TAGSYNC_PATCH
Monitor *origselmon = selmon;
for (selmon = mons; selmon; selmon = selmon->next) {
#endif // TAGSYNC_PATCH
#if PERTAG_PATCH
int i;
#endif // PERTAG_PATCH
Expand Down Expand Up @@ -4111,11 +4121,25 @@ toggleview(const Arg *arg)
togglebar(NULL);
#endif // PERTAGBAR_PATCH
#endif // PERTAG_PATCH
#if !TAGSYNC_PATCH
focus(NULL);
arrange(selmon);
#endif // TAGSYNC_PATCH
#if !EMPTYVIEW_PATCH
}
#endif // EMPTYVIEW_PATCH
#if TAGSYNC_PATCH
}
selmon = origselmon;
#if !EMPTYVIEW_PATCH
if (newtagset) {
#endif // EMPTYVIEW_PATCH
focus(NULL);
arrange(NULL);
#if !EMPTYVIEW_PATCH
}
#endif // EMPTYVIEW_PATCH
#endif // TAGSYNC_PATCH
#if BAR_EWMHTAGS_PATCH
updatecurrentdesktop();
#endif // BAR_EWMHTAGS_PATCH
Expand Down Expand Up @@ -4659,6 +4683,10 @@ updatewmhints(Client *c)
void
view(const Arg *arg)
{
#if TAGSYNC_PATCH
Monitor *origselmon = selmon;
for (selmon = mons; selmon; selmon = selmon->next) {
#endif // TAGSYNC_PATCH
#if EMPTYVIEW_PATCH
if (arg->ui && (arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
#else
Expand All @@ -4673,18 +4701,20 @@ view(const Arg *arg)
selmon->seltags ^= 1; /* toggle sel tagset */
#if PERTAG_PATCH
pertagview(arg);
#if SWAPFOCUS_PATCH
Client *unmodified = selmon->pertag->prevclient[selmon->pertag->curtag];
#endif // SWAPFOCUS_PATCH
#else
if (arg->ui & TAGMASK)
selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
#endif // PERTAG_PATCH
#if TAGSYNC_PATCH
}
selmon = origselmon;
#endif // TAGSYNC_PATCH
focus(NULL);
#if SWAPFOCUS_PATCH && PERTAG_PATCH
selmon->pertag->prevclient[selmon->pertag->curtag] = unmodified;
#endif // SWAPFOCUS_PATCH
#if TAGSYNC_PATCH
arrange(NULL);
#else
arrange(selmon);
#endif // TAGSYNC_PATCH
#if BAR_EWMHTAGS_PATCH
updatecurrentdesktop();
#endif // BAR_EWMHTAGS_PATCH
Expand Down
1 change: 0 additions & 1 deletion patch/bar_ewmhtags.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,3 @@ updatecurrentdesktop(void)
long data[] = { i };
XChangeProperty(dpy, root, netatom[NetCurrentDesktop], XA_CARDINAL, 32, PropModeReplace, (unsigned char *)data, 1);
}

15 changes: 2 additions & 13 deletions patch/combo.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,10 @@ combotag(const Arg *arg)
void
comboview(const Arg *arg)
{
unsigned newtags = arg->ui & TAGMASK;
if (combo) {
selmon->tagset[selmon->seltags] |= newtags;
view(&((Arg) { .ui = selmon->tagset[selmon->seltags] | (arg->ui & TAGMASK) }));
} else {
selmon->seltags ^= 1; /*toggle tagset*/
combo = 1;
if (newtags) {
#if PERTAG_PATCH
pertagview(&((Arg) { .ui = newtags }));
#else
selmon->tagset[selmon->seltags] = newtags;
#endif // PERTAG_PATCH
}
view(arg);
}
focus(NULL);
arrange(selmon);
}

18 changes: 16 additions & 2 deletions patch/distributetags.c
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
void
distributetags(const Arg *arg)
{
Client *c;
unsigned int ui = 1;
int i = 0;
for (Client *c = selmon->clients; c; c = c->next) {

#if TAGSYNC_PATCH
Monitor *origselmon = selmon;
for (selmon = mons; selmon; selmon = selmon->next) {
#endif // TAGSYNC_PATCH

for (c = selmon->clients; c; c = c->next) {
if (HIDDEN(c))
continue;
if (!(c->tags & TAGMASK))
continue;
c->tags = (ui << i) & TAGMASK;
i = (i + 1) % NUMTAGS;
}

#if TAGSYNC_PATCH
}
selmon = origselmon;
focus(NULL);
arrange(NULL);
#else
focus(NULL);
arrange(selmon);
#endif // TAGSYNC_PATCH
}

49 changes: 4 additions & 45 deletions patch/focusadjacenttag.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,7 @@ viewtoleft(const Arg *arg)
{
if (__builtin_popcount(selmon->tagset[selmon->seltags] & TAGMASK) == 1
&& selmon->tagset[selmon->seltags] > 1) {
selmon->seltags ^= 1; /* toggle sel tagset */
#if PERTAG_PATCH
pertagview(&((Arg) { .ui = selmon->tagset[selmon->seltags ^ 1] >> 1 }));
#else
selmon->tagset[selmon->seltags] = selmon->tagset[selmon->seltags ^ 1] >> 1;
#endif // pertagview
focus(NULL);
arrange(selmon);
#if BAR_EWMHTAGS_PATCH
updatecurrentdesktop();
#endif // BAR_EWMHTAGS_PATCH
view(&((Arg) { .ui = selmon->tagset[selmon->seltags] >> 1 }));
}
}

Expand All @@ -46,17 +36,7 @@ viewtoright(const Arg *arg)
{
if (__builtin_popcount(selmon->tagset[selmon->seltags] & TAGMASK) == 1
&& selmon->tagset[selmon->seltags] & (TAGMASK >> 1)) {
selmon->seltags ^= 1; /* toggle sel tagset */
#if PERTAG_PATCH
pertagview(&((Arg) { .ui = selmon->tagset[selmon->seltags ^ 1] << 1 }));
#else
selmon->tagset[selmon->seltags] = selmon->tagset[selmon->seltags ^ 1] << 1;
#endif // pertagview
focus(NULL);
arrange(selmon);
#if BAR_EWMHTAGS_PATCH
updatecurrentdesktop();
#endif // BAR_EWMHTAGS_PATCH
view(&((Arg) { .ui = selmon->tagset[selmon->seltags] << 1 }));
}
}

Expand All @@ -67,17 +47,7 @@ tagandviewtoleft(const Arg *arg)
&& __builtin_popcount(selmon->tagset[selmon->seltags] & TAGMASK) == 1
&& selmon->tagset[selmon->seltags] > 1) {
selmon->sel->tags >>= 1;
selmon->seltags ^= 1; /* toggle sel tagset */
#if PERTAG_PATCH
pertagview(&((Arg) { .ui = selmon->tagset[selmon->seltags ^ 1] >> 1 }));
#else
selmon->tagset[selmon->seltags] = selmon->tagset[selmon->seltags ^ 1] >> 1;
#endif // pertagview
focus(selmon->sel);
arrange(selmon);
#if BAR_EWMHTAGS_PATCH
updatecurrentdesktop();
#endif // BAR_EWMHTAGS_PATCH
view(&((Arg) { .ui = selmon->tagset[selmon->seltags] >> 1 }));
}
}

Expand All @@ -88,17 +58,6 @@ tagandviewtoright(const Arg *arg)
&& __builtin_popcount(selmon->tagset[selmon->seltags] & TAGMASK) == 1
&& selmon->tagset[selmon->seltags] & (TAGMASK >> 1)) {
selmon->sel->tags <<= 1;
selmon->seltags ^= 1; /* toggle sel tagset */
#if PERTAG_PATCH
pertagview(&((Arg) { .ui = selmon->tagset[selmon->seltags ^ 1] << 1 }));
#else
selmon->tagset[selmon->seltags] = selmon->tagset[selmon->seltags ^ 1] << 1;
#endif // pertagview
focus(selmon->sel);
arrange(selmon);
#if BAR_EWMHTAGS_PATCH
updatecurrentdesktop();
#endif // BAR_EWMHTAGS_PATCH
view(&((Arg) { .ui = selmon->tagset[selmon->seltags] << 1 }));
}
}

58 changes: 36 additions & 22 deletions patch/reorganizetags.c
Original file line number Diff line number Diff line change
@@ -1,28 +1,42 @@
void
reorganizetags(const Arg *arg)
{
Client *c;
unsigned int occ, unocc, i;
unsigned int tagdest[NUMTAGS];
Client *c;
unsigned int occ, unocc, i;
unsigned int tagdest[NUMTAGS];

occ = 0;
for (c = selmon->clients; c; c = c->next)
occ |= (1 << (ffs(c->tags)-1));
unocc = 0;
for (i = 0; i < NUMTAGS; ++i) {
while (unocc < i && (occ & (1 << unocc)))
unocc++;
if (occ & (1 << i)) {
tagdest[i] = unocc;
occ &= ~(1 << i);
occ |= 1 << unocc;
}
}
#if TAGSYNC_PATCH
Monitor *origselmon = selmon;
for (selmon = mons; selmon; selmon = selmon->next) {
#endif // TAGSYNC_PATCH

for (c = selmon->clients; c; c = c->next)
c->tags = 1 << tagdest[ffs(c->tags)-1];
if (selmon->sel)
selmon->tagset[selmon->seltags] = selmon->sel->tags;
arrange(selmon);
}
occ = 0;
for (c = selmon->clients; c; c = c->next)
occ |= (1 << (ffs(c->tags)-1));
unocc = 0;
for (i = 0; i < NUMTAGS; ++i) {
while (unocc < i && (occ & (1 << unocc)))
unocc++;
if (occ & (1 << i)) {
tagdest[i] = unocc;
occ &= ~(1 << i);
occ |= 1 << unocc;
}
}

for (c = selmon->clients; c; c = c->next)
c->tags = 1 << tagdest[ffs(c->tags)-1];
#if TAGSYNC_PATCH
}
selmon = origselmon;
#endif // TAGSYNC_PATCH

if (selmon->sel)
view(&((Arg) { .ui = selmon->sel->tags }));
else
#if TAGSYNC_PATCH
arrange(NULL);
#else
arrange(selmon);
#endif // TAGSYNC_PATCH
}
15 changes: 12 additions & 3 deletions patch/shiftviewclients.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ shiftviewclients(const Arg *arg)
Client *c;
unsigned int tagmask = 0;

for (c = selmon->clients; c; c = c->next)
#if TAGSYNC_PATCH
Monitor *origselmon = selmon;
for (selmon = mons; selmon; selmon = selmon->next)
#endif // TAGSYNC_PATCH
for (c = selmon->clients; c; c = c->next) {
#if SCRATCHPADS_PATCH
if (!(c->tags & SPTAGMASK))
tagmask = tagmask | c->tags;
Expand All @@ -15,28 +19,33 @@ shiftviewclients(const Arg *arg)
#else
tagmask = tagmask | c->tags;
#endif // SCRATCHPADS_PATCH
}
#if TAGSYNC_PATCH
selmon = origselmon;
#endif // TAGSYNC_PATCH

#if SCRATCHPADS_PATCH
shifted.ui = selmon->tagset[selmon->seltags] & ~SPTAGMASK;
#else
shifted.ui = selmon->tagset[selmon->seltags];
#endif // SCRATCHPADS_PATCH
if (arg->i > 0) // left circular shift
if (arg->i > 0) { // left circular shift
do {
shifted.ui = (shifted.ui << arg->i)
| (shifted.ui >> (NUMTAGS - arg->i));
#if SCRATCHPADS_PATCH
shifted.ui &= ~SPTAGMASK;
#endif // SCRATCHPADS_PATCH
} while (tagmask && !(shifted.ui & tagmask));
else // right circular shift
} else { // right circular shift
do {
shifted.ui = (shifted.ui >> (- arg->i)
| shifted.ui << (NUMTAGS + arg->i));
#if SCRATCHPADS_PATCH
shifted.ui &= ~SPTAGMASK;
#endif // SCRATCHPADS_PATCH
} while (tagmask && !(shifted.ui & tagmask));
}

view(&shifted);
}
Expand Down
34 changes: 21 additions & 13 deletions patch/swaptags.c
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
void
swaptags(const Arg *arg)
{
unsigned int newtag = arg->ui & TAGMASK;
unsigned int curtag = selmon->tagset[selmon->seltags];
Client *c;
unsigned int newtag = arg->ui & TAGMASK;
unsigned int curtag = selmon->tagset[selmon->seltags];

if (newtag == curtag || !curtag || (curtag & (curtag-1)))
return;
if (newtag == curtag || !curtag || (curtag & (curtag-1)))
return;

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

if (!c->tags)
c->tags = newtag;
}
for (c = selmon->clients; c != NULL; c = c->next) {
if ((c->tags & newtag) || (c->tags & curtag))
c->tags ^= curtag ^ newtag;

selmon->tagset[selmon->seltags] = newtag;
if (!c->tags)
c->tags = newtag;
}

focus(NULL);
arrange(selmon);
#if TAGSYNC_PATCH
}
selmon = origselmon;
#endif // TAGSYNC_PATCH

view(&((Arg) { .ui = newtag }));
}

Loading