added line height setting.

This commit is contained in:
Crony Akatsuki 2022-07-21 17:31:35 +02:00
parent 0f9f6f0ea0
commit ce3c2b5ce2
3 changed files with 17 additions and 5 deletions

View File

@ -4,8 +4,7 @@
static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */ static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */
/* -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[] = {
"monospace:size=10", "JetBrainsMonoMedium Nerd Font:size=9",
"NotoColor:pixelsize=8:antialias=true:autohint=true"
}; };
static const unsigned int bgalpha = 0xe0; static const unsigned int bgalpha = 0xe0;
static const unsigned int fgalpha = OPAQUE; static const unsigned int fgalpha = OPAQUE;
@ -25,6 +24,9 @@ static const unsigned int alphas[SchemeLast][2] = {
/* -l option; if nonzero, dmenu uses vertical list with given number of lines */ /* -l option; if nonzero, dmenu uses vertical list with given number of lines */
static unsigned int lines = 0; static unsigned int lines = 0;
/* -h option; minimum height of a menu line */
static unsigned int lineheight = 23;
static unsigned int min_lineheight = 8;
/* /*
* Characters not considered part of a word while deleting words * Characters not considered part of a word while deleting words

View File

@ -6,6 +6,8 @@ dmenu \- dynamic menu
.RB [ \-bfirvP ] .RB [ \-bfirvP ]
.RB [ \-l .RB [ \-l
.IR lines ] .IR lines ]
.RB [ \-h
.IR height ]
.RB [ \-m .RB [ \-m
.IR monitor ] .IR monitor ]
.RB [ \-p .RB [ \-p
@ -56,6 +58,9 @@ dmenu will reject any input which would result in no matching option left.
.BI \-l " lines" .BI \-l " lines"
dmenu lists items vertically, with the given number of lines. dmenu lists items vertically, with the given number of lines.
.TP .TP
.BI \-h " height"
dmenu uses a menu line of at least 'height' pixels tall, but no less than 8.
.TP
.BI \-m " monitor" .BI \-m " monitor"
dmenu is displayed on the monitor number supplied. Monitor numbers are starting dmenu is displayed on the monitor number supplied. Monitor numbers are starting
from 0. from 0.

11
dmenu.c
View File

@ -180,7 +180,7 @@ drawmenu(void)
{ {
unsigned int curpos; unsigned int curpos;
struct item *item; struct item *item;
int x = 0, y = 0, w; int x = 0, y = 0, fh = drw->fonts->h, w;
char *censort; char *censort;
drw_setscheme(drw, scheme[SchemeNorm]); drw_setscheme(drw, scheme[SchemeNorm]);
@ -203,7 +203,7 @@ drawmenu(void)
curpos = TEXTW(text) - TEXTW(&text[cursor]); curpos = TEXTW(text) - TEXTW(&text[cursor]);
if ((curpos += lrpad / 2 - 1) < w) { if ((curpos += lrpad / 2 - 1) < w) {
drw_setscheme(drw, scheme[SchemeNorm]); drw_setscheme(drw, scheme[SchemeNorm]);
drw_rect(drw, x + curpos, 2, 2, bh - 4, 1, 0); drw_rect(drw, x + curpos, 2 + (bh - fh) / 2, 2, fh - 4, 1, 0);
} }
if (lines > 0) { if (lines > 0) {
@ -809,6 +809,7 @@ setup(void)
/* calculate menu geometry */ /* calculate menu geometry */
bh = drw->fonts->h + 2; bh = drw->fonts->h + 2;
bh = MAX(bh,lineheight); /* make a menu line AT LEAST 'lineheight' tall */
lines = MAX(lines, 0); lines = MAX(lines, 0);
mh = (lines + 1) * bh; mh = (lines + 1) * bh;
#ifdef XINERAMA #ifdef XINERAMA
@ -892,7 +893,7 @@ setup(void)
static void static void
usage(void) usage(void)
{ {
fputs("usage: dmenu [-bfiPrv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" fputs("usage: dmenu [-bfiPrv] [-l lines] [-h height] [-p prompt] [-fn font] [-m monitor]\n"
" [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr); " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr);
exit(1); exit(1);
} }
@ -964,6 +965,10 @@ 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], "-h")) { /* minimum height of one menu line */
lineheight = atoi(argv[++i]);
lineheight = MAX(lineheight, min_lineheight);
}
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 */