Adding grid patch

This commit is contained in:
bakkeby 2020-08-05 11:31:54 +02:00
parent c4cac2c195
commit ee3e48fe0b
5 changed files with 66 additions and 3 deletions

View File

@ -15,6 +15,8 @@ Refer to [https://tools.suckless.org/dmenu/](https://tools.suckless.org/dmenu/)
### Changelog: ### Changelog:
2020-08-05 - Added the grid patch
2020-06-13 - Added the pango patch 2020-06-13 - Added the pango patch
2020-06-10 - Added the case-insensitive 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/) - [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 - 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/) - [incremental](https://tools.suckless.org/dmenu/patches/incremental/)
- this patch causes dmenu to print out the current text each time a key is pressed - this patch causes dmenu to print out the current text each time a key is pressed

View File

@ -60,6 +60,10 @@ static const char *colors[][2] =
}; };
/* -l option; if nonzero, dmenu uses vertical list with given number of lines */ /* -l option; if nonzero, dmenu uses vertical list with given number of lines */
static unsigned int lines = 0; 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 #if LINE_HEIGHT_PATCH
static unsigned int lineheight = 0; /* -h option; minimum height of a menu line */ static unsigned int lineheight = 0; /* -h option; minimum height of a menu line */
#endif // LINE_HEIGHT_PATCH #endif // LINE_HEIGHT_PATCH

View File

@ -22,8 +22,8 @@ FREETYPEINC = /usr/include/freetype2
#XRENDER = -lXrender #XRENDER = -lXrender
# Uncomment for the pango patch / PANGO_PATCH # Uncomment for the pango patch / PANGO_PATCH
#PANGOINC = `pkg-config --cflags xft pango pangoxft` PANGOINC = `pkg-config --cflags xft pango pangoxft`
#PANGOLIB = `pkg-config --libs xft pango pangoxft` PANGOLIB = `pkg-config --libs xft pango pangoxft`
# includes and libs # includes and libs
INCS = -I$(X11INC) -I$(FREETYPEINC) ${PANGOINC} INCS = -I$(X11INC) -I$(FREETYPEINC) ${PANGOINC}

48
dmenu.c
View File

@ -160,7 +160,14 @@ calcoffsets(void)
int i, n; int i, n;
if (lines > 0) if (lines > 0)
#if GRID_PATCH
if (columns)
n = lines * columns * bh;
else
n = lines * bh;
#else
n = lines * bh; n = lines * bh;
#endif // GRID_PATCH
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 */
@ -334,6 +341,33 @@ drawmenu(void)
#endif // SCROLL_PATCH #endif // SCROLL_PATCH
if (lines > 0) { 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 */ /* draw vertical list */
for (item = curr; item != next; item = item->right) for (item = curr; item != next; item = item->right)
#if VERTFULL_PATCH #if VERTFULL_PATCH
@ -341,6 +375,7 @@ drawmenu(void)
#else #else
drawitem(item, x, y += bh, mw - x); drawitem(item, x, y += bh, mw - x);
#endif // VERTFULL_PATCH #endif // VERTFULL_PATCH
#endif // GRID_PATCH
} else if (matches) { } else if (matches) {
/* draw horizontal list */ /* draw horizontal list */
x += inputw; x += inputw;
@ -1224,7 +1259,11 @@ usage(void)
#if REJECTNOMATCH_PATCH #if REJECTNOMATCH_PATCH
"R" // (changed from r to R due to conflict with INCREMENTAL_PATCH) "R" // (changed from r to R due to conflict with INCREMENTAL_PATCH)
#endif // REJECTNOMATCH_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]" "\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 #if ALPHA_PATCH || BORDER_PATCH || INITIALTEXT_PATCH || LINE_HEIGHT_PATCH || NAVHISTORY_PATCH || XYW_PATCH
"\n " "\n "
@ -1322,6 +1361,13 @@ main(int argc, char *argv[])
else if (!strcmp(argv[i], "-H")) else if (!strcmp(argv[i], "-H"))
histfile = argv[++i]; histfile = argv[++i];
#endif // NAVHISTORY_PATCH #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 */ else if (!strcmp(argv[i], "-l")) /* number of lines in vertical list */
lines = atoi(argv[++i]); lines = atoi(argv[++i]);
#if XYW_PATCH #if XYW_PATCH

View File

@ -43,6 +43,13 @@
*/ */
#define FUZZYMATCH_PATCH 0 #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. /* This patch causes dmenu to print out the current text each time a key is pressed.
* https://tools.suckless.org/dmenu/patches/incremental/ * https://tools.suckless.org/dmenu/patches/incremental/
*/ */