sites

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

dmenu-xyw-20171207-f0a5b75.diff (3332B)


      1 From 204361f6d459b50eb513a9ccc01d775d71388bc3 Mon Sep 17 00:00:00 2001
      2 From: Alessandro Caputo <nonedisponibile@gmail.com>
      3 Date: Thu, 7 Dec 2017 15:54:42 +0100
      4 Subject: [PATCH] dmenu-xyw
      5 
      6 ---
      7  dmenu.1 | 18 ++++++++++++++++++
      8  dmenu.c | 21 +++++++++++++++------
      9  2 files changed, 33 insertions(+), 6 deletions(-)
     10 
     11 diff --git a/dmenu.1 b/dmenu.1
     12 index 9eab758..c3922c9 100644
     13 --- a/dmenu.1
     14 +++ b/dmenu.1
     15 @@ -50,6 +50,24 @@ dmenu matches menu items case insensitively.
     16  .BI \-l " lines"
     17  dmenu lists items vertically, with the given number of lines.
     18  .TP
     19 +.BI \-x " xoffset"
     20 +dmenu is placed at this offset measured from the left side of the monitor.
     21 +Can be negative.
     22 +If option
     23 +.B \-m
     24 +is present, the measurement will use the given monitor.
     25 +.TP
     26 +.BI \-y " yoffset"
     27 +dmenu is placed at this offset measured from the top of the monitor.  If the
     28 +.B \-b
     29 +option is used, the offset is measured from the bottom.  Can be negative.
     30 +If option
     31 +.B \-m
     32 +is present, the measurement will use the given monitor.
     33 +.TP
     34 +.BI \-w " width"
     35 +sets the width of the dmenu window.
     36 +.TP
     37  .BI \-m " monitor"
     38  dmenu is displayed on the monitor number supplied. Monitor numbers are starting
     39  from 0.
     40 diff --git a/dmenu.c b/dmenu.c
     41 index eae5685..e607c2a 100644
     42 --- a/dmenu.c
     43 +++ b/dmenu.c
     44 @@ -36,6 +36,8 @@ struct item {
     45  static char text[BUFSIZ] = "";
     46  static char *embed;
     47  static int bh, mw, mh;
     48 +static int dmx = 0, dmy = 0; /* put dmenu at these x and y offsets */
     49 +static unsigned int dmw = 0; /* make dmenu this wide */
     50  static int inputw = 0, promptw;
     51  static int lrpad; /* sum of left and right padding */
     52  static size_t cursor;
     53 @@ -590,9 +592,9 @@ setup(void)
     54  				if (INTERSECT(x, y, 1, 1, info[i]))
     55  					break;
     56  
     57 -		x = info[i].x_org;
     58 -		y = info[i].y_org + (topbar ? 0 : info[i].height - mh);
     59 -		mw = info[i].width;
     60 +		x = info[i].x_org + dmx;
     61 +		y = info[i].y_org + (topbar ? dmy : info[i].height - mh - dmy);
     62 +		mw = (dmw>0 ? dmw : info[i].width);
     63  		XFree(info);
     64  	} else
     65  #endif
     66 @@ -600,9 +602,9 @@ setup(void)
     67  		if (!XGetWindowAttributes(dpy, parentwin, &wa))
     68  			die("could not get embedding window attributes: 0x%lx",
     69  			    parentwin);
     70 -		x = 0;
     71 -		y = topbar ? 0 : wa.height - mh;
     72 -		mw = wa.width;
     73 +		x = dmx;
     74 +		y = topbar ? dmy : wa.height - mh - dmy;
     75 +		mw = (dmw>0 ? dmw : wa.width);
     76  	}
     77  	promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
     78  	inputw = MIN(inputw, mw/3);
     79 @@ -640,6 +642,7 @@ static void
     80  usage(void)
     81  {
     82  	fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
     83 +	      "             [-x xoffset] [-y yoffset] [-w width]\n"
     84  	      "             [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr);
     85  	exit(1);
     86  }
     87 @@ -667,6 +670,12 @@ main(int argc, char *argv[])
     88  		/* these options take one argument */
     89  		else if (!strcmp(argv[i], "-l"))   /* number of lines in vertical list */
     90  			lines = atoi(argv[++i]);
     91 +		else if (!strcmp(argv[i], "-x"))   /* window x offset */
     92 +			dmx = atoi(argv[++i]);
     93 +		else if (!strcmp(argv[i], "-y"))   /* window y offset (from bottom up if -b) */
     94 +			dmy = atoi(argv[++i]);
     95 +		else if (!strcmp(argv[i], "-w"))   /* make dmenu this wide */
     96 +			dmw = atoi(argv[++i]);
     97  		else if (!strcmp(argv[i], "-m"))
     98  			mon = atoi(argv[++i]);
     99  		else if (!strcmp(argv[i], "-p"))   /* adds prompt to left of input field */
    100 -- 
    101 2.15.1
    102