dwm-dwmfifo-6.1.diff - sites - public wiki contents of suckless.org
 (HTM) git clone git://git.suckless.org/sites
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
       dwm-dwmfifo-6.1.diff (6832B)
       ---
            1 diff --git a/config.def.h b/config.def.h
            2 index 7054c06..9f4ef79 100644
            3 --- a/config.def.h
            4 +++ b/config.def.h
            5 @@ -111,3 +111,66 @@ static Button buttons[] = {
            6          { ClkTagBar,            MODKEY,         Button3,        toggletag,      {0} },
            7  };
            8  
            9 +static const char *dwmfifo = "/tmp/dwm.fifo";
           10 +static Command commands[] = {
           11 +        { "dmenu",           spawn,          {.v = dmenucmd} },
           12 +        { "term",            spawn,          {.v = termcmd} },
           13 +        { "quit",            quit,           {0} },
           14 +        { "togglebar",       togglebar,      {0} },
           15 +        { "focusstack+",     focusstack,     {.i = +1} },
           16 +        { "focusstack-",     focusstack,     {.i = -1} },
           17 +        { "incnmaster+",     incnmaster,     {.i = +1} },
           18 +        { "incnmaster-",     incnmaster,     {.i = -1} },
           19 +        { "setmfact+",       setmfact,       {.f = +0.05} },
           20 +        { "setmfact-",       setmfact,       {.f = -0.05} },
           21 +        { "zoom",            zoom,           {0} },
           22 +        { "view",            view,           {0} },
           23 +        { "killclient",      killclient,     {0} },
           24 +        { "setlayout-tiled", setlayout,      {.v = &layouts[0]} },
           25 +        { "setlayout-float", setlayout,      {.v = &layouts[1]} },
           26 +        { "setlayout-mono",  setlayout,      {.v = &layouts[2]} },
           27 +        { "togglelayout",    setlayout,      {0} },
           28 +        { "togglefloating",  togglefloating, {0} },
           29 +        { "viewall",         view,           {.ui = ~0} },
           30 +        { "tag",             tag,            {.ui = ~0} },
           31 +        { "focusmon+",       focusmon,       {.i = +1} },
           32 +        { "focusmon-",       focusmon,       {.i = -1} },
           33 +        { "tagmon+",         tagmon,         {.i = +1} },
           34 +        { "tagmon-",         tagmon,         {.i = -1} },
           35 +        { "view1",           view,           {.ui = 1 << 0} },
           36 +        { "view2",           view,           {.ui = 1 << 1} },
           37 +        { "view3",           view,           {.ui = 1 << 2} },
           38 +        { "view4",           view,           {.ui = 1 << 3} },
           39 +        { "view5",           view,           {.ui = 1 << 4} },
           40 +        { "view6",           view,           {.ui = 1 << 5} },
           41 +        { "view7",           view,           {.ui = 1 << 6} },
           42 +        { "view8",           view,           {.ui = 1 << 7} },
           43 +        { "view9",           view,           {.ui = 1 << 8} },
           44 +        { "toggleview1",     toggleview,     {.ui = 1 << 0} },
           45 +        { "toggleview2",     toggleview,     {.ui = 1 << 1} },
           46 +        { "toggleview3",     toggleview,     {.ui = 1 << 2} },
           47 +        { "toggleview4",     toggleview,     {.ui = 1 << 3} },
           48 +        { "toggleview5",     toggleview,     {.ui = 1 << 4} },
           49 +        { "toggleview6",     toggleview,     {.ui = 1 << 5} },
           50 +        { "toggleview7",     toggleview,     {.ui = 1 << 6} },
           51 +        { "toggleview8",     toggleview,     {.ui = 1 << 7} },
           52 +        { "toggleview9",     toggleview,     {.ui = 1 << 8} },
           53 +        { "tag1",            tag,            {.ui = 1 << 0} },
           54 +        { "tag2",            tag,            {.ui = 1 << 1} },
           55 +        { "tag3",            tag,            {.ui = 1 << 2} },
           56 +        { "tag4",            tag,            {.ui = 1 << 3} },
           57 +        { "tag5",            tag,            {.ui = 1 << 4} },
           58 +        { "tag6",            tag,            {.ui = 1 << 5} },
           59 +        { "tag7",            tag,            {.ui = 1 << 6} },
           60 +        { "tag8",            tag,            {.ui = 1 << 7} },
           61 +        { "tag9",            tag,            {.ui = 1 << 8} },
           62 +        { "toggletag1",      toggletag,      {.ui = 1 << 0} },
           63 +        { "toggletag2",      toggletag,      {.ui = 1 << 1} },
           64 +        { "toggletag3",      toggletag,      {.ui = 1 << 2} },
           65 +        { "toggletag4",      toggletag,      {.ui = 1 << 3} },
           66 +        { "toggletag5",      toggletag,      {.ui = 1 << 4} },
           67 +        { "toggletag6",      toggletag,      {.ui = 1 << 5} },
           68 +        { "toggletag7",      toggletag,      {.ui = 1 << 6} },
           69 +        { "toggletag8",      toggletag,      {.ui = 1 << 7} },
           70 +        { "toggletag9",      toggletag,      {.ui = 1 << 8} },
           71 +};
           72 diff --git a/dwm.c b/dwm.c
           73 index 0362114..5c45d2a 100644
           74 --- a/dwm.c
           75 +++ b/dwm.c
           76 @@ -21,6 +21,7 @@
           77   * To understand everything else, start reading main().
           78   */
           79  #include <errno.h>
           80 +#include <fcntl.h>
           81  #include <locale.h>
           82  #include <signal.h>
           83  #include <stdarg.h>
           84 @@ -28,6 +29,7 @@
           85  #include <stdlib.h>
           86  #include <string.h>
           87  #include <unistd.h>
           88 +#include <sys/select.h>
           89  #include <sys/types.h>
           90  #include <sys/wait.h>
           91  #include <X11/cursorfont.h>
           92 @@ -141,6 +144,12 @@ typedef struct {
           93          int monitor;
           94  } Rule;
           95  
           96 +typedef struct {
           97 +        const char *name;
           98 +        void (*func)(const Arg *arg);
           99 +        const Arg arg;
          100 +} Command;
          101 +
          102  /* function declarations */
          103  static void applyrules(Client *c);
          104  static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact);
          105 @@ -162,9 +171,11 @@ static void destroynotify(XEvent *e);
          106  static void detach(Client *c);
          107  static void detachstack(Client *c);
          108  static Monitor *dirtomon(int dir);
          109 +static void dispatchcmd(void);
          110  static void drawbar(Monitor *m);
          111  static void drawbars(void);
          112  static void enternotify(XEvent *e);
          113 +static Bool evpredicate();
          114  static void expose(XEvent *e);
          115  static void focus(Client *c);
          116  static void focusin(XEvent *e);
          117 @@ -266,6 +277,7 @@ static Display *dpy;
          118  static Drw *drw;
          119  static Monitor *mons, *selmon;
          120  static Window root;
          121 +static int fifofd;
          122  
          123  /* configuration, allows nested code to access above variables */
          124  #include "config.h"
          125 @@ -490,6 +502,7 @@ cleanup(void)
          126          XSync(dpy, False);
          127          XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
          128          XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
          129 +        close(fifofd);
          130  }
          131  
          132  void
          133 @@ -701,6 +714,26 @@ dirtomon(int dir)
          134          return m;
          135  }
          136  
          137 +void
          138 +dispatchcmd(void)
          139 +{
          140 +        int i;
          141 +        char buf[BUFSIZ];
          142 +        ssize_t n;
          143 +
          144 +        n = read(fifofd, buf, sizeof(buf) - 1);
          145 +        if (n == -1)
          146 +                die("Failed to read() from DWM fifo %s:", dwmfifo);
          147 +        buf[n] = '\0';
          148 +        buf[strcspn(buf, "\n")] = '\0';
          149 +        for (i = 0; i < LENGTH(commands); i++) {
          150 +                if (strcmp(commands[i].name, buf) == 0) {
          151 +                        commands[i].func(&commands[i].arg);
          152 +                        break;
          153 +                }
          154 +        }
          155 +}
          156 +
          157  void
          158  drawbar(Monitor *m)
          159  {
          160 @@ -781,6 +813,12 @@ enternotify(XEvent *e)
          161          focus(c);
          162  }
          163  
          164 +Bool
          165 +evpredicate()
          166 +{
          167 +        return True;
          168 +}
          169 +
          170  void
          171  expose(XEvent *e)
          172  {
          173 @@ -1390,11 +1428,30 @@ void
          174  run(void)
          175  {
          176          XEvent ev;
          177 +        fd_set rfds;
          178 +        int n;
          179 +        int dpyfd, maxfd;
          180          /* main event loop */
          181          XSync(dpy, False);
          182 -        while (running && !XNextEvent(dpy, &ev))
          183 -                if (handler[ev.type])
          184 -                        handler[ev.type](&ev); /* call handler */
          185 +        dpyfd = ConnectionNumber(dpy);
          186 +        maxfd = fifofd;
          187 +        if (dpyfd > maxfd)
          188 +                maxfd = dpyfd;
          189 +        maxfd++;
          190 +        while (running) {
          191 +                FD_ZERO(&rfds);
          192 +                FD_SET(fifofd, &rfds);
          193 +                FD_SET(dpyfd, &rfds);
          194 +                n = select(maxfd, &rfds, NULL, NULL, NULL);
          195 +                if (n > 0) {
          196 +                        if (FD_ISSET(fifofd, &rfds))
          197 +                                dispatchcmd();
          198 +                        if (FD_ISSET(dpyfd, &rfds))
          199 +                                while (XCheckIfEvent(dpy, &ev, evpredicate, NULL))
          200 +                                        if (handler[ev.type])
          201 +                                                handler[ev.type](&ev); /* call handler */
          202 +                }
          203 +        }
          204  }
          205  
          206  void
          207 @@ -1601,6 +1658,9 @@ setup(void)
          208          XSelectInput(dpy, root, wa.event_mask);
          209          grabkeys();
          210          focus(NULL);
          211 +        fifofd = open(dwmfifo, O_RDWR | O_NONBLOCK);
          212 +        if (fifofd < 0)
          213 +                die("Failed to open() DWM fifo %s:", dwmfifo);
          214  }
          215  
          216  void