diff options
| author | bakkeby <[email protected]> | 2022-06-20 14:00:09 +0200 |
|---|---|---|
| committer | bakkeby <[email protected]> | 2022-06-20 14:00:09 +0200 |
| commit | 2f70c42aab2ac71f5cdb1996499247f2268c98ce (patch) | |
| tree | daa286e6af9ea7ea0abb8ff77a62182759ce6a67 /patch | |
| parent | d7456b235a0eb549c752d0cf06198fd29264e21a (diff) | |
| download | dwm-flexipatch-2f70c42aab2ac71f5cdb1996499247f2268c98ce.tar.gz dwm-flexipatch-2f70c42aab2ac71f5cdb1996499247f2268c98ce.zip | |
Adding renamed scratchpads patch
Diffstat (limited to 'patch')
| -rw-r--r-- | patch/bar_flexwintitle.c | 7 | ||||
| -rw-r--r-- | patch/dwmc.c | 4 | ||||
| -rw-r--r-- | patch/include.c | 4 | ||||
| -rw-r--r-- | patch/include.h | 4 | ||||
| -rw-r--r-- | patch/pertag.c | 2 | ||||
| -rw-r--r-- | patch/renamed_scratchpads.c | 151 | ||||
| -rw-r--r-- | patch/renamed_scratchpads.h | 4 | ||||
| -rw-r--r-- | patch/setborderpx.c | 2 | ||||
| -rw-r--r-- | patch/shiftview.c | 4 | ||||
| -rw-r--r-- | patch/shiftviewclients.c | 6 | ||||
| -rw-r--r-- | patch/xrdb.c | 10 |
11 files changed, 187 insertions, 11 deletions
diff --git a/patch/bar_flexwintitle.c b/patch/bar_flexwintitle.c index e71a98d..c8cd4b6 100644 --- a/patch/bar_flexwintitle.c +++ b/patch/bar_flexwintitle.c @@ -182,6 +182,13 @@ flextitledraw(Monitor *m, Client *c, int unused, int x, int w, int tabscheme, Ar int tw = w; int clientscheme = ( + #if RENAMED_SCRATCHPADS_PATCH + c->scratchkey != 0 && c == selmon->sel + ? SchemeScratchSel + : c->scratchkey != 0 + ? SchemeScratchNorm + : + #endif // RENAMED_SCRATCHPADS_PATCH c == selmon->sel && HIDDEN(c) ? SchemeHidSel : HIDDEN(c) diff --git a/patch/dwmc.c b/patch/dwmc.c index b515f87..374944c 100644 --- a/patch/dwmc.c +++ b/patch/dwmc.c @@ -13,7 +13,7 @@ viewex(const Arg *arg) void viewallex(const Arg *arg) { - #if SCRATCHPADS_PATCH + #if SCRATCHPADS_PATCH && !RENAMED_SCRATCHPADS_PATCH view(&((Arg){.ui = ~SPTAGMASK})); #else view(&((Arg){.ui = ~0})); @@ -41,7 +41,7 @@ toggletagex(const Arg *arg) void tagallex(const Arg *arg) { - #if SCRATCHPADS_PATCH + #if SCRATCHPADS_PATCH && !RENAMED_SCRATCHPADS_PATCH tag(&((Arg){.ui = ~SPTAGMASK})); #else tag(&((Arg){.ui = ~0})); diff --git a/patch/include.c b/patch/include.c index cf24638..17f2e81 100644 --- a/patch/include.c +++ b/patch/include.c @@ -218,7 +218,9 @@ #if ROUNDED_CORNERS_PATCH #include "roundedcorners.c" #endif -#if SCRATCHPADS_PATCH +#if RENAMED_SCRATCHPADS_PATCH +#include "renamed_scratchpads.c" +#elif SCRATCHPADS_PATCH #include "scratchpad.c" #endif #if SCRATCHPAD_ALT_1_PATCH diff --git a/patch/include.h b/patch/include.h index 52da603..0cf267a 100644 --- a/patch/include.h +++ b/patch/include.h @@ -217,7 +217,9 @@ #if ROUNDED_CORNERS_PATCH #include "roundedcorners.h" #endif -#if SCRATCHPADS_PATCH +#if RENAMED_SCRATCHPADS_PATCH +#include "renamed_scratchpads.h" +#elif SCRATCHPADS_PATCH #include "scratchpad.h" #endif #if SCRATCHPAD_ALT_1_PATCH diff --git a/patch/pertag.c b/patch/pertag.c index f534023..a9f5565 100644 --- a/patch/pertag.c +++ b/patch/pertag.c @@ -33,7 +33,7 @@ pertagview(const Arg *arg) if (arg->ui & TAGMASK) { selmon->pertag->prevtag = selmon->pertag->curtag; selmon->tagset[selmon->seltags] = arg->ui & TAGMASK; - #if SCRATCHPADS_PATCH + #if SCRATCHPADS_PATCH && !RENAMED_SCRATCHPADS_PATCH if (arg->ui == ~SPTAGMASK) #else if (arg->ui == ~0) diff --git a/patch/renamed_scratchpads.c b/patch/renamed_scratchpads.c new file mode 100644 index 0000000..db99723 --- /dev/null +++ b/patch/renamed_scratchpads.c @@ -0,0 +1,151 @@ +void +removescratch(const Arg *arg) +{ + Client *c = selmon->sel; + if (!c) + return; + c->scratchkey = 0; +} + +void +setscratch(const Arg *arg) +{ + Client *c = selmon->sel; + if (!c) + return; + + c->scratchkey = ((char**)arg->v)[0][0]; +} + +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 +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); + } +} + diff --git a/patch/renamed_scratchpads.h b/patch/renamed_scratchpads.h new file mode 100644 index 0000000..3260462 --- /dev/null +++ b/patch/renamed_scratchpads.h @@ -0,0 +1,4 @@ +static void removescratch(const Arg *arg); +static void setscratch(const Arg *arg); +static void spawnscratch(const Arg *arg); +static void togglescratch(const Arg *arg); diff --git a/patch/setborderpx.c b/patch/setborderpx.c index 56c7636..6cc0b34 100644 --- a/patch/setborderpx.c +++ b/patch/setborderpx.c @@ -39,7 +39,7 @@ setborderpx(const Arg *arg) if (HIDDEN(c)) continue; #endif // BAR_WINTITLEACTIONS_PATCH - #if SCRATCHPADS_PATCH + #if SCRATCHPADS_PATCH && !RENAMED_SCRATCHPADS_PATCH if ((c->tags & SPTAGMASK) && !ISVISIBLE(c)) continue; #endif // SCRATCHPADS_PATCH diff --git a/patch/shiftview.c b/patch/shiftview.c index b9c811a..efb5674 100644 --- a/patch/shiftview.c +++ b/patch/shiftview.c @@ -2,7 +2,7 @@ void shiftview(const Arg *arg) { Arg shifted; - #if SCRATCHPADS_PATCH + #if SCRATCHPADS_PATCH && !RENAMED_SCRATCHPADS_PATCH unsigned int seltagset = selmon->tagset[selmon->seltags] & ~SPTAGMASK; #else unsigned int seltagset = selmon->tagset[selmon->seltags]; @@ -11,7 +11,7 @@ shiftview(const Arg *arg) shifted.ui = (seltagset << arg->i) | (seltagset >> (NUMTAGS - arg->i)); else // right circular shift shifted.ui = (seltagset >> -arg->i) | (seltagset << (NUMTAGS + arg->i)); - #if SCRATCHPADS_PATCH + #if SCRATCHPADS_PATCH && !RENAMED_SCRATCHPADS_PATCH shifted.ui &= ~SPTAGMASK; #endif // SCRATCHPADS_PATCH diff --git a/patch/shiftviewclients.c b/patch/shiftviewclients.c index adeaab7..5755e7c 100644 --- a/patch/shiftviewclients.c +++ b/patch/shiftviewclients.c @@ -10,7 +10,7 @@ shiftviewclients(const Arg *arg) for (selmon = mons; selmon; selmon = selmon->next) #endif // TAGSYNC_PATCH for (c = selmon->clients; c; c = c->next) { - #if SCRATCHPADS_PATCH + #if SCRATCHPADS_PATCH && !RENAMED_SCRATCHPADS_PATCH if (!(c->tags & SPTAGMASK)) tagmask = tagmask | c->tags; #elif SCRATCHPAD_ALT_1_PATCH @@ -24,7 +24,7 @@ shiftviewclients(const Arg *arg) selmon = origselmon; #endif // TAGSYNC_PATCH - #if SCRATCHPADS_PATCH + #if SCRATCHPADS_PATCH && !RENAMED_SCRATCHPADS_PATCH shifted.ui = selmon->tagset[selmon->seltags] & ~SPTAGMASK; #else shifted.ui = selmon->tagset[selmon->seltags]; @@ -37,7 +37,7 @@ shiftviewclients(const Arg *arg) else // right circular shift shifted.ui = (shifted.ui >> -arg->i) | (shifted.ui << (NUMTAGS + arg->i)); - #if SCRATCHPADS_PATCH + #if SCRATCHPADS_PATCH && !RENAMED_SCRATCHPADS_PATCH shifted.ui &= ~SPTAGMASK; #endif // SCRATCHPADS_PATCH } while (tagmask && !(shifted.ui & tagmask)); diff --git a/patch/xrdb.c b/patch/xrdb.c index 1490ace..aa32854 100644 --- a/patch/xrdb.c +++ b/patch/xrdb.c @@ -48,6 +48,16 @@ loadxrdb() XRDB_LOAD_COLOR("dwm.urgbgcolor", urgbgcolor); XRDB_LOAD_COLOR("dwm.urgbordercolor", urgbordercolor); XRDB_LOAD_COLOR("dwm.urgfloatcolor", urgfloatcolor); + #if RENAMED_SCRATCHPADS_PATCH + XRDB_LOAD_COLOR("dwm.scratchselfgcolor", scratchselfgcolor); + XRDB_LOAD_COLOR("dwm.scratchselbgcolor", scratchselbgcolor); + XRDB_LOAD_COLOR("dwm.scratchselbordercolor", scratchselbordercolor); + XRDB_LOAD_COLOR("dwm.scratchselfloatcolor", scratchselfloatcolor); + XRDB_LOAD_COLOR("dwm.scratchnormfgcolor", scratchnormfgcolor); + XRDB_LOAD_COLOR("dwm.scratchnormbgcolor", scratchnormbgcolor); + XRDB_LOAD_COLOR("dwm.scratchnormbordercolor", scratchnormbordercolor); + XRDB_LOAD_COLOR("dwm.scratchnormfloatcolor", scratchnormfloatcolor); + #endif // RENAMED_SCRATCHPADS_PATCH #if BAR_FLEXWINTITLE_PATCH XRDB_LOAD_COLOR("dwm.normTTBbgcolor", normTTBbgcolor); XRDB_LOAD_COLOR("dwm.normLTRbgcolor", normLTRbgcolor); |
