Added ability to give tags a text-based name at runtime.
authorAaron Taylor <ataylor@subgeniuskitty.com>
Fri, 3 Feb 2023 01:09:57 +0000 (17:09 -0800)
committerAaron Taylor <ataylor@subgeniuskitty.com>
Fri, 3 Feb 2023 01:09:57 +0000 (17:09 -0800)
README
config.def.h
config.h
dwm.c

diff --git a/README b/README
index 5d8ecab..c6357e7 100644 (file)
--- a/README
+++ b/README
@@ -2,7 +2,11 @@ This git repository contains my personal branch of dwm-6.4.
 
 The changes made to stock dwm add the following abilities.
 
 
 The changes made to stock dwm add the following abilities.
 
-  - 
+  - Assign text names to tags at runtime.
+    <https://dwm.suckless.org/patches/nametag/>
+
+  - Layout menu popup presents available layouts.
+    <https://dwm.suckless.org/patches/layoutmenu/>
 
   - Select multiple tags for simultaneous display or window assignment.
     <https://dwm.suckless.org/patches/combo/>
 
   - Select multiple tags for simultaneous display or window assignment.
     <https://dwm.suckless.org/patches/combo/>
@@ -13,14 +17,15 @@ The changes made to stock dwm add the following abilities.
   - Center window names in status bar.
     <https://dwm.suckless.org/patches/centeredwindowname/>
 
   - Center window names in status bar.
     <https://dwm.suckless.org/patches/centeredwindowname/>
 
-In addition to the usual dependencies for dwm (see the original README at the
-bottom of this file), there are the following new dependencies.
+In addition to the usual dependencies and installation tasks for dwm (see the
+original README at the bottom of this file), there are the following new
+dependencies/tasks.
 
   - xmenu from <https://github.com/phillbush/xmenu>. This requires freetype2
     and imlib2, available in FreeBSD's ports collection under `print/freetype2`
 
   - xmenu from <https://github.com/phillbush/xmenu>. This requires freetype2
     and imlib2, available in FreeBSD's ports collection under `print/freetype2`
-    and `graphics/imlib2`.
-
+    and `graphics/imlib2`. This is required for the layout menu popup.
 
 
+  - Customize (if needed) and install `layoutmenu.sh` somewhere in your `$PATH`.
 
 ================================================================================
 ================================================================================
 
 ================================================================================
 ================================================================================
index bcc9748..9835e4d 100644 (file)
@@ -20,7 +20,8 @@ static const char *colors[][3]      = {
 };
 
 /* tagging */
 };
 
 /* tagging */
-static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
+#define MAX_TAGLEN 16
+static char tags[][MAX_TAGLEN] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
 
 static const Rule rules[] = {
        /* xprop(1):
 
 static const Rule rules[] = {
        /* xprop(1):
@@ -86,6 +87,7 @@ static const Key keys[] = {
        { MODKEY,                       XK_period, focusmon,       {.i = +1 } },
        { MODKEY|ShiftMask,             XK_comma,  tagmon,         {.i = -1 } },
        { MODKEY|ShiftMask,             XK_period, tagmon,         {.i = +1 } },
        { 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)
        TAGKEYS(                        XK_1,                      0)
        TAGKEYS(                        XK_2,                      1)
        TAGKEYS(                        XK_3,                      2)
index bcc9748..9835e4d 100644 (file)
--- a/config.h
+++ b/config.h
@@ -20,7 +20,8 @@ static const char *colors[][3]      = {
 };
 
 /* tagging */
 };
 
 /* tagging */
-static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
+#define MAX_TAGLEN 16
+static char tags[][MAX_TAGLEN] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
 
 static const Rule rules[] = {
        /* xprop(1):
 
 static const Rule rules[] = {
        /* xprop(1):
@@ -86,6 +87,7 @@ static const Key keys[] = {
        { MODKEY,                       XK_period, focusmon,       {.i = +1 } },
        { MODKEY|ShiftMask,             XK_comma,  tagmon,         {.i = -1 } },
        { MODKEY|ShiftMask,             XK_period, tagmon,         {.i = +1 } },
        { 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)
        TAGKEYS(                        XK_1,                      0)
        TAGKEYS(                        XK_2,                      1)
        TAGKEYS(                        XK_3,                      2)
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)
 {