From 0b3d70706a0aca6d4414d20a3f2ac4928e70d04e Mon Sep 17 00:00:00 2001 From: wochap Date: Wed, 6 Mar 2024 14:36:48 -0500 Subject: [PATCH] add focusortogglematchingscratch works like focusortoggle but it also hides all others scratchpads --- dwl.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/dwl.c b/dwl.c index 6b5d55db646cd4d16eb97b4c00b7272ab354b9da..e179940ed6f1f6d4c3b95574fd86a933486b67f2 100644 --- a/dwl.c +++ b/dwl.c @@ -318,6 +318,7 @@ static void togglefloating(const Arg *arg); static void togglefullscreen(const Arg *arg); static void togglescratch(const Arg *arg); static void focusortogglescratch(const Arg *arg); +static void focusortogglematchingscratch(const Arg *arg); static void toggletag(const Arg *arg); static void toggleview(const Arg *arg); static void unlocksession(struct wl_listener *listener, void *data); @@ -2528,6 +2529,48 @@ focusortogglescratch(const Arg *arg) } } +void +focusortogglematchingscratch(const Arg *arg) +{ + Client *c; + unsigned int found = 0; + + wl_list_for_each(c, &clients, link) { + if (c->scratchkey == 0) { + continue; + } + if (c->scratchkey == ((char**)arg->v)[0][0]) { + found = 1; + if (VISIBLEON(c, selmon)) { + if (focustop(selmon) == c) { + // hide + c->tags = 0; + focusclient(focustop(selmon), 1); + } else { + // focus + focusclient(c, 1); + } + } else { + // show + c->tags = selmon->tagset[selmon->seltags]; + // focus + focusclient(c, 1); + } + continue; + } + if (VISIBLEON(c, selmon)) { + // hide + c->tags = 0; + } + } + + if (found) { + arrange(selmon); + } else { + spawnscratch(arg); + } +} + void toggletag(const Arg *arg) {