[wiki] [sites] Add line height option (-lh <height>) || Xarchus

From: <git_AT_suckless.org>
Date: Fri, 20 Nov 2015 02:55:17 +0100

commit 2bf08a4442b94fc254d017c74796e97d6e8fe2a4
Author: Xarchus <xarchus_AT_comcast.net>
Date: Thu Nov 19 17:53:52 2015 -0800

    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.

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
new file mode 100644
index 0000000..bb2a6bb
--- /dev/null
+++ b/tools.suckless.org/dmenu/patches/dmenu-4.6-line-height.diff
_AT_@ -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
+_AT_@ -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
+_AT_@ -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
+_AT_@ -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);
+_AT_@ -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)
+_AT_@ -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
+_AT_@ -608,7 +609,7 @@ setup(void)
+ static void
+ usage(void)
+ {
+- fputs("usage: dmenu [-b] [-f] [-i] [-l lines] [-p prompt] [-fn font] [-m monitor]
"
++ fputs("usage: dmenu [-b] [-f] [-i] [-l lines] [-p prompt] [-fn font] [-lh height] [-m monitor]
"
+ " [-nb color] [-nf color] [-sb color] [-sf color] [-v]
", stderr);
+ exit(1);
+ }
+_AT_@ -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
+_AT_@ -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
new file mode 100644
index 0000000..24c6023
Binary files /dev/null and b/tools.suckless.org/dmenu/patches/dmenu-default-height.png differ
diff --git a/tools.suckless.org/dmenu/patches/dmenu-line-height.png b/tools.suckless.org/dmenu/patches/dmenu-line-height.png
new file mode 100644
index 0000000..fa29b71
Binary files /dev/null and b/tools.suckless.org/dmenu/patches/dmenu-line-height.png differ
diff --git a/tools.suckless.org/dmenu/patches/line-height.md b/tools.suckless.org/dmenu/patches/line-height.md
new file mode 100644
index 0000000..e8c973d
--- /dev/null
+++ b/tools.suckless.org/dmenu/patches/line-height.md
_AT_@ -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
Received on Fri Nov 20 2015 - 02:55:17 CET

This archive was generated by hypermail 2.3.0 : Fri Nov 20 2015 - 03:00:13 CET