diff --git a/README.md b/README.md index c3f69ea..fadc83a 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,8 @@ Refer to [https://tools.suckless.org/dmenu/](https://tools.suckless.org/dmenu/) ### Changelog: +2020-08-05 - Added the grid patch + 2020-06-13 - Added the pango patch 2020-06-10 - Added the case-insensitive patch @@ -55,6 +57,10 @@ Refer to [https://tools.suckless.org/dmenu/](https://tools.suckless.org/dmenu/) - [fuzzymatch](https://tools.suckless.org/dmenu/patches/fuzzymatch/) - adds support for fuzzy-matching to dmenu, allowing users to type non-consecutive portions of the string to be matched + - [grid](https://tools.suckless.org/dmenu/patches/grid/) + - allows dmenu's entries to be rendered in a grid by adding a new `-g` flag to specify the number of grid columns + - the `-g` and `-l` options can be used together to create a G columns * L lines grid + - [incremental](https://tools.suckless.org/dmenu/patches/incremental/) - this patch causes dmenu to print out the current text each time a key is pressed diff --git a/config.def.h b/config.def.h index e4fda08..a7c431e 100644 --- a/config.def.h +++ b/config.def.h @@ -60,6 +60,10 @@ static const char *colors[][2] = }; /* -l option; if nonzero, dmenu uses vertical list with given number of lines */ static unsigned int lines = 0; +#if GRID_PATCH +/* -g option; if nonzero, dmenu uses a grid comprised of columns and lines */ +static unsigned int columns = 0; +#endif // GRID_PATCH #if LINE_HEIGHT_PATCH static unsigned int lineheight = 0; /* -h option; minimum height of a menu line */ #endif // LINE_HEIGHT_PATCH diff --git a/config.mk b/config.mk index 45b75a0..b7021d7 100644 --- a/config.mk +++ b/config.mk @@ -22,8 +22,8 @@ FREETYPEINC = /usr/include/freetype2 #XRENDER = -lXrender # Uncomment for the pango patch / PANGO_PATCH -#PANGOINC = `pkg-config --cflags xft pango pangoxft` -#PANGOLIB = `pkg-config --libs xft pango pangoxft` +PANGOINC = `pkg-config --cflags xft pango pangoxft` +PANGOLIB = `pkg-config --libs xft pango pangoxft` # includes and libs INCS = -I$(X11INC) -I$(FREETYPEINC) ${PANGOINC} diff --git a/dmenu.c b/dmenu.c index fef13b2..4e909a7 100644 --- a/dmenu.c +++ b/dmenu.c @@ -160,7 +160,14 @@ calcoffsets(void) int i, n; if (lines > 0) + #if GRID_PATCH + if (columns) + n = lines * columns * bh; + else + n = lines * bh; + #else n = lines * bh; + #endif // GRID_PATCH else n = mw - (promptw + inputw + TEXTW("<") + TEXTW(">")); /* calculate which items will begin the next page and previous page */ @@ -334,6 +341,33 @@ drawmenu(void) #endif // SCROLL_PATCH if (lines > 0) { + #if GRID_PATCH + /* draw grid */ + int i = 0; + for (item = curr; item != next; item = item->right, i++) + if (columns) + #if VERTFULL_PATCH + drawitem( + item, + 0 + ((i / lines) * (mw / columns)), + y + (((i % lines) + 1) * bh), + mw / columns + ); + #else + drawitem( + item, + x + ((i / lines) * ((mw - x) / columns)), + y + (((i % lines) + 1) * bh), + (mw - x) / columns + ); + #endif // VERTFULL_PATCH + else + #if VERTFULL_PATCH + drawitem(item, 0, y += bh, mw); + #else + drawitem(item, x, y += bh, mw - x); + #endif // VERTFULL_PATCH + #else /* draw vertical list */ for (item = curr; item != next; item = item->right) #if VERTFULL_PATCH @@ -341,6 +375,7 @@ drawmenu(void) #else drawitem(item, x, y += bh, mw - x); #endif // VERTFULL_PATCH + #endif // GRID_PATCH } else if (matches) { /* draw horizontal list */ x += inputw; @@ -1224,7 +1259,11 @@ usage(void) #if REJECTNOMATCH_PATCH "R" // (changed from r to R due to conflict with INCREMENTAL_PATCH) #endif // REJECTNOMATCH_PATCH - "] [-l lines] [-p prompt] [-fn font] [-m monitor]" + "] " + #if GRID_PATCH + "[-g columns] " + #endif // GRID_PATCH + "[-l lines] [-p prompt] [-fn font] [-m monitor]" "\n [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]" #if ALPHA_PATCH || BORDER_PATCH || INITIALTEXT_PATCH || LINE_HEIGHT_PATCH || NAVHISTORY_PATCH || XYW_PATCH "\n " @@ -1322,6 +1361,13 @@ main(int argc, char *argv[]) else if (!strcmp(argv[i], "-H")) histfile = argv[++i]; #endif // NAVHISTORY_PATCH + #if GRID_PATCH + else if (!strcmp(argv[i], "-g")) { /* number of columns in grid */ + columns = atoi(argv[++i]); + if (columns && lines == 0) + lines = 1; + } + #endif // GRID_PATCH else if (!strcmp(argv[i], "-l")) /* number of lines in vertical list */ lines = atoi(argv[++i]); #if XYW_PATCH diff --git a/patches.def.h b/patches.def.h index 9fdffd2..d0ab33e 100644 --- a/patches.def.h +++ b/patches.def.h @@ -43,6 +43,13 @@ */ #define FUZZYMATCH_PATCH 0 +/* Allows dmenu's entries to be rendered in a grid by adding a new -g flag to specify + * the number of grid columns. The -g and -l options can be used together to create a + * G columns * L lines grid. + * https://tools.suckless.org/dmenu/patches/grid/ + */ +#define GRID_PATCH 0 + /* This patch causes dmenu to print out the current text each time a key is pressed. * https://tools.suckless.org/dmenu/patches/incremental/ */