diff --git a/README.md b/README.md index 5593af3..4b3fdd5 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ dmenu, how to install it and how it works. ### Changelog: -2021-05-17 - Added the restrict return, no sort and plain-prompt (listfullwidth) patches +2021-05-17 - Added the restrict return, no sort, gridnav and plain-prompt (listfullwidth) patches 2021-05-15 - Added the tsv and printindex patches @@ -92,6 +92,9 @@ dmenu, how to install it and how it works. number of grid columns - the `-g` and `-l` options can be used together to create a G columns * L lines grid + - [gridnav](https://tools.suckless.org/dmenu/patches/gridnav/) + - adds the ability to move left and right through a grid (when using the grid patch) + - [highlight](https://tools.suckless.org/dmenu/patches/highlight/) - this patch highlights the individual characters of matched text for each dmenu list entry diff --git a/dmenu.c b/dmenu.c index 6044ae0..700e126 100644 --- a/dmenu.c +++ b/dmenu.c @@ -32,6 +32,9 @@ #include "drw.h" #include "util.h" +#if GRIDNAV_PATCH +#include +#endif // GRIDNAV_PATCH #if JSON_PATCH #include #endif // JSON_PATCH @@ -775,6 +778,11 @@ keypress(XKeyEvent *ev) #endif // PREFIXCOMPLETION_PATCH KeySym ksym; Status status; + #if GRID_PATCH && GRIDNAV_PATCH + int i; + struct item *tmpsel; + bool offscreen = false; + #endif // GRIDNAV_PATCH len = XmbLookupString(xic, ev, buf, sizeof buf, &ksym, &status); switch (status) { @@ -908,6 +916,26 @@ insert: calcoffsets(); break; case XK_Left: + #if GRID_PATCH && GRIDNAV_PATCH + if (columns > 1) { + if (!sel) + return; + tmpsel = sel; + for (i = 0; i < lines; i++) { + if (!tmpsel->left || tmpsel->left->right != tmpsel) + return; + if (tmpsel == curr) + offscreen = true; + tmpsel = tmpsel->left; + } + sel = tmpsel; + if (offscreen) { + curr = prev; + calcoffsets(); + } + break; + } + #endif // GRIDNAV_PATCH if (cursor > 0 && (!sel || !sel->left || lines > 0)) { cursor = nextrune(-1); break; @@ -1005,6 +1033,26 @@ insert: #endif // MULTI_SELECTION_PATCH break; case XK_Right: + #if GRID_PATCH && GRIDNAV_PATCH + if (columns > 1) { + if (!sel) + return; + tmpsel = sel; + for (i = 0; i < lines; i++) { + if (!tmpsel->right || tmpsel->right->left != tmpsel) + return; + tmpsel = tmpsel->right; + if (tmpsel == next) + offscreen = true; + } + sel = tmpsel; + if (offscreen) { + curr = next; + calcoffsets(); + } + break; + } + #endif // GRIDNAV_PATCH if (text[cursor] != '\0') { cursor = nextrune(+1); break; diff --git a/patches.def.h b/patches.def.h index b4abfb2..687080d 100644 --- a/patches.def.h +++ b/patches.def.h @@ -57,6 +57,12 @@ */ #define GRID_PATCH 0 +/* This patch adds the ability to move left and right through a grid. + * This patch depends on the grid patch. + * https://tools.suckless.org/dmenu/patches/gridnav/ + */ +#define GRIDNAV_PATCH 0 + /* This patch highlights the individual characters of matched text for each dmenu list entry. * The fuzzy highlight patch takes precedence over this patch. * https://tools.suckless.org/dmenu/patches/highlight/