sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

dwm-layoutmenu-6.2.diff (2869B)


      1 From e45e286b3d639b90ef202996d87054cced1fd80e Mon Sep 17 00:00:00 2001
      2 From: tdu <tdukv@protonmail.com>
      3 Date: Mon, 31 Aug 2020 00:07:32 +0300
      4 Subject: [PATCH] Right clicking the layout symbol opens an xmenu prompt to
      5  select layout.
      6 
      7 Xmenu need to be installed for this to work.
      8 Edit layoutmenu.sh with the correct layout table, and place in PATH.
      9 ---
     10  config.def.h  |  3 ++-
     11  dwm.c         | 19 +++++++++++++++++++
     12  layoutmenu.sh |  7 +++++++
     13  3 files changed, 28 insertions(+), 1 deletion(-)
     14  create mode 100755 layoutmenu.sh
     15 
     16 diff --git a/config.def.h b/config.def.h
     17 index 1c0b587..c9e0833 100644
     18 --- a/config.def.h
     19 +++ b/config.def.h
     20 @@ -58,6 +58,7 @@ static const Layout layouts[] = {
     21  static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */
     22  static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
     23  static const char *termcmd[]  = { "st", NULL };
     24 +static const char *layoutmenu_cmd = "layoutmenu.sh";
     25  
     26  static Key keys[] = {
     27  	/* modifier                     key        function        argument */
     28 @@ -101,7 +102,7 @@ static Key keys[] = {
     29  static Button buttons[] = {
     30  	/* click                event mask      button          function        argument */
     31  	{ ClkLtSymbol,          0,              Button1,        setlayout,      {0} },
     32 -	{ ClkLtSymbol,          0,              Button3,        setlayout,      {.v = &layouts[2]} },
     33 +	{ ClkLtSymbol,          0,              Button3,        layoutmenu,     {0} },
     34  	{ ClkWinTitle,          0,              Button2,        zoom,           {0} },
     35  	{ ClkStatusText,        0,              Button2,        spawn,          {.v = termcmd } },
     36  	{ ClkClientWin,         MODKEY,         Button1,        movemouse,      {0} },
     37 diff --git a/dwm.c b/dwm.c
     38 index 4465af1..2508a0a 100644
     39 --- a/dwm.c
     40 +++ b/dwm.c
     41 @@ -177,6 +177,7 @@ static void grabkeys(void);
     42  static void incnmaster(const Arg *arg);
     43  static void keypress(XEvent *e);
     44  static void killclient(const Arg *arg);
     45 +static void layoutmenu(const Arg *arg);
     46  static void manage(Window w, XWindowAttributes *wa);
     47  static void mappingnotify(XEvent *e);
     48  static void maprequest(XEvent *e);
     49 @@ -1014,6 +1015,24 @@ killclient(const Arg *arg)
     50  	}
     51  }
     52  
     53 +void
     54 +layoutmenu(const Arg *arg) {
     55 +	FILE *p;
     56 +	char c[3], *s;
     57 +	int i;
     58 +
     59 +	if (!(p = popen(layoutmenu_cmd, "r")))
     60 +		 return;
     61 +	s = fgets(c, sizeof(c), p);
     62 +	pclose(p);
     63 +
     64 +	if (!s || *s == '\0' || c == '\0')
     65 +		 return;
     66 +
     67 +	i = atoi(c);
     68 +	setlayout(&((Arg) { .v = &layouts[i] }));
     69 +}
     70 +
     71  void
     72  manage(Window w, XWindowAttributes *wa)
     73  {
     74 diff --git a/layoutmenu.sh b/layoutmenu.sh
     75 new file mode 100755
     76 index 0000000..1bf95f2
     77 --- /dev/null
     78 +++ b/layoutmenu.sh
     79 @@ -0,0 +1,7 @@
     80 +#!/bin/sh
     81 +
     82 +cat <<EOF | xmenu
     83 +[]= Tiled Layout	0
     84 +><> Floating Layout	1
     85 +[M] Monocle Layout	2
     86 +EOF
     87 -- 
     88 2.28.0
     89