[wiki] [sites] [dmenu][mouse-support-motion]: collapse into a single loop || NRK

From: <git_AT_suckless.org>
Date: Mon, 28 Nov 2022 11:34:48 +0100

commit 1c91ee26e45cc7509a4d5ea9e0e97aeb758bdd79
Author: NRK <nrk_AT_disroot.org>
Date: Mon Nov 28 16:33:11 2022 +0600

    [dmenu][mouse-support-motion]: collapse into a single loop
    
    both branches are similar enough that they can be easily collapsed down
    into a single loop.

diff --git a/tools.suckless.org/dmenu/patches/mouse-support/dmenu-mousesupport-motion-5.2.diff b/tools.suckless.org/dmenu/patches/mouse-support/dmenu-mousesupport-motion-5.2.diff
index ec15a72a..414201c5 100644
--- a/tools.suckless.org/dmenu/patches/mouse-support/dmenu-mousesupport-motion-5.2.diff
+++ b/tools.suckless.org/dmenu/patches/mouse-support/dmenu-mousesupport-motion-5.2.diff
_AT_@ -1,49 +1,38 @@
 diff --git a/dmenu.c b/dmenu.c
-index 48d4980..5363aa1 100644
+index 48d4980..7677401 100644
 --- a/dmenu.c
 +++ b/dmenu.c
-_AT_@ -641,6 +641,40 @@ buttonpress(XEvent *e)
+_AT_@ -641,6 +641,29 @@ buttonpress(XEvent *e)
          }
  }
  
 +static void
 +motionevent(XButtonEvent *ev)
 +{
-+ struct item *it, *psel = sel;
++ struct item *it;
++ int xy, ev_xy;
 +
-+ if (ev->window != win)
++ if (ev->window != win || matches == 0)
 + return;
 +
-+ if (lines > 0) { /* vertical list */
-+ int y = bh;
-+ for (it = curr; it && it != next; it = it->right) {
-+ if (ev->y >= y && ev->y < (y + bh)) {
-+ sel = it;
-+ break;
-+ }
-+ y += bh;
-+ }
-+ } else if (matches) {
-+ int x = inputw + promptw + TEXTW("<");
-+ for (it = curr; it && it != next; it = it->right) {
-+ int w = textw_clamp(it->text, mw - x - TEXTW(">"));
-+ if (ev->x >= x && ev->x < (x + w)) {
-+ sel = it;
-+ break;
-+ }
-+ x += w;
++ xy = lines > 0 ? bh : inputw + promptw + TEXTW("<");
++ ev_xy = lines > 0 ? ev->y : ev->x;
++ for (it = curr; it && it != next; it = it->right) {
++ int wh = lines > 0 ? bh : textw_clamp(it->text, mw - xy - TEXTW(">"));
++ if (ev_xy >= xy && ev_xy < (xy + wh)) {
++ sel = it;
++ calcoffsets();
++ drawmenu();
++ break;
 + }
-+ }
-+ if (psel != sel) {
-+ calcoffsets();
-+ drawmenu();
++ xy += wh;
 + }
 +}
 +
  static void
  paste(void)
  {
-_AT_@ -702,6 +736,9 @@ run(void)
+_AT_@ -702,6 +725,9 @@ run(void)
                  case ButtonPress:
                          buttonpress(&ev);
                          break;
_AT_@ -53,7 +42,7 @@ index 48d4980..5363aa1 100644
                  case Expose:
                          if (ev.xexpose.count == 0)
                                  drw_map(drw, win, 0, 0, mw, mh);
-_AT_@ -800,7 +837,7 @@ setup(void)
+_AT_@ -800,7 +826,7 @@ setup(void)
          swa.override_redirect = True;
          swa.background_pixel = scheme[SchemeNorm][ColBg].pixel;
          swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask |
Received on Mon Nov 28 2022 - 11:34:48 CET

This archive was generated by hypermail 2.3.0 : Mon Nov 28 2022 - 11:36:41 CET