Skip to content

Instantly share code, notes, and snippets.

@mjkloeckner
Created March 16, 2022 03:51
Show Gist options
  • Save mjkloeckner/5a59bad5c9fc3837a6942a4121f7904d to your computer and use it in GitHub Desktop.
Save mjkloeckner/5a59bad5c9fc3837a6942a4121f7904d to your computer and use it in GitHub Desktop.
dmenu scroll one line per time (you need to have mousesupport patched already)
From 462180ca92f799021500ea43128dbd1817fb057a Mon Sep 17 00:00:00 2001
From: klewer-martin <martin.cachari@gmail.com>
Date: Wed, 16 Mar 2022 00:44:41 -0300
Subject: [PATCH] scroll per line support
---
dmenu.c | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)
diff --git a/dmenu.c b/dmenu.c
index d997033..f7e1d72 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -93,9 +93,7 @@ calcoffsets(void)
if ((i += (lines > 0) ? bh : MIN(TEXTW(next->text), n)) > n)
break;
- for (i = 0, prev = curr; prev && prev->left; prev = prev->left)
- if ((i += (lines > 0) ? bh : MIN(TEXTW(prev->left->text), n)) > n)
- break;
+ prev = curr->left;
}
static int
@@ -613,7 +611,7 @@ buttonpress(XEvent *e)
{
struct item *item;
XButtonPressedEvent *ev = &e->xbutton;
- int x = 0, y = 0, h = bh, w;
+ int x = 0, y = 0, h = bh, w, i, n;
if (ev->window != win)
return;
@@ -648,14 +646,29 @@ buttonpress(XEvent *e)
}
/* scroll up */
if (ev->button == Button4 && prev) {
- sel = curr = prev;
+ curr = prev;
+ if (lines > 0)
+ n = (lines - 1) * bh;
+ else
+ n = mw - (promptw + inputw + TEXTW("<") + TEXTW(">"));
+
+ /* we need to seek the final element */
+ for (i = 0, next = curr; next->right; next = next->right)
+ if ((i += (lines > 0) ? bh : MIN(TEXTW(next->text), n)) > n)
+ break;
+
+ if(sel == next->right)
+ sel = ((lines > 0) ? next : next->left);
+
calcoffsets();
drawmenu();
return;
}
/* scroll down */
if (ev->button == Button5 && next) {
- sel = curr = next;
+ curr = curr->right;
+ if(sel == curr->left)
+ sel = curr;
calcoffsets();
drawmenu();
return;
--
2.35.1
@mjkloeckner
Copy link
Author

WARNING! this patch causes a seg fault

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment