sites

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

dmenu-lineheight-4.9.diff (3306B)


      1 From 87f92a561c31246f6f9effc0e89ef92677c87746 Mon Sep 17 00:00:00 2001
      2 From: astier <aleksandrs.stier@uni-bielefeld.de>
      3 Date: Wed, 27 Feb 2019 21:44:55 +0100
      4 Subject: [PATCH] Add an option which defines the lineheight
      5 
      6 Despite both the panel and dmenu using the same font (a Terminus 12),
      7 dmenu is shorter and the panel is visible from under the dmenu bar.
      8 The appearance can be even more distracting when using similar colors
      9 for background and selections. With the option added by this patch,
     10 dmenu can be launched with a '-h 24', thus completely covering the panel.
     11 ---
     12  config.def.h |  1 +
     13  dmenu.1      |  3 +++
     14  dmenu.c      | 10 ++++++++--
     15  3 files changed, 12 insertions(+), 2 deletions(-)
     16 
     17 diff --git a/config.def.h b/config.def.h
     18 index 1edb647..317fa2f 100644
     19 --- a/config.def.h
     20 +++ b/config.def.h
     21 @@ -15,6 +15,7 @@ static const char *colors[SchemeLast][2] = {
     22  };
     23  /* -l option; if nonzero, dmenu uses vertical list with given number of lines */
     24  static unsigned int lines      = 0;
     25 +static unsigned int lineheight = 0;         /* -h option; minimum height of a menu line     */
     26  
     27  /*
     28   * Characters not considered part of a word while deleting words
     29 diff --git a/dmenu.1 b/dmenu.1
     30 index 323f93c..7ef34d2 100644
     31 --- a/dmenu.1
     32 +++ b/dmenu.1
     33 @@ -50,6 +50,9 @@ dmenu matches menu items case insensitively.
     34  .BI \-l " lines"
     35  dmenu lists items vertically, with the given number of lines.
     36  .TP
     37 +.BI \-h " height"
     38 +dmenu uses a menu line of at least 'height' pixels tall, but no less than 8.
     39 +.TP
     40  .BI \-m " monitor"
     41  dmenu is displayed on the monitor number supplied. Monitor numbers are starting
     42  from 0.
     43 diff --git a/dmenu.c b/dmenu.c
     44 index 6b8f51b..45d1946 100644
     45 --- a/dmenu.c
     46 +++ b/dmenu.c
     47 @@ -131,7 +131,7 @@ drawmenu(void)
     48  {
     49  	unsigned int curpos;
     50  	struct item *item;
     51 -	int x = 0, y = 0, w;
     52 +	int x = 0, y = 0, fh = drw->fonts->h, w;
     53  
     54  	drw_setscheme(drw, scheme[SchemeNorm]);
     55  	drw_rect(drw, 0, 0, mw, mh, 1, 1);
     56 @@ -148,7 +148,7 @@ drawmenu(void)
     57  	curpos = TEXTW(text) - TEXTW(&text[cursor]);
     58  	if ((curpos += lrpad / 2 - 1) < w) {
     59  		drw_setscheme(drw, scheme[SchemeNorm]);
     60 -		drw_rect(drw, x + curpos, 2, 2, bh - 4, 1, 0);
     61 +		drw_rect(drw, x + curpos, 2 + (bh-fh)/2, 2, fh - 4, 1, 0);
     62  	}
     63  
     64  	if (lines > 0) {
     65 @@ -604,6 +604,7 @@ setup(void)
     66  
     67  	/* calculate menu geometry */
     68  	bh = drw->fonts->h + 2;
     69 +	bh = MAX(bh,lineheight);	/* make a menu line AT LEAST 'lineheight' tall */
     70  	lines = MAX(lines, 0);
     71  	mh = (lines + 1) * bh;
     72  #ifdef XINERAMA
     73 @@ -683,6 +684,7 @@ static void
     74  usage(void)
     75  {
     76  	fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
     77 +	      "             [-h height]\n"
     78  	      "             [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr);
     79  	exit(1);
     80  }
     81 @@ -716,6 +718,10 @@ main(int argc, char *argv[])
     82  			prompt = argv[++i];
     83  		else if (!strcmp(argv[i], "-fn"))  /* font or font set */
     84  			fonts[0] = argv[++i];
     85 +		else if(!strcmp(argv[i], "-h")) { /* minimum height of one menu line */
     86 +			lineheight = atoi(argv[++i]);
     87 +			lineheight = MAX(lineheight,8); /* reasonable default in case of value too small/negative */
     88 +		}
     89  		else if (!strcmp(argv[i], "-nb"))  /* normal background color */
     90  			colors[SchemeNorm][ColBg] = argv[++i];
     91  		else if (!strcmp(argv[i], "-nf"))  /* normal foreground color */
     92 -- 
     93 2.21.0
     94