diff --git a/README.md b/README.md index a349526..62472d0 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,8 @@ Browsing patches? There is a [map of patches](https://coggle.it/diagram/X9IiSSM6 ### Changelog: +2022-06-20 - Added the renamed scratchpads patch + 2022-06-17 - Ported the seamless restart feature from dusk into dwm-flexipatch 2022-02-11 - Added the isfreesize version of the sizehints patch and the [tagsync](https://github.com/bakkeby/dwm-flexipatch/pull/219) patch (contributed by [Bagelli](https://github.com/Bagellll)) @@ -565,6 +567,9 @@ Browsing patches? There is a [map of patches](https://coggle.it/diagram/X9IiSSM6 - [push](https://dwm.suckless.org/patches/push/) - this patch provides a way to move clients up and down inside the client list + - [renamed_scratchpads](https://github.com/bakkeby/patches/wiki/renamedscratchpads) + - variant of the [named scratchpads](https://dwm.suckless.org/patches/namedscratchpads/) patch + - [reorganizetags](https://dwm.suckless.org/patches/reorganizetags/) - shifts all clients per tag to leftmost unoccupied tags - e.g. if clients A, B, C are tagged on tags 1, 5, 9 respectively, when reorganized they will diff --git a/config.def.h b/config.def.h index f74b909..40c9f46 100644 --- a/config.def.h +++ b/config.def.h @@ -173,6 +173,18 @@ static char urgbgcolor[] = "#222222"; static char urgbordercolor[] = "#ff0000"; static char urgfloatcolor[] = "#db8fd9"; +#if RENAMED_SCRATCHPADS_PATCH +static char scratchselfgcolor[] = "#FFF7D4"; +static char scratchselbgcolor[] = "#77547E"; +static char scratchselbordercolor[] = "#894B9F"; +static char scratchselfloatcolor[] = "#894B9F"; + +static char scratchnormfgcolor[] = "#FFF7D4"; +static char scratchnormbgcolor[] = "#664C67"; +static char scratchnormbordercolor[] = "#77547E"; +static char scratchnormfloatcolor[] = "#77547E"; +#endif // RENAMED_SCRATCHPADS_PATCH + #if BAR_FLEXWINTITLE_PATCH static char normTTBbgcolor[] = "#330000"; static char normLTRbgcolor[] = "#330033"; @@ -223,6 +235,10 @@ static const unsigned int alphas[][3] = { [SchemeHidNorm] = { OPAQUE, baralpha, borderalpha }, [SchemeHidSel] = { OPAQUE, baralpha, borderalpha }, [SchemeUrg] = { OPAQUE, baralpha, borderalpha }, + #if RENAMED_SCRATCHPADS_PATCH + [SchemeScratchSel] = { OPAQUE, baralpha, borderalpha }, + [SchemeScratchNorm] = { OPAQUE, baralpha, borderalpha }, + #endif // RENAMED_SCRATCHPADS_PATCH #if BAR_FLEXWINTITLE_PATCH [SchemeFlexActTTB] = { OPAQUE, baralpha, borderalpha }, [SchemeFlexActLTR] = { OPAQUE, baralpha, borderalpha }, @@ -288,6 +304,10 @@ static char *colors[][ColCount] = { [SchemeHidNorm] = { hidnormfgcolor, hidnormbgcolor, c000000, c000000 }, [SchemeHidSel] = { hidselfgcolor, hidselbgcolor, c000000, c000000 }, [SchemeUrg] = { urgfgcolor, urgbgcolor, urgbordercolor, urgfloatcolor }, + #if RENAMED_SCRATCHPADS_PATCH + [SchemeScratchSel] = { scratchselfgcolor, scratchselbgcolor, scratchselbordercolor, scratchselfloatcolor }, + [SchemeScratchNorm] = { scratchnormfgcolor, scratchnormbgcolor, scratchnormbordercolor, scratchnormfloatcolor }, + #endif // RENAMED_SCRATCHPADS_PATCH #if BAR_FLEXWINTITLE_PATCH [SchemeFlexActTTB] = { titleselfgcolor, actTTBbgcolor, actTTBbgcolor, c000000 }, [SchemeFlexActLTR] = { titleselfgcolor, actLTRbgcolor, actLTRbgcolor, c000000 }, @@ -351,7 +371,9 @@ static const char *const autostart[] = { }; #endif // COOL_AUTOSTART_PATCH -#if SCRATCHPADS_PATCH +#if RENAMED_SCRATCHPADS_PATCH +static const char *scratchpadcmd[] = {"s", "st", "-n", "spterm", NULL}; +#elif SCRATCHPADS_PATCH const char *spcmd1[] = {"st", "-n", "spterm", "-g", "120x34", NULL }; static Sp scratchpads[] = { /* name cmd */ @@ -437,7 +459,9 @@ static const Rule rules[] = { RULE(.wintype = WTYPE "SPLASH", .isfloating = 1) RULE(.class = "Gimp", .tags = 1 << 4) RULE(.class = "Firefox", .tags = 1 << 7) - #if SCRATCHPADS_PATCH + #if RENAMED_SCRATCHPADS_PATCH + RULE(.instance = "spterm", .scratchkey = 's', .isfloating = 1) + #elif SCRATCHPADS_PATCH RULE(.instance = "spterm", .tags = SPTAG(0), .isfloating = 1) #endif // SCRATCHPADS_PATCH }; @@ -1018,11 +1042,15 @@ static Key keys[] = { #if NO_MOD_BUTTONS_PATCH { MODKEY|ShiftMask, XK_Escape, togglenomodbuttons, {0} }, #endif // NO_MOD_BUTTONS_PATCH - #if SCRATCHPADS_PATCH + #if RENAMED_SCRATCHPADS_PATCH + { MODKEY, XK_grave, togglescratch, {.v = scratchpadcmd } }, + { MODKEY|ControlMask, XK_grave, setscratch, {.v = scratchpadcmd } }, + { MODKEY|ShiftMask, XK_grave, removescratch, {.v = scratchpadcmd } }, + #elif SCRATCHPADS_PATCH { MODKEY, XK_grave, togglescratch, {.ui = 0 } }, { MODKEY|ControlMask, XK_grave, setscratch, {.ui = 0 } }, { MODKEY|ShiftMask, XK_grave, removescratch, {.ui = 0 } }, - #endif // SCRATCHPADS_PATCH + #endif // SCRATCHPADS_PATCH | RENAMED_SCRATCHPADS_PATCH #if UNFLOATVISIBLE_PATCH { MODKEY|Mod4Mask, XK_space, unfloatvisible, {0} }, { MODKEY|ShiftMask, XK_t, unfloatvisible, {.v = &layouts[0]} }, @@ -1043,7 +1071,7 @@ static Key keys[] = { { MODKEY, XK_minus, scratchpad_show, {0} }, { MODKEY|ShiftMask, XK_minus, scratchpad_hide, {0} }, { MODKEY, XK_equal, scratchpad_remove, {0} }, - #elif SCRATCHPADS_PATCH + #elif SCRATCHPADS_PATCH && !RENAMED_SCRATCHPADS_PATCH { MODKEY, XK_0, view, {.ui = ~SPTAGMASK } }, { MODKEY|ShiftMask, XK_0, tag, {.ui = ~SPTAGMASK } }, #else @@ -1447,7 +1475,7 @@ static Signal signals[] = { { "toggleverticalmax", toggleverticalmax }, { "togglemax", togglemax }, #endif // MAXIMIZE_PATCH - #if SCRATCHPADS_PATCH + #if SCRATCHPADS_PATCH && !RENAMED_SCRATCHPADS_PATCH { "togglescratch", togglescratch }, #endif // SCRATCHPADS_PATCH #if UNFLOATVISIBLE_PATCH @@ -1572,7 +1600,7 @@ static IPCCommand ipccommands[] = { #if ROTATESTACK_PATCH IPCCOMMAND( rotatestack, 1, {ARG_TYPE_SINT} ), #endif // ROTATESTACK_PATCH - #if SCRATCHPADS_PATCH + #if SCRATCHPADS_PATCH && !RENAMED_SCRATCHPADS_PATCH IPCCOMMAND( togglescratch, 1, {ARG_TYPE_UINT} ), #endif // SCRATCHPADS_PATCH #if SELFRESTART_PATCH diff --git a/dwm.c b/dwm.c index 02dea6b..8d8ca19 100644 --- a/dwm.c +++ b/dwm.c @@ -101,7 +101,7 @@ #define WIDTH(X) ((X)->w + 2 * (X)->bw) #define HEIGHT(X) ((X)->h + 2 * (X)->bw) #define WTYPE "_NET_WM_WINDOW_TYPE_" -#if SCRATCHPADS_PATCH +#if SCRATCHPADS_PATCH && !RENAMED_SCRATCHPADS_PATCH #define TOTALTAGS (NUMTAGS + LENGTH(scratchpads)) #define TAGMASK ((1 << TOTALTAGS) - 1) #define SPTAG(i) ((1 << NUMTAGS) << (i)) @@ -144,6 +144,10 @@ enum { SchemeHidNorm, SchemeHidSel, SchemeUrg, + #if RENAMED_SCRATCHPADS_PATCH + SchemeScratchSel, + SchemeScratchNorm, + #endif // RENAMED_SCRATCHPADS_PATCH #if BAR_FLEXWINTITLE_PATCH SchemeFlexActTTB, SchemeFlexActLTR, @@ -402,6 +406,9 @@ struct Client { #if IPC_PATCH ClientState prevstate; #endif // IPC_PATCH + #if RENAMED_SCRATCHPADS_PATCH + char scratchkey; + #endif // RENAMED_SCRATCHPADS_PATCH #if XKB_PATCH XkbInfo *xkb; #endif // XKB_PATCH @@ -543,6 +550,9 @@ typedef struct { const char *floatpos; #endif // FLOATPOS_PATCH int monitor; + #if RENAMED_SCRATCHPADS_PATCH + const char scratchkey; + #endif // RENAMED_SCRATCHPADS_PATCH #if XKB_PATCH int xkb_layout; #endif // XKB_PATCH @@ -849,6 +859,9 @@ applyrules(Client *c) #endif // SIZEHINTS_ISFREESIZE_PATCH c->isfloating = 0; c->tags = 0; + #if RENAMED_SCRATCHPADS_PATCH + c->scratchkey = 0; + #endif // RENAMED_SCRATCHPADS_PATCH XGetClassHint(dpy, c->win, &ch); class = ch.res_class ? ch.res_class : broken; instance = ch.res_name ? ch.res_name : broken; @@ -890,7 +903,9 @@ applyrules(Client *c) #endif // SIZEHINTS_ISFREESIZE_PATCH c->isfloating = r->isfloating; c->tags |= r->tags; - #if SCRATCHPADS_PATCH + #if RENAMED_SCRATCHPADS_PATCH + c->scratchkey = r->scratchkey; + #elif SCRATCHPADS_PATCH if ((r->tags & SPTAGMASK) && r->isfloating) { c->x = c->mon->wx + (c->mon->ww / 2 - WIDTH(c) / 2); c->y = c->mon->wy + (c->mon->wh / 2 - HEIGHT(c) / 2); @@ -963,7 +978,7 @@ applyrules(Client *c) XFree(ch.res_name); #if EMPTYVIEW_PATCH if (c->tags & TAGMASK) c->tags = c->tags & TAGMASK; - #if SCRATCHPADS_PATCH + #if SCRATCHPADS_PATCH && !RENAMED_SCRATCHPADS_PATCH else if (c->mon->tagset[c->mon->seltags]) c->tags = c->mon->tagset[c->mon->seltags] & ~SPTAGMASK; #elif SCRATCHPAD_ALT_1_PATCH else if (c->tags != SCRATCHPAD_MASK && c->mon->tagset[c->mon->seltags]) c->tags = c->mon->tagset[c->mon->seltags]; @@ -971,7 +986,7 @@ applyrules(Client *c) else if (c->mon->tagset[c->mon->seltags]) c->tags = c->mon->tagset[c->mon->seltags]; #endif // SCRATCHPADS_PATCH else c->tags = 1; - #elif SCRATCHPADS_PATCH + #elif SCRATCHPADS_PATCH && !RENAMED_SCRATCHPADS_PATCH c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : (c->mon->tagset[c->mon->seltags] & ~SPTAGMASK); #elif SCRATCHPAD_ALT_1_PATCH if (c->tags != SCRATCHPAD_MASK) @@ -1997,10 +2012,21 @@ focus(Client *c) attachstack(c); grabbuttons(c, 1); #if !BAR_FLEXWINTITLE_PATCH + #if RENAMED_SCRATCHPADS_PATCH + if (c->scratchkey != 0 && c->isfloating) + XSetWindowBorder(dpy, c->win, scheme[SchemeScratchSel][ColFloat].pixel); + else if (c->scratchkey != 0) + XSetWindowBorder(dpy, c->win, scheme[SchemeScratchSel][ColBorder].pixel); + else if (c->isfloating) + XSetWindowBorder(dpy, c->win, scheme[SchemeSel][ColFloat].pixel); + else + XSetWindowBorder(dpy, c->win, scheme[SchemeSel][ColBorder].pixel); + #else if (c->isfloating) XSetWindowBorder(dpy, c->win, scheme[SchemeSel][ColFloat].pixel); else XSetWindowBorder(dpy, c->win, scheme[SchemeSel][ColBorder].pixel); + #endif // RENAMED_SCRATCHPADS_PATCH #endif // BAR_FLEXWINTITLE_PATCH setfocus(c); } else { @@ -2688,7 +2714,7 @@ movemouse(const Arg *arg) XUngrabPointer(dpy, CurrentTime); if ((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) { - #if SCRATCHPADS_PATCH + #if SCRATCHPADS_PATCH && !RENAMED_SCRATCHPADS_PATCH if (c->tags & SPTAGMASK) { c->mon->tagset[c->mon->seltags] ^= (c->tags & SPTAGMASK); m->tagset[m->seltags] |= (c->tags & SPTAGMASK); @@ -3040,7 +3066,7 @@ resizemouse(const Arg *arg) XUngrabPointer(dpy, CurrentTime); while (XCheckMaskEvent(dpy, EnterWindowMask, &ev)); if ((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) { - #if SCRATCHPADS_PATCH + #if SCRATCHPADS_PATCH && !RENAMED_SCRATCHPADS_PATCH if (c->tags & SPTAGMASK) { c->mon->tagset[c->mon->seltags] ^= (c->tags & SPTAGMASK); m->tagset[m->seltags] |= (c->tags & SPTAGMASK); @@ -3239,7 +3265,7 @@ sendmon(Client *c, Monitor *m) arrange(c->mon); #endif // SENDMON_KEEPFOCUS_PATCH c->mon = m; - #if SCRATCHPADS_PATCH + #if SCRATCHPADS_PATCH && !RENAMED_SCRATCHPADS_PATCH if (!(c->tags & SPTAGMASK)) #endif // SCRATCHPADS_PATCH #if EMPTYVIEW_PATCH @@ -3782,6 +3808,7 @@ showhide(Client *c) if (!c) return; if (ISVISIBLE(c)) { + #if !RENAMED_SCRATCHPADS_PATCH #if SCRATCHPADS_PATCH && SCRATCHPADS_KEEP_POSITION_AND_SIZE_PATCH if ( (c->tags & SPTAGMASK) && @@ -3802,6 +3829,7 @@ showhide(Client *c) c->y = c->mon->wy + (c->mon->wh / 2 - HEIGHT(c) / 2); } #endif // SCRATCHPADS_KEEP_POSITION_AND_SIZE_PATCH | SCRATCHPADS_PATCH + #endif // RENAMED_SCRATCHPADS_PATCH /* show clients top down */ #if SAVEFLOATS_PATCH || EXRESIZE_PATCH if (!c->mon->lt[c->mon->sellt]->arrange && c->sfx != -9999 && !c->isfullscreen) { @@ -3829,6 +3857,11 @@ showhide(Client *c) resize(c, c->x, c->y, c->w, c->h, 0); showhide(c->snext); } else { + #if RENAMED_SCRATCHPADS_PATCH && RENAMED_SCRATCHPADS_AUTO_HIDE_PATCH + /* optional: auto-hide scratchpads when moving to other tags */ + if (c->scratchkey != 0 && !(c->tags & c->mon->tagset[c->mon->seltags])) + c->tags = 0; + #endif // RENAMED_SCRATCHPADS_AUTO_HIDE_PATCH /* hide clients bottom up */ showhide(c->snext); XMoveWindow(dpy, c->win, WIDTH(c) * -2, c->y); @@ -4168,7 +4201,7 @@ toggleview(const Arg *arg) selmon->tagset[selmon->seltags] = newtagset; #if PERTAG_PATCH - #if SCRATCHPADS_PATCH + #if SCRATCHPADS_PATCH && !RENAMED_SCRATCHPADS_PATCH if (newtagset == ~SPTAGMASK) #else if (newtagset == ~0) @@ -4238,10 +4271,21 @@ unfocus(Client *c, int setfocus, Client *nextfocus) #endif // LOSEFULLSCREEN_PATCH grabbuttons(c, 0); #if !BAR_FLEXWINTITLE_PATCH + #if RENAMED_SCRATCHPADS_PATCH + if (c->scratchkey != 0 && c->isfloating) + XSetWindowBorder(dpy, c->win, scheme[SchemeScratchNorm][ColFloat].pixel); + else if (c->scratchkey != 0) + XSetWindowBorder(dpy, c->win, scheme[SchemeScratchNorm][ColBorder].pixel); + else if (c->isfloating) + XSetWindowBorder(dpy, c->win, scheme[SchemeNorm][ColFloat].pixel); + else + XSetWindowBorder(dpy, c->win, scheme[SchemeNorm][ColBorder].pixel); + #else if (c->isfloating) XSetWindowBorder(dpy, c->win, scheme[SchemeNorm][ColFloat].pixel); else XSetWindowBorder(dpy, c->win, scheme[SchemeNorm][ColBorder].pixel); + #endif // RENAMED_SCRATCHPADS_PATCH #endif // BAR_FLEXWINTITLE_PATCH if (setfocus) { XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); 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); diff --git a/patches.def.h b/patches.def.h index 759e97b..3cc9756 100644 --- a/patches.def.h +++ b/patches.def.h @@ -844,6 +844,18 @@ */ #define PUSH_NO_MASTER_PATCH 0 +/* Variant of the named scratchpads patch allowing scratch keys to be added or removed + * on demand, allowing multiple scratchpad windows to be toggled into and out of view + * in unison, as well as including multi-monitor support. + * + * https://github.com/bakkeby/patches/wiki/renamedscratchpads + */ +#define RENAMED_SCRATCHPADS_PATCH 0 + +/* Renamed scratchpads option to auto-hide scratchpads when moving to a different tag. + * This behaviour is similar to that of the (multiple) scratchpads patch. */ +#define RENAMED_SCRATCHPADS_AUTO_HIDE_PATCH 0 + /* Shifts all clients per tag to leftmost unoccupied tags. * * For example, if clients A, B, C are tagged on tags 1, 5, 9 respectively, when