aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.h11
-rw-r--r--dwm.c41
2 files changed, 50 insertions, 2 deletions
diff --git a/config.h b/config.h
index 790a9de..68ea2e1 100644
--- a/config.h
+++ b/config.h
@@ -53,7 +53,15 @@ static Sp scratchpads[] = {
};
/* tagging */
-static const char *tags[] = { "一", "二", "三", "四", "五", "六", "七", "八", "九" };
+#define MAX_TAGNAME_LEN 14 /* excludes TAG_PREPEND */
+#define TAG_PREPEND "%s"
+#define MAX_TAGLEN 16 /* altogether */
+#define TAGS { "一", "二", "三", "四", "五", "六", "七", "八", "九" }
+static char tags[][MAX_TAGLEN] = TAGS;
+/* append_nametag:
+ * 1: append the new nametag to the original tag label from above
+ * 0: overwrite original tag label with new nametag */
+static const unsigned int append_nametag = 1;
static const Rule rules[] = {
/* xprop(1):
@@ -243,6 +251,7 @@ static const Key keys[] = {
{ MODKEY|ShiftMask, XK_Left, tagmon, {.i = -1 } },
{ MODKEY, XK_Right, focusmon, {.i = +1 } },
{ MODKEY|ShiftMask, XK_Right, tagmon, {.i = +1 } },
+ {MODKEY, XK_n, nametag, {0}},
{ MODKEY, XK_Page_Up, shiftview, { .i = -1 } },
{ MODKEY|ShiftMask, XK_Page_Up, shifttag, { .i = -1 } },
diff --git a/dwm.c b/dwm.c
index da70ec7..3fb7185 100644
--- a/dwm.c
+++ b/dwm.c
@@ -268,6 +268,7 @@ static void maprequest(XEvent *e);
static void monocle(Monitor *m);
static void motionnotify(XEvent *e);
static void movemouse(const Arg *arg);
+static void nametag(const Arg *arg);
static Client *nexttagged(Client *c);
static Client *nexttiled(Client *c);
static void pop(Client *c);
@@ -423,6 +424,7 @@ struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
/* function implementations */
static int combo = 0;
+static char tags_original[][MAX_TAGLEN] = TAGS;
void
keyrelease(XEvent *e) {
@@ -1672,6 +1674,43 @@ movemouse(const Arg *arg)
}
}
+void
+nametag(const Arg *arg) {
+ char *p, name[MAX_TAGNAME_LEN];
+ FILE *f;
+ int i;
+
+ errno = 0; // popen(3p) says on failure it "may" set errno
+ if(!(f = popen("dmenu < /dev/null", "r"))) {
+ fprintf(stderr, WMNAME ": popen 'dmenu < /dev/null' failed%s%s\n", errno ? ": " : "", errno ? strerror(errno) : "");
+ return;
+ }
+ if (!(p = fgets(name, MAX_TAGNAME_LEN, f)) && (i = errno) && ferror(f))
+ fprintf(stderr, WMNAME ": fgets failed: %s\n", strerror(i));
+ if (pclose(f) < 0)
+ fprintf(stderr, WMNAME ": 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)) {
+ if (append_nametag == 1) {
+ strcpy(tags[i], tags_original[i]);
+
+ if (strlen(name) != 0)
+ strcat(tags[i], " ");
+
+ sprintf(tags[i], TAG_PREPEND, tags[i]);
+ strcat(tags[i], name);
+ } else {
+ strcpy(tags[i], name);
+ }
+ }
+ drawbars();
+}
+
Client *
nexttagged(Client *c) {
Client *walked = c->mon->clients;
@@ -3251,7 +3290,7 @@ main(int argc, char *argv[])
if (argc == 2 && !strcmp("-v", argv[1]))
die(WMNAME "-"VERSION);
else if (argc != 1)
- die("usage: dwm [-v]");
+ die("usage: " WMNAME " [-v]");
if (!setlocale(LC_CTYPE, "") || !XSupportsLocale())
fputs("warning: no locale support\n", stderr);
if (!(dpy = XOpenDisplay(NULL)))