From 6f5b1582d6e1cdc9f7fb851d2aa9ad2e319e718f Mon Sep 17 00:00:00 2001 From: bakkeby Date: Sat, 26 Sep 2020 12:42:56 +0200 Subject: [PATCH 1/4] scratchpads: enhancing scratchpad by allowing arbitrary clients to be added to (and removed from) each scratchpad area --- config.def.h | 10 ++---- patch/scratchpad.c | 81 ++++++++++++++++++++++++++++++---------------- patch/scratchpad.h | 2 ++ 3 files changed, 58 insertions(+), 35 deletions(-) diff --git a/config.def.h b/config.def.h index 454f0cb..839ac26 100644 --- a/config.def.h +++ b/config.def.h @@ -305,13 +305,9 @@ static const char *const autostart[] = { #if SCRATCHPADS_PATCH const char *spcmd1[] = {"st", "-n", "spterm", "-g", "120x34", NULL }; -const char *spcmd2[] = {"st", "-n", "spfm", "-g", "144x41", "-e", "ranger", NULL }; -const char *spcmd3[] = {"keepassxc", NULL }; static Sp scratchpads[] = { /* name cmd */ {"spterm", spcmd1}, - {"spranger", spcmd2}, - {"keepassxc", spcmd3}, }; #endif // SCRATCHPADS_PATCH @@ -395,8 +391,6 @@ static const Rule rules[] = { RULE(.class = "Firefox", .tags = 1 << 7) #if SCRATCHPADS_PATCH RULE(.instance = "spterm", .tags = SPTAG(0), .isfloating = 1) - RULE(.instance = "spfm", .tags = SPTAG(1), .isfloating = 1) - RULE(.instance = "keepassxc", .tags = SPTAG(2)) #endif // SCRATCHPADS_PATCH }; @@ -903,8 +897,8 @@ static Key keys[] = { #endif // NO_MOD_BUTTONS_PATCH #if SCRATCHPADS_PATCH { MODKEY, XK_grave, togglescratch, {.ui = 0 } }, - { MODKEY|ControlMask, XK_grave, togglescratch, {.ui = 1 } }, - { MODKEY|ShiftMask, XK_grave, togglescratch, {.ui = 2 } }, + { MODKEY|ControlMask, XK_grave, setscratch, {.ui = 0 } }, + { MODKEY|ShiftMask, XK_grave, removescratch, {.ui = 0 } }, #endif // SCRATCHPADS_PATCH #if UNFLOATVISIBLE_PATCH { MODKEY|Mod4Mask, XK_space, unfloatvisible, {0} }, diff --git a/patch/scratchpad.c b/patch/scratchpad.c index 5813b6f..2034d0d 100644 --- a/patch/scratchpad.c +++ b/patch/scratchpad.c @@ -1,45 +1,72 @@ +void +removescratch(const Arg *arg) +{ + Client *c = selmon->sel; + if (!c) + return; + unsigned int scratchtag = SPTAG(arg->ui); + c->tags = c->mon->tagset[c->mon->seltags] ^ scratchtag; + arrange(c->mon); +} + +void +setscratch(const Arg *arg) +{ + Client *c = selmon->sel; + if (!c) + return; + unsigned int scratchtag = SPTAG(arg->ui); + c->tags = scratchtag; + arrange(c->mon); +} + void togglescratch(const Arg *arg) { - Client *c = NULL; + Client *c = NULL, *next = NULL, *found = NULL; Monitor *mon; - unsigned int found = 0; unsigned int scratchtag = SPTAG(arg->ui); - unsigned int newtagset; + unsigned int newtagset = 0; int nh = 0, nw = 0; Arg sparg = {.v = scratchpads[arg->ui].cmd}; - for (mon = mons; mon && !found; mon = mon->next) - for (c = mon->clients; c && !(found = c->tags & scratchtag); c = c->next); + for (mon = mons; mon; mon = mon->next) { + for (c = mon->clients; c; c = next) { + next = c->next; + if (!(c->tags & scratchtag)) + continue; + + found = c; + + if (HIDDEN(c)) { + XMapWindow(dpy, c->win); + setclientstate(c, NormalState); + newtagset = 0; + } else + newtagset = selmon->tagset[selmon->seltags] ^ scratchtag; + + if (c->mon != selmon) { + if (c->mon->tagset[c->mon->seltags] & SPTAGMASK) + c->mon->tagset[c->mon->seltags] ^= scratchtag; + if (c->w > selmon->ww) + nw = selmon->ww - c->bw * 2; + if (c->h > selmon->wh) + nh = selmon->wh - c->bw * 2; + if (nw > 0 || nh > 0) + resizeclient(c, c->x, c->y, nw ? nw : c->w, nh ? nh : c->h); + sendmon(c, selmon); + } + } + } if (found) { - - if (HIDDEN(c)) { - XMapWindow(dpy, c->win); - setclientstate(c, NormalState); - newtagset = 0; - } else - newtagset = selmon->tagset[selmon->seltags] ^ scratchtag; - - if (c->mon != selmon) { - if (c->mon->tagset[c->mon->seltags] & SPTAGMASK) - c->mon->tagset[c->mon->seltags] ^= scratchtag; - if (c->w > selmon->ww) - nw = selmon->ww - c->bw * 2; - if (c->h > selmon->wh) - nh = selmon->wh - c->bw * 2; - if (nw > 0 || nh > 0) - resizeclient(c, c->x, c->y, nw ? nw : c->w, nh ? nh : c->h); - sendmon(c, selmon); - } - if (newtagset) { selmon->tagset[selmon->seltags] = newtagset; focus(NULL); arrange(selmon); } - if (ISVISIBLE(c)) { - focus(c); + if (ISVISIBLE(found)) { + focus(found); restack(selmon); } } else { diff --git a/patch/scratchpad.h b/patch/scratchpad.h index 3142cdf..42e592b 100644 --- a/patch/scratchpad.h +++ b/patch/scratchpad.h @@ -3,4 +3,6 @@ typedef struct { const void *cmd; } Sp; +static void removescratch(const Arg *arg); +static void setscratch(const Arg *arg); static void togglescratch(const Arg *arg); \ No newline at end of file From efeb5fcbf4bbc74a0947efc4998ac3a04240d9dd Mon Sep 17 00:00:00 2001 From: B4rc1 <0b4rc1@gmail.com> Date: Sat, 26 Sep 2020 23:44:15 +0200 Subject: [PATCH 2/4] fixed warp patch for local monitor --- dwm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dwm.c b/dwm.c index e667a16..37f9c69 100644 --- a/dwm.c +++ b/dwm.c @@ -2780,7 +2780,7 @@ restack(Monitor *m) (m->lt[m->sellt]->arrange != &monocle && !(m->ltaxis[MASTER] == MONOCLE && (abs(m->ltaxis[LAYOUT] == NO_SPLIT || !m->nmaster || n <= m->nmaster)))) #elif MONOCLE_LAYOUT - m->lt[m->sellt]->arrange == &monocle + m->lt[m->sellt]->arrange != &monocle #else !(m->ltaxis[MASTER] == MONOCLE && (abs(m->ltaxis[LAYOUT] == NO_SPLIT || !m->nmaster || n <= m->nmaster))) #endif // FLEXTILE_DELUXE_LAYOUT From 74c9528c385310a57e9da1ad365d1c1429a7c89f Mon Sep 17 00:00:00 2001 From: B4rc1 <0b4rc1@gmail.com> Date: Sun, 27 Sep 2020 00:42:19 +0200 Subject: [PATCH 3/4] fixed warp patch for other monitor --- patch/warp.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/patch/warp.c b/patch/warp.c index acc69f8..58e2c99 100644 --- a/patch/warp.c +++ b/patch/warp.c @@ -13,10 +13,10 @@ warp(const Client *c) y > c->y - c->bw && x < c->x + c->w + c->bw*2 && y < c->y + c->h + c->bw*2) || - x < c->mon->wx || - x > c->mon->wx + c->mon->ww || - y < c->mon->wy || - y > c->mon->wy + c->mon->wh + (x < c->mon->wx && + x > c->mon->wx + c->mon->ww) || + (y < c->mon->wy || + y > c->mon->wy + c->mon->wh) ) return; From fcf96c0920fa81541d4b003c5828113338d3d896 Mon Sep 17 00:00:00 2001 From: bakkeby Date: Sun, 27 Sep 2020 11:15:45 +0200 Subject: [PATCH 4/4] warp: do not warp if mouse cursor is on top of any of the bars --- patch/warp.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/patch/warp.c b/patch/warp.c index 58e2c99..45048e2 100644 --- a/patch/warp.c +++ b/patch/warp.c @@ -1,6 +1,8 @@ void warp(const Client *c) { + Monitor *m; + Bar *bar; int x, y; if (!c) { @@ -12,13 +14,17 @@ warp(const Client *c) (x > c->x - c->bw && y > c->y - c->bw && x < c->x + c->w + c->bw*2 && - y < c->y + c->h + c->bw*2) || - (x < c->mon->wx && - x > c->mon->wx + c->mon->ww) || - (y < c->mon->wy || - y > c->mon->wy + c->mon->wh) + y < c->y + c->h + c->bw*2) ) return; + for (m = mons; m; m = m->next) + for (bar = m->bar; bar; bar = bar->next) + if (x > bar->bx && + x < bar->bx + bar->bw && + y > bar->by && + y < bar->by + bar->bh) + return; + XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w / 2, c->h / 2); }