[wiki] [sites] [dwm][patch] namedscratchpads: spawn/hide multiple windows with keybinds || Joshua O'Connor
commit ba8ba39ded2cb518d578cc812ec0bbfdde878358
Author: Joshua O'Connor <joshua_AT_joshuao.com>
Date: Sun Apr 26 15:14:55 2020 +0100
[dwm][patch] namedscratchpads: spawn/hide multiple windows with keybinds
diff --git a/dwm.suckless.org/patches/namedscratchpads/dwm-namedscratchpads-6.2.diff b/dwm.suckless.org/patches/namedscratchpads/dwm-namedscratchpads-6.2.diff
new file mode 100644
index 00000000..d0071187
--- /dev/null
+++ b/dwm.suckless.org/patches/namedscratchpads/dwm-namedscratchpads-6.2.diff
_AT_@ -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
+_AT_@ -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) */
+_AT_@ -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
+_AT_@ -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;
+_AT_@ -139,6 +140,7 @@ typedef struct {
+ unsigned int tags;
+ int isfloating;
+ int monitor;
++ const char scratchkey;
+ } Rule;
+
+ /* function declarations */
+_AT_@ -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);
+_AT_@ -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;
+_AT_@ -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;
+_AT_@ -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];
+ }
+
+_AT_@ -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)
+ {
+_AT_@ -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
new file mode 100644
index 00000000..ccb99de2
--- /dev/null
+++ b/dwm.suckless.org/patches/namedscratchpads/index.md
_AT_@ -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_AT_joshuao.com>
Received on Mon Apr 27 2020 - 09:43:36 CEST
This archive was generated by hypermail 2.3.0
: Mon Apr 27 2020 - 09:48:49 CEST