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" },
[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 columns = 0;
/*
* Characters not considered part of a word while deleting words

View file

@ -4,6 +4,8 @@ dmenu \- dynamic menu
.SH SYNOPSIS
.B dmenu
.RB [ \-bFfiv ]
.RB [ \-g
.IR columns ]
.RB [ \-l
.IR lines ]
.RB [ \-m
@ -58,8 +60,11 @@ is faster, but will lock up X until stdin reaches end\-of\-file.
.B \-i
dmenu matches menu items case insensitively.
.TP
.BI \-g " columns"
dmenu lists items in a grid with the given number of columns.
.TP
.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
.BI \-m " monitor"
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;
if (lines > 0)
n = lines * bh;
n = lines * columns * bh;
else
n = mw - (promptw + inputw + TEXTW("<") + TEXTW(">"));
/* calculate which items will begin the next page and previous page */
@ -212,9 +212,15 @@ drawmenu(void)
}
if (lines > 0) {
/* draw vertical list */
for (item = curr; item != next; item = item->right)
drawitem(item, x, y += bh, mw - x);
/* draw grid */
int i = 0;
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) {
/* draw horizontal list */
x += inputw;
@ -871,9 +877,13 @@ main(int argc, char *argv[])
} else if (i + 1 == argc)
usage();
/* 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]);
else if (!strcmp(argv[i], "-m"))
if (columns == 0) columns = 1;
} else if (!strcmp(argv[i], "-m"))
mon = atoi(argv[++i]);
else if (!strcmp(argv[i], "-p")) /* adds prompt to left of input field */
prompt = argv[++i];