[wiki] [sites] Add relativecontrols patch || Mišo Barišić

From: <git_AT_suckless.org>
Date: Mon, 16 Aug 2021 23:46:12 +0200

commit 1f8de6bfcbacd64ec2a6d897a110395a1a21e5a7
Author: Mišo Barišić <miki.barisic5_AT_gmail.com>
Date: Mon Aug 16 23:45:51 2021 +0200

    Add relativecontrols patch

diff --git a/dwm.suckless.org/patches/relativecontrols/dwm-relative-controls.diff b/dwm.suckless.org/patches/relativecontrols/dwm-relative-controls.diff
new file mode 100644
index 00000000..07d6d9ee
--- /dev/null
+++ b/dwm.suckless.org/patches/relativecontrols/dwm-relative-controls.diff
_AT_@ -0,0 +1,344 @@
+diff --git a/config.def.h b/config.def.h
+index a2ac963..5e7ca5b 100644
+--- a/config.def.h
++++ b/config.def.h
+_AT_@ -44,13 +44,14 @@ static const Layout layouts[] = {
+ { "[M]", monocle },
+ };
+
++#include "tags.c"
++
+ /* key definitions */
+ #define MODKEY Mod1Mask
+ #define TAGKEYS(KEY,TAG) \
+- { MODKEY, KEY, view, {.ui = 1 << TAG} }, \
+- { MODKEY|ControlMask, KEY, toggleview, {.ui = 1 << TAG} }, \
+- { MODKEY|ShiftMask, KEY, tag, {.ui = 1 << TAG} }, \
+- { MODKEY|ControlMask|ShiftMask, KEY, toggletag, {.ui = 1 << TAG} },
++ { MODKEY, KEY, view, {.ui = TAG} }, \
++ { MODKEY|ShiftMask, KEY, tag, {.ui = TAG} }, \
++ { MODKEY|ControlMask, KEY, viewtag, {.ui = TAG} },
+
+ /* helper for spawning shell commands in the pre dwm-5.0 fashion */
+ #define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }
+_AT_@ -95,6 +96,15 @@ static Key keys[] = {
+ TAGKEYS( XK_8, 7)
+ TAGKEYS( XK_9, 8)
+ { MODKEY|ShiftMask, XK_q, quit, {0} },
++ // Relative controls
++ { MODKEY, XK_s, relativeview, {.i = +1} },
++ { MODKEY, XK_a, relativeview, {.i = -1} },
++ { MODKEY|ShiftMask, XK_s, relativemoveview, {.i = +1} },
++ { MODKEY|ShiftMask, XK_a, relativemoveview, {.i = -1} },
++ { MODKEY|ShiftMask, XK_x, relativemove, {.i = +1} },
++ // Different keyboard layouts
++ { MODKEY|ShiftMask, XK_y, relativemove, {.i = -1} },
++ { MODKEY|ShiftMask, XK_z, relativemove, {.i = -1} },
+ };
+
+ /* button definitions */
+diff --git a/dwm.c b/dwm.c
+index 5e4d494..97b1e6d 100644
+--- a/dwm.c
++++ b/dwm.c
+_AT_@ -124,6 +124,7 @@ struct Monitor {
+ unsigned int tagset[2];
+ int showbar;
+ int topbar;
++ int selectedtag;
+ Client *clients;
+ Client *sel;
+ Client *stack;
+_AT_@ -639,6 +640,7 @@ createmon(void)
+ m->nmaster = nmaster;
+ m->showbar = showbar;
+ m->topbar = topbar;
++ m->selectedtag = 1;
+ m->lt[0] = &layouts[0];
+ m->lt[1] = &layouts[1 % LENGTH(layouts)];
+ strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
+_AT_@ -1653,16 +1655,17 @@ spawn(const Arg *arg)
+ }
+ }
+
+-void
+-tag(const Arg *arg)
+-{
+- if (selmon->sel && arg->ui & TAGMASK) {
+- selmon->sel->tags = arg->ui & TAGMASK;
+- focus(NULL);
+- arrange(selmon);
+- }
++void
++tag(const Arg *arg) {
++ int endtag = 1 << arg->ui;
++ if (selmon->sel && endtag & TAGMASK) {
++ selmon->sel->tags = endtag & TAGMASK;
++ focus(NULL);
++ arrange(selmon);
++ }
+ }
+
++
+ void
+ tagmon(const Arg *arg)
+ {
+_AT_@ -2035,16 +2038,18 @@ updatewmhints(Client *c)
+ }
+ }
+
++
+ void
+-view(const Arg *arg)
+-{
+- if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
+- return;
+- selmon->seltags ^= 1; /* toggle sel tagset */
+- if (arg->ui & TAGMASK)
+- selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
+- focus(NULL);
+- arrange(selmon);
++view(const Arg *arg) {
++ int endtag = 1 << arg->ui;
++ if ((endtag & TAGMASK) == selmon->tagset[selmon->seltags])
++ return;
++ selmon->seltags ^= 1; /* toggle sel tagset */
++ if (endtag & TAGMASK)
++ selmon->tagset[selmon->seltags] = endtag & TAGMASK;
++ selmon->selectedtag = arg->ui;
++ focus(NULL);
++ arrange(selmon);
+ }
+
+ Client *
+diff --git a/tags.c b/tags.c
+new file mode 100644
+index 0000000..78b7b20
+--- /dev/null
++++ b/tags.c
+_AT_@ -0,0 +1,52 @@
++void relativemove(const Arg *arg) {
++ if (selmon->sel && arg->i) {
++ int endtag = selmon->selectedtag + arg->i;
++ if (endtag < 0 || endtag > LENGTH(tags) - 1)
++ return;
++ selmon->sel->tags = 1 << endtag;
++ focus(NULL);
++ arrange(selmon);
++ }
++}
++
++void relativeview(const Arg *arg) {
++ int newmon = selmon->selectedtag + arg->i;
++ if (newmon < 0 || newmon > LENGTH(tags) - 1)
++ return;
++ int endtag = 1 << newmon;
++ if ((endtag & TAGMASK) == selmon->tagset[selmon->seltags])
++ return;
++ selmon->seltags ^= 1;
++ if (endtag & TAGMASK)
++ selmon->tagset[selmon->seltags] = endtag & TAGMASK;
++ selmon->selectedtag = newmon;
++ focus(NULL);
++ arrange(selmon);
++}
++
++void relativemoveview(const Arg *arg) {
++ if (selmon->sel && arg->i) {
++ int endtag = selmon->selectedtag + arg->i;
++ if (endtag < 0 || endtag > LENGTH(tags) - 1)
++ return;
++ selmon->sel->tags = 1 << endtag;
++ }
++ int newmon = selmon->selectedtag + arg->i;
++ int endtag = 1 << newmon;
++ if (endtag & TAGMASK)
++ selmon->tagset[selmon->seltags] = endtag & TAGMASK;
++ selmon->selectedtag = newmon;
++ focus(NULL);
++ arrange(selmon);
++}
++
++void viewtag(const Arg *arg) {
++ int endtag = 1 << arg->ui;
++ if (selmon->sel && endtag) {
++ selmon->sel->tags = endtag & TAGMASK;
++ selmon->selectedtag = arg->ui;
++ focus(NULL);
++ view(arg);
++ arrange(selmon);
++ }
++}
+\ No newline at end of file
+diff --git a/config.def.h b/config.def.h
+index a2ac963..5e7ca5b 100644
+--- a/config.def.h
++++ b/config.def.h
+_AT_@ -44,13 +44,14 @@ static const Layout layouts[] = {
+ { "[M]", monocle },
+ };
+
++#include "tags.c"
++
+ /* key definitions */
+ #define MODKEY Mod1Mask
+ #define TAGKEYS(KEY,TAG) \
+- { MODKEY, KEY, view, {.ui = 1 << TAG} }, \
+- { MODKEY|ControlMask, KEY, toggleview, {.ui = 1 << TAG} }, \
+- { MODKEY|ShiftMask, KEY, tag, {.ui = 1 << TAG} }, \
+- { MODKEY|ControlMask|ShiftMask, KEY, toggletag, {.ui = 1 << TAG} },
++ { MODKEY, KEY, view, {.ui = TAG} }, \
++ { MODKEY|ShiftMask, KEY, tag, {.ui = TAG} }, \
++ { MODKEY|ControlMask, KEY, viewtag, {.ui = TAG} },
+
+ /* helper for spawning shell commands in the pre dwm-5.0 fashion */
+ #define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }
+_AT_@ -95,6 +96,15 @@ static Key keys[] = {
+ TAGKEYS( XK_8, 7)
+ TAGKEYS( XK_9, 8)
+ { MODKEY|ShiftMask, XK_q, quit, {0} },
++ // Relative controls
++ { MODKEY, XK_s, relativeview, {.i = +1} },
++ { MODKEY, XK_a, relativeview, {.i = -1} },
++ { MODKEY|ShiftMask, XK_s, relativemoveview, {.i = +1} },
++ { MODKEY|ShiftMask, XK_a, relativemoveview, {.i = -1} },
++ { MODKEY|ShiftMask, XK_x, relativemove, {.i = +1} },
++ // Different keyboard layouts
++ { MODKEY|ShiftMask, XK_y, relativemove, {.i = -1} },
++ { MODKEY|ShiftMask, XK_z, relativemove, {.i = -1} },
+ };
+
+ /* button definitions */
+diff --git a/dwm.c b/dwm.c
+index 5e4d494..97b1e6d 100644
+--- a/dwm.c
++++ b/dwm.c
+_AT_@ -124,6 +124,7 @@ struct Monitor {
+ unsigned int tagset[2];
+ int showbar;
+ int topbar;
++ int selectedtag;
+ Client *clients;
+ Client *sel;
+ Client *stack;
+_AT_@ -639,6 +640,7 @@ createmon(void)
+ m->nmaster = nmaster;
+ m->showbar = showbar;
+ m->topbar = topbar;
++ m->selectedtag = 1;
+ m->lt[0] = &layouts[0];
+ m->lt[1] = &layouts[1 % LENGTH(layouts)];
+ strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
+_AT_@ -1653,16 +1655,17 @@ spawn(const Arg *arg)
+ }
+ }
+
+-void
+-tag(const Arg *arg)
+-{
+- if (selmon->sel && arg->ui & TAGMASK) {
+- selmon->sel->tags = arg->ui & TAGMASK;
+- focus(NULL);
+- arrange(selmon);
+- }
++void
++tag(const Arg *arg) {
++ int endtag = 1 << arg->ui;
++ if (selmon->sel && endtag & TAGMASK) {
++ selmon->sel->tags = endtag & TAGMASK;
++ focus(NULL);
++ arrange(selmon);
++ }
+ }
+
++
+ void
+ tagmon(const Arg *arg)
+ {
+_AT_@ -2035,16 +2038,18 @@ updatewmhints(Client *c)
+ }
+ }
+
++
+ void
+-view(const Arg *arg)
+-{
+- if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
+- return;
+- selmon->seltags ^= 1; /* toggle sel tagset */
+- if (arg->ui & TAGMASK)
+- selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
+- focus(NULL);
+- arrange(selmon);
++view(const Arg *arg) {
++ int endtag = 1 << arg->ui;
++ if ((endtag & TAGMASK) == selmon->tagset[selmon->seltags])
++ return;
++ selmon->seltags ^= 1; /* toggle sel tagset */
++ if (endtag & TAGMASK)
++ selmon->tagset[selmon->seltags] = endtag & TAGMASK;
++ selmon->selectedtag = arg->ui;
++ focus(NULL);
++ arrange(selmon);
+ }
+
+ Client *
+diff --git a/tags.c b/tags.c
+new file mode 100644
+index 0000000..78b7b20
+--- /dev/null
++++ b/tags.c
+_AT_@ -0,0 +1,52 @@
++void relativemove(const Arg *arg) {
++ if (selmon->sel && arg->i) {
++ int endtag = selmon->selectedtag + arg->i;
++ if (endtag < 0 || endtag > LENGTH(tags) - 1)
++ return;
++ selmon->sel->tags = 1 << endtag;
++ focus(NULL);
++ arrange(selmon);
++ }
++}
++
++void relativeview(const Arg *arg) {
++ int newmon = selmon->selectedtag + arg->i;
++ if (newmon < 0 || newmon > LENGTH(tags) - 1)
++ return;
++ int endtag = 1 << newmon;
++ if ((endtag & TAGMASK) == selmon->tagset[selmon->seltags])
++ return;
++ selmon->seltags ^= 1;
++ if (endtag & TAGMASK)
++ selmon->tagset[selmon->seltags] = endtag & TAGMASK;
++ selmon->selectedtag = newmon;
++ focus(NULL);
++ arrange(selmon);
++}
++
++void relativemoveview(const Arg *arg) {
++ if (selmon->sel && arg->i) {
++ int endtag = selmon->selectedtag + arg->i;
++ if (endtag < 0 || endtag > LENGTH(tags) - 1)
++ return;
++ selmon->sel->tags = 1 << endtag;
++ }
++ int newmon = selmon->selectedtag + arg->i;
++ int endtag = 1 << newmon;
++ if (endtag & TAGMASK)
++ selmon->tagset[selmon->seltags] = endtag & TAGMASK;
++ selmon->selectedtag = newmon;
++ focus(NULL);
++ arrange(selmon);
++}
++
++void viewtag(const Arg *arg) {
++ int endtag = 1 << arg->ui;
++ if (selmon->sel && endtag) {
++ selmon->sel->tags = endtag & TAGMASK;
++ selmon->selectedtag = arg->ui;
++ focus(NULL);
++ view(arg);
++ arrange(selmon);
++ }
++}
+\ No newline at end of file
diff --git a/dwm.suckless.org/patches/relativecontrols/index.md b/dwm.suckless.org/patches/relativecontrols/index.md
new file mode 100644
index 00000000..8468ae10
--- /dev/null
+++ b/dwm.suckless.org/patches/relativecontrols/index.md
_AT_@ -0,0 +1,19 @@
+relative-controls
+============
+
+Description
+-----------
+All floating windows are centered, like the center patch, but
+without a rule.
+
+Git repo and installation guide
+-----------
+* [GitHub](https://github.com/misobarisic/dwm-relative-controls)
+
+Download
+--------
+* [dwm-relative-controls.diff](dwm-relative-controls.diff)
+
+Author
+-------
+* Mišo Barišić - <miso_AT_misobarisic.com>
Received on Mon Aug 16 2021 - 23:46:12 CEST

This archive was generated by hypermail 2.3.0 : Mon Aug 16 2021 - 23:48:44 CEST