mirror of https://github.com/bakkeby/patches
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
240 lines
6.9 KiB
Diff
240 lines
6.9 KiB
Diff
From 332fb0f170f9dac1c7f153ca8744056a3b1d2432 Mon Sep 17 00:00:00 2001
|
|
From: bakkeby <bakkeby@gmail.com>
|
|
Date: Mon, 21 Dec 2020 20:18:18 +0100
|
|
Subject: [PATCH] Another namedscratchpads variant where scratchpads remain on
|
|
the monitors where they reside
|
|
|
|
---
|
|
config.def.h | 13 ++++++--
|
|
dwm.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
2 files changed, 102 insertions(+), 3 deletions(-)
|
|
|
|
diff --git a/config.def.h b/config.def.h
|
|
index 1c0b587..d05180d 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) */
|
|
@@ -59,10 +60,16 @@ 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_g, togglescratch, {.v = scratchpadcmd } },
|
|
+ { MODKEY|ShiftMask, XK_g, removescratch, {.v = scratchpadcmd } },
|
|
+ { MODKEY|ControlMask, XK_g, setscratch, {.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 4465af1..a07409e 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 */
|
|
@@ -188,6 +190,7 @@ static void pop(Client *);
|
|
static void propertynotify(XEvent *e);
|
|
static void quit(const Arg *arg);
|
|
static Monitor *recttomon(int x, int y, int w, int h);
|
|
+static void removescratch(const Arg *arg);
|
|
static void resize(Client *c, int x, int y, int w, int h, int interact);
|
|
static void resizeclient(Client *c, int x, int y, int w, int h);
|
|
static void resizemouse(const Arg *arg);
|
|
@@ -201,16 +204,19 @@ static void setfocus(Client *c);
|
|
static void setfullscreen(Client *c, int fullscreen);
|
|
static void setlayout(const Arg *arg);
|
|
static void setmfact(const Arg *arg);
|
|
+static void setscratch(const Arg *arg);
|
|
static void setup(void);
|
|
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 *);
|
|
static void togglebar(const Arg *arg);
|
|
static void togglefloating(const Arg *arg);
|
|
+static void togglescratch(const Arg *arg);
|
|
static void toggletag(const Arg *arg);
|
|
static void toggleview(const Arg *arg);
|
|
static void unfocus(Client *c, int setfocus);
|
|
@@ -287,6 +293,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;
|
|
@@ -299,6 +306,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;
|
|
@@ -308,6 +316,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];
|
|
}
|
|
|
|
@@ -1265,6 +1274,15 @@ recttomon(int x, int y, int w, int h)
|
|
return r;
|
|
}
|
|
|
|
+void
|
|
+removescratch(const Arg *arg)
|
|
+{
|
|
+ Client *c = selmon->sel;
|
|
+ if (!c)
|
|
+ return;
|
|
+ c->scratchkey = 0;
|
|
+}
|
|
+
|
|
void
|
|
resize(Client *c, int x, int y, int w, int h, int interact)
|
|
{
|
|
@@ -1526,6 +1544,16 @@ setmfact(const Arg *arg)
|
|
arrange(selmon);
|
|
}
|
|
|
|
+void
|
|
+setscratch(const Arg *arg)
|
|
+{
|
|
+ Client *c = selmon->sel;
|
|
+ if (!c)
|
|
+ return;
|
|
+
|
|
+ c->scratchkey = ((char**)arg->v)[0][0];
|
|
+}
|
|
+
|
|
void
|
|
setup(void)
|
|
{
|
|
@@ -1622,6 +1650,9 @@ showhide(Client *c)
|
|
resize(c, c->x, c->y, c->w, c->h, 0);
|
|
showhide(c->snext);
|
|
} else {
|
|
+ /* optional: auto-hide scratchpads when moving to other tags */
|
|
+ if (c->scratchkey != 0 && c->tags != 0)
|
|
+ c->tags = 0;
|
|
/* hide clients bottom up */
|
|
showhide(c->snext);
|
|
XMoveWindow(dpy, c->win, WIDTH(c) * -2, c->y);
|
|
@@ -1652,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)
|
|
{
|
|
@@ -1719,6 +1763,54 @@ togglefloating(const Arg *arg)
|
|
arrange(selmon);
|
|
}
|
|
|
|
+void
|
|
+togglescratch(const Arg *arg)
|
|
+{
|
|
+ Client *c, *next, *found = NULL;
|
|
+ Monitor *mon;
|
|
+ int tags = 0, monfound;
|
|
+
|
|
+ for (mon = mons; mon; mon = mon->next) {
|
|
+ monfound = 0;
|
|
+ for (c = mon->stack; c; c = next) {
|
|
+ next = c->snext;
|
|
+ if (c->scratchkey != ((char**)arg->v)[0][0])
|
|
+ continue;
|
|
+
|
|
+ /* awesomebar / wintitleactions compatibility
|
|
+ if (HIDDEN(c)) {
|
|
+ XMapWindow(dpy, c->win);
|
|
+ setclientstate(c, NormalState);
|
|
+ }
|
|
+ */
|
|
+
|
|
+ unfocus(c, 0);
|
|
+ monfound = 1;
|
|
+
|
|
+ if (!found || mon == selmon) {
|
|
+ found = c;
|
|
+ tags = (c->tags == 0 ? selmon->tagset[selmon->seltags] : 0);
|
|
+ }
|
|
+
|
|
+ detachstack(c);
|
|
+ attachstack(c);
|
|
+ c->tags = tags;
|
|
+ if (c->tags && c->isfloating)
|
|
+ XRaiseWindow(dpy, c->win);
|
|
+ }
|
|
+
|
|
+ if (monfound)
|
|
+ arrange(mon);
|
|
+ }
|
|
+
|
|
+ if (found) {
|
|
+ focus(ISVISIBLE(found) ? found : NULL);
|
|
+ arrange(selmon);
|
|
+ } else {
|
|
+ spawnscratch(arg);
|
|
+ }
|
|
+}
|
|
+
|
|
void
|
|
toggletag(const Arg *arg)
|
|
{
|
|
--
|
|
2.19.1
|
|
|