Adding gridnav patch

This commit is contained in:
bakkeby 2021-05-17 11:46:50 +02:00
parent f469820531
commit 608fa3e837
3 changed files with 58 additions and 1 deletions

View File

@ -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

48
dmenu.c
View File

@ -32,6 +32,9 @@
#include "drw.h"
#include "util.h"
#if GRIDNAV_PATCH
#include <stdbool.h>
#endif // GRIDNAV_PATCH
#if JSON_PATCH
#include <jansson.h>
#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;

View File

@ -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/