@@ 36,7 36,7 @@ index db0babc..3205165 100644
{ MODKEY, XKB_KEY_k, focusstack, {.i = -1} },
{ MODKEY, XKB_KEY_i, incnmaster, {.i = +1} },
diff --git a/dwl.c b/dwl.c
-index ef27a1d..4c40f86 100644
+index ef27a1d..4786f12 100644
--- a/dwl.c
+++ b/dwl.c
@@ -130,6 +130,7 @@ typedef struct {
@@ 105,7 105,7 @@ index ef27a1d..4c40f86 100644
void
startdrag(struct wl_listener *listener, void *data)
{
-@@ -2454,6 +2472,114 @@ togglefullscreen(const Arg *arg)
+@@ -2454,6 +2472,122 @@ togglefullscreen(const Arg *arg)
setfullscreen(sel, !sel->isfullscreen);
}
@@ 157,7 157,11 @@ index ef27a1d..4c40f86 100644
+ }
+ } else {
+ // show
-+ c->tags = selmon->tagset[selmon->seltags];
++ if (c->mon == selmon) {
++ c->tags = selmon->tagset[selmon->seltags];
++ } else {
++ setmon(c, selmon, 0);
++ }
+ focusclient(c, 1);
+ }
+ arrange(selmon);
@@ 197,7 201,11 @@ index ef27a1d..4c40f86 100644
+ }
+ } else {
+ // show
-+ c->tags = selmon->tagset[selmon->seltags];
++ if (c->mon == selmon) {
++ c->tags = selmon->tagset[selmon->seltags];
++ } else {
++ setmon(c, selmon, 0);
++ }
+ // focus
+ focusclient(c, 1);
+ }
@@ 220,178 228,3 @@ index ef27a1d..4c40f86 100644
void
toggletag(const Arg *arg)
{
-diff --git a/namedscratchpads.patch b/namedscratchpads.patch
-new file mode 100644
-index 0000000..aaba3f7
---- /dev/null
-+++ b/namedscratchpads.patch
-@@ -0,0 +1,169 @@
-+diff --git a/config.def.h b/config.def.h
-+index db0babc..0f672d4 100644
-+--- a/config.def.h
-++++ b/config.def.h
-+@@ -20,11 +20,12 @@ static const float fullscreen_bg[] = {0.1, 0.1, 0.1, 1.0}; /* You can al
-+ static int log_level = WLR_ERROR;
-+
-+ static const Rule rules[] = {
-+- /* app_id title tags mask isfloating monitor */
-++ /* app_id title tags mask isfloating monitor scratchkey */
-+ /* examples:
-+ { "Gimp", NULL, 0, 1, -1 },
-+ */
-+- { "firefox", NULL, 1 << 8, 0, -1 },
-++ { "firefox", NULL, 1 << 8, 0, -1, 0 },
-++ { NULL, "scratchpad", 0, 1, -1, 's' },
-+ };
-+
-+ /* layout(s) */
-+@@ -115,11 +116,16 @@ static const enum libinput_config_tap_button_map button_map = LIBINPUT_CONFIG_TA
-+ static const char *termcmd[] = { "foot", NULL };
-+ static const char *menucmd[] = { "bemenu-run", NULL };
-+
-++/* named scratchpads - First arg only serves to match against key in rules*/
-++static const char *scratchpadcmd[] = { "s", "alacritty", "-t", "scratchpad", NULL };
-++
-+ static const Key keys[] = {
-+ /* Note that Shift changes certain key codes: c -> C, 2 -> at, etc. */
-+ /* modifier key function argument */
-+ { MODKEY, XKB_KEY_p, spawn, {.v = menucmd} },
-+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_Return, spawn, {.v = termcmd} },
-++ { MODKEY, XKB_KEY_grave, togglescratch, {.v = scratchpadcmd } },
-++ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_grave, focusortogglescratch, {.v = scratchpadcmd } },
-+ { MODKEY, XKB_KEY_j, focusstack, {.i = +1} },
-+ { MODKEY, XKB_KEY_k, focusstack, {.i = -1} },
-+ { MODKEY, XKB_KEY_i, incnmaster, {.i = +1} },
-+diff --git a/dwl.c b/dwl.c
-+index ef27a1d..6b5d55d 100644
-+--- a/dwl.c
-++++ b/dwl.c
-+@@ -130,6 +130,7 @@ typedef struct {
-+ uint32_t tags;
-+ int isfloating, isurgent, isfullscreen;
-+ uint32_t resize; /* configure serial of a pending resize */
-++ char scratchkey;
-+ } Client;
-+
-+ typedef struct {
-+@@ -215,6 +216,7 @@ typedef struct {
-+ uint32_t tags;
-+ int isfloating;
-+ int monitor;
-++ const char scratchkey;
-+ } Rule;
-+
-+ typedef struct {
-+@@ -307,12 +309,15 @@ static void setpsel(struct wl_listener *listener, void *data);
-+ static void setsel(struct wl_listener *listener, void *data);
-+ static void setup(void);
-+ static void spawn(const Arg *arg);
-++static void spawnscratch(const Arg *arg);
-+ static void startdrag(struct wl_listener *listener, void *data);
-+ static void tag(const Arg *arg);
-+ static void tagmon(const Arg *arg);
-+ static void tile(Monitor *m);
-+ static void togglefloating(const Arg *arg);
-+ static void togglefullscreen(const Arg *arg);
-++static void togglescratch(const Arg *arg);
-++static void focusortogglescratch(const Arg *arg);
-+ static void toggletag(const Arg *arg);
-+ static void toggleview(const Arg *arg);
-+ static void unlocksession(struct wl_listener *listener, void *data);
-+@@ -424,6 +429,7 @@ applyrules(Client *c)
-+ Monitor *mon = selmon, *m;
-+
-+ c->isfloating = client_is_float_type(c);
-++ c->scratchkey = 0;
-+ if (!(appid = client_get_appid(c)))
-+ appid = broken;
-+ if (!(title = client_get_title(c)))
-+@@ -433,6 +439,7 @@ applyrules(Client *c)
-+ if ((!r->title || strstr(title, r->title))
-+ && (!r->id || strstr(appid, r->id))) {
-+ c->isfloating = r->isfloating;
-++ c->scratchkey = r->scratchkey;
-+ newtags |= r->tags;
-+ i = 0;
-+ wl_list_for_each(m, &mons, link)
-+@@ -2372,6 +2379,16 @@ spawn(const Arg *arg)
-+ }
-+ }
-+
-++void spawnscratch(const Arg *arg)
-++{
-++ if (fork() == 0) {
-++ dup2(STDERR_FILENO, STDOUT_FILENO);
-++ setsid();
-++ execvp(((char **)arg->v)[1], ((char **)arg->v)+1);
-++ die("dwl: execvp %s failed:", ((char **)arg->v)[1]);
-++ }
-++}
-++
-+ void
-+ startdrag(struct wl_listener *listener, void *data)
-+ {
-+@@ -2454,6 +2471,63 @@ togglefullscreen(const Arg *arg)
-+ setfullscreen(sel, !sel->isfullscreen);
-+ }
-+
-++void
-++togglescratch(const Arg *arg)
-++{
-++ Client *c;
-++ unsigned int found = 0;
-++
-++ /* search for first window that matches the scratchkey */
-++ wl_list_for_each(c, &clients, link)
-++ if (c->scratchkey == ((char**)arg->v)[0][0]) {
-++ found = 1;
-++ break;
-++ }
-++
-++ if (found) {
-++ c->tags = VISIBLEON(c, selmon) ? 0 : selmon->tagset[selmon->seltags];
-++
-++ focusclient(c->tags == 0 ? focustop(selmon) : c, 1);
-++ arrange(selmon);
-++ } else{
-++ spawnscratch(arg);
-++ }
-++}
-++
-++void
-++focusortogglescratch(const Arg *arg)
-++{
-++ Client *c;
-++ unsigned int found = 0;
-++
-++ /* search for first window that matches the scratchkey */
-++ wl_list_for_each(c, &clients, link)
-++ if (c->scratchkey == ((char**)arg->v)[0][0]) {
-++ found = 1;
-++ break;
-++ }
-++
-++ if (found) {
-++ if (VISIBLEON(c, selmon)) {
-++ if (focustop(selmon) == c) {
-++ // hide
-++ c->tags = 0;
-++ focusclient(focustop(selmon), 1);
-++ } else {
-++ // focus
-++ focusclient(c, 1);
-++ }
-++ } else {
-++ // show
-++ c->tags = selmon->tagset[selmon->seltags];
-++ focusclient(c, 1);
-++ }
-++ arrange(selmon);
-++ } else{
-++ spawnscratch(arg);
-++ }
-++}
-++
-+ void
-+ toggletag(const Arg *arg)
-+ {
@@ 1,7 1,7 @@
From 0dc34efe899c9e6dca6eb8770f3dedd2afe5ee83 Mon Sep 17 00:00:00 2001
From: wochap <gean.marroquin@gmail.com>
Date: Wed, 22 Nov 2023 18:55:15 -0500
-Subject: [PATCH 1/6] apply main...loumray:namedscratchpads.patch
+Subject: [PATCH 1/7] apply main...loumray:namedscratchpads.patch
---
config.def.h | 9 +++++++--
@@ 142,13 142,13 @@ index ef27a1d..81e5db8 100644
toggletag(const Arg *arg)
{
--
-2.42.0
+2.43.2
From e750aa243a25ec78e611883b5e72314067326746 Mon Sep 17 00:00:00 2001
From: wochap <gean.marroquin@gmail.com>
Date: Wed, 22 Nov 2023 18:58:57 -0500
-Subject: [PATCH 2/6] add focusortogglescratch function
+Subject: [PATCH 2/7] add focusortogglescratch function
---
config.def.h | 1 +
@@ 223,13 223,13 @@ index 81e5db8..83d771e 100644
toggletag(const Arg *arg)
{
--
-2.42.0
+2.43.2
From 5ee62daed7e4fb60d09ba72793bf872307697203 Mon Sep 17 00:00:00 2001
From: wochap <gean.marroquin@gmail.com>
Date: Wed, 22 Nov 2023 20:42:20 -0500
-Subject: [PATCH 3/6] fix focus after hiding
+Subject: [PATCH 3/7] fix focus after hiding
---
dwl.c | 6 ++----
@@ 262,13 262,13 @@ index 83d771e..6b5d55d 100644
// focus
focusclient(c, 1);
--
-2.42.0
+2.43.2
From 0b3d70706a0aca6d4414d20a3f2ac4928e70d04e Mon Sep 17 00:00:00 2001
From: wochap <gean.marroquin@gmail.com>
Date: Wed, 6 Mar 2024 14:36:48 -0500
-Subject: [PATCH 4/6] add focusortogglematchingscratch
+Subject: [PATCH 4/7] add focusortogglematchingscratch
works like focusortoggle but it also hides all others scratchpads
---
@@ 337,13 337,13 @@ index 6b5d55d..e179940 100644
toggletag(const Arg *arg)
{
--
-2.42.0
+2.43.2
From a14d6da36f1a77cd73daf751828224dd407e78f9 Mon Sep 17 00:00:00 2001
From: wochap <gean.marroquin@gmail.com>
Date: Wed, 6 Mar 2024 15:20:45 -0500
-Subject: [PATCH 5/6] fix: edge case where there are more than 1 window with
+Subject: [PATCH 5/7] fix: edge case where there are more than 1 window with
the same scratchkey
---
@@ 391,13 391,13 @@ index e179940..4c40f86 100644
}
if (VISIBLEON(c, selmon)) {
--
-2.42.0
+2.43.2
From 8d86b275615f4f6242828d2ce4606380ba309c58 Mon Sep 17 00:00:00 2001
From: wochap <gean.marroquin@gmail.com>
Date: Wed, 6 Mar 2024 15:22:24 -0500
-Subject: [PATCH 6/6] add examples
+Subject: [PATCH 6/7] add examples
---
config.def.h | 3 ++-
@@ 418,5 418,48 @@ index 0f672d4..3205165 100644
{ MODKEY, XKB_KEY_k, focusstack, {.i = -1} },
{ MODKEY, XKB_KEY_i, incnmaster, {.i = +1} },
--
-2.42.0
+2.43.2
+
+
+From 3787e1d356af7f59f6f096e2125233ab29617862 Mon Sep 17 00:00:00 2001
+From: wochap <gean.marroquin@gmail.com>
+Date: Mon, 8 Apr 2024 16:36:56 -0500
+Subject: [PATCH 7/7] fix: move window to focused monitor if necessary
+
+---
+ dwl.c | 12 ++++++++++--
+ 1 file changed, 10 insertions(+), 2 deletions(-)
+
+diff --git a/dwl.c b/dwl.c
+index 4c40f86..4786f12 100644
+--- a/dwl.c
++++ b/dwl.c
+@@ -2520,7 +2520,11 @@ focusortogglescratch(const Arg *arg)
+ }
+ } else {
+ // show
+- c->tags = selmon->tagset[selmon->seltags];
++ if (c->mon == selmon) {
++ c->tags = selmon->tagset[selmon->seltags];
++ } else {
++ setmon(c, selmon, 0);
++ }
+ focusclient(c, 1);
+ }
+ arrange(selmon);
+@@ -2560,7 +2564,11 @@ focusortogglematchingscratch(const Arg *arg)
+ }
+ } else {
+ // show
+- c->tags = selmon->tagset[selmon->seltags];
++ if (c->mon == selmon) {
++ c->tags = selmon->tagset[selmon->seltags];
++ } else {
++ setmon(c, selmon, 0);
++ }
+ // focus
+ focusclient(c, 1);
+ }
+--
+2.43.2