sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

commit ba8ba39ded2cb518d578cc812ec0bbfdde878358
parent 852bb4a5cdb68f338a5d0dbd40deee26ce1bd93a
Author: Joshua O'Connor <joshua@joshuao.com>
Date:   Sun, 26 Apr 2020 15:14:55 +0100

[dwm][patch] namedscratchpads: spawn/hide multiple windows with keybinds

Diffstat:
Adwm.suckless.org/patches/namedscratchpads/dwm-namedscratchpads-6.2.diff | 138+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Adwm.suckless.org/patches/namedscratchpads/index.md | 22++++++++++++++++++++++
2 files changed, 160 insertions(+), 0 deletions(-)

diff --git a/dwm.suckless.org/patches/namedscratchpads/dwm-namedscratchpads-6.2.diff b/dwm.suckless.org/patches/namedscratchpads/dwm-namedscratchpads-6.2.diff @@ -0,0 +1,138 @@ +diff '--color=auto' -up dwm-6.2/config.def.h dwm-6.2-new/config.def.h +--- dwm-6.2/config.def.h 2019-02-02 12:55:28.000000000 +0000 ++++ dwm-6.2-new/config.def.h 2020-04-26 13:51:06.713332746 +0100 +@@ -26,9 +26,10 @@ static const Rule rules[] = { + * WM_CLASS(STRING) = instance, class + * WM_NAME(STRING) = title + */ +- /* class instance title tags mask isfloating monitor */ +- { "Gimp", NULL, NULL, 0, 1, -1 }, +- { "Firefox", NULL, NULL, 1 << 8, 0, -1 }, ++ /* class instance title tags mask isfloating monitor scratch key */ ++ { "Gimp", NULL, NULL, 0, 1, -1, 0 }, ++ { "firefox", NULL, NULL, 1 << 8, 0, -1, 0 }, ++ { NULL, NULL, "scratchpad", 0, 1, -1, 's' }, + }; + + /* layout(s) */ +@@ -59,10 +60,14 @@ static char dmenumon[2] = "0"; /* compon + static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL }; + static const char *termcmd[] = { "st", NULL }; + ++/*First arg only serves to match against key in rules*/ ++static const char *scratchpadcmd[] = {"s", "st", "-t", "scratchpad", NULL}; ++ + static Key keys[] = { + /* modifier key function argument */ + { MODKEY, XK_p, spawn, {.v = dmenucmd } }, + { MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } }, ++ { MODKEY, XK_grave, togglescratch, {.v = scratchpadcmd } }, + { MODKEY, XK_b, togglebar, {0} }, + { MODKEY, XK_j, focusstack, {.i = +1 } }, + { MODKEY, XK_k, focusstack, {.i = -1 } }, +diff '--color=auto' -up dwm-6.2/dwm.c dwm-6.2-new/dwm.c +--- dwm-6.2/dwm.c 2019-02-02 12:55:28.000000000 +0000 ++++ dwm-6.2-new/dwm.c 2020-04-26 13:55:56.820584361 +0100 +@@ -93,6 +93,7 @@ struct Client { + int bw, oldbw; + unsigned int tags; + int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen; ++ char scratchkey; + Client *next; + Client *snext; + Monitor *mon; +@@ -139,6 +140,7 @@ typedef struct { + unsigned int tags; + int isfloating; + int monitor; ++ const char scratchkey; + } Rule; + + /* function declarations */ +@@ -206,11 +208,13 @@ static void seturgent(Client *c, int urg + static void showhide(Client *c); + static void sigchld(int unused); + static void spawn(const Arg *arg); ++static void spawnscratch(const Arg *arg); + static void tag(const Arg *arg); + static void tagmon(const Arg *arg); + static void tile(Monitor *); + static void togglebar(const Arg *arg); + static void togglefloating(const Arg *arg); ++static void togglescratch(const Arg *arg); + static void toggletag(const Arg *arg); + static void toggleview(const Arg *arg); + static void unfocus(Client *c, int setfocus); +@@ -287,6 +291,7 @@ applyrules(Client *c) + /* rule matching */ + c->isfloating = 0; + c->tags = 0; ++ c->scratchkey = 0; + XGetClassHint(dpy, c->win, &ch); + class = ch.res_class ? ch.res_class : broken; + instance = ch.res_name ? ch.res_name : broken; +@@ -299,6 +304,7 @@ applyrules(Client *c) + { + c->isfloating = r->isfloating; + c->tags |= r->tags; ++ c->scratchkey = r->scratchkey; + for (m = mons; m && m->num != r->monitor; m = m->next); + if (m) + c->mon = m; +@@ -308,6 +314,7 @@ 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]; + } + +@@ -1652,6 +1659,19 @@ spawn(const Arg *arg) + } + } + ++void spawnscratch(const Arg *arg) ++{ ++ if (fork() == 0) { ++ if (dpy) ++ close(ConnectionNumber(dpy)); ++ setsid(); ++ execvp(((char **)arg->v)[1], ((char **)arg->v)+1); ++ fprintf(stderr, "dwm: execvp %s", ((char **)arg->v)[1]); ++ perror(" failed"); ++ exit(EXIT_SUCCESS); ++ } ++} ++ + void + tag(const Arg *arg) + { +@@ -1720,6 +1740,28 @@ togglefloating(const Arg *arg) + } + + void ++togglescratch(const Arg *arg) ++{ ++ Client *c; ++ unsigned int found = 0; ++ ++ for (c = selmon->clients; c && !(found = c->scratchkey == ((char**)arg->v)[0][0]); c = c->next); ++ if (found) { ++ c->tags = ISVISIBLE(c) ? 0 : selmon->tagset[selmon->seltags]; ++ focus(NULL); ++ arrange(selmon); ++ ++ if (ISVISIBLE(c)) { ++ focus(c); ++ restack(selmon); ++ } ++ ++ } else{ ++ spawnscratch(arg); ++ } ++} ++ ++void + toggletag(const Arg *arg) + { + unsigned int newtags; diff --git a/dwm.suckless.org/patches/namedscratchpads/index.md b/dwm.suckless.org/patches/namedscratchpads/index.md @@ -0,0 +1,22 @@ +namedscratchpads +========== + +Description +----------- +Allows for the creation of multiple scratchpad windows, each assigned to different keybinds. + +On pressing the keybind the window will either: +* Spawn based on the given command, if it's not already running +* Toggle visibility of the window + +A new field in the rules array is added to associate the command with the corresponding rule. + +Works well with [floatrules](../floatrules/) for window positioning. + +Download +-------- +* [dwm-namedscratchpads-6.2.diff](dwm-namedscratchpads-6.2.diff) + +Author +------ +* Joshua O'Connor <joshua@joshuao.com>