sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

commit b28a0414dc33912d1647a1edb37ee486ec9e424d
parent 1cc8e58588c2286ce557f65ee25a7b16778679ef
Author: Xarchus <xarchus@comcast.net>
Date:   Thu, 19 Nov 2015 17:53:52 -0800

[dmenu][PATCH] Add line height option (-lh <height>)

Make the menu line(s) at least 'height' pixels tall, independent of the
size of the font used.  It helps to improve the appearance when dmenu is
integrated with other UIs (e.g. some status bars), by matching their
height.

Diffstat:
Atools.suckless.org/dmenu/patches/dmenu-4.6-line-height.diff | 99+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atools.suckless.org/dmenu/patches/dmenu-default-height.png | 0
Atools.suckless.org/dmenu/patches/dmenu-line-height.png | 0
Atools.suckless.org/dmenu/patches/line-height.md | 36++++++++++++++++++++++++++++++++++++
4 files changed, 135 insertions(+), 0 deletions(-)

diff --git a/tools.suckless.org/dmenu/patches/dmenu-4.6-line-height.diff b/tools.suckless.org/dmenu/patches/dmenu-4.6-line-height.diff @@ -0,0 +1,99 @@ +diff --git a/config.def.h b/config.def.h +index a9122f7..6d936b7 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -15,3 +15,6 @@ static const char *outbgcolor = "#00ffff"; + static const char *outfgcolor = "#000000"; + /* -l option; if nonzero, dmenu uses vertical list with given number of lines */ + static unsigned int lines = 0; ++ ++static unsigned int lineheight = 0; /* -lh option; minimum height of a menu line */ ++ +diff --git a/dmenu.1 b/dmenu.1 +index d3ab805..9fe4434 100644 +--- a/dmenu.1 ++++ b/dmenu.1 +@@ -51,6 +51,9 @@ dmenu matches menu items case insensitively. + .BI \-l " lines" + dmenu lists items vertically, with the given number of lines. + .TP ++.BI \-lh " height" ++dmenu uses a menu line of at least 'height' pixels tall, but no less than 8. ++.TP + .BI \-m " monitor" + dmenu is displayed on the monitor number supplied. Monitor numbers are starting + from 0. +diff --git a/dmenu.c b/dmenu.c +index a07f8e3..25832a7 100644 +--- a/dmenu.c ++++ b/dmenu.c +@@ -119,7 +119,7 @@ drawmenu(void) + { + int curpos; + struct item *item; +- int x = 0, y = 0, h = bh, w; ++ int x = 0, y = 0, fh = drw->fonts[0]->h, w; + + drw_setscheme(drw, &scheme[SchemeNorm]); + drw_rect(drw, 0, 0, mw, mh, 1, 1, 1); +@@ -134,16 +134,16 @@ drawmenu(void) + drw_setscheme(drw, &scheme[SchemeNorm]); + drw_text(drw, x, 0, w, bh, text, 0); + +- if ((curpos = TEXTNW(text, cursor) + bh / 2 - 2) < w) { ++ if ((curpos = TEXTNW(text, cursor) + fh / 2 - 2) < w) { + drw_setscheme(drw, &scheme[SchemeNorm]); +- drw_rect(drw, x + curpos + 2, 2, 1, bh - 4, 1, 1, 0); ++ drw_rect(drw, x + curpos + 2, 2 + (bh-fh)/2, 1, fh - 4, 1, 1, 0); + } + + if (lines > 0) { + /* draw vertical list */ + w = mw - x; + for (item = curr; item != next; item = item->right) { +- y += h; ++ y += bh; + if (item == sel) + drw_setscheme(drw, &scheme[SchemeSel]); + else if (item->out) +@@ -544,6 +544,7 @@ setup(void) + + /* calculate menu geometry */ + bh = drw->fonts[0]->h + 2; ++ bh = MAX(bh,lineheight); /* make a menu line AT LEAST 'lineheight' tall */ + lines = MAX(lines, 0); + mh = (lines + 1) * bh; + #ifdef XINERAMA +@@ -608,7 +609,7 @@ setup(void) + static void + usage(void) + { +- fputs("usage: dmenu [-b] [-f] [-i] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" ++ fputs("usage: dmenu [-b] [-f] [-i] [-l lines] [-p prompt] [-fn font] [-lh height] [-m monitor]\n" + " [-nb color] [-nf color] [-sb color] [-sf color] [-v]\n", stderr); + exit(1); + } +@@ -641,6 +642,10 @@ main(int argc, char *argv[]) + prompt = argv[++i]; + else if (!strcmp(argv[i], "-fn")) /* font or font set */ + fonts[0] = argv[++i]; ++ else if(!strcmp(argv[i], "-lh")) { /* minimum height of one menu line */ ++ lineheight = atoi(argv[++i]); ++ lineheight = MAX(lineheight,8); /* reasonable default in case of value too small/negative */ ++ } + else if (!strcmp(argv[i], "-nb")) /* normal background color */ + normbgcolor = argv[++i]; + else if (!strcmp(argv[i], "-nf")) /* normal foreground color */ +diff --git a/drw.c b/drw.c +index 80e3c39..f4a741f 100644 +--- a/drw.c ++++ b/drw.c +@@ -291,7 +291,7 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *tex + if (render) { + th = curfont->ascent + curfont->descent; + ty = y + (h / 2) - (th / 2) + curfont->ascent; +- tx = x + (h / 2); ++ tx = x + (drw->fonts[0]->h / 2); + XftDrawStringUtf8(d, invert ? &drw->scheme->bg->rgb : &drw->scheme->fg->rgb, curfont->xfont, tx, ty, (XftChar8 *)buf, len); + } + x += tex.w; diff --git a/tools.suckless.org/dmenu/patches/dmenu-default-height.png b/tools.suckless.org/dmenu/patches/dmenu-default-height.png Binary files differ. diff --git a/tools.suckless.org/dmenu/patches/dmenu-line-height.png b/tools.suckless.org/dmenu/patches/dmenu-line-height.png Binary files differ. diff --git a/tools.suckless.org/dmenu/patches/line-height.md b/tools.suckless.org/dmenu/patches/line-height.md @@ -0,0 +1,36 @@ +Line height +=========== + +The patch adds a '-lh' option, which sets the minimum height of a dmenu line. +This helps integrate dmenu with other UI elements that require a particular +vertical size. + +Example: + +By default, dmenu calculates its height as the height of the font used plus 2. +So when opening dmenu over a panel bar that is 24 pixels high, it would look +like this: + +->[![Screenshot dmenu default height](dmenu-default-height.png)](dmenu-default-height.png)<- + +Despite both the panel and dmenu using the same font (a Terminus 12), dmenu is +shorter and the panel is visible from under the dmenu bar. The appearance can +be even more distracting when using similar colors for background and +selections. + +With the option added by this patch, dmenu can be launched with a '-lh 24', +thus completely covering the panel, as shown below: + +->[![Screenshot dmenu with line height patch](dmenu-line-height.png)](dmenu-line-height.png)<- + +The line height value is also used when dmenu is used in 'vertical' mode ('-l' option). + +The patch applies cleanly against 4.6 (32f2564dbbbf5aeafb7190a3d35066142f34448f). + +Download +-------- +* [dmenu-4.6-line-height.diff](dmenu-4.6-line-height.diff) + +Author +------ +* Xarchus