feat: applied named scratchpads patch

This commit is contained in:
Solomon Laing 2026-03-20 18:04:45 +10:30
parent 40dfc558de
commit 298967b6ce
2 changed files with 58 additions and 3 deletions

View File

@ -26,9 +26,10 @@ static const Rule rules[] = {
* WM_CLASS(STRING) = instance, class * WM_CLASS(STRING) = instance, class
* WM_NAME(STRING) = title * WM_NAME(STRING) = title
*/ */
/* class instance title tags mask isfloating monitor */ /* class instance title tags mask isfloating monitor scratch key */
{ "Gimp", NULL, NULL, 0, 1, -1 }, { "Gimp", NULL, NULL, 0, 1, -1, 0 },
{ "Firefox", NULL, NULL, 1 << 8, 0, -1 }, { "firefox", NULL, NULL, 1 << 8, 0, -1, 0 },
{ NULL, NULL, "scratchpad", 0, 1, -1, 's' },
}; };
/* layout(s) */ /* layout(s) */
@ -61,10 +62,14 @@ static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn()
static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL }; static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
static const char *termcmd[] = { "st", NULL }; static const char *termcmd[] = { "st", NULL };
/*First arg only serves to match against key in rules*/
static const char *scratchpadcmd[] = {"s", "st", "-t", "scratchpad", NULL};
static const Key keys[] = { static const Key keys[] = {
/* modifier key function argument */ /* modifier key function argument */
{ MODKEY, XK_p, spawn, {.v = dmenucmd } }, { MODKEY, XK_p, spawn, {.v = dmenucmd } },
{ MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } }, { MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } },
{ MODKEY, XK_grave, togglescratch, {.v = scratchpadcmd } },
{ MODKEY, XK_b, togglebar, {0} }, { MODKEY, XK_b, togglebar, {0} },
{ MODKEY, XK_j, focusstack, {.i = +1 } }, { MODKEY, XK_j, focusstack, {.i = +1 } },
{ MODKEY, XK_k, focusstack, {.i = -1 } }, { MODKEY, XK_k, focusstack, {.i = -1 } },

50
dwm.c
View File

@ -92,6 +92,7 @@ struct Client {
int bw, oldbw; int bw, oldbw;
unsigned int tags; unsigned int tags;
int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen; int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen;
char scratchkey;
Client *next; Client *next;
Client *snext; Client *snext;
Monitor *mon; Monitor *mon;
@ -138,6 +139,7 @@ typedef struct {
unsigned int tags; unsigned int tags;
int isfloating; int isfloating;
int monitor; int monitor;
const char scratchkey;
} Rule; } Rule;
/* function declarations */ /* function declarations */
@ -205,11 +207,13 @@ static void setup(void);
static void seturgent(Client *c, int urg); static void seturgent(Client *c, int urg);
static void showhide(Client *c); static void showhide(Client *c);
static void spawn(const Arg *arg); static void spawn(const Arg *arg);
static void spawnscratch(const Arg *arg);
static void tag(const Arg *arg); static void tag(const Arg *arg);
static void tagmon(const Arg *arg); static void tagmon(const Arg *arg);
static void tile(Monitor *m); static void tile(Monitor *m);
static void togglebar(const Arg *arg); static void togglebar(const Arg *arg);
static void togglefloating(const Arg *arg); static void togglefloating(const Arg *arg);
static void togglescratch(const Arg *arg);
static void toggletag(const Arg *arg); static void toggletag(const Arg *arg);
static void toggleview(const Arg *arg); static void toggleview(const Arg *arg);
static void unfocus(Client *c, int setfocus); static void unfocus(Client *c, int setfocus);
@ -286,6 +290,7 @@ applyrules(Client *c)
/* rule matching */ /* rule matching */
c->isfloating = 0; c->isfloating = 0;
c->tags = 0; c->tags = 0;
c->scratchkey = 0;
XGetClassHint(dpy, c->win, &ch); XGetClassHint(dpy, c->win, &ch);
class = ch.res_class ? ch.res_class : broken; class = ch.res_class ? ch.res_class : broken;
instance = ch.res_name ? ch.res_name : broken; instance = ch.res_name ? ch.res_name : broken;
@ -298,6 +303,7 @@ applyrules(Client *c)
{ {
c->isfloating = r->isfloating; c->isfloating = r->isfloating;
c->tags |= r->tags; c->tags |= r->tags;
c->scratchkey = r->scratchkey;
for (m = mons; m && m->num != r->monitor; m = m->next); for (m = mons; m && m->num != r->monitor; m = m->next);
if (m) if (m)
c->mon = m; c->mon = m;
@ -307,6 +313,7 @@ applyrules(Client *c)
XFree(ch.res_class); XFree(ch.res_class);
if (ch.res_name) if (ch.res_name)
XFree(ch.res_name); XFree(ch.res_name);
c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : c->mon->tagset[c->mon->seltags]; c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : c->mon->tagset[c->mon->seltags];
} }
@ -1666,6 +1673,27 @@ spawn(const Arg *arg)
} }
} }
void spawnscratch(const Arg *arg)
{
struct sigaction sa;
if (fork() == 0) {
if (dpy)
close(ConnectionNumber(dpy));
setsid();
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
sa.sa_handler = SIG_DFL;
sigaction(SIGCHLD, &sa, NULL);
execvp(((char **)arg->v)[1], ((char **)arg->v)+1);
fprintf(stderr, "dwm: execvp %s", ((char **)arg->v)[1]);
perror(" failed");
exit(EXIT_SUCCESS);
}
}
void void
tag(const Arg *arg) tag(const Arg *arg)
{ {
@ -1735,6 +1763,28 @@ togglefloating(const Arg *arg)
arrange(selmon); arrange(selmon);
} }
void
togglescratch(const Arg *arg)
{
Client *c;
unsigned int found = 0;
for (c = selmon->clients; c && !(found = c->scratchkey == ((char**)arg->v)[0][0]); c = c->next);
if (found) {
c->tags = ISVISIBLE(c) ? 0 : selmon->tagset[selmon->seltags];
focus(NULL);
arrange(selmon);
if (ISVISIBLE(c)) {
focus(c);
restack(selmon);
}
} else{
spawnscratch(arg);
}
}
void void
toggletag(const Arg *arg) toggletag(const Arg *arg)
{ {