diff options
| author | Thomas Ulmer <thomasmulmer02@gmail.com> | 2026-02-20 18:39:46 -0800 |
|---|---|---|
| committer | Thomas Ulmer <thomasmulmer02@gmail.com> | 2026-02-20 18:39:46 -0800 |
| commit | 5b8463c04f0e3620467bdd4c27397c68b14dde5a (patch) | |
| tree | f2def68100383365d2e0c9ae3004916b81eb36be /tree/src/dwm/dwm-6.6 | |
| parent | bc701dc35fe084196244f45a93bcac4d119c1f76 (diff) | |
dwm scratchpad with -/+/=
Diffstat (limited to 'tree/src/dwm/dwm-6.6')
| -rw-r--r-- | tree/src/dwm/dwm-6.6/config.def.h | 3 | ||||
| -rw-r--r-- | tree/src/dwm/dwm-6.6/dwm.c | 109 |
2 files changed, 110 insertions, 2 deletions
diff --git a/tree/src/dwm/dwm-6.6/config.def.h b/tree/src/dwm/dwm-6.6/config.def.h index 7a94e14..93b891a 100644 --- a/tree/src/dwm/dwm-6.6/config.def.h +++ b/tree/src/dwm/dwm-6.6/config.def.h @@ -115,6 +115,9 @@ static const Key keys[] = { TAGKEYS( XK_8, 7) TAGKEYS( XK_9, 8) { MODKEY|ShiftMask, XK_q, quitprompt, {0} }, + { MODKEY, XK_minus, scratchpad_show, {0} }, + { MODKEY|ShiftMask, XK_minus, scratchpad_hide, {0} }, + { MODKEY, XK_equal,scratchpad_remove,{0} }, }; /* button definitions */ diff --git a/tree/src/dwm/dwm-6.6/dwm.c b/tree/src/dwm/dwm-6.6/dwm.c index b51fd0d..0369cd3 100644 --- a/tree/src/dwm/dwm-6.6/dwm.c +++ b/tree/src/dwm/dwm-6.6/dwm.c @@ -203,6 +203,12 @@ static void resizemouse(const Arg *arg); static void restack(Monitor *m); static void run(void); static void scan(void); +static void scratchpad_hide (); +static _Bool scratchpad_last_showed_is_killed (void); +static void scratchpad_remove (); +static void scratchpad_show (); +static void scratchpad_show_client (Client * c); +static void scratchpad_show_first (void); static void selectclient(const Arg *arg); static int sendevent(Client *c, Atom proto); static void sendmon(Client *c, Monitor *m); @@ -282,11 +288,15 @@ static Monitor *mons, *selmon; static Window root, wmcheckwin; static Clientlist *cl; +/* scratchpad */ +# define SCRATCHPAD_MASK (1u << sizeof tags / sizeof * tags) +static Client * scratchpad_last_showed = NULL; + /* configuration, allows nested code to access above variables */ #include "config.h" /* compile-time check if all tags fit into an unsigned int bit array. */ -struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; }; +struct NumTags { char limitexceeded[LENGTH(tags) > 30 ? -1 : 1]; }; /* function implementations */ void @@ -322,7 +332,8 @@ 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]; + if (c->tags != SCRATCHPAD_MASK) + c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : c->mon->tagset[c->mon->seltags]; } int @@ -1594,6 +1605,98 @@ selectclient(const Arg *_arg) } } +static void scratchpad_hide () +{ + if (selmon -> sel) + { + selmon -> sel -> tags = SCRATCHPAD_MASK; + selmon -> sel -> isfloating = 1; + focus(NULL); + arrange(selmon); + } +} + +static _Bool scratchpad_last_showed_is_killed (void) +{ + _Bool killed = 1; + for (Client * c = selmon->cl->clients; c != NULL; c = c -> next) + { + if (c == scratchpad_last_showed) + { + killed = 0; + break; + } + } + return killed; +} + +static void scratchpad_remove () +{ + if (selmon -> sel && scratchpad_last_showed != NULL && selmon -> sel == scratchpad_last_showed) + scratchpad_last_showed = NULL; +} + +static void scratchpad_show () +{ + if (scratchpad_last_showed == NULL || scratchpad_last_showed_is_killed ()) + scratchpad_show_first (); + else + { + if (scratchpad_last_showed -> tags != SCRATCHPAD_MASK) + { + scratchpad_last_showed -> tags = SCRATCHPAD_MASK; + focus(NULL); + arrange(selmon); + } + else + { + _Bool found_current = 0; + _Bool found_next = 0; + for (Client * c = selmon->cl->clients; c != NULL; c = c -> next) + { + if (found_current == 0) + { + if (c == scratchpad_last_showed) + { + found_current = 1; + continue; + } + } + else + { + if (c -> tags == SCRATCHPAD_MASK) + { + found_next = 1; + scratchpad_show_client (c); + break; + } + } + } + if (found_next == 0) scratchpad_show_first (); + } + } +} + +static void scratchpad_show_client (Client * c) +{ + scratchpad_last_showed = c; + c -> tags = selmon->tagset[selmon->seltags]; + focus(c); + arrange(selmon); +} + +static void scratchpad_show_first (void) +{ + for (Client * c = selmon->cl->clients; c != NULL; c = c -> next) + { + if (c -> tags == SCRATCHPAD_MASK) + { + scratchpad_show_client (c); + break; + } + } +} + void sendmon(Client *c, Monitor *m) { @@ -2008,6 +2111,8 @@ unmanage(Client *c, int destroyed) XSetErrorHandler(xerror); XUngrabServer(dpy); } + if (scratchpad_last_showed == c) + scratchpad_last_showed = NULL; free(c); focus(NULL); updateclientlist(); |
