Hi list,

attached patch (against 1528:b4f5309d6253) allows to name the tags for
each monitor. You can name your tags for as many monitors as you like.
If you still have more monitors, it uses the last defined as a fallback
for these.
Also included is a slight modification of Evan Gates' nametag patch to
rename tags while dwm is running.

I appreciate any comments.

-- 
Thomas Dahms
diff -r b4f5309d6253 config.def.h
--- a/config.def.h      Fri Nov 19 11:53:59 2010 +0000
+++ b/config.def.h      Fri Nov 26 09:49:54 2010 +0100
@@ -14,7 +14,21 @@
 static const Bool topbar            = True;     /* False means bottom bar */
 
 /* tagging */
-static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
+#define MAX_TAGLEN 16
+#define MONS_TAGGED 2
+#define TAGMON(mon) (mon->num < MONS_TAGGED ? mon->num : MONS_TAGGED-1) 
+static char tags[][MONS_TAGGED][MAX_TAGLEN] = {
+       /* monitor 0, monitor 1, ... */
+       { "1",        "1" },
+       { "2",        "2" },
+       { "3",        "3" },
+       { "4",        "4" },
+       { "5",        "5" },
+       { "6",        "6" },
+       { "7",        "7" },
+       { "8",        "8" },
+       { "9",        "9" },
+};
 
 static const Rule rules[] = {
        /* class      instance    title       tags mask     isfloating   
monitor */
@@ -71,6 +85,7 @@
        { MODKEY,                       XK_period, focusmon,       {.i = +1 } },
        { MODKEY|ShiftMask,             XK_comma,  tagmon,         {.i = -1 } },
        { MODKEY|ShiftMask,             XK_period, tagmon,         {.i = +1 } },
+       { MODKEY,                       XK_n,      nametag,        {0} },
        TAGKEYS(                        XK_1,                      0)
        TAGKEYS(                        XK_2,                      1)
        TAGKEYS(                        XK_3,                      2)
diff -r b4f5309d6253 config.mk
--- a/config.mk Fri Nov 19 11:53:59 2010 +0000
+++ b/config.mk Fri Nov 26 09:49:54 2010 +0100
@@ -19,7 +19,7 @@
 LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 ${XINERAMALIBS}
 
 # flags
-CPPFLAGS = -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
+CPPFLAGS = -D_BSD_SOURCE -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
 CFLAGS = -g -std=c99 -pedantic -Wall -O0 ${INCS} ${CPPFLAGS}
 #CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
 LDFLAGS = -g ${LIBS}
diff -r b4f5309d6253 dwm.c
--- a/dwm.c     Fri Nov 19 11:53:59 2010 +0000
+++ b/dwm.c     Fri Nov 26 09:49:54 2010 +0100
@@ -198,6 +198,7 @@
 static void maprequest(XEvent *e);
 static void monocle(Monitor *m);
 static void movemouse(const Arg *arg);
+static void nametag(const Arg *arg);
 static Client *nexttiled(Client *c);
 static Monitor *ptrtomon(int x, int y);
 static void propertynotify(XEvent *e);
@@ -432,7 +433,7 @@
        if(ev->window == selmon->barwin) {
                i = x = 0;
                do {
-                       x += TEXTW(tags[i]);
+                       x += TEXTW(tags[i][TAGMON(selmon)]);
                } while(ev->x >= x && ++i < LENGTH(tags));
                if(i < LENGTH(tags)) {
                        click = ClkTagBar;
@@ -689,9 +690,9 @@
        }
        dc.x = 0;
        for(i = 0; i < LENGTH(tags); i++) {
-               dc.w = TEXTW(tags[i]);
+               dc.w = TEXTW(tags[i][TAGMON(m)]);
                col = m->tagset[m->seltags] & 1 << i ? dc.sel : dc.norm;
-               drawtext(tags[i], col, urg & 1 << i);
+               drawtext(tags[i][TAGMON(m)], col, urg & 1 << i);
                drawsquare(m == selmon && selmon->sel && selmon->sel->tags & 1 
<< i,
                           occ & 1 << i, urg & 1 << i, col);
                dc.x += dc.w;
@@ -1232,6 +1233,25 @@
        }
 }
 
+void
+nametag(const Arg *arg) {
+       char *cp, name[MAX_TAGLEN];
+       FILE *fp;
+       int i;
+
+       if(!(fp = (FILE*)popen("echo -n | dmenu", "r")))
+               fprintf(stderr, "dwm: Could not popen 'echo -n | dmenu'\n");
+       cp = fgets(name, MAX_TAGLEN, fp);
+       pclose(fp);
+       if(cp == NULL)
+               return;
+
+       for(i = 0; i < LENGTH(tags); i++)
+               if(selmon->tagset[selmon->seltags] & (1 << i))
+                       memcpy(tags[i][TAGMON(selmon)], name, MAX_TAGLEN);
+       drawbars();
+}
+
 Client *
 nexttiled(Client *c) {
        for(; c && (c->isfloating || !ISVISIBLE(c)); c = c->next);

Reply via email to