[wiki] [sites] dwm: patch to allow 3 scratchpads that can be toggled with individual keypress || anukul

From: <git_AT_suckless.org>
Date: Sat, 30 Oct 2021 05:59:16 +0200

commit 9b62eeb8c276185ad97b5e3252d0c426cd38292c
Author: anukul <hi_AT_anukul.com.np>
Date: Sat Oct 30 09:42:55 2021 +0545

    dwm: patch to allow 3 scratchpads that can be toggled with individual keypress

diff --git a/dwm.suckless.org/patches/multipledynamicscratchpads/dwm-multiple-dynamic-scratchpads.diff b/dwm.suckless.org/patches/multipledynamicscratchpads/dwm-multiple-dynamic-scratchpads.diff
new file mode 100644
index 00000000..1d0892a1
--- /dev/null
+++ b/dwm.suckless.org/patches/multipledynamicscratchpads/dwm-multiple-dynamic-scratchpads.diff
_AT_@ -0,0 +1,204 @@
+diff --git a/config.def.h b/config.def.h
+index a2ac963..1c82453 100644
+--- a/config.def.h
++++ b/config.def.h
+_AT_@ -95,6 +95,13 @@ static Key keys[] = {
+ TAGKEYS( XK_8, 7)
+ TAGKEYS( XK_9, 8)
+ { MODKEY|ShiftMask, XK_q, quit, {0} },
++ { MODKEY, XK_s, scratchpad_show, {.i = 1} },
++ { MODKEY, XK_y, scratchpad_show, {.i = 2} },
++ { MODKEY, XK_u, scratchpad_show, {.i = 3} },
++ { MODKEY|ShiftMask, XK_s, scratchpad_hide, {.i = 1} },
++ { MODKEY|ShiftMask, XK_y, scratchpad_hide, {.i = 2} },
++ { MODKEY|ShiftMask, XK_u, scratchpad_hide, {.i = 3} },
++ { MODKEY|ShiftMask, XK_r, scratchpad_remove, {0} },
+ };
+
+ /* button definitions */
+diff --git a/dwm.c b/dwm.c
+index 5e4d494..8e6fe18 100644
+--- a/dwm.c
++++ b/dwm.c
+_AT_@ -195,6 +195,11 @@ static void resizemouse(const Arg *arg);
+ static void restack(Monitor *m);
+ static void run(void);
+ static void scan(void);
++static void scratchpad_hide();
++static void scratchpad_remove();
++static void scratchpad_show();
++static void scratchpad_show_client(Client *c);
++static void scratchpad_show_first(int scratchNum);
+ static int sendevent(Client *c, Atom proto);
+ static void sendmon(Client *c, Monitor *m);
+ static void setclientstate(Client *c, long state);
+_AT_@ -269,11 +274,19 @@ static Drw *drw;
+ static Monitor *mons, *selmon;
+ static Window root, wmcheckwin;
+
++/* scratchpad */
++#define SCRATCHPAD_MASK_1 512
++#define SCRATCHPAD_MASK_2 1024
++#define SCRATCHPAD_MASK_3 2048
++static int scratchpad_hide_flag = 0;
++static Client *scratchpad_last_showed_1 = NULL;
++static Client *scratchpad_last_showed_2 = NULL;
++static Client *scratchpad_last_showed_3 = NULL;
+ /* configuration, allows nested code to access above variables */
+ #include "config.h"
+
+ /* compile-time check if all tags fit into an unsigned int bit array. */
+-struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
++struct NumTags { char limitexceeded[LENGTH(tags) > 30 ? -1 : 1]; };
+
+ /* function implementations */
+ void
+_AT_@ -309,7 +322,9 @@ applyrules(Client *c)
+ XFree(ch.res_class);
+ if (ch.res_name)
+ XFree(ch.res_name);
++ if(c->tags != SCRATCHPAD_MASK_1 && c->tags != SCRATCHPAD_MASK_2 && c->tags != SCRATCHPAD_MASK_3) {
+ c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : c->mon->tagset[c->mon->seltags];
++ }
+ }
+
+ int
+_AT_@ -1408,6 +1423,121 @@ scan(void)
+ }
+ }
+
++static void scratchpad_hide(const Arg *arg) {
++ if(scratchpad_hide_flag < 4) {
++ if(arg->i == 1) {
++ if(selmon->sel) {
++ selmon->sel->tags = SCRATCHPAD_MASK_1;
++ selmon->sel->isfloating = 1;
++ focus(NULL);
++ arrange(selmon);
++ scratchpad_hide_flag++;
++ }
++ }
++ else if(arg->i == 2) {
++ if(selmon->sel) {
++ selmon->sel->tags = SCRATCHPAD_MASK_2;
++ selmon->sel->isfloating = 1;
++ focus(NULL);
++ arrange(selmon);
++ scratchpad_hide_flag++;
++ }
++ }
++ else if(arg->i == 3) {
++ if(selmon->sel) {
++ selmon->sel->tags = SCRATCHPAD_MASK_3;
++ selmon->sel->isfloating = 1;
++ focus(NULL);
++ arrange(selmon);
++ scratchpad_hide_flag++;
++ }
++ }
++ }
++}
++
++static void scratchpad_remove() {
++ if(selmon->sel && (scratchpad_last_showed_1 != NULL || scratchpad_last_showed_2 != NULL ||scratchpad_last_showed_3 != NULL) && (selmon->sel == scratchpad_last_showed_1 || selmon->sel == scratchpad_last_showed_2 || selmon->sel == scratchpad_last_showed_3)) {
++ if(scratchpad_last_showed_1 == selmon->sel) {
++ scratchpad_last_showed_1 = NULL;
++ }
++ else if(scratchpad_last_showed_2 == selmon->sel) {
++ scratchpad_last_showed_2 = NULL;
++ }
++ else if(scratchpad_last_showed_3 == selmon->sel) {
++ scratchpad_last_showed_3 = NULL;
++ }
++ }
++}
++
++static void scratchpad_show(const Arg *arg) {
++ if(arg->i == 1) {
++ if(scratchpad_last_showed_1 == NULL) {
++ scratchpad_show_first(arg->i);
++ }
++ else {
++ if(scratchpad_last_showed_1->tags != SCRATCHPAD_MASK_1) {
++ scratchpad_last_showed_1->tags = SCRATCHPAD_MASK_1;
++ focus(NULL);
++ arrange(selmon);
++ }
++ else {
++ scratchpad_show_first(arg->i);
++ }
++ }
++ }
++ else if(arg->i == 2) {
++ if(scratchpad_last_showed_2 == NULL) {
++ scratchpad_show_first(arg->i);
++ }
++ else {
++ if(scratchpad_last_showed_2->tags != SCRATCHPAD_MASK_2) {
++ scratchpad_last_showed_2->tags = SCRATCHPAD_MASK_2;
++ focus(NULL);
++ arrange(selmon);
++ }
++ else {
++ scratchpad_show_first(arg->i);
++ }
++ }
++ }
++ else if(arg->i == 3) {
++ if(scratchpad_last_showed_3 == NULL) {
++ scratchpad_show_first(arg->i);
++ }
++ else {
++ if(scratchpad_last_showed_3->tags != SCRATCHPAD_MASK_3) {
++ scratchpad_last_showed_3->tags = SCRATCHPAD_MASK_3;
++ focus(NULL);
++ arrange(selmon);
++ }
++ else {
++ scratchpad_show_first(arg->i);
++ }
++ }
++ }
++}
++
++static void scratchpad_show_client(Client *c) {
++ c->tags = selmon->tagset[selmon->seltags];
++ focus(c);
++ arrange(selmon);
++}
++
++static void scratchpad_show_first(int scratchNum) {
++ for(Client *c = selmon->clients; c !=NULL; c = c->next) {
++ if(c->tags == SCRATCHPAD_MASK_1 && scratchNum == 1) {
++ scratchpad_last_showed_1 = c;
++ scratchpad_show_client(c);
++ } else if(c->tags == SCRATCHPAD_MASK_2 && scratchNum == 2) {
++ scratchpad_last_showed_2 = c;
++ scratchpad_show_client(c);
++ } else if(c->tags == SCRATCHPAD_MASK_3 && scratchNum == 3) {
++ scratchpad_last_showed_3 = c;
++ scratchpad_show_client(c);
++ }
++ }
++}
++
+ void
+ sendmon(Client *c, Monitor *m)
+ {
+_AT_@ -1781,6 +1911,16 @@ unmanage(Client *c, int destroyed)
+ XSetErrorHandler(xerror);
+ XUngrabServer(dpy);
+ }
++ if(scratchpad_last_showed_1 == c) {
++ scratchpad_last_showed_1 = NULL;
++ }
++ if(scratchpad_last_showed_2 == c) {
++ scratchpad_last_showed_2 = NULL;
++ }
++ if(scratchpad_last_showed_3 == c) {
++ scratchpad_last_showed_3 = NULL;
++ }
++
+ free(c);
+ focus(NULL);
+ updateclientlist();
diff --git a/dwm.suckless.org/patches/multipledynamicscratchpads/index.md b/dwm.suckless.org/patches/multipledynamicscratchpads/index.md
new file mode 100644
index 00000000..09d57fdb
--- /dev/null
+++ b/dwm.suckless.org/patches/multipledynamicscratchpads/index.md
_AT_@ -0,0 +1,21 @@
+multipledynamicscratchpads
+==========
+
+Description
+-----------
+The scratchpad patch allows you to spawn or restore a multiple floating windows.
+It is usually useful to have multiple windows spawn and hidden quickly using individual keys.
+
+By default your keybinding are `MODKEY+XK_{s, y, u}` to to show scratchpad,
+`MODKEY|ShiftMask+XK_{s, y, u}` to create a scratchpad and
+`MODKEY|ShiftMask+XK_r` to remove scratchpad.
+
+A `config.def.h` change is included in the patch.
+
+Download
+--------
+* [dwm-multiple-dynamic-scratchpads.diff](dwm-multiple-dynamic-scratchpads.diff) - 2021-10-30
+
+Authors
+-------
+* Anukul Adhikari <hi_AT_anukul.com.np>
Received on Sat Oct 30 2021 - 05:59:16 CEST

This archive was generated by hypermail 2.3.0 : Sat Oct 30 2021 - 06:00:59 CEST