Added layout menu popup which presents available layouts after right-clicking the...
authorAaron Taylor <ataylor@subgeniuskitty.com>
Fri, 3 Feb 2023 01:00:32 +0000 (17:00 -0800)
committerAaron Taylor <ataylor@subgeniuskitty.com>
Fri, 3 Feb 2023 01:00:32 +0000 (17:00 -0800)
config.def.h
config.h
dwm.c
layoutmenu.sh [new file with mode: 0644]

index 46333e6..bcc9748 100644 (file)
@@ -59,6 +59,7 @@ static const Layout layouts[] = {
 /* commands */
 static const char *dmenucmd[] = { "dmenu_run", "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
 static const char *termcmd[]  = { "st", NULL };
 /* commands */
 static const char *dmenucmd[] = { "dmenu_run", "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
 static const char *termcmd[]  = { "st", NULL };
+static const char *layoutmenu_cmd = "layoutmenu.sh";
 
 static const Key keys[] = {
        /* modifier                     key        function        argument */
 
 static const Key keys[] = {
        /* modifier                     key        function        argument */
@@ -102,7 +103,7 @@ static const Key keys[] = {
 static const Button buttons[] = {
        /* click                event mask      button          function        argument */
        { ClkLtSymbol,          0,              Button1,        setlayout,      {0} },
 static const Button buttons[] = {
        /* click                event mask      button          function        argument */
        { ClkLtSymbol,          0,              Button1,        setlayout,      {0} },
-       { ClkLtSymbol,          0,              Button3,        setlayout,      {.v = &layouts[2]} },
+       { ClkLtSymbol,          0,              Button3,        layoutmenu,     {0} },
        { ClkWinTitle,          0,              Button2,        zoom,           {0} },
        { ClkStatusText,        0,              Button2,        spawn,          {.v = termcmd } },
        { ClkClientWin,         MODKEY,         Button1,        movemouse,      {0} },
        { ClkWinTitle,          0,              Button2,        zoom,           {0} },
        { ClkStatusText,        0,              Button2,        spawn,          {.v = termcmd } },
        { ClkClientWin,         MODKEY,         Button1,        movemouse,      {0} },
index 46333e6..bcc9748 100644 (file)
--- a/config.h
+++ b/config.h
@@ -59,6 +59,7 @@ static const Layout layouts[] = {
 /* commands */
 static const char *dmenucmd[] = { "dmenu_run", "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
 static const char *termcmd[]  = { "st", NULL };
 /* commands */
 static const char *dmenucmd[] = { "dmenu_run", "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
 static const char *termcmd[]  = { "st", NULL };
+static const char *layoutmenu_cmd = "layoutmenu.sh";
 
 static const Key keys[] = {
        /* modifier                     key        function        argument */
 
 static const Key keys[] = {
        /* modifier                     key        function        argument */
@@ -102,7 +103,7 @@ static const Key keys[] = {
 static const Button buttons[] = {
        /* click                event mask      button          function        argument */
        { ClkLtSymbol,          0,              Button1,        setlayout,      {0} },
 static const Button buttons[] = {
        /* click                event mask      button          function        argument */
        { ClkLtSymbol,          0,              Button1,        setlayout,      {0} },
-       { ClkLtSymbol,          0,              Button3,        setlayout,      {.v = &layouts[2]} },
+       { ClkLtSymbol,          0,              Button3,        layoutmenu,     {0} },
        { ClkWinTitle,          0,              Button2,        zoom,           {0} },
        { ClkStatusText,        0,              Button2,        spawn,          {.v = termcmd } },
        { ClkClientWin,         MODKEY,         Button1,        movemouse,      {0} },
        { ClkWinTitle,          0,              Button2,        zoom,           {0} },
        { ClkStatusText,        0,              Button2,        spawn,          {.v = termcmd } },
        { ClkClientWin,         MODKEY,         Button1,        movemouse,      {0} },
diff --git a/dwm.c b/dwm.c
index 14fe6cc..a94b759 100644 (file)
--- a/dwm.c
+++ b/dwm.c
@@ -178,6 +178,7 @@ static void grabkeys(void);
 static void incnmaster(const Arg *arg);
 static void keypress(XEvent *e);
 static void killclient(const Arg *arg);
 static void incnmaster(const Arg *arg);
 static void keypress(XEvent *e);
 static void killclient(const Arg *arg);
+static void layoutmenu(const Arg *arg);
 static void manage(Window w, XWindowAttributes *wa);
 static void mappingnotify(XEvent *e);
 static void maprequest(XEvent *e);
 static void manage(Window w, XWindowAttributes *wa);
 static void mappingnotify(XEvent *e);
 static void maprequest(XEvent *e);
@@ -1068,6 +1069,24 @@ killclient(const Arg *arg)
        }
 }
 
        }
 }
 
+void
+layoutmenu(const Arg *arg) {
+       FILE *p;
+       char c[3], *s;
+       int i;
+
+       if (!(p = popen(layoutmenu_cmd, "r")))
+                return;
+       s = fgets(c, sizeof(c), p);
+       pclose(p);
+
+       if (!s || *s == '\0' || c[0] == '\0')
+                return;
+
+       i = atoi(c);
+       setlayout(&((Arg) { .v = &layouts[i] }));
+}
+
 void
 manage(Window w, XWindowAttributes *wa)
 {
 void
 manage(Window w, XWindowAttributes *wa)
 {
diff --git a/layoutmenu.sh b/layoutmenu.sh
new file mode 100644 (file)
index 0000000..1bf95f2
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+cat <<EOF | xmenu
+[]= Tiled Layout       0
+><> Floating Layout    1
+[M] Monocle Layout     2
+EOF