modify togglescratch function to dismiss all

This commit is contained in:
mrsu 2024-06-12 14:36:26 +01:00
parent d155eb41fb
commit 5a7b533e39
2 changed files with 44 additions and 20 deletions

View File

@ -49,11 +49,15 @@ typedef struct {
const char *spcmd0[] = {"st", "-n", "spterm0", "-T", "scratchpad (y)", "-g", "150x50", NULL }; 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 *spcmd1[] = {"st", "-n", "spterm1", "-T", "scratchpad (u)", "-g", "150x50", NULL };
const char *spcmd2[] = {"st", "-n", "spterm2", "-T", "scratchpad (i)", "-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[] = { static Sp scratchpads[] = {
/* name cmd */ /* name cmd */
{"spterm0", spcmd0}, {"spterm0", spcmd0},
{"spterm1", spcmd1}, {"spterm1", spcmd1},
{"spterm2", spcmd2}, {"spterm2", spcmd2},
{"spterm3", spcmd3},
{"spterm4", spcmd4},
}; };
@ -73,6 +77,8 @@ static const Rule rules[] = {
{ NULL, "spterm0", NULL, SPTAG(0), 1, 1, 0 -1 }, { NULL, "spterm0", NULL, SPTAG(0), 1, 1, 0 -1 },
{ NULL, "spterm1", NULL, SPTAG(1), 1, 1, 0 -1 }, { NULL, "spterm1", NULL, SPTAG(1), 1, 1, 0 -1 },
{ NULL, "spterm2", NULL, SPTAG(2), 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 */ { 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_y, togglescratch, {.ui = 0 } },
{ MODKEY, XK_u, togglescratch, {.ui = 1 } }, { MODKEY, XK_u, togglescratch, {.ui = 1 } },
{ MODKEY, XK_i, togglescratch, {.ui = 2 } }, { 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 */ /* button definitions */

55
dwm.c
View File

@ -1916,27 +1916,42 @@ togglefloating(const Arg *arg)
void void
togglescratch(const Arg *arg) togglescratch(const Arg *arg)
{ {
Client *c; Client *c;
unsigned int found = 0; unsigned int found = 0;
unsigned int scratchtag = SPTAG(arg->ui); int i;
Arg sparg = {.v = scratchpads[arg->ui].cmd};
for (c = selmon->clients; c && !(found = c->tags & scratchtag); c = c->next); if (arg->ui == -1) { // Hide all visible scratchpads
if (found) { for (i = 0; i < LENGTH(scratchpads); i++) {
unsigned int newtagset = selmon->tagset[selmon->seltags] ^ scratchtag; unsigned int scratchtag = SPTAG(i);
if (newtagset) { for (c = selmon->clients; c && !(found = c->tags & scratchtag); c = c->next);
selmon->tagset[selmon->seltags] = newtagset; if (found && ISVISIBLE(c)) { // Only hide if visible
focus(NULL); unsigned int newtagset = selmon->tagset[selmon->seltags] ^ scratchtag;
arrange(selmon); selmon->tagset[selmon->seltags] = newtagset;
} focus(NULL);
if (ISVISIBLE(c)) { arrange(selmon);
focus(c); }
restack(selmon); }
} } else { // Handle individual scratchpads as before
} else { unsigned int scratchtag = SPTAG(arg->ui);
selmon->tagset[selmon->seltags] |= scratchtag; Arg sparg = {.v = scratchpads[arg->ui].cmd};
spawn(&sparg);
} 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 void