dmenu

my fork of dmenu
Index Commits Files Refs README LICENSE
patches/dmenu-mousesupport-scrollperline.diff (1656B)
   1 From 462180ca92f799021500ea43128dbd1817fb057a Mon Sep 17 00:00:00 2001
   2 From: klewer-martin <martin.cachari@gmail.com>
   3 Date: Wed, 16 Mar 2022 00:44:41 -0300
   4 Subject: [PATCH] scroll per line support
   5 
   6 ---
   7  dmenu.c | 25 +++++++++++++++++++------
   8  1 file changed, 19 insertions(+), 6 deletions(-)
   9 
  10 diff --git a/dmenu.c b/dmenu.c
  11 index d997033..f7e1d72 100644
  12 --- a/dmenu.c
  13 +++ b/dmenu.c
  14 @@ -93,9 +93,7 @@ calcoffsets(void)
  15          if ((i += (lines > 0) ? bh : MIN(TEXTW(next->text), n)) > n)
  16              break;
  17  
  18 -    for (i = 0, prev = curr; prev && prev->left; prev = prev->left)
  19 -        if ((i += (lines > 0) ? bh : MIN(TEXTW(prev->left->text), n)) > n)
  20 -            break;
  21 +    prev = curr->left;
  22  }
  23  
  24  static int
  25 @@ -613,7 +611,7 @@ buttonpress(XEvent *e)
  26  {
  27      struct item *item;
  28      XButtonPressedEvent *ev = &e->xbutton;
  29 -    int x = 0, y = 0, h = bh, w;
  30 +    int x = 0, y = 0, h = bh, w, i, n;
  31  
  32      if (ev->window != win)
  33          return;
  34 @@ -648,14 +646,29 @@ buttonpress(XEvent *e)
  35      }
  36      /* scroll up */
  37      if (ev->button == Button4 && prev) {
  38 -        sel = curr = prev;
  39 +        curr = prev;
  40 +        if (lines > 0)
  41 +            n = (lines - 1) * bh;
  42 +        else
  43 +            n = mw - (promptw + inputw + TEXTW("<") + TEXTW(">"));
  44 +
  45 +        /* we need to seek the final element */
  46 +        for (i = 0, next = curr; next->right; next = next->right)
  47 +            if ((i += (lines > 0) ? bh : MIN(TEXTW(next->text), n)) > n)
  48 +                break;
  49 +
  50 +        if(sel == next->right)
  51 +            sel = ((lines > 0) ? next : next->left);
  52 +
  53          calcoffsets();
  54          drawmenu();
  55          return;
  56      }
  57      /* scroll down */
  58      if (ev->button == Button5 && next) {
  59 -        sel = curr = next;
  60 +        curr = curr->right;
  61 +        if(sel == curr->left)
  62 +            sel = curr;
  63          calcoffsets();
  64          drawmenu();
  65          return;
  66 -- 
  67 2.35.1
  68