Return to repo list

suckless-gf-dmenu

Gentoo-friendly patches for Suckless's dmenu.
Return to HMagellan.com

commit 91cf37d990c735956429cb6a0be5e26cd12a3403
parent f00a53c510edeee64469c6d9837ec5ceac62bcd4
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Sat, 15 Aug 2020 16:37:24 -0500

Added center

Diffstat:
Apatches/center/USAGE | 50++++++++++++++++++++++++++++++++++++++++++++++++++
Apatches/center/center.patch | 57+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apatches/center/centeroption.patch | 97+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 204 insertions(+), 0 deletions(-)

diff --git a/patches/center/USAGE b/patches/center/USAGE @@ -0,0 +1,50 @@ +center - Spawn dmenu smack in the center of the screen +Source: https://tools.suckless.org/dmenu/patches/center/dmenu-center-4.8.diff +Original Author: Ed van Bruggen edvb@uw.edu + +Description from source: + """ + This patch centers dmenu in the middle of the screen. + + Previously this has been achieved through the xyw patch and a bash script to calculate + the centered x and y positions. However, this is a slow and overly complex way which is + hard to integrate into programs which call dmenu directly, eg surf or tabbed. On the + other hand, This small standalone patch is instantaneous and works globally. + """ + +== YOU MUST == +(1). Place the patch file in /etc/portage/patches/x11-misc/dmenu/ and run 'emerge dmenu' + +== YOU PROBABLY SHOULD == +No further action is required. + +== PATCH MODIFICATIONS == +(1). Modified for loop in 'max_textw' to conform to pre-C99 syntax, since apparently that is needed. + +== INCOMPATIBILITIES == +No known specific incompatibilities. + +################################################################################################### +################################################################################################### + +centeroption - Add a '-c' option to center dmenu from the command line +Source: https://tools.suckless.org/dmenu/patches/center/dmenu-center-20200111-8cd37e1.diff +Original Author: Nihal Jere nihal@nihaljere.xyz (20200111) + +Description from source: + """ + With dmenu-center-20200111-8cd37e1.diff, you can use -c to center dmenu. + """ + +== YOU MUST == +(1). Place the patch file in /etc/portage/patches/x11-misc/dmenu/ and run 'emerge dmenu' + +== YOU PROBABLY SHOULD == +(1). Run dmenu with the '-c' option to center it. + +== PATCH MODIFICATIONS == +(1). Removed lines relating to config.def.h +(2). Modified for loop in 'max_textw' to conform to pre-C99 syntax, since apparently that is needed. + +== INCOMPATIBILITIES == +No known specific incompatibilities. diff --git a/patches/center/center.patch b/patches/center/center.patch @@ -0,0 +1,57 @@ +diff --git a/dmenu.c b/dmenu.c +index 5e9c367..2268ea9 100644 +--- a/dmenu.c ++++ b/dmenu.c +@@ -88,6 +88,16 @@ calcoffsets(void) + break; + } + ++static int ++max_textw(void) ++{ ++ int len = 0; ++ struct item *item = items; ++ for (item = items; item && item->text; item++) ++ len = MAX(TEXTW(item->text), len); ++ return len; ++} ++ + static void + cleanup(void) + { +@@ -598,6 +607,7 @@ setup(void) + bh = drw->fonts->h + 2; + lines = MAX(lines, 0); + mh = (lines + 1) * bh; ++ promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0; + #ifdef XINERAMA + i = 0; + if (parentwin == root && (info = XineramaQueryScreens(dpy, &n))) { +@@ -624,9 +634,9 @@ setup(void) + if (INTERSECT(x, y, 1, 1, info[i])) + break; + +- x = info[i].x_org; +- y = info[i].y_org + (topbar ? 0 : info[i].height - mh); +- mw = info[i].width; ++ mw = MIN(MAX(max_textw() + promptw, 100), info[i].width); ++ x = info[i].x_org + ((info[i].width - mw) / 2); ++ y = info[i].y_org + ((info[i].height - mh) / 2); + XFree(info); + } else + #endif +@@ -634,11 +644,10 @@ setup(void) + if (!XGetWindowAttributes(dpy, parentwin, &wa)) + die("could not get embedding window attributes: 0x%lx", + parentwin); +- x = 0; +- y = topbar ? 0 : wa.height - mh; +- mw = wa.width; ++ mw = MIN(MAX(max_textw() + promptw, 100), wa.width); ++ x = (wa.width - mw) / 2; ++ y = (wa.height - mh) / 2; + } +- promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0; + inputw = MIN(inputw, mw/3); + match(); + diff --git a/patches/center/centeroption.patch b/patches/center/centeroption.patch @@ -0,0 +1,97 @@ +diff --git a/dmenu.1 b/dmenu.1 +index 323f93c..c036baa 100644 +--- a/dmenu.1 ++++ b/dmenu.1 +@@ -40,6 +40,9 @@ which lists programs in the user's $PATH and runs the result in their $SHELL. + .B \-b + dmenu appears at the bottom of the screen. + .TP ++.B \-c ++dmenu appears centered on the screen. ++.TP + .B \-f + dmenu grabs the keyboard before reading stdin if not reading from a tty. This + is faster, but will lock up X until stdin reaches end\-of\-file. +diff --git a/dmenu.c b/dmenu.c +index 65f25ce..041c7f8 100644 +--- a/dmenu.c ++++ b/dmenu.c +@@ -89,6 +89,16 @@ calcoffsets(void) + break; + } + ++static int ++max_textw(void) ++{ ++ int len = 0; ++ struct item *item = items; ++ for (item = items; item && item->text; item++) ++ len = MAX(TEXTW(item->text), len); ++ return len; ++} ++ + static void + cleanup(void) + { +@@ -611,6 +620,7 @@ setup(void) + bh = drw->fonts->h + 2; + lines = MAX(lines, 0); + mh = (lines + 1) * bh; ++ promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0; + #ifdef XINERAMA + i = 0; + if (parentwin == root && (info = XineramaQueryScreens(dpy, &n))) { +@@ -637,9 +647,16 @@ setup(void) + if (INTERSECT(x, y, 1, 1, info[i])) + break; + +- x = info[i].x_org; +- y = info[i].y_org + (topbar ? 0 : info[i].height - mh); +- mw = info[i].width; ++ if (centered) { ++ mw = MIN(MAX(max_textw() + promptw, min_width), info[i].width); ++ x = info[i].x_org + ((info[i].width - mw) / 2); ++ y = info[i].y_org + ((info[i].height - mh) / 2); ++ } else { ++ x = info[i].x_org; ++ y = info[i].y_org + (topbar ? 0 : info[i].height - mh); ++ mw = info[i].width; ++ } ++ + XFree(info); + } else + #endif +@@ -647,11 +664,17 @@ setup(void) + if (!XGetWindowAttributes(dpy, parentwin, &wa)) + die("could not get embedding window attributes: 0x%lx", + parentwin); +- x = 0; +- y = topbar ? 0 : wa.height - mh; +- mw = wa.width; ++ ++ if (centered) { ++ mw = MIN(MAX(max_textw() + promptw, min_width), wa.width); ++ x = (wa.width - mw) / 2; ++ y = (wa.height - mh) / 2; ++ } else { ++ x = 0; ++ y = topbar ? 0 : wa.height - mh; ++ mw = wa.width; ++ } + } +- promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0; + inputw = MIN(inputw, mw/3); + match(); + +@@ -709,6 +732,8 @@ main(int argc, char *argv[]) + topbar = 0; + else if (!strcmp(argv[i], "-f")) /* grabs keyboard before reading stdin */ + fast = 1; ++ else if (!strcmp(argv[i], "-c")) /* centers dmenu on screen */ ++ centered = 1; + else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */ + fstrncmp = strncasecmp; + fstrstr = cistrstr; +-- +2.24.1 +