modify togglescratch function to dismiss all

This commit is contained in:
mrsu 2024-06-12 14:36:26 +01:00
parent 277bc1e112
commit 4df2e26a5c
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 *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 */

55
dwm.c
View File

@ -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