Added max_width option (-z)

This commit is contained in:
Santiago Lo Coco 2021-08-13 16:20:29 -03:00
parent 4350772753
commit 72c2aeca25
3 changed files with 9 additions and 2 deletions

View File

@ -2,7 +2,8 @@
/* Default settings; can be overriden by command line. */ /* Default settings; can be overriden by command line. */
static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */ static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */
static int centered = 1; /* -c option; centers dmenu on screen */ static int centered = 1; /* -c option; centers dmenu on screen (for -c option to work it needs to be centedered = 0) */
static int max_width = 1500; /* -z option; max-width when centered */
static int min_width = 750; /* minimum width when centered */ static int min_width = 750; /* minimum width when centered */
/* -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[] = {

View File

@ -43,6 +43,9 @@ dmenu appears at the bottom of the screen.
.B \-c .B \-c
dmenu appears centered on the screen. dmenu appears centered on the screen.
.TP .TP
.B \-z
max_width for dmenu (when it is centered).
.TP
.B \-f .B \-f
dmenu grabs the keyboard before reading stdin if not reading from a tty. This 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. is faster, but will lock up X until stdin reaches end\-of\-file.

View File

@ -660,7 +660,8 @@ setup(void)
break; break;
if (centered) { if (centered) {
mw = MIN(MAX(max_textw() + promptw, min_width), info[i].width); //mw = MIN(MAX(max_textw() + promptw, min_width), info[i].width);
mw = MIN(MAX(max_textw() + promptw, min_width), max_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 {
@ -754,6 +755,8 @@ main(int argc, char *argv[])
/* these options take one argument */ /* these options take one argument */
else if (!strcmp(argv[i], "-l")) /* number of lines in vertical list */ else if (!strcmp(argv[i], "-l")) /* number of lines in vertical list */
lines = atoi(argv[++i]); lines = atoi(argv[++i]);
else if (!strcmp(argv[i], "-z")) /* max_width when centered */
max_width = atoi(argv[++i]);
else if (!strcmp(argv[i], "-m")) else if (!strcmp(argv[i], "-m"))
mon = atoi(argv[++i]); mon = atoi(argv[++i]);
else if (!strcmp(argv[i], "-p")) /* adds prompt to left of input field */ else if (!strcmp(argv[i], "-p")) /* adds prompt to left of input field */