Added ability to give tags a text-based name at runtime.
[dwm] / dwm.c
diff --git a/dwm.c b/dwm.c
index a94b759..21393d8 100644 (file)
--- a/dwm.c
+++ b/dwm.c
@@ -185,6 +185,7 @@ 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 Client *nexttiled(Client *c);
 static void pop(Client *c);
 static void propertynotify(XEvent *e);
@@ -1261,6 +1262,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)
 {