~mil/sxmo-devel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

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

Details
Message ID
<20201121103257.11013-1-galen@galenabell.com>
DKIM signature
pass
Download raw message
Patch: +30 -6
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
Details
Message ID
<20201121170827.xa6opkk2nktpkm77@worker.anaproy.lxd>
In-Reply-To
<20201121103257.11013-1-galen@galenabell.com> (view parent)
DKIM signature
missing
Download raw message
Thanks! It works great this time! Applied.

--
Maarten van Gompel (proycon)
https://proycon.anaproy.nl
Reply to thread Export thread (mbox)