From 5a7b533e3971b3939f03c2f3c845570be8e838bd Mon Sep 17 00:00:00 2001 From: mrsu Date: Wed, 12 Jun 2024 14:36:26 +0100 Subject: [PATCH] modify togglescratch function to dismiss all --- config.def.h | 9 +++++++++ dwm.c | 55 +++++++++++++++++++++++++++++++++------------------- 2 files changed, 44 insertions(+), 20 deletions(-) diff --git a/config.def.h b/config.def.h index 77d97a6..f6ec084 100644 --- a/config.def.h +++ b/config.def.h @@ -49,11 +49,15 @@ typedef struct { const char *spcmd0[] = {"st", "-n", "spterm0", "-T", "scratchpad (y)", "-g", "150x50", NULL }; const char *spcmd1[] = {"st", "-n", "spterm1", "-T", "scratchpad (u)", "-g", "150x50", NULL }; const char *spcmd2[] = {"st", "-n", "spterm2", "-T", "scratchpad (i)", "-g", "150x50", NULL }; +const char *spcmd3[] = {"st", "-n", "spterm3", "-T", "color-chooser", "-g", "90x30", "kcolorchooser", NULL }; +const char *spcmd4[] = {"st", "-n", "spterm4", "-T", "clipboard-view", "-g", "140x50", "dmenu-clipper", NULL }; static Sp scratchpads[] = { /* name cmd */ {"spterm0", spcmd0}, {"spterm1", spcmd1}, {"spterm2", spcmd2}, + {"spterm3", spcmd3}, + {"spterm4", spcmd4}, }; @@ -73,6 +77,8 @@ static const Rule rules[] = { { NULL, "spterm0", NULL, SPTAG(0), 1, 1, 0 -1 }, { NULL, "spterm1", NULL, SPTAG(1), 1, 1, 0 -1 }, { NULL, "spterm2", NULL, SPTAG(2), 1, 1, 0 -1 }, + { NULL, "spterm3", NULL, SPTAG(3), 1, 1, 0 -1 }, + { NULL, "spterm4", NULL, SPTAG(4), 1, 1, 0 -1 }, { NULL, NULL, "Event Tester", 0, 0, 0, 1, -1 }, /* xev */ }; @@ -147,6 +153,9 @@ static const Key keys[] = { { MODKEY, XK_y, togglescratch, {.ui = 0 } }, { MODKEY, XK_u, togglescratch, {.ui = 1 } }, { MODKEY, XK_i, togglescratch, {.ui = 2 } }, + { MODKEY, XK_c, togglescratch, {.ui = 3 } }, + { MODKEY|ShiftMask, XK_c, togglescratch, {.ui = 4 } }, + { MODKEY, XK_o, togglescratch, {.ui = -1 } }, }; /* button definitions */ diff --git a/dwm.c b/dwm.c index 61306af..bb6e873 100644 --- a/dwm.c +++ b/dwm.c @@ -1916,27 +1916,42 @@ togglefloating(const Arg *arg) void togglescratch(const Arg *arg) { - Client *c; - unsigned int found = 0; - unsigned int scratchtag = SPTAG(arg->ui); - Arg sparg = {.v = scratchpads[arg->ui].cmd}; + Client *c; + unsigned int found = 0; + int i; - for (c = selmon->clients; c && !(found = c->tags & scratchtag); c = c->next); - if (found) { - unsigned int newtagset = selmon->tagset[selmon->seltags] ^ scratchtag; - if (newtagset) { - selmon->tagset[selmon->seltags] = newtagset; - focus(NULL); - arrange(selmon); - } - if (ISVISIBLE(c)) { - focus(c); - restack(selmon); - } - } else { - selmon->tagset[selmon->seltags] |= scratchtag; - spawn(&sparg); - } + if (arg->ui == -1) { // Hide all visible scratchpads + for (i = 0; i < LENGTH(scratchpads); i++) { + unsigned int scratchtag = SPTAG(i); + for (c = selmon->clients; c && !(found = c->tags & scratchtag); c = c->next); + if (found && ISVISIBLE(c)) { // Only hide if visible + unsigned int newtagset = selmon->tagset[selmon->seltags] ^ scratchtag; + selmon->tagset[selmon->seltags] = newtagset; + focus(NULL); + arrange(selmon); + } + } + } else { // Handle individual scratchpads as before + unsigned int scratchtag = SPTAG(arg->ui); + Arg sparg = {.v = scratchpads[arg->ui].cmd}; + + for (c = selmon->clients; c && !(found = c->tags & scratchtag); c = c->next); + if (found) { + unsigned int newtagset = selmon->tagset[selmon->seltags] ^ scratchtag; + if (newtagset) { + selmon->tagset[selmon->seltags] = newtagset; + focus(NULL); + arrange(selmon); + } + if (ISVISIBLE(c)) { + focus(c); + restack(selmon); + } + } else { + selmon->tagset[selmon->seltags] |= scratchtag; + spawn(&sparg); + } + } } void