From fe7de921bbf1a5b7f5afecb57300520f80de904b Mon Sep 17 00:00:00 2001 From: speedie Date: Thu, 9 Feb 2023 18:12:03 +0100 Subject: [PATCH] rewrite line height feature, now works more like dwm bar height patch --- docs/example.Xresources | 3 +-- options.h | 3 +-- spmenu.c | 15 ++++++++++----- xresources.h | 3 +-- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/docs/example.Xresources b/docs/example.Xresources index a83d0a2..9192495 100644 --- a/docs/example.Xresources +++ b/docs/example.Xresources @@ -40,10 +40,9 @@ spmenu.alpha: 1 spmenu.accuratewidth: 1 spmenu.bordercentered: 1 spmenu.borderwidth: 2 +spmenu.lineheight: 0 spmenu.lines: 0 spmenu.columns: 10 -spmenu.lineheight: 5 -spmenu.minlineheight: 5 spmenu.maxhist: 64 spmenu.histnodup: 1 spmenu.casesensitive: 0 diff --git a/options.h b/options.h index ccf179a..164d778 100644 --- a/options.h +++ b/options.h @@ -36,10 +36,9 @@ static int accuratewidth = 1; /* Enable accurate width. May have a static int fuzzy = 1; /* Whether or not to enable fuzzy matching by default */ /* Line options */ +static int lineheight = 0; /* Line height (0: Calculate automatically) */ static int lines = 0; /* Default number of lines */ static int columns = 10; /* Default number of columns */ -static int lineheight = 20; /* Height of each line */ -static int minlineheight = 5; /* Minimum line height */ /* History options */ static unsigned int maxhist = 64; /* Max number of history entries */ diff --git a/spmenu.c b/spmenu.c index 2f192dc..93510d3 100644 --- a/spmenu.c +++ b/spmenu.c @@ -98,6 +98,8 @@ static char numbers[NUMBERSBUFSIZE] = ""; static char *embed; static int numlockmask = 0; static int bh, mw, mh; +static int reqlineheight; /* required menu height */ +static int clineheight; /* menu height added through argument */ static int dmx = 0; /* put spmenu at this x offset */ static int dmy = 0; /* put spmenu at this y offset (measured from the bottom if menuposition is 0) */ static unsigned int dmw = 0; /* make spmenu this wide */ @@ -1574,9 +1576,13 @@ setup(void) types = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False); dock = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DOCK", False); + if (!clineheight) + reqlineheight += lineheight; + else + reqlineheight = clineheight; + /* calculate menu geometry */ - bh = drw->font->h + 2; - bh = MAX(bh, lineheight); /* make a menu line AT LEAST 'lineheight' tall */ + bh = drw->font->h + 2 + reqlineheight; lines = MAX(lines, 0); mh = (lines + 1) * bh; promptw = (prompt && *prompt) ? TEXTWM(prompt) - lrpad / 4 : 0; @@ -1710,7 +1716,7 @@ usage(void) fputs("spmenu: dynamic menu\n\n" "- Arguments -\n" "spmenu -l Set line count to stdin\n" - "spmenu -h Set spmenu height to \n" + "spmenu -h Set spmenu line height to \n" "spmenu -g Set the number of grids to \n" "spmenu -rw Enable relative input width\n" "spmenu -nrw Disable relative input width\n" @@ -1890,8 +1896,7 @@ main(int argc, char *argv[]) } else if (!strcmp(argv[i], "-l")) { /* number of lines in grid */ lines = atoi(argv[++i]); } else if (!strcmp(argv[i], "-h")) { /* minimum height of one menu line */ - lineheight = atoi(argv[++i]); - lineheight = MAX(lineheight, minlineheight); + clineheight += atoi(argv[++i]); if (columns == 0) columns = 1; } else if (!strcmp(argv[i], "-lp")) { menupaddingv = atoi(argv[++i]); diff --git a/xresources.h b/xresources.h index 167a7c9..2796b25 100644 --- a/xresources.h +++ b/xresources.h @@ -101,9 +101,8 @@ ResourcePref resources[] = { { "bordercentered", INTEGER, &bordercentered }, { "borderwidth", INTEGER, &borderwidth }, { "lines", INTEGER, &lines }, + { "lineheight", INTEGER, &lineheight }, { "columns", INTEGER, &columns }, - { "lineheight", INTEGER, &lineheight }, - { "minlineheight", INTEGER, &minlineheight }, { "maxhist", INTEGER, &maxhist }, { "hidematchcount", INTEGER, &hidematchcount }, { "histnodup", INTEGER, &histnodup },