mirror of
https://github.com/bakkeby/patches
synced 2024-11-17 15:29:53 +00:00
358 lines
12 KiB
Diff
358 lines
12 KiB
Diff
From 07804818ec69a86887533f47f4393f040de5a447 Mon Sep 17 00:00:00 2001
|
|
From: Bakkeby <bakkeby@gmail.com>
|
|
Date: Mon, 10 Jan 2022 13:23:00 +0100
|
|
Subject: [PATCH] Named scratchpad variant
|
|
|
|
---
|
|
config.def.h | 17 ++++-
|
|
dwm.c | 175 ++++++++++++++++++++++++++++++++++++++++++++++++++-
|
|
2 files changed, 186 insertions(+), 6 deletions(-)
|
|
|
|
diff --git a/config.def.h b/config.def.h
|
|
index a2ac963..049b29f 100644
|
|
--- a/config.def.h
|
|
+++ b/config.def.h
|
|
@@ -12,10 +12,14 @@ static const char col_gray2[] = "#444444";
|
|
static const char col_gray3[] = "#bbbbbb";
|
|
static const char col_gray4[] = "#eeeeee";
|
|
static const char col_cyan[] = "#005577";
|
|
+static const char col_red[] = "#FF0000";
|
|
+static const char col_orange[] = "#FF8800";
|
|
static const char *colors[][3] = {
|
|
/* fg bg border */
|
|
[SchemeNorm] = { col_gray3, col_gray1, col_gray2 },
|
|
[SchemeSel] = { col_gray4, col_cyan, col_cyan },
|
|
+ [SchemeScratchSel] = { col_gray4, col_cyan, col_red },
|
|
+ [SchemeScratchNorm] = { col_gray4, col_cyan, col_orange },
|
|
};
|
|
|
|
/* tagging */
|
|
@@ -26,9 +30,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 +65,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 a96f33c..c58c6ed 100644
|
|
--- a/dwm.c
|
|
+++ b/dwm.c
|
|
@@ -59,7 +59,7 @@
|
|
|
|
/* enums */
|
|
enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
|
|
-enum { SchemeNorm, SchemeSel }; /* color schemes */
|
|
+enum { SchemeNorm, SchemeSel, SchemeScratchNorm, SchemeScratchSel }; /* color schemes */
|
|
enum { NetSupported, NetWMName, NetWMState, NetWMCheck,
|
|
NetWMFullscreen, NetActiveWindow, NetWMWindowType,
|
|
NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */
|
|
@@ -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 */
|
|
@@ -189,6 +191,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);
|
|
@@ -202,16 +205,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);
|
|
@@ -288,6 +294,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 +307,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 +317,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];
|
|
}
|
|
|
|
@@ -799,7 +808,10 @@ focus(Client *c)
|
|
detachstack(c);
|
|
attachstack(c);
|
|
grabbuttons(c, 1);
|
|
- XSetWindowBorder(dpy, c->win, scheme[SchemeSel][ColBorder].pixel);
|
|
+ if (c->scratchkey != 0)
|
|
+ XSetWindowBorder(dpy, c->win, scheme[SchemeScratchSel][ColBorder].pixel);
|
|
+ else
|
|
+ XSetWindowBorder(dpy, c->win, scheme[SchemeSel][ColBorder].pixel);
|
|
setfocus(c);
|
|
} else {
|
|
XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
|
|
@@ -1269,6 +1281,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)
|
|
{
|
|
@@ -1530,6 +1551,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)
|
|
{
|
|
@@ -1626,6 +1657,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 & c->mon->tagset[c->mon->seltags]))
|
|
+ c->tags = 0;
|
|
/* hide clients bottom up */
|
|
showhide(c->snext);
|
|
XMoveWindow(dpy, c->win, WIDTH(c) * -2, c->y);
|
|
@@ -1656,6 +1690,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)
|
|
{
|
|
@@ -1725,6 +1772,125 @@ togglefloating(const Arg *arg)
|
|
arrange(selmon);
|
|
}
|
|
|
|
+void
|
|
+togglescratch(const Arg *arg)
|
|
+{
|
|
+ Client *c, *next, *last = NULL, *found = NULL, *monclients = NULL;
|
|
+ Monitor *mon;
|
|
+ int scratchvisible = 0; // whether the scratchpads are currently visible or not
|
|
+ int multimonscratch = 0; // whether we have scratchpads that are placed on multiple monitors
|
|
+ int scratchmon = -1; // the monitor where the scratchpads exist
|
|
+ int numscratchpads = 0; // count of scratchpads
|
|
+
|
|
+ /* Looping through monitors and client's twice, the first time to work out whether we need
|
|
+ to move clients across from one monitor to another or not */
|
|
+ for (mon = mons; mon; mon = mon->next)
|
|
+ for (c = mon->clients; c; c = c->next) {
|
|
+ if (c->scratchkey != ((char**)arg->v)[0][0])
|
|
+ continue;
|
|
+ if (scratchmon != -1 && scratchmon != mon->num)
|
|
+ multimonscratch = 1;
|
|
+ if (c->mon->tagset[c->mon->seltags] & c->tags) // && !HIDDEN(c)
|
|
+ ++scratchvisible;
|
|
+ scratchmon = mon->num;
|
|
+ ++numscratchpads;
|
|
+ }
|
|
+
|
|
+ /* Now for the real deal. The logic should go like:
|
|
+ - hidden scratchpads will be shown
|
|
+ - shown scratchpads will be hidden, unless they are being moved to the current monitor
|
|
+ - the scratchpads will be moved to the current monitor if they all reside on the same monitor
|
|
+ - multiple scratchpads residing on separate monitors will be left in place
|
|
+ */
|
|
+ for (mon = mons; mon; mon = mon->next) {
|
|
+ for (c = mon->stack; c; c = next) {
|
|
+ next = c->snext;
|
|
+ if (c->scratchkey != ((char**)arg->v)[0][0])
|
|
+ continue;
|
|
+
|
|
+ /* awesomebar / wintitleactions compatibility, unhide scratchpad if hidden
|
|
+ if (HIDDEN(c)) {
|
|
+ XMapWindow(dpy, c->win);
|
|
+ setclientstate(c, NormalState);
|
|
+ }
|
|
+ */
|
|
+
|
|
+ /* Record the first found scratchpad client for focus purposes, but prioritise the
|
|
+ scratchpad on the current monitor if one exists */
|
|
+ if (!found || (mon == selmon && found->mon != selmon))
|
|
+ found = c;
|
|
+
|
|
+ /* If scratchpad clients reside on another monitor and we are moving them across then
|
|
+ as we are looping through monitors we could be moving a client to a monitor that has
|
|
+ not been processed yet, hence we could be processing a scratchpad twice. To avoid
|
|
+ this we detach them and add them to a temporary list (monclients) which is to be
|
|
+ processed later. */
|
|
+ if (!multimonscratch && c->mon != selmon) {
|
|
+ detach(c);
|
|
+ detachstack(c);
|
|
+ c->next = NULL;
|
|
+ /* Note that we are adding clients at the end of the list, this is to preserve the
|
|
+ order of clients as they were on the adjacent monitor (relevant when tiled) */
|
|
+ if (last)
|
|
+ last = last->next = c;
|
|
+ else
|
|
+ last = monclients = c;
|
|
+ } else if (scratchvisible == numscratchpads) {
|
|
+ c->tags = 0;
|
|
+ } else {
|
|
+ XSetWindowBorder(dpy, c->win, scheme[SchemeScratchNorm][ColBorder].pixel);
|
|
+ c->tags = c->mon->tagset[c->mon->seltags];
|
|
+ if (c->isfloating)
|
|
+ XRaiseWindow(dpy, c->win);
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+
|
|
+ /* Attach moved scratchpad clients on the selected monitor */
|
|
+ for (c = monclients; c; c = next) {
|
|
+ next = c->next;
|
|
+ mon = c->mon;
|
|
+ c->mon = selmon;
|
|
+ c->tags = selmon->tagset[selmon->seltags];
|
|
+ /* Attach scratchpad clients from other monitors at the bottom of the stack */
|
|
+ if (selmon->clients) {
|
|
+ for (last = selmon->clients; last && last->next; last = last->next);
|
|
+ last->next = c;
|
|
+ } else
|
|
+ selmon->clients = c;
|
|
+ c->next = NULL;
|
|
+ attachstack(c);
|
|
+
|
|
+ /* Center floating scratchpad windows when moved from one monitor to another */
|
|
+ if (c->isfloating) {
|
|
+ if (c->w > selmon->ww)
|
|
+ c->w = selmon->ww - c->bw * 2;
|
|
+ if (c->h > selmon->wh)
|
|
+ c->h = selmon->wh - c->bw * 2;
|
|
+
|
|
+ if (numscratchpads > 1) {
|
|
+ c->x = c->mon->wx + (c->x - mon->wx) * ((double)(abs(c->mon->ww - WIDTH(c))) / MAX(abs(mon->ww - WIDTH(c)), 1));
|
|
+ c->y = c->mon->wy + (c->y - mon->wy) * ((double)(abs(c->mon->wh - HEIGHT(c))) / MAX(abs(mon->wh - HEIGHT(c)), 1));
|
|
+ } else if (c->x < c->mon->mx || c->x > c->mon->mx + c->mon->mw ||
|
|
+ c->y < c->mon->my || c->y > c->mon->my + c->mon->mh) {
|
|
+ c->x = c->mon->wx + (c->mon->ww / 2 - WIDTH(c) / 2);
|
|
+ c->y = c->mon->wy + (c->mon->wh / 2 - HEIGHT(c) / 2);
|
|
+ }
|
|
+ resizeclient(c, c->x, c->y, c->w, c->h);
|
|
+ XRaiseWindow(dpy, c->win);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ if (found) {
|
|
+ focus(ISVISIBLE(found) ? found : NULL);
|
|
+ arrange(NULL);
|
|
+ if (found->isfloating)
|
|
+ XRaiseWindow(dpy, found->win);
|
|
+ } else {
|
|
+ spawnscratch(arg);
|
|
+ }
|
|
+}
|
|
+
|
|
void
|
|
toggletag(const Arg *arg)
|
|
{
|
|
@@ -1758,7 +1924,10 @@ unfocus(Client *c, int setfocus)
|
|
if (!c)
|
|
return;
|
|
grabbuttons(c, 0);
|
|
- XSetWindowBorder(dpy, c->win, scheme[SchemeNorm][ColBorder].pixel);
|
|
+ if (c->scratchkey != 0)
|
|
+ XSetWindowBorder(dpy, c->win, scheme[SchemeScratchNorm][ColBorder].pixel);
|
|
+ else
|
|
+ XSetWindowBorder(dpy, c->win, scheme[SchemeNorm][ColBorder].pixel);
|
|
if (setfocus) {
|
|
XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
|
|
XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
|
|
--
|
|
2.19.1
|
|
|