Adding configurable minimum width when using the center patch #1

This commit is contained in:
bakkeby 2020-01-27 09:43:10 +01:00
parent 9d3c424dea
commit d7f418468d
3 changed files with 8 additions and 7 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
*.o *.o
config.h config.h
patches.h patches.h
dmenu
stest

View File

@ -13,6 +13,7 @@ static int instant = 0; /* -n option; if 1, selects matchin
#endif // INSTANT_PATCH #endif // INSTANT_PATCH
#if CENTER_PATCH #if CENTER_PATCH
static int center = 1; /* -c option; if 0, dmenu won't be centered on the screen */ static int center = 1; /* -c option; if 0, dmenu won't be centered on the screen */
static int min_width = 500; /* minimum width when centered */
#endif // CENTER_PATCH #endif // CENTER_PATCH
/* -fn option overrides fonts[0]; default X11 font or font set */ /* -fn option overrides fonts[0]; default X11 font or font set */
static const char *fonts[] = { static const char *fonts[] = {

12
dmenu.c
View File

@ -880,8 +880,7 @@ setup(void)
lines = MAX(lines, 0); lines = MAX(lines, 0);
mh = (lines + 1) * bh; mh = (lines + 1) * bh;
#if CENTER_PATCH #if CENTER_PATCH
if (center) promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
#endif // CENTER_PATCH #endif // CENTER_PATCH
#ifdef XINERAMA #ifdef XINERAMA
i = 0; i = 0;
@ -911,7 +910,7 @@ setup(void)
#if CENTER_PATCH #if CENTER_PATCH
if (center) { if (center) {
mw = MIN(MAX(max_textw() + promptw, 100), info[i].width); mw = MIN(MAX(max_textw() + promptw, min_width), info[i].width);
x = info[i].x_org + ((info[i].width - mw) / 2); x = info[i].x_org + ((info[i].width - mw) / 2);
y = info[i].y_org + ((info[i].height - mh) / 2); y = info[i].y_org + ((info[i].height - mh) / 2);
} else { } else {
@ -943,7 +942,7 @@ setup(void)
parentwin); parentwin);
#if CENTER_PATCH #if CENTER_PATCH
if (center) { if (center) {
mw = MIN(MAX(max_textw() + promptw, 100), wa.width); mw = MIN(MAX(max_textw() + promptw, min_width), wa.width);
x = (wa.width - mw) / 2; x = (wa.width - mw) / 2;
y = (wa.height - mh) / 2; y = (wa.height - mh) / 2;
} else { } else {
@ -967,9 +966,8 @@ setup(void)
mw = wa.width; mw = wa.width;
#endif // CENTER_PATCH / XYW_PATCH #endif // CENTER_PATCH / XYW_PATCH
} }
#if CENTER_PATCH #if !CENTER_PATCH
if (!center) promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
#endif // CENTER_PATCH #endif // CENTER_PATCH
inputw = MIN(inputw, mw/3); inputw = MIN(inputw, mw/3);
match(); match();