[hackers] [dmenu][PATCH 2/2] Add floating window option

From: Jérémy Lefaure <jeremy-dev_AT_lefaure.fr>
Date: Sun, 29 Nov 2020 18:59:50 +0100

With the -fw option, the dmenu window pops in the middle of the screen,
giving a UI alternative to top or bottom menus.
---
 config.def.h |  2 ++
 dmenu.1      |  4 ++++
 dmenu.c      | 18 ++++++++++++++++--
 3 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/config.def.h b/config.def.h
index 1edb647..d7fd009 100644
--- a/config.def.h
+++ b/config.def.h
_AT_@ -21,3 +21,5 @@ static unsigned int lines      = 0;
  * for example: " /?\"&[]"
  */
 static const char worddelimiters[] = " ";
+
+static int floating_window = 0;
diff --git a/dmenu.1 b/dmenu.1
index 323f93c..c1cb38d 100644
--- a/dmenu.1
+++ b/dmenu.1
_AT_@ -4,6 +4,7 @@ dmenu \- dynamic menu
 .SH SYNOPSIS
 .B dmenu
 .RB [ \-bfiv ]
+.RB [ \-fw ]
 .RB [ \-l
 .IR lines ]
 .RB [ \-m
_AT_@ -47,6 +48,9 @@ is faster, but will lock up X until stdin reaches end\-of\-file.
 .B \-i
 dmenu matches menu items case insensitively.
 .TP
+.B \-fw
+dmenu appears as a floating window.
+.TP
 .BI \-l " lines"
 dmenu lists items vertically, with the given number of lines.
 .TP
diff --git a/dmenu.c b/dmenu.c
index 86dbe16..31d6a0f 100644
--- a/dmenu.c
+++ b/dmenu.c
_AT_@ -649,6 +649,12 @@ setup(void)
 		x = info[i].x_org;
 		y = info[i].y_org + (topbar ? 0 : info[i].height - mh);
 		mw = info[i].width;
+		if (floating_window)
+		{
+			x += info[i].width / 3;
+			y = info[i].height / 4;
+			mw -= 2 * info[i].width / 3;
+		}
 		XFree(info);
 	} else
 #endif
_AT_@ -659,6 +665,12 @@ setup(void)
 		x = 0;
 		y = topbar ? 0 : wa.height - mh;
 		mw = wa.width;
+		if (floating_window)
+		{
+			x = wa.width / 3;
+			y = wa.height / 4;
+			mw -= 2 * wa.width / 3;
+		}
 	}
 	promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
 	inputw = MIN(inputw, mw/3);
_AT_@ -698,7 +710,7 @@ setup(void)
 static void
 usage(void)
 {
-	fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
+	fputs("usage: dmenu [-bfiv] [-fw] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
 	      "             [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr);
 	exit(1);
 }
_AT_@ -721,7 +733,9 @@ main(int argc, char *argv[])
 		else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */
 			fstrncmp = strncasecmp;
 			fstrstr = cistrstr;
-		} else if (i + 1 == argc)
+		} else if (!strcmp(argv[i], "-fw"))  /* floating window */
+			floating_window = 1;
+		else if (i + 1 == argc)
 			usage();
 		/* these options take one argument */
 		else if (!strcmp(argv[i], "-l"))   /* number of lines in vertical list */
-- 
2.29.2
Received on Sun Nov 29 2020 - 18:59:50 CET

This archive was generated by hypermail 2.3.0 : Sun Nov 29 2020 - 19:00:42 CET