mirror of
https://github.com/mintycube/dwm.git
synced 2024-10-22 14:05:45 +02:00
Refactoring shift functions ref. #270
This commit is contained in:
parent
274602fa7a
commit
20692bea01
@ -232,6 +232,9 @@
|
||||
#if SETBORDERPX_PATCH
|
||||
#include "setborderpx.c"
|
||||
#endif
|
||||
#if SHIFTBOTH_PATCH || SHIFTSWAPTAGS_PATCH || SHIFTTAG_PATCH || SHIFTTAGCLIENTS_PATCH || SHIFTVIEW_PATCH || SHIFTVIEW_CLIENTS_PATCH
|
||||
#include "shift.c"
|
||||
#endif
|
||||
#if SHIFTBOTH_PATCH
|
||||
#include "shiftboth.c"
|
||||
#endif
|
||||
|
@ -234,6 +234,9 @@
|
||||
#if SETBORDERPX_PATCH
|
||||
#include "setborderpx.h"
|
||||
#endif
|
||||
#if SHIFTBOTH_PATCH || SHIFTSWAPTAGS_PATCH || SHIFTTAG_PATCH || SHIFTTAGCLIENTS_PATCH || SHIFTVIEW_PATCH || SHIFTVIEW_CLIENTS_PATCH
|
||||
#include "shift.h"
|
||||
#endif
|
||||
#if SHIFTBOTH_PATCH
|
||||
#include "shiftboth.h"
|
||||
#endif
|
||||
|
46
patch/shift.c
Normal file
46
patch/shift.c
Normal 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
1
patch/shift.h
Normal file
@ -0,0 +1 @@
|
||||
static Arg shift(const Arg *arg, int clients);
|
@ -1,21 +1,7 @@
|
||||
void
|
||||
shiftboth(const Arg *arg)
|
||||
{
|
||||
Arg shifted;
|
||||
#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
|
||||
|
||||
Arg shifted = shift(arg, 0);
|
||||
tag(&shifted);
|
||||
view(&shifted);
|
||||
}
|
||||
|
@ -2,19 +2,6 @@
|
||||
void
|
||||
shiftswaptags(const Arg *arg)
|
||||
{
|
||||
Arg shifted;
|
||||
#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
|
||||
Arg shifted = shift(arg, 0);
|
||||
swaptags(&shifted);
|
||||
}
|
||||
|
@ -2,19 +2,6 @@
|
||||
void
|
||||
shifttag(const Arg *arg)
|
||||
{
|
||||
Arg shifted;
|
||||
#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
|
||||
Arg shifted = shift(arg, 0);
|
||||
tag(&shifted);
|
||||
}
|
||||
|
@ -2,48 +2,6 @@
|
||||
void
|
||||
shifttagclients(const Arg *arg)
|
||||
{
|
||||
Arg shifted;
|
||||
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));
|
||||
|
||||
Arg shifted = shift(arg, 1);
|
||||
tag(&shifted);
|
||||
}
|
||||
|
@ -1,19 +1,6 @@
|
||||
void
|
||||
shiftview(const Arg *arg)
|
||||
{
|
||||
Arg shifted;
|
||||
#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
|
||||
|
||||
Arg shifted = shift(arg, 0);
|
||||
view(&shifted);
|
||||
}
|
||||
|
@ -1,48 +1,6 @@
|
||||
void
|
||||
shiftviewclients(const Arg *arg)
|
||||
{
|
||||
Arg shifted;
|
||||
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));
|
||||
|
||||
Arg shifted = shift(arg, 1);
|
||||
view(&shifted);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user