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.
patches/dwm/dwm-renamedscratchpads-stat...

140 lines
5.0 KiB
Diff

From fb46e7d8f708a5ba87ac36f3a614869a1f266cc7 Mon Sep 17 00:00:00 2001
From: Bakkeby <bakkeby@gmail.com>
Date: Mon, 10 Jan 2022 13:30:39 +0100
Subject: [PATCH 2/2] Another namedscratchpads variant where scratchpads remain
on the monitors where they reside
---
dwm.c | 101 ++++++++++------------------------------------------------
1 file changed, 16 insertions(+), 85 deletions(-)
diff --git a/dwm.c b/dwm.c
index c58c6ed..6e49100 100644
--- a/dwm.c
+++ b/dwm.c
@@ -1775,34 +1775,12 @@ togglefloating(const Arg *arg)
void
togglescratch(const Arg *arg)
{
- Client *c, *next, *last = NULL, *found = NULL, *monclients = NULL;
+ Client *c, *next, *found = 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;
- }
+ int tags = 0, monfound;
- /* 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) {
+ monfound = 0;
for (c = mon->stack; c; c = next) {
next = c->snext;
if (c->scratchkey != ((char**)arg->v)[0][0])
@@ -1815,70 +1793,23 @@ togglescratch(const Arg *arg)
}
*/
- /* 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;
+ unfocus(c, 0);
+ monfound = 1;
- /* 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);
+ if (!found || mon == selmon) {
+ found = c;
+ tags = (c->tags == 0 ? c->mon->tagset[c->mon->seltags] : 0);
}
- }
- }
- /* 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);
+ detachstack(c);
+ attachstack(c);
+ c->tags = tags;
+ if (c->tags && c->isfloating)
+ XRaiseWindow(dpy, c->win);
}
+
+ if (monfound)
+ arrange(mon);
}
if (found) {
--
2.19.1