Return to repo list

suckless-gf-dmenu

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

grid.patch (2229B)


      1 diff --git a/dmenu.1 b/dmenu.1
      2 index 323f93c..d0a734a 100644
      3 --- a/dmenu.1
      4 +++ b/dmenu.1
      5 @@ -4,6 +4,8 @@ dmenu \- dynamic menu
      6  .SH SYNOPSIS
      7  .B dmenu
      8  .RB [ \-bfiv ]
      9 +.RB [ \-g
     10 +.IR columns ]
     11  .RB [ \-l
     12  .IR lines ]
     13  .RB [ \-m
     14 @@ -47,8 +49,11 @@ is faster, but will lock up X until stdin reaches end\-of\-file.
     15  .B \-i
     16  dmenu matches menu items case insensitively.
     17  .TP
     18 +.BI \-g " columns"
     19 +dmenu lists items in a grid with the given number of columns.
     20 +.TP
     21  .BI \-l " lines"
     22 -dmenu lists items vertically, with the given number of lines.
     23 +dmenu lists items in a grid with the given number of lines.
     24  .TP
     25  .BI \-m " monitor"
     26  dmenu is displayed on the monitor number supplied. Monitor numbers are starting
     27 diff --git a/dmenu.c b/dmenu.c
     28 index 6b8f51b..d79b6bb 100644
     29 --- a/dmenu.c
     30 +++ b/dmenu.c
     31 @@ -77,7 +77,7 @@ calcoffsets(void)
     32  	int i, n;
     33  
     34  	if (lines > 0)
     35 -		n = lines * bh;
     36 +		n = lines * columns * bh;
     37  	else
     38  		n = mw - (promptw + inputw + TEXTW("<") + TEXTW(">"));
     39  	/* calculate which items will begin the next page and previous page */
     40 @@ -152,9 +152,15 @@ drawmenu(void)
     41  	}
     42  
     43  	if (lines > 0) {
     44 -		/* draw vertical list */
     45 -		for (item = curr; item != next; item = item->right)
     46 -			drawitem(item, x, y += bh, mw - x);
     47 +		/* draw grid */
     48 +		int i = 0;
     49 +		for (item = curr; item != next; item = item->right, i++)
     50 +			drawitem(
     51 +				item,
     52 +				x + ((i / lines) *  ((mw - x) / columns)),
     53 +				y + (((i % lines) + 1) * bh),
     54 +				(mw - x) / columns
     55 +			);
     56  	} else if (matches) {
     57  		/* draw horizontal list */
     58  		x += inputw;
     59 @@ -708,9 +714,13 @@ main(int argc, char *argv[])
     60  		} else if (i + 1 == argc)
     61  			usage();
     62  		/* these options take one argument */
     63 -		else if (!strcmp(argv[i], "-l"))   /* number of lines in vertical list */
     64 +		else if (!strcmp(argv[i], "-g")) {   /* number of columns in grid */
     65 +			columns = atoi(argv[++i]);
     66 +			if (lines == 0) lines = 1;
     67 +		} else if (!strcmp(argv[i], "-l")) { /* number of lines in grid */
     68  			lines = atoi(argv[++i]);
     69 -		else if (!strcmp(argv[i], "-m"))
     70 +			if (columns == 0) columns = 1;
     71 +		} else if (!strcmp(argv[i], "-m"))
     72  			mon = atoi(argv[++i]);
     73  		else if (!strcmp(argv[i], "-p"))   /* adds prompt to left of input field */
     74  			prompt = argv[++i];
     75 -- 
     76 2.23.1
     77