Refactoring shift functions ref. #270

This commit is contained in:
bakkeby 2022-07-05 13:51:27 +02:00
parent 274602fa7a
commit 20692bea01
10 changed files with 59 additions and 143 deletions

View File

@ -232,6 +232,9 @@
#if SETBORDERPX_PATCH #if SETBORDERPX_PATCH
#include "setborderpx.c" #include "setborderpx.c"
#endif #endif
#if SHIFTBOTH_PATCH || SHIFTSWAPTAGS_PATCH || SHIFTTAG_PATCH || SHIFTTAGCLIENTS_PATCH || SHIFTVIEW_PATCH || SHIFTVIEW_CLIENTS_PATCH
#include "shift.c"
#endif
#if SHIFTBOTH_PATCH #if SHIFTBOTH_PATCH
#include "shiftboth.c" #include "shiftboth.c"
#endif #endif

View File

@ -234,6 +234,9 @@
#if SETBORDERPX_PATCH #if SETBORDERPX_PATCH
#include "setborderpx.h" #include "setborderpx.h"
#endif #endif
#if SHIFTBOTH_PATCH || SHIFTSWAPTAGS_PATCH || SHIFTTAG_PATCH || SHIFTTAGCLIENTS_PATCH || SHIFTVIEW_PATCH || SHIFTVIEW_CLIENTS_PATCH
#include "shift.h"
#endif
#if SHIFTBOTH_PATCH #if SHIFTBOTH_PATCH
#include "shiftboth.h" #include "shiftboth.h"
#endif #endif

46
patch/shift.c Normal file
View File

@ -0,0 +1,46 @@
static Arg
shift(const Arg *arg, int clients)
{
Arg shifted;
Client *c;
unsigned int tagmask = 0;
#if SCRATCHPADS_PATCH && !RENAMED_SCRATCHPADS_PATCH
shifted.ui = selmon->tagset[selmon->seltags];
#else
shifted.ui = selmon->tagset[selmon->seltags];
#endif // SCRATCHPADS_PATCH
#if TAGSYNC_PATCH
Monitor *origselmon = selmon;
for (selmon = mons; selmon; selmon = selmon->next)
#endif // TAGSYNC_PATCH
for (c = selmon->clients; c && clients; c = c->next) {
if (c == selmon->sel)
continue;
#if SCRATCHPADS_PATCH && !RENAMED_SCRATCHPADS_PATCH
if (!(c->tags & SPTAGMASK))
tagmask |= c->tags;
#elif SCRATCHPAD_ALT_1_PATCH
if (!(c->tags & SCRATCHPAD_MASK))
tagmask |= c->tags;
#else
tagmask |= c->tags;
#endif // SCRATCHPADS_PATCH
}
#if TAGSYNC_PATCH
selmon = origselmon;
#endif // TAGSYNC_PATCH
do {
if (arg->i > 0) // left circular shift
shifted.ui = (shifted.ui << arg->i) | (shifted.ui >> (NUMTAGS - arg->i));
else // right circular shift
shifted.ui = (shifted.ui >> -arg->i) | (shifted.ui << (NUMTAGS + arg->i));
#if SCRATCHPADS_PATCH && !RENAMED_SCRATCHPADS_PATCH
shifted.ui &= ~SPTAGMASK;
#endif // SCRATCHPADS_PATCH
} while (tagmask && !(shifted.ui & tagmask));
return shifted;
}

1
patch/shift.h Normal file
View File

@ -0,0 +1 @@
static Arg shift(const Arg *arg, int clients);

View File

@ -1,21 +1,7 @@
void void
shiftboth(const Arg *arg) shiftboth(const Arg *arg)
{ {
Arg shifted; Arg shifted = shift(arg, 0);
#if SCRATCHPADS_PATCH && !RENAMED_SCRATCHPADS_PATCH
shifted.ui = selmon->tagset[selmon->seltags];
#else
shifted.ui = selmon->tagset[selmon->seltags];
#endif // SCRATCHPADS_PATCH
if (arg->i > 0) /* left circular shift */
shifted.ui = ((shifted.ui << arg->i) | (shifted.ui >> (NUMTAGS - arg->i)));
else /* right circular shift */
shifted.ui = ((shifted.ui >> -arg->i) | (shifted.ui << (NUMTAGS + arg->i)));
#if SCRATCHPADS_PATCH && !RENAMED_SCRATCHPADS_PATCH
shifted.ui &= ~SPTAGMASK;
#endif // SCRATCHPADS_PATCH
tag(&shifted); tag(&shifted);
view(&shifted); view(&shifted);
} }

View File

@ -2,19 +2,6 @@
void void
shiftswaptags(const Arg *arg) shiftswaptags(const Arg *arg)
{ {
Arg shifted; Arg shifted = shift(arg, 0);
#if SCRATCHPADS_PATCH && !RENAMED_SCRATCHPADS_PATCH
shifted.ui = selmon->tagset[selmon->seltags];
#else
shifted.ui = selmon->tagset[selmon->seltags];
#endif // SCRATCHPADS_PATCH
if (arg->i > 0) /* left circular shift */
shifted.ui = ((shifted.ui << arg->i) | (shifted.ui >> (NUMTAGS - arg->i)));
else /* right circular shift */
shifted.ui = ((shifted.ui >> -arg->i) | (shifted.ui << (NUMTAGS + arg->i)));
#if SCRATCHPADS_PATCH && !RENAMED_SCRATCHPADS_PATCH
shifted.ui &= ~SPTAGMASK;
#endif // SCRATCHPADS_PATCH
swaptags(&shifted); swaptags(&shifted);
} }

View File

@ -2,19 +2,6 @@
void void
shifttag(const Arg *arg) shifttag(const Arg *arg)
{ {
Arg shifted; Arg shifted = shift(arg, 0);
#if SCRATCHPADS_PATCH && !RENAMED_SCRATCHPADS_PATCH
shifted.ui = selmon->tagset[selmon->seltags];
#else
shifted.ui = selmon->tagset[selmon->seltags];
#endif // SCRATCHPADS_PATCH
if (arg->i > 0) /* left circular shift */
shifted.ui = ((shifted.ui << arg->i) | (shifted.ui >> (NUMTAGS - arg->i)));
else /* right circular shift */
shifted.ui = ((shifted.ui >> -arg->i) | (shifted.ui << (NUMTAGS + arg->i)));
#if SCRATCHPADS_PATCH && !RENAMED_SCRATCHPADS_PATCH
shifted.ui &= ~SPTAGMASK;
#endif // SCRATCHPADS_PATCH
tag(&shifted); tag(&shifted);
} }

View File

@ -2,48 +2,6 @@
void void
shifttagclients(const Arg *arg) shifttagclients(const Arg *arg)
{ {
Arg shifted; Arg shifted = shift(arg, 1);
Client *c;
unsigned int tagmask = 0;
#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 (c == selmon->sel)
continue;
#if SCRATCHPADS_PATCH && !RENAMED_SCRATCHPADS_PATCH
if (!(c->tags & SPTAGMASK))
tagmask = tagmask | c->tags;
#elif SCRATCHPAD_ALT_1_PATCH
if (!(c->tags & SCRATCHPAD_MASK))
tagmask = tagmask | c->tags;
#else
tagmask = tagmask | c->tags;
#endif // SCRATCHPADS_PATCH
}
#if TAGSYNC_PATCH
selmon = origselmon;
#endif // TAGSYNC_PATCH
#if SCRATCHPADS_PATCH && !RENAMED_SCRATCHPADS_PATCH
shifted.ui = selmon->tagset[selmon->seltags] & ~SPTAGMASK;
#else
shifted.ui = selmon->tagset[selmon->seltags];
#endif // SCRATCHPADS_PATCH
do {
if (arg->i > 0) // left circular shift
shifted.ui = (shifted.ui << arg->i)
| (shifted.ui >> (NUMTAGS - arg->i));
else // right circular shift
shifted.ui = (shifted.ui >> -arg->i)
| (shifted.ui << (NUMTAGS + arg->i));
#if SCRATCHPADS_PATCH && !RENAMED_SCRATCHPADS_PATCH
shifted.ui &= ~SPTAGMASK;
#endif // SCRATCHPADS_PATCH
} while (tagmask && !(shifted.ui & tagmask));
tag(&shifted); tag(&shifted);
} }

View File

@ -1,19 +1,6 @@
void void
shiftview(const Arg *arg) shiftview(const Arg *arg)
{ {
Arg shifted; Arg shifted = shift(arg, 0);
#if SCRATCHPADS_PATCH && !RENAMED_SCRATCHPADS_PATCH
unsigned int seltagset = selmon->tagset[selmon->seltags] & ~SPTAGMASK;
#else
unsigned int seltagset = selmon->tagset[selmon->seltags];
#endif // SCRATCHPADS_PATCH
if (arg->i > 0) // left circular shift
shifted.ui = (seltagset << arg->i) | (seltagset >> (NUMTAGS - arg->i));
else // right circular shift
shifted.ui = (seltagset >> -arg->i) | (seltagset << (NUMTAGS + arg->i));
#if SCRATCHPADS_PATCH && !RENAMED_SCRATCHPADS_PATCH
shifted.ui &= ~SPTAGMASK;
#endif // SCRATCHPADS_PATCH
view(&shifted); view(&shifted);
} }

View File

@ -1,48 +1,6 @@
void void
shiftviewclients(const Arg *arg) shiftviewclients(const Arg *arg)
{ {
Arg shifted; Arg shifted = shift(arg, 1);
Client *c;
unsigned int tagmask = 0;
#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 (c == selmon->sel)
continue;
#if SCRATCHPADS_PATCH && !RENAMED_SCRATCHPADS_PATCH
if (!(c->tags & SPTAGMASK))
tagmask = tagmask | c->tags;
#elif SCRATCHPAD_ALT_1_PATCH
if (!(c->tags & SCRATCHPAD_MASK))
tagmask = tagmask | c->tags;
#else
tagmask = tagmask | c->tags;
#endif // SCRATCHPADS_PATCH
}
#if TAGSYNC_PATCH
selmon = origselmon;
#endif // TAGSYNC_PATCH
#if SCRATCHPADS_PATCH && !RENAMED_SCRATCHPADS_PATCH
shifted.ui = selmon->tagset[selmon->seltags] & ~SPTAGMASK;
#else
shifted.ui = selmon->tagset[selmon->seltags];
#endif // SCRATCHPADS_PATCH
do {
if (arg->i > 0) // left circular shift
shifted.ui = (shifted.ui << arg->i)
| (shifted.ui >> (NUMTAGS - arg->i));
else // right circular shift
shifted.ui = (shifted.ui >> -arg->i)
| (shifted.ui << (NUMTAGS + arg->i));
#if SCRATCHPADS_PATCH && !RENAMED_SCRATCHPADS_PATCH
shifted.ui &= ~SPTAGMASK;
#endif // SCRATCHPADS_PATCH
} while (tagmask && !(shifted.ui & tagmask));
view(&shifted); view(&shifted);
} }