Here's a fixed version of dwmfifo using the naming conventions that
seem current give
practice in st and discussion here: since it's against a release
version nothing but that
in the tag.

I like the st format for names of patches against non-release ok,
though I can see the
case for git commit as well.  It seems odd to have patches for dates
for which there is
no commit.  I guess the devs are just pasting the current date in,
which of course could
cause confusion for those trying to apply the patch if the devs repo
wasn't up-to-date
when they made the patch...

Britton
From 5fcae4cc3cc895f641f94bd09e426237aa86aab2 Mon Sep 17 00:00:00 2001
From: Britton Leo Kerin <britton.ke...@gmail.com>
Date: Thu, 16 Jun 2016 14:27:23 -0800
Subject: [PATCH] Squashed commit of the following:

commit e8daba47f246dcd2ae5a5452221a993a6e489892
Author: Britton Leo Kerin <britton.ke...@gmail.com>
Date:   Sat Jun 11 16:04:38 2016 -0800

    Better messages on failure

commit f57b4d2aef1f9e796f828220e55c885c919b2a9c
Author: Britton Leo Kerin <britton.ke...@gmail.com>
Date:   Sat Jun 11 15:58:22 2016 -0800

    Fixed patch failure resolution mistake

commit 25c36a5536ec95faad3317cdfa8483af26c25b44
Author: Britton Leo Kerin <britton.ke...@gmail.com>
Date:   Sat Jun 11 14:46:01 2016 -0800

    Suckless dwmfifo, with fixes
---
 config.def.h | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 dwm.c        | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 127 insertions(+), 5 deletions(-)

diff --git a/config.def.h b/config.def.h
index 7054c06..9f4ef79 100644
--- a/config.def.h
+++ b/config.def.h
@@ -111,3 +111,65 @@ static Button buttons[] = {
        { ClkTagBar,            MODKEY,         Button3,        toggletag,      
{0} },
 };
 
+static const char *dwmfifo = "/tmp/dwm.fifo";
+static Command commands[] = {
+       { "dmenu",           spawn,          {.v = dmenucmd} },
+       { "term",            spawn,          {.v = termcmd} },
+       { "togglebar",       togglebar,      {0} },
+       { "focusstack+",     focusstack,     {.i = +1} },
+       { "focusstack-",     focusstack,     {.i = -1} },
+       { "incnmaster+",     incnmaster,     {.i = +1} },
+       { "incnmaster-",     incnmaster,     {.i = -1} },
+       { "setmfact+",       setmfact,       {.f = +0.05} },
+       { "setmfact-",       setmfact,       {.f = -0.05} },
+       { "zoom",            zoom,           {0} },
+       { "view",            view,           {0} },
+       { "killclient",      killclient,     {0} },
+       { "setlayout-tiled", setlayout,      {.v = &layouts[0]} },
+       { "setlayout-float", setlayout,      {.v = &layouts[1]} },
+       { "setlayout-mono",  setlayout,      {.v = &layouts[2]} },
+       { "togglelayout",    setlayout,      {0} },
+       { "togglefloating",  togglefloating, {0} },
+       { "viewall",         view,           {.ui = ~0} },
+       { "tag",             tag,            {.ui = ~0} },
+       { "focusmon+",       focusmon,       {.i = +1} },
+       { "focusmon-",       focusmon,       {.i = -1} },
+       { "tagmon+",         tagmon,         {.i = +1} },
+       { "tagmon-",         tagmon,         {.i = -1} },
+       { "view1",           view,           {.ui = 1 << 0} },
+       { "view2",           view,           {.ui = 1 << 1} },
+       { "view3",           view,           {.ui = 1 << 2} },
+       { "view4",           view,           {.ui = 1 << 3} },
+       { "view5",           view,           {.ui = 1 << 4} },
+       { "view6",           view,           {.ui = 1 << 5} },
+       { "view7",           view,           {.ui = 1 << 6} },
+       { "view8",           view,           {.ui = 1 << 7} },
+       { "view9",           view,           {.ui = 1 << 8} },
+       { "toggleview1",     toggleview,     {.ui = 1 << 0} },
+       { "toggleview2",     toggleview,     {.ui = 1 << 1} },
+       { "toggleview3",     toggleview,     {.ui = 1 << 2} },
+       { "toggleview4",     toggleview,     {.ui = 1 << 3} },
+       { "toggleview5",     toggleview,     {.ui = 1 << 4} },
+       { "toggleview6",     toggleview,     {.ui = 1 << 5} },
+       { "toggleview7",     toggleview,     {.ui = 1 << 6} },
+       { "toggleview8",     toggleview,     {.ui = 1 << 7} },
+       { "toggleview9",     toggleview,     {.ui = 1 << 8} },
+       { "tag1",            tag,            {.ui = 1 << 0} },
+       { "tag2",            tag,            {.ui = 1 << 1} },
+       { "tag3",            tag,            {.ui = 1 << 2} },
+       { "tag4",            tag,            {.ui = 1 << 3} },
+       { "tag5",            tag,            {.ui = 1 << 4} },
+       { "tag6",            tag,            {.ui = 1 << 5} },
+       { "tag7",            tag,            {.ui = 1 << 6} },
+       { "tag8",            tag,            {.ui = 1 << 7} },
+       { "tag9",            tag,            {.ui = 1 << 8} },
+       { "toggletag1",      toggletag,      {.ui = 1 << 0} },
+       { "toggletag2",      toggletag,      {.ui = 1 << 1} },
+       { "toggletag3",      toggletag,      {.ui = 1 << 2} },
+       { "toggletag4",      toggletag,      {.ui = 1 << 3} },
+       { "toggletag5",      toggletag,      {.ui = 1 << 4} },
+       { "toggletag6",      toggletag,      {.ui = 1 << 5} },
+       { "toggletag7",      toggletag,      {.ui = 1 << 6} },
+       { "toggletag8",      toggletag,      {.ui = 1 << 7} },
+       { "toggletag9",      toggletag,      {.ui = 1 << 8} },
+};
diff --git a/dwm.c b/dwm.c
index 0362114..5c45d2a 100644
--- a/dwm.c
+++ b/dwm.c
@@ -21,6 +21,7 @@
  * To understand everything else, start reading main().
  */
 #include <errno.h>
+#include <fcntl.h>
 #include <locale.h>
 #include <signal.h>
 #include <stdarg.h>
@@ -28,6 +29,8 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <sys/select.h>
+#include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <X11/cursorfont.h>
@@ -141,6 +144,12 @@ typedef struct {
        int monitor;
 } Rule;
 
+typedef struct {
+       const char *name;
+       void (*func)(const Arg *arg);
+       const Arg arg;
+} Command;
+
 /* function declarations */
 static void applyrules(Client *c);
 static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int 
interact);
@@ -162,9 +171,11 @@ static void destroynotify(XEvent *e);
 static void detach(Client *c);
 static void detachstack(Client *c);
 static Monitor *dirtomon(int dir);
+static void dispatchcmd(void);
 static void drawbar(Monitor *m);
 static void drawbars(void);
 static void enternotify(XEvent *e);
+static Bool evpredicate();
 static void expose(XEvent *e);
 static void focus(Client *c);
 static void focusin(XEvent *e);
@@ -266,6 +277,7 @@ static Display *dpy;
 static Drw *drw;
 static Monitor *mons, *selmon;
 static Window root;
+static int fifofd;
 
 /* configuration, allows nested code to access above variables */
 #include "config.h"
@@ -490,6 +502,7 @@ cleanup(void)
        XSync(dpy, False);
        XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
        XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
+       close(fifofd);
 }
 
 void
@@ -702,6 +715,25 @@ dirtomon(int dir)
 }
 
 void
+dispatchcmd(void)
+{
+       int i;
+       char buf[BUFSIZ];
+       ssize_t n;
+
+       n = read(fifofd, buf, sizeof(buf) - 1);
+       if (n == -1)
+               die("Failed to read() from DWM fifo %s:", dwmfifo);
+       buf[n] = '\0';
+       for (i = 0; i < LENGTH(commands); i++) {
+               if (strcmp(commands[i].name, buf) == 0) {
+                       commands[i].func(&commands[i].arg);
+                       break;
+               }
+       }
+}
+
+void
 drawbar(Monitor *m)
 {
        int x, xx, w, dx;
@@ -781,6 +813,12 @@ enternotify(XEvent *e)
        focus(c);
 }
 
+Bool
+evpredicate()
+{
+       return True;
+}
+
 void
 expose(XEvent *e)
 {
@@ -1390,11 +1428,30 @@ void
 run(void)
 {
        XEvent ev;
-       /* main event loop */
-       XSync(dpy, False);
-       while (running && !XNextEvent(dpy, &ev))
-               if (handler[ev.type])
-                       handler[ev.type](&ev); /* call handler */
+        fd_set rfds;
+        int n;
+        int dpyfd, maxfd;
+        /* main event loop */
+        XSync(dpy, False);
+        dpyfd = ConnectionNumber(dpy);
+        maxfd = fifofd;
+        if (dpyfd > maxfd)
+                maxfd = dpyfd;
+        maxfd++;
+        while (running) {
+                FD_ZERO(&rfds);
+                FD_SET(fifofd, &rfds);
+                FD_SET(dpyfd, &rfds);
+                n = select(maxfd, &rfds, NULL, NULL, NULL);
+                if (n > 0) {
+                        if (FD_ISSET(fifofd, &rfds))
+                                dispatchcmd();
+                        if (FD_ISSET(dpyfd, &rfds))
+                                while (XCheckIfEvent(dpy, &ev, evpredicate, 
NULL))
+                                        if (handler[ev.type])
+                                                handler[ev.type](&ev); /* call 
handler */
+                }
+        }
 }
 
 void
@@ -1601,6 +1658,9 @@ setup(void)
        XSelectInput(dpy, root, wa.event_mask);
        grabkeys();
        focus(NULL);
+       fifofd = open(dwmfifo, O_RDWR | O_NONBLOCK);
+       if (fifofd < 0)
+               die("Failed to open() DWM fifo %s:", dwmfifo);
 }
 
 void
-- 
2.1.4

Reply via email to