Skip to content

Instantly share code, notes, and snippets.

@mjkloeckner
Created March 16, 2022 03:51
Show Gist options
  • Select an option

  • Save mjkloeckner/5a59bad5c9fc3837a6942a4121f7904d to your computer and use it in GitHub Desktop.

Select an option

Save mjkloeckner/5a59bad5c9fc3837a6942a4121f7904d to your computer and use it in GitHub Desktop.

Revisions

  1. mjkloeckner created this gist Mar 16, 2022.
    68 changes: 68 additions & 0 deletions dmenu-mousesupport-scrollperline.diff
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,68 @@
    From 462180ca92f799021500ea43128dbd1817fb057a Mon Sep 17 00:00:00 2001
    From: klewer-martin <[email protected]>
    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