From e750aa243a25ec78e611883b5e72314067326746 Mon Sep 17 00:00:00 2001 From: wochap Date: Wed, 22 Nov 2023 18:58:57 -0500 Subject: [PATCH] add focusortogglescratch function --- config.def.h | 1 + dwl.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/config.def.h b/config.def.h index 157aee4..0f672d4 100644 --- a/config.def.h +++ b/config.def.h @@ -125,6 +125,7 @@ static const Key keys[] = { { MODKEY, XKB_KEY_p, spawn, {.v = menucmd} }, { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_Return, spawn, {.v = termcmd} }, { MODKEY, XKB_KEY_grave, togglescratch, {.v = scratchpadcmd } }, + { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_grave, focusortogglescratch, {.v = scratchpadcmd } }, { MODKEY, XKB_KEY_j, focusstack, {.i = +1} }, { MODKEY, XKB_KEY_k, focusstack, {.i = -1} }, { MODKEY, XKB_KEY_i, incnmaster, {.i = +1} }, diff --git a/dwl.c b/dwl.c index 81e5db8..83d771e 100644 --- a/dwl.c +++ b/dwl.c @@ -317,6 +317,7 @@ static void tile(Monitor *m); 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 toggletag(const Arg *arg); static void toggleview(const Arg *arg); static void unlocksession(struct wl_listener *listener, void *data); @@ -2493,6 +2494,42 @@ togglescratch(const Arg *arg) } } +void +focusortogglescratch(const Arg *arg) +{ + Client *c; + Client *cwithfocus; + unsigned int found = 0; + + /* search for first window that matches the scratchkey */ + wl_list_for_each(c, &clients, link) + if (c->scratchkey == ((char**)arg->v)[0][0]) { + found = 1; + break; + } + + if (found) { + if (VISIBLEON(c, selmon)) { + cwithfocus = focustop(selmon); + if (cwithfocus == c) { + // hide + c->tags = 0; + focusclient(cwithfocus, 1); + } else { + // focus + focusclient(c, 1); + } + } else { + // show + c->tags = selmon->tagset[selmon->seltags]; + focusclient(c, 1); + } + arrange(selmon); + } else{ + spawnscratch(arg); + } +} + void toggletag(const Arg *arg) { -- 2.49.0