Return to repo list

suckless-gf-dmenu

Gentoo-friendly patches for Suckless's dmenu.
Return to HMagellan.com

center.patch (1470B)


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