patch: grid

This commit is contained in:
frosty 2024-08-20 01:53:15 +00:00
parent 33361d3def
commit ee32d32218
3 changed files with 24 additions and 8 deletions

View file

@ -16,8 +16,9 @@ static const char *colors[SchemeLast][2] = {
[SchemeNormHighlight] = { "#ffc978", "#222222" }, [SchemeNormHighlight] = { "#ffc978", "#222222" },
[SchemeOut] = { "#000000", "#00ffff" }, [SchemeOut] = { "#000000", "#00ffff" },
}; };
/* -l option; if nonzero, dmenu uses vertical list with given number of lines */ /* -l and -g options; controls number of lines and columns in grid if > 0 */
static unsigned int lines = 0; static unsigned int lines = 0;
static unsigned int columns = 0;
/* /*
* Characters not considered part of a word while deleting words * Characters not considered part of a word while deleting words

View file

@ -4,6 +4,8 @@ dmenu \- dynamic menu
.SH SYNOPSIS .SH SYNOPSIS
.B dmenu .B dmenu
.RB [ \-bFfiv ] .RB [ \-bFfiv ]
.RB [ \-g
.IR columns ]
.RB [ \-l .RB [ \-l
.IR lines ] .IR lines ]
.RB [ \-m .RB [ \-m
@ -58,8 +60,11 @@ is faster, but will lock up X until stdin reaches end\-of\-file.
.B \-i .B \-i
dmenu matches menu items case insensitively. dmenu matches menu items case insensitively.
.TP .TP
.BI \-g " columns"
dmenu lists items in a grid with the given number of columns.
.TP
.BI \-l " lines" .BI \-l " lines"
dmenu lists items vertically, with the given number of lines. dmenu lists items in a grid with the given number of lines.
.TP .TP
.BI \-m " monitor" .BI \-m " monitor"
dmenu is displayed on the monitor number supplied. Monitor numbers are starting dmenu is displayed on the monitor number supplied. Monitor numbers are starting

22
dmenu.c
View file

@ -87,7 +87,7 @@ calcoffsets(void)
int i, n; int i, n;
if (lines > 0) if (lines > 0)
n = lines * bh; n = lines * columns * bh;
else else
n = mw - (promptw + inputw + TEXTW("<") + TEXTW(">")); n = mw - (promptw + inputw + TEXTW("<") + TEXTW(">"));
/* calculate which items will begin the next page and previous page */ /* calculate which items will begin the next page and previous page */
@ -212,9 +212,15 @@ drawmenu(void)
} }
if (lines > 0) { if (lines > 0) {
/* draw vertical list */ /* draw grid */
for (item = curr; item != next; item = item->right) int i = 0;
drawitem(item, x, y += bh, mw - x); for (item = curr; item != next; item = item->right, i++)
drawitem(
item,
x + ((i / lines) * ((mw - x) / columns)),
y + (((i % lines) + 1) * bh),
(mw - x) / columns
);
} else if (matches) { } else if (matches) {
/* draw horizontal list */ /* draw horizontal list */
x += inputw; x += inputw;
@ -871,9 +877,13 @@ main(int argc, char *argv[])
} else if (i + 1 == argc) } else if (i + 1 == argc)
usage(); usage();
/* these options take one argument */ /* these options take one argument */
else if (!strcmp(argv[i], "-l")) /* number of lines in vertical list */ else if (!strcmp(argv[i], "-g")) { /* number of columns in grid */
columns = atoi(argv[++i]);
if (lines == 0) lines = 1;
} else if (!strcmp(argv[i], "-l")) { /* number of lines in grid */
lines = atoi(argv[++i]); lines = atoi(argv[++i]);
else if (!strcmp(argv[i], "-m")) if (columns == 0) columns = 1;
} else if (!strcmp(argv[i], "-m"))
mon = atoi(argv[++i]); mon = atoi(argv[++i]);
else if (!strcmp(argv[i], "-p")) /* adds prompt to left of input field */ else if (!strcmp(argv[i], "-p")) /* adds prompt to left of input field */
prompt = argv[++i]; prompt = argv[++i];