Change restart function to call SGK-modified version of dwm.
[dwm] / dwm.c
diff --git a/dwm.c b/dwm.c
index a94b759..52d34ad 100644 (file)
--- a/dwm.c
+++ b/dwm.c
@@ -185,10 +185,12 @@ static void maprequest(XEvent *e);
 static void monocle(Monitor *m);
 static void motionnotify(XEvent *e);
 static void movemouse(const Arg *arg);
 static void monocle(Monitor *m);
 static void motionnotify(XEvent *e);
 static void movemouse(const Arg *arg);
+static void nametag(const Arg *arg);
 static Client *nexttiled(Client *c);
 static void pop(Client *c);
 static void propertynotify(XEvent *e);
 static void quit(const Arg *arg);
 static Client *nexttiled(Client *c);
 static void pop(Client *c);
 static void propertynotify(XEvent *e);
 static void quit(const Arg *arg);
+static void quitprompt(const Arg *arg);
 static Monitor *recttomon(int x, int y, int w, int h);
 static void resize(Client *c, int x, int y, int w, int h, int interact);
 static void resizeclient(Client *c, int x, int y, int w, int h);
 static Monitor *recttomon(int x, int y, int w, int h);
 static void resize(Client *c, int x, int y, int w, int h, int interact);
 static void resizeclient(Client *c, int x, int y, int w, int h);
@@ -270,6 +272,7 @@ static void (*handler[LASTEvent]) (XEvent *) = {
 };
 static Atom wmatom[WMLast], netatom[NetLast];
 static int running = 1;
 };
 static Atom wmatom[WMLast], netatom[NetLast];
 static int running = 1;
+static int restart = 1;
 static Cur *cursor[CurLast];
 static Clr **scheme;
 static Display *dpy;
 static Cur *cursor[CurLast];
 static Clr **scheme;
 static Display *dpy;
@@ -1261,6 +1264,32 @@ movemouse(const Arg *arg)
        }
 }
 
        }
 }
 
+void
+nametag(const Arg *arg) {
+       char *p, name[MAX_TAGLEN];
+       FILE *f;
+       int i;
+
+       errno = 0; // popen(3p) says on failure it "may" set errno
+       if(!(f = popen("dmenu < /dev/null", "r"))) {
+               fprintf(stderr, "dwm: popen 'dmenu < /dev/null' failed%s%s\n", errno ? ": " : "", errno ? strerror(errno) : "");
+               return;
+       }
+       if (!(p = fgets(name, MAX_TAGLEN, f)) && (i = errno) && ferror(f))
+               fprintf(stderr, "dwm: fgets failed: %s\n", strerror(i));
+       if (pclose(f) < 0)
+               fprintf(stderr, "dwm: pclose failed: %s\n", strerror(errno));
+       if(!p)
+               return;
+       if((p = strchr(name, '\n')))
+               *p = '\0';
+
+       for(i = 0; i < LENGTH(tags); i++)
+               if(selmon->tagset[selmon->seltags] & (1 << i))
+                       strcpy(tags[i], name);
+       drawbars();
+}
+
 Client *
 nexttiled(Client *c)
 {
 Client *
 nexttiled(Client *c)
 {
@@ -1320,6 +1349,31 @@ quit(const Arg *arg)
        running = 0;
 }
 
        running = 0;
 }
 
+void
+quitprompt(const Arg *arg)
+{
+       FILE *pp = popen("echo -e \"no\nrestart\nyes\" | dmenu -i -sb red -p \"Quit DWM?\"", "r");
+       if(pp != NULL) {
+               char buf[1024];
+               if (fgets(buf, sizeof(buf), pp) == NULL) {
+                       fprintf(stderr, "Quitprompt: Error reading pipe!\n");
+                       return;
+               }
+               if (strcmp(buf, "yes\n") == 0) {
+                       pclose(pp);
+                       restart = 0;
+                       quit(NULL);
+               } else if (strcmp(buf, "restart\n") == 0) {
+                       pclose(pp);
+                       restart = 1;
+                       quit(NULL);
+               } else if (strcmp(buf, "no\n") == 0) {
+                       pclose(pp);
+                       return;
+               }
+       }
+}
+
 Monitor *
 recttomon(int x, int y, int w, int h)
 {
 Monitor *
 recttomon(int x, int y, int w, int h)
 {
@@ -2209,5 +2263,8 @@ main(int argc, char *argv[])
        run();
        cleanup();
        XCloseDisplay(dpy);
        run();
        cleanup();
        XCloseDisplay(dpy);
+       if (restart == 1) {
+               execlp("dwm-sgk", "dwm-sgk", NULL);
+       }
        return EXIT_SUCCESS;
 }
        return EXIT_SUCCESS;
 }