commit 8ddf8523e8eec6b94f905c895a62c5d5b266af04
parent 58660d1c988bd37ef212a8109aaa3ddcb98788fe
Author: explosion-mental <explosion0mental@gmail.com>
Date: Mon, 4 Jul 2022 12:52:10 -0500
[dwm][shift-tools] Update the patch
- fix shift-tools.c if statement `if (!(c->tags))` since it was a
leftover of the scratchpad variant
- don't repeat code, use a function :)
- description: better wording
Diffstat:
2 files changed, 77 insertions(+), 90 deletions(-)
diff --git a/dwm.suckless.org/patches/shift-tools/index.md b/dwm.suckless.org/patches/shift-tools/index.md
@@ -5,32 +5,41 @@ Description
-----------
A group of functions that shift. Inspired by
[shiftview](https://lists.suckless.org/dev/1104/7590.html),
-[focusadjacenttag](../focusadjacenttag) and [swaptags](../swaptags). There is also a
-[version](shift-tools-scratchpads.c) compatible with the
-[scratchpads](../scratchpads) patch with only needs you to include the file
-`#include "shift-tools-scratchpads.c"` before the keys[] array.
+[focusadjacenttag](../focusadjacenttag) and [swaptags](../swaptags).
+Usually you just `#include "shift-tools.c"` before the `keys[]` array to use
+these function, since no internal changes are needed other than to add the
+keybindings to `config.h`.
-* **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, if none it 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,
- 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** - used on shiftswaptags, original code on
- [swaptags](../swaptags).
+There is also a [version](shift-tools-scratchpads.c) compatible with the
+[scratchpads](../scratchpads) patch: `#include "shift-tools-scratchpads.c"`
-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/-1 and you can change it.
+Whenever I say `next/prev` I'm describing the function with argument `+1/-1`,
+default and generally what you will use. Changing these do make a difference on
+how many tags the function should `shift`.
+
+
+* **shifttag** - send a window to the next/prev tag.
+* **shifttagclients** - send a window to the next/prev tag that has a client,
+ else it moves it to the next/prev one.
+* **shiftview** - view the next/prev tag.
+* **shiftviewclients** - view the next/prev tag that has a client, else view
+ the next/prev tag.
+* **shiftboth** - move the active window to the next/prev tag and view it's new
+ tag.
+* **shiftswaptags** - swaps "tags" (all the clients on it) with the next/prev
+ tag.
+
+* helpers:
+ * **swaptags** - used on shiftswaptags, original code on [swaptags](../swaptags).
+ * **shift** - shift bits in acordance to the LENGTH of the `tags`.
+
+
+Remember that these functions _shift_, which means you can go from tag 1 (the
+first tag) to 9 (or whatever is your last tag).
Download
--------
diff --git a/dwm.suckless.org/patches/shift-tools/shift-tools.c b/dwm.suckless.org/patches/shift-tools/shift-tools.c
@@ -1,100 +1,84 @@
-/* Sends a window to the next/prev tag */
+void
+shift(unsigned int *tag, int i)
+{
+ if (i > 0) /* left circular shift */
+ *tag = ((*tag << i) | (*tag >> (LENGTH(tags) - i)));
+ else /* right circular shift */
+ *tag = (*tag >> (- i) | *tag << (LENGTH(tags) + i));
+}
+
+/* send a window to the next/prev tag */
void
shifttag(const Arg *arg)
{
- Arg shifted;
- shifted.ui = selmon->tagset[selmon->seltags];
+ Arg shifted = { .ui = selmon->tagset[selmon->seltags] };
+ if (!selmon->clients)
+ return;
- 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));
+ shift(&shifted.ui, 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. */
+
+/* send 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;
+ Arg shifted = { .ui = selmon->tagset[selmon->seltags] };
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));
+ tagmask = tagmask | c->tags;
+
+ do
+ shift(&shifted.ui, arg->i);
+ while (tagmask && !(shifted.ui & tagmask));
+
tag(&shifted);
}
-/* Navigate to the next/prev tag */
+
+/* view the next/prev tag */
void
shiftview(const Arg *arg)
{
- Arg shifted;
- shifted.ui = selmon->tagset[selmon->seltags];
+ Arg 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));
- }
+ shift(&shifted.ui, arg->i);
view(&shifted);
}
-/* Navigate to the next/prev tag that has a client, else moves it to the next/prev tag */
+
+/* view the next/prev tag that has a client, else view the next/prev tag */
void
shiftviewclients(const Arg *arg)
{
- Arg shifted;
+ Arg shifted = { .ui = selmon->tagset[selmon->seltags] };
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));
+ tagmask = tagmask | c->tags;
+
+ do
+ shift(&shifted.ui, 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 */
+
+/* move the active window to the next/prev tag and view it's new tag */
void
shiftboth(const Arg *arg)
{
- Arg shifted;
- shifted.ui = selmon->tagset[selmon->seltags];
+ Arg 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)));
+ shift(&shifted.ui, arg->i);
tag(&shifted);
view(&shifted);
}
-//helper function for shiftswaptags found on:
-//https://github.com/moizifty/DWM-Build/blob/65379c62640788881486401a0d8c79333751b02f/config.h#L48
+
+/* swaptags: https://dwm.suckless.org/patches/swaptags, used below */
void
swaptags(const Arg *arg)
{
@@ -108,29 +92,23 @@ swaptags(const Arg *arg)
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
+ //uncomment to 'view' the new swaped tag
//selmon->tagset[selmon->seltags] = newtag;
focus(NULL);
arrange(selmon);
}
-/* swaps "tags" (all the clients) with the next/prev tag. */
+
+/* swaps "tags" (all the clients on it) with the next/prev tag */
void
shiftswaptags(const Arg *arg)
{
- Arg shifted;
- shifted.ui = selmon->tagset[selmon->seltags];
+ Arg 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)));
+ shift(&shifted.ui, arg->i);
swaptags(&shifted);
- // uncomment if you also want to "go" (view) the tag where the the clients are going
- //view(&shifted);
}