1 From 8cd37e1ab9e7cb025224aeb3543f1a5be8bceb93 Mon Sep 17 00:00:00 2001
2 From: Nihal Jere <nihal@nihaljere.xyz>
3 Date: Sat, 11 Jan 2020 21:16:08 -0600
4 Subject: [PATCH] center patch now has adjustable minimum width
9 dmenu.c | 39 ++++++++++++++++++++++++++++++++-------
10 3 files changed, 37 insertions(+), 7 deletions(-)
12 diff --git a/config.def.h b/config.def.h
13 index 1edb647..88ef264 100644
17 /* Default settings; can be overriden by command line. */
19 static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */
20 +static int centered = 0; /* -c option; centers dmenu on screen */
21 +static int min_width = 500; /* minimum width when centered */
22 /* -fn option overrides fonts[0]; default X11 font or font set */
23 static const char *fonts[] = {
25 diff --git a/dmenu.1 b/dmenu.1
26 index 323f93c..c036baa 100644
29 @@ -40,6 +40,9 @@ which lists programs in the user's $PATH and runs the result in their $SHELL.
31 dmenu appears at the bottom of the screen.
34 +dmenu appears centered on the screen.
37 dmenu grabs the keyboard before reading stdin if not reading from a tty. This
38 is faster, but will lock up X until stdin reaches end\-of\-file.
39 diff --git a/dmenu.c b/dmenu.c
40 index 65f25ce..041c7f8 100644
43 @@ -89,6 +89,15 @@ calcoffsets(void)
51 + for (struct item *item = items; item && item->text; item++)
52 + len = MAX(TEXTW(item->text), len);
59 @@ -611,6 +620,7 @@ setup(void)
60 bh = drw->fonts->h + 2;
61 lines = MAX(lines, 0);
62 mh = (lines + 1) * bh;
63 + promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
66 if (parentwin == root && (info = XineramaQueryScreens(dpy, &n))) {
67 @@ -637,9 +647,16 @@ setup(void)
68 if (INTERSECT(x, y, 1, 1, info[i]))
72 - y = info[i].y_org + (topbar ? 0 : info[i].height - mh);
75 + mw = MIN(MAX(max_textw() + promptw, min_width), info[i].width);
76 + x = info[i].x_org + ((info[i].width - mw) / 2);
77 + y = info[i].y_org + ((info[i].height - mh) / 2);
80 + y = info[i].y_org + (topbar ? 0 : info[i].height - mh);
87 @@ -647,11 +664,17 @@ setup(void)
88 if (!XGetWindowAttributes(dpy, parentwin, &wa))
89 die("could not get embedding window attributes: 0x%lx",
92 - y = topbar ? 0 : wa.height - mh;
96 + mw = MIN(MAX(max_textw() + promptw, min_width), wa.width);
97 + x = (wa.width - mw) / 2;
98 + y = (wa.height - mh) / 2;
101 + y = topbar ? 0 : wa.height - mh;
105 - promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
106 inputw = MIN(inputw, mw/3);
109 @@ -709,6 +732,8 @@ main(int argc, char *argv[])
111 else if (!strcmp(argv[i], "-f")) /* grabs keyboard before reading stdin */
113 + else if (!strcmp(argv[i], "-c")) /* centers dmenu on screen */
115 else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */
116 fstrncmp = strncasecmp;