sites

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

dmenu-lineheight-5.2.diff (3464B)


      1 From ba103e38ea4ab07f9a3ee90627714b9bea17c329 Mon Sep 17 00:00:00 2001
      2 From: pskry <peter@skrypalle.dk>
      3 Date: Sun, 8 Nov 2020 22:04:22 +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 |  3 +++
     13  dmenu.1      |  5 +++++
     14  dmenu.c      | 11 ++++++++---
     15  3 files changed, 16 insertions(+), 3 deletions(-)
     16 
     17 diff --git a/config.def.h b/config.def.h
     18 index 1edb647..4394dec 100644
     19 --- a/config.def.h
     20 +++ b/config.def.h
     21 @@ -15,6 +15,9 @@ 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 +/* -h option; minimum height of a menu line */
     26 +static unsigned int lineheight = 0;
     27 +static unsigned int min_lineheight = 8;
     28  
     29  /*
     30   * Characters not considered part of a word while deleting words
     31 diff --git a/dmenu.1 b/dmenu.1
     32 index 323f93c..f2a82b4 100644
     33 --- a/dmenu.1
     34 +++ b/dmenu.1
     35 @@ -6,6 +6,8 @@ dmenu \- dynamic menu
     36  .RB [ \-bfiv ]
     37  .RB [ \-l
     38  .IR lines ]
     39 +.RB [ \-h
     40 +.IR height ]
     41  .RB [ \-m
     42  .IR monitor ]
     43  .RB [ \-p
     44 @@ -50,6 +52,9 @@ dmenu matches menu items case insensitively.
     45  .BI \-l " lines"
     46  dmenu lists items vertically, with the given number of lines.
     47  .TP
     48 +.BI \-h " height"
     49 +dmenu uses a menu line of at least 'height' pixels tall, but no less than 8.
     50 +.TP
     51  .BI \-m " monitor"
     52  dmenu is displayed on the monitor number supplied. Monitor numbers are starting
     53  from 0.
     54 diff --git a/dmenu.c b/dmenu.c
     55 index e7be8af..82b204b 100644
     56 --- a/dmenu.c
     57 +++ b/dmenu.c
     58 @@ -148,7 +148,7 @@ drawmenu(void)
     59  {
     60  	unsigned int curpos;
     61  	struct item *item;
     62 -	int x = 0, y = 0, w;
     63 +	int x = 0, y = 0, fh = drw->fonts->h, w;
     64  
     65  	drw_setscheme(drw, scheme[SchemeNorm]);
     66  	drw_rect(drw, 0, 0, mw, mh, 1, 1);
     67 @@ -165,7 +165,7 @@ drawmenu(void)
     68  	curpos = TEXTW(text) - TEXTW(&text[cursor]);
     69  	if ((curpos += lrpad / 2 - 1) < w) {
     70  		drw_setscheme(drw, scheme[SchemeNorm]);
     71 -		drw_rect(drw, x + curpos, 2, 2, bh - 4, 1, 0);
     72 +		drw_rect(drw, x + curpos, 2 + (bh - fh) / 2, 2, fh - 4, 1, 0);
     73  	}
     74  
     75  	if (lines > 0) {
     76 @@ -630,6 +630,7 @@ setup(void)
     77  
     78  	/* calculate menu geometry */
     79  	bh = drw->fonts->h + 2;
     80 +	bh = MAX(bh,lineheight);	/* make a menu line AT LEAST 'lineheight' tall */
     81  	lines = MAX(lines, 0);
     82  	mh = (lines + 1) * bh;
     83  #ifdef XINERAMA
     84 @@ -710,7 +711,7 @@ setup(void)
     85  static void
     86  usage(void)
     87  {
     88 -	die("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
     89 +	die("usage: dmenu [-bfiv] [-l lines] [-h height] [-p prompt] [-fn font] [-m monitor]\n"
     90  	    "             [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]");
     91  }
     92  
     93 @@ -737,6 +738,10 @@ main(int argc, char *argv[])
     94  		/* these options take one argument */
     95  		else if (!strcmp(argv[i], "-l"))   /* number of lines in vertical list */
     96  			lines = atoi(argv[++i]);
     97 +		else if (!strcmp(argv[i], "-h")) { /* minimum height of one menu line */
     98 +			lineheight = atoi(argv[++i]);
     99 +			lineheight = MAX(lineheight, min_lineheight);
    100 +		}
    101  		else if (!strcmp(argv[i], "-m"))
    102  			mon = atoi(argv[++i]);
    103  		else if (!strcmp(argv[i], "-p"))   /* adds prompt to left of input field */
    104 -- 
    105 2.38.1
    106