2
0
mirror of https://github.com/bakkeby/patches synced 2024-11-13 07:10:31 +00:00

Adding "ghost" scratchpads patch

This commit is contained in:
bakkeby 2021-09-20 10:04:47 +02:00
parent 0583919648
commit cf91903524

View File

@ -0,0 +1,159 @@
From 60109531c98801c19b7bf9eb8639455105b8ff26 Mon Sep 17 00:00:00 2001
From: Bakkeby <bakkeby@gmail.com>
Date: Mon, 20 Sep 2021 09:59:52 +0200
Subject: [PATCH] Example patch for "ghost" scratchpads which allows for
windows to be focused without being displayed.
The patch was created in relation to this reddit post:
https://www.reddit.com/r/suckless/comments/p6qbay/looking_for_a_dwm_patch_or_the_interest_to/
---
config.def.h | 11 ++++++++---
dwm.c | 43 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 51 insertions(+), 3 deletions(-)
diff --git a/config.def.h b/config.def.h
index a2ac963..b873a40 100644
--- a/config.def.h
+++ b/config.def.h
@@ -26,9 +26,10 @@ static const Rule rules[] = {
* WM_CLASS(STRING) = instance, class
* WM_NAME(STRING) = title
*/
- /* class instance title tags mask isfloating monitor */
- { "Gimp", NULL, NULL, 0, 1, -1 },
- { "Firefox", NULL, NULL, 1 << 8, 0, -1 },
+ /* class instance title tags mask isfloating monitor scratch key */
+ { "Gimp", NULL, NULL, 0, 1, -1, 0 },
+ { "firefox", NULL, NULL, 1 << 8, 0, -1, 0 },
+ { NULL, NULL, "scratchpad", 0, 1, -1, 's' },
};
/* layout(s) */
@@ -60,10 +61,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 *termcmd[] = { "st", NULL };
+/*First arg only serves to match against key in rules*/
+static const char *scratchpadcmd[] = {"s", "st", "-t", "scratchpad", NULL};
+
static Key keys[] = {
/* modifier key function argument */
{ MODKEY, XK_p, spawn, {.v = dmenucmd } },
{ MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } },
+ { MODKEY, XK_grave, focusscratch, {.v = scratchpadcmd } },
{ MODKEY, XK_b, togglebar, {0} },
{ MODKEY, XK_j, focusstack, {.i = +1 } },
{ MODKEY, XK_k, focusstack, {.i = -1 } },
diff --git a/dwm.c b/dwm.c
index 5e4d494..253bc06 100644
--- a/dwm.c
+++ b/dwm.c
@@ -93,6 +93,7 @@ struct Client {
int bw, oldbw;
unsigned int tags;
int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen;
+ char scratchkey;
Client *next;
Client *snext;
Monitor *mon;
@@ -139,6 +140,7 @@ typedef struct {
unsigned int tags;
int isfloating;
int monitor;
+ const char scratchkey;
} Rule;
/* function declarations */
@@ -168,6 +170,7 @@ static void expose(XEvent *e);
static void focus(Client *c);
static void focusin(XEvent *e);
static void focusmon(const Arg *arg);
+static void focusscratch(const Arg *arg);
static void focusstack(const Arg *arg);
static Atom getatomprop(Client *c, Atom prop);
static int getrootptr(int *x, int *y);
@@ -207,6 +210,7 @@ static void seturgent(Client *c, int urg);
static void showhide(Client *c);
static void sigchld(int unused);
static void spawn(const Arg *arg);
+static void spawnscratch(const Arg *arg);
static void tag(const Arg *arg);
static void tagmon(const Arg *arg);
static void tile(Monitor *);
@@ -288,6 +292,7 @@ applyrules(Client *c)
/* rule matching */
c->isfloating = 0;
c->tags = 0;
+ c->scratchkey = 0;
XGetClassHint(dpy, c->win, &ch);
class = ch.res_class ? ch.res_class : broken;
instance = ch.res_name ? ch.res_name : broken;
@@ -300,6 +305,7 @@ applyrules(Client *c)
{
c->isfloating = r->isfloating;
c->tags |= r->tags;
+ c->scratchkey = r->scratchkey;
for (m = mons; m && m->num != r->monitor; m = m->next);
if (m)
c->mon = m;
@@ -309,6 +315,7 @@ applyrules(Client *c)
XFree(ch.res_class);
if (ch.res_name)
XFree(ch.res_name);
+
c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : c->mon->tagset[c->mon->seltags];
}
@@ -830,6 +837,29 @@ focusmon(const Arg *arg)
focus(NULL);
}
+void
+focusscratch(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) {
+ if (c == selmon->sel) {
+ unfocus(c, 0);
+ focus(NULL);
+ arrange(selmon);
+ } else {
+ unfocus(selmon->sel, 0);
+ grabbuttons(c, 1);
+ setfocus(c);
+ selmon->sel = c;
+ }
+ } else {
+ spawnscratch(arg);
+ }
+}
+
void
focusstack(const Arg *arg)
{
@@ -1653,6 +1683,19 @@ spawn(const Arg *arg)
}
}
+void spawnscratch(const Arg *arg)
+{
+ if (fork() == 0) {
+ if (dpy)
+ close(ConnectionNumber(dpy));
+ setsid();
+ execvp(((char **)arg->v)[1], ((char **)arg->v)+1);
+ fprintf(stderr, "dwm: execvp %s", ((char **)arg->v)[1]);
+ perror(" failed");
+ exit(EXIT_SUCCESS);
+ }
+}
+
void
tag(const Arg *arg)
{
--
2.33.0