shift-tools - shifttag, moves the current selected client to the adjacent tag - shifttagclients, moves the current selected client to the adjacent tag that has at least one client else acts as shifttag - shiftview, view adjacent tag - shiftviewclients, view the closes tag that has a client. If none acts as shiftview - shiftboth, shifttag and shiftview. Basically moves the window to the next/prev tag and follows it. - shiftswaptags, its a shift implementation on the swaptags function (see 65379c6264/config.h (L48) for more details), which in short 'swaps tags' (swaps all clients with the clients on the adjacent tag). A pretty useful example of this is chosing a tag empty and sending all your clients to that tag. - swapfunction is the 'helper' function for the shiftswaptags. remember that these functions **shift**, which means you can go from tag 1 to 9 or 9 to 1. Also remember that the default argument is 1 and you can change it.
This commit is contained in:
135
shift-tools.c
Normal file
135
shift-tools.c
Normal file
@@ -0,0 +1,135 @@
|
||||
/* Sends a window to the next/prev tag */
|
||||
void
|
||||
shifttag(const Arg *arg)
|
||||
{
|
||||
Arg shifted;
|
||||
shifted.ui = selmon->tagset[selmon->seltags];
|
||||
|
||||
|
||||
if (arg->i > 0) /* left circular shift */
|
||||
shifted.ui = ((shifted.ui << arg->i) | (shifted.ui >> (LENGTH(tags) - arg->i)));
|
||||
else /* right circular shift */
|
||||
shifted.ui = (shifted.ui >> (- arg->i) | shifted.ui << (LENGTH(tags) + arg->i));
|
||||
tag(&shifted);
|
||||
}
|
||||
/* Sends a window to the next/prev tag that has a client, else it moves it to the next/prev one. */
|
||||
void
|
||||
shifttagclients(const Arg *arg)
|
||||
{
|
||||
|
||||
Arg shifted;
|
||||
Client *c;
|
||||
unsigned int tagmask = 0;
|
||||
shifted.ui = selmon->tagset[selmon->seltags];
|
||||
|
||||
for (c = selmon->clients; c; c = c->next)
|
||||
if (!(c->tags))
|
||||
tagmask = tagmask | c->tags;
|
||||
|
||||
|
||||
if (arg->i > 0) /* left circular shift */
|
||||
do {
|
||||
shifted.ui = (shifted.ui << arg->i)
|
||||
| (shifted.ui >> (LENGTH(tags) - arg->i));
|
||||
} while (tagmask && !(shifted.ui & tagmask));
|
||||
else /* right circular shift */
|
||||
do {
|
||||
shifted.ui = (shifted.ui >> (- arg->i)
|
||||
| shifted.ui << (LENGTH(tags) + arg->i));
|
||||
} while (tagmask && !(shifted.ui & tagmask));
|
||||
tag(&shifted);
|
||||
}
|
||||
/* Navigate to the next/prev tag */
|
||||
void
|
||||
shiftview(const Arg *arg)
|
||||
{
|
||||
Arg shifted;
|
||||
shifted.ui = selmon->tagset[selmon->seltags];
|
||||
|
||||
if (arg->i > 0) /* left circular shift */
|
||||
shifted.ui = (shifted.ui << arg->i) | (shifted.ui >> (LENGTH(tags) - arg->i));
|
||||
else /* right circular shift */
|
||||
shifted.ui = (shifted.ui >> (- arg->i) | shifted.ui << (LENGTH(tags) + arg->i));
|
||||
view(&shifted);
|
||||
}
|
||||
/* Navigate to the next/prev tag that has a client, else moves it to the next/prev tag */
|
||||
void
|
||||
shiftviewclients(const Arg *arg)
|
||||
{
|
||||
Arg shifted;
|
||||
Client *c;
|
||||
unsigned int tagmask = 0;
|
||||
shifted.ui = selmon->tagset[selmon->seltags];
|
||||
|
||||
for (c = selmon->clients; c; c = c->next)
|
||||
if (!(c->tags))
|
||||
tagmask = tagmask | c->tags;
|
||||
|
||||
|
||||
if (arg->i > 0) /* left circular shift */
|
||||
do {
|
||||
shifted.ui = (shifted.ui << arg->i)
|
||||
| (shifted.ui >> (LENGTH(tags) - arg->i));
|
||||
} while (tagmask && !(shifted.ui & tagmask));
|
||||
else /* right circular shift */
|
||||
do {
|
||||
shifted.ui = (shifted.ui >> (- arg->i)
|
||||
| shifted.ui << (LENGTH(tags) + arg->i));
|
||||
} while (tagmask && !(shifted.ui & tagmask));
|
||||
view(&shifted);
|
||||
}
|
||||
/* move the current active window to the next/prev tag and view it. More like following the window */
|
||||
void
|
||||
shiftboth(const Arg *arg)
|
||||
{
|
||||
Arg shifted;
|
||||
shifted.ui = selmon->tagset[selmon->seltags];
|
||||
|
||||
if (arg->i > 0) /* left circular shift */
|
||||
shifted.ui = ((shifted.ui << arg->i) | (shifted.ui >> (LENGTH(tags) - arg->i)));
|
||||
else /* right circular shift */
|
||||
shifted.ui = ((shifted.ui >> (- arg->i) | shifted.ui << (LENGTH(tags) + arg->i)));
|
||||
tag(&shifted);
|
||||
view(&shifted);
|
||||
}
|
||||
//helper function for shiftswaptags.
|
||||
//see: https://github.com/moizifty/DWM-Build/blob/65379c62640788881486401a0d8c79333751b02f/config.h#L48
|
||||
void
|
||||
swaptags(const Arg *arg)
|
||||
{
|
||||
Client *c;
|
||||
unsigned int newtag = arg->ui & TAGMASK;
|
||||
unsigned int curtag = selmon->tagset[selmon->seltags];
|
||||
|
||||
if (newtag == curtag || !curtag || (curtag & (curtag-1)))
|
||||
return;
|
||||
|
||||
for (c = selmon->clients; c != NULL; c = c->next) {
|
||||
if ((c->tags & newtag) || (c->tags & curtag))
|
||||
c->tags ^= curtag ^ newtag;
|
||||
|
||||
if (!c->tags)
|
||||
c->tags = newtag;
|
||||
}
|
||||
|
||||
//move to the swaped tag
|
||||
//selmon->tagset[selmon->seltags] = newtag;
|
||||
|
||||
focus(NULL);
|
||||
arrange(selmon);
|
||||
}
|
||||
/* swaps "tags" (all the clients) with the next/prev tag. */
|
||||
void
|
||||
shiftswaptags(const Arg *arg)
|
||||
{
|
||||
Arg shifted;
|
||||
shifted.ui = selmon->tagset[selmon->seltags];
|
||||
|
||||
if (arg->i > 0) /* left circular shift */
|
||||
shifted.ui = ((shifted.ui << arg->i) | (shifted.ui >> (LENGTH(tags) - arg->i)));
|
||||
else /* right circular shift */
|
||||
shifted.ui = ((shifted.ui >> (- arg->i) | shifted.ui << (LENGTH(tags) + arg->i)));
|
||||
swaptags(&shifted);
|
||||
// uncomment if you also want to "go" (view) the tag where the the clients are going
|
||||
//view(&shifted);
|
||||
}
|
||||
Reference in New Issue
Block a user