~mil/sxmo-devel

sxmo-dmenu: Add optional wrap around to top/bottom of list v3 APPLIED

Galen Abell: 1
 Add optional wrap around to top/bottom of list

 2 files changed, 30 insertions(+), 6 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~mil/sxmo-devel/patches/15206/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH sxmo-dmenu v3] Add optional wrap around to top/bottom of list Export this patch

When paging up on the first item or down on the last item, the selection
will jump to the bottom or top item, respectively. This behavior is
disabled by default but can be enabled by setting the DMENU_WRAP_AROUND
environment variable.
---
This fixes the previous (reverted) version to correctly jump to and from
the other "pages" in the menu when the cursor reaches the end or
beginning of the list.

 config.def.h |  3 +++
 dmenu.c      | 33 +++++++++++++++++++++++++++------
 2 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/config.def.h b/config.def.h
index 24eb8db..dc6c99c 100644
--- a/config.def.h
+++ b/config.def.h
@@ -29,3 +29,6 @@ static const char worddelimiters[] = " ";

/* Size of the window border */
static const unsigned int border_width = 5;

/* Whether to wrap around to the top and bottom of the menu */
static int wrap_around = 0;
diff --git a/dmenu.c b/dmenu.c
index aaf4e5d..d34acc7 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -537,11 +537,23 @@ insert:
		if (lines > 0)
			return;
		/* fallthrough */
  case XF86XK_AudioRaiseVolume:
	case XF86XK_AudioRaiseVolume:
	case XK_Up:
		if (sel && sel->left && (sel = sel->left)->right == curr) {
		if (sel && sel->left) {
			sel = sel->left;
			if (sel->right == curr) {
				curr = prev;
				calcoffsets();
			}
		} else if (wrap_around) {
			// if there is no previous item, jump to the bottom of the list
			curr = matchend;
			calcoffsets();
			curr = prev;
			calcoffsets();
			while (next && (curr = curr->right))
				calcoffsets();
			sel = matchend;
		}
		break;
	case XK_Next:
@@ -578,12 +590,18 @@ insert:
		if (lines > 0)
			return;
		/* fallthrough */
  case XF86XK_AudioLowerVolume:
	case XF86XK_AudioLowerVolume:
	case XK_Down:
		if (sel && sel->right && (sel = sel->right) == next) {
			curr = next;
			calcoffsets();
		if (sel && sel->right) {
			sel = sel->right;
			if (sel == next) {
				curr = next;
			}
		} else if (wrap_around) {
			// if there is no next item, jump to the top of the list
			sel = curr = matches;
		}
		calcoffsets();
		break;
	case XK_Tab:
		if (!sel)
@@ -991,6 +1009,9 @@ main(int argc, char *argv[])
		else
			usage();

	if (getenv("DMENU_WRAP_AROUND"))
		wrap_around = 1;

	if (!setlocale(LC_CTYPE, "") || !XSupportsLocale())
		fputs("warning: no locale support\n", stderr);
	if (!XSetLocaleModifiers(""))
-- 
2.29.2
Thanks! It works great this time! Applied.

--
Maarten van Gompel (proycon)
https://proycon.anaproy.nl