sites

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

dmenu-center-4.8.diff (1452B)


      1 diff --git a/dmenu.c b/dmenu.c
      2 index 5e9c367..2268ea9 100644
      3 --- a/dmenu.c
      4 +++ b/dmenu.c
      5 @@ -88,6 +88,15 @@ calcoffsets(void)
      6  			break;
      7  }
      8  
      9 +static int
     10 +max_textw(void)
     11 +{
     12 +	int len = 0;
     13 +	for (struct item *item = items; item && item->text; item++)
     14 +		len = MAX(TEXTW(item->text), len);
     15 +	return len;
     16 +}
     17 +
     18  static void
     19  cleanup(void)
     20  {
     21 @@ -598,6 +607,7 @@ setup(void)
     22  	bh = drw->fonts->h + 2;
     23  	lines = MAX(lines, 0);
     24  	mh = (lines + 1) * bh;
     25 +	promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
     26  #ifdef XINERAMA
     27  	i = 0;
     28  	if (parentwin == root && (info = XineramaQueryScreens(dpy, &n))) {
     29 @@ -624,9 +634,9 @@ setup(void)
     30  				if (INTERSECT(x, y, 1, 1, info[i]))
     31  					break;
     32  
     33 -		x = info[i].x_org;
     34 -		y = info[i].y_org + (topbar ? 0 : info[i].height - mh);
     35 -		mw = info[i].width;
     36 +		mw = MIN(MAX(max_textw() + promptw, 100), info[i].width);
     37 +		x = info[i].x_org + ((info[i].width  - mw) / 2);
     38 +		y = info[i].y_org + ((info[i].height - mh) / 2);
     39  		XFree(info);
     40  	} else
     41  #endif
     42 @@ -634,11 +644,10 @@ setup(void)
     43  		if (!XGetWindowAttributes(dpy, parentwin, &wa))
     44  			die("could not get embedding window attributes: 0x%lx",
     45  			    parentwin);
     46 -		x = 0;
     47 -		y = topbar ? 0 : wa.height - mh;
     48 -		mw = wa.width;
     49 +		mw = MIN(MAX(max_textw() + promptw, 100), wa.width);
     50 +		x = (wa.width  - mw) / 2;
     51 +		y = (wa.height - mh) / 2;
     52  	}
     53 -	promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
     54  	inputw = MIN(inputw, mw/3);
     55  	match();
     56