dmenu

my build of dynamic menu
git clone git://git.kocotian.pl/dmenu.git
Log | Files | Refs | README | LICENSE

commit f829f538ade27f441389a22eb51734d655e42636
parent 9b73a5952fc98cf7e08b0ba540f4f4ec0dbd0da9
Author: kocotian <kocotian@kocotian.pl>
Date:   Wed, 30 Dec 2020 11:51:26 +0100

grid

Diffstat:
Mconfig.def.h | 3++-
Mdmenu.1 | 7++++++-
Mdmenu.c | 24+++++++++++++++++-------
Mpatches/dmenu-grid-4.9.diff | 0
4 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -16,8 +16,9 @@ static const char *colors[SchemeLast][2] = { [SchemeSel] = { "#eeeeee", "#005577" }, [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; /* -h option; minimum height of a menu line */ static unsigned int lineheight = 25; static unsigned int min_lineheight = 8; diff --git a/dmenu.1 b/dmenu.1 @@ -4,6 +4,8 @@ dmenu \- dynamic menu .SH SYNOPSIS .B dmenu .RB [ \-bfinv ] +.RB [ \-g +.IR columns ] .RB [ \-l .IR lines ] .RB [ \-h @@ -52,8 +54,11 @@ dmenu matches menu items case insensitively. .B \-n dmenu instantly selects if only one match. .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 \-h " height" dmenu uses a menu line of at least 'height' pixels tall, but no less than 8. diff --git a/dmenu.c b/dmenu.c @@ -80,7 +80,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 */ @@ -155,9 +155,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; @@ -807,7 +813,7 @@ main(int argc, char *argv[]) fast = 1; else if (!strcmp(argv[i], "-F")) /* not fuzzy match */ fuzzy = 0; - else if (!strcmp(argv[i], "-i")); /* for scripts compatibility, insensitive + else if (!strcmp(argv[i], "-i")); /* for scripts compatibility, insensitive matching is default by patch */ else if (!strcmp(argv[i], "-s")) { /* case-sensitive item matching */ fstrncmp = strncmp; @@ -817,9 +823,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], "-l")) { /* number of lines in vertical list */ lines = atoi(argv[++i]); - else if (!strcmp(argv[i], "-h")) { /* minimum height of one menu line */ + if (columns == 0) columns = 1; + } 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], "-h")) { /* minimum height of one menu line */ lineheight = atoi(argv[++i]); lineheight = MAX(lineheight, min_lineheight); } diff --git a/patches/dmenu-grid-4.9.diff b/patches/dmenu-grid-4.9.diff