sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

commit cc344f979c36af4d26d13a1bbb588ed37f641614
parent c7d8c3245a8b6d012d330bb0ffc744c7b9d426bb
Author: Karol Kosek <krkk@krkk.ct8.pl>
Date:   Sat, 23 Jan 2021 20:17:56 +0100

[dmenu][patch][mouse-support] fix mouse hover on vertical lists with prompt text

Diffstat:
Atools.suckless.org/dmenu/patches/mouse-support/dmenu-mousesupporthoverbgcol-20210123-1a13d04.diff | 196+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtools.suckless.org/dmenu/patches/mouse-support/index.md | 3++-
2 files changed, 198 insertions(+), 1 deletion(-)

diff --git a/tools.suckless.org/dmenu/patches/mouse-support/dmenu-mousesupporthoverbgcol-20210123-1a13d04.diff b/tools.suckless.org/dmenu/patches/mouse-support/dmenu-mousesupporthoverbgcol-20210123-1a13d04.diff @@ -0,0 +1,196 @@ +From 51331aed8a535323702b73681c5ce2af6f8f5868 Mon Sep 17 00:00:00 2001 +From: Karol Kosek <krkk@krkk.ct8.pl> +Date: Sat, 23 Jan 2021 20:16:19 +0100 +Subject: [PATCH] fix mouse hover on vertical lists with prompt text + +--- + dmenu.c | 159 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- + 1 file changed, 158 insertions(+), 1 deletion(-) + +diff --git a/dmenu.c b/dmenu.c +index 65f25ce..aff2768 100644 +--- a/dmenu.c ++++ b/dmenu.c +@@ -500,6 +500,156 @@ draw: + drawmenu(); + } + ++static void ++buttonpress(XEvent *e) ++{ ++ struct item *item; ++ XButtonPressedEvent *ev = &e->xbutton; ++ int x = 0, y = 0, h = bh, w; ++ ++ if (ev->window != win) ++ return; ++ ++ /* right-click: exit */ ++ if (ev->button == Button3) ++ exit(1); ++ ++ if (prompt && *prompt) ++ x += promptw; ++ ++ /* input field */ ++ w = (lines > 0 || !matches) ? mw - x : inputw; ++ ++ /* left-click on input: clear input, ++ * NOTE: if there is no left-arrow the space for < is reserved so ++ * add that to the input width */ ++ if (ev->button == Button1 && ++ ((lines <= 0 && ev->x >= 0 && ev->x <= x + w + ++ ((!prev || !curr->left) ? TEXTW("<") : 0)) || ++ (lines > 0 && ev->y >= y && ev->y <= y + h))) { ++ insert(NULL, -cursor); ++ drawmenu(); ++ return; ++ } ++ /* middle-mouse click: paste selection */ ++ if (ev->button == Button2) { ++ XConvertSelection(dpy, (ev->state & ShiftMask) ? clip : XA_PRIMARY, ++ utf8, utf8, win, CurrentTime); ++ drawmenu(); ++ return; ++ } ++ /* scroll up */ ++ if (ev->button == Button4 && prev) { ++ sel = curr = prev; ++ calcoffsets(); ++ drawmenu(); ++ return; ++ } ++ /* scroll down */ ++ if (ev->button == Button5 && next) { ++ sel = curr = next; ++ calcoffsets(); ++ drawmenu(); ++ return; ++ } ++ if (ev->button != Button1) ++ return; ++ /* disabled below, needs to be fixed */ ++ /* ++ if (ev->state & ~ControlMask) ++ return; ++ */ ++ if (lines > 0) { ++ /* vertical list: (ctrl)left-click on item */ ++ w = mw - x; ++ for (item = curr; item != next; item = item->right) { ++ y += h; ++ if (ev->y >= y && ev->y <= (y + h)) { ++ puts(item->text); ++ if (!(ev->state & ControlMask)) ++ exit(0); ++ sel = item; ++ if (sel) { ++ sel->out = 1; ++ drawmenu(); ++ } ++ return; ++ } ++ } ++ } else if (matches) { ++ /* left-click on left arrow */ ++ x += inputw; ++ w = TEXTW("<"); ++ if (prev && curr->left) { ++ if (ev->x >= x && ev->x <= x + w) { ++ sel = curr = prev; ++ calcoffsets(); ++ drawmenu(); ++ return; ++ } ++ } ++ /* horizontal list: (ctrl)left-click on item */ ++ for (item = curr; item != next; item = item->right) { ++ x += w; ++ w = MIN(TEXTW(item->text), mw - x - TEXTW(">")); ++ if (ev->x >= x && ev->x <= x + w) { ++ puts(item->text); ++ if (!(ev->state & ControlMask)) ++ exit(0); ++ sel = item; ++ if (sel) { ++ sel->out = 1; ++ drawmenu(); ++ } ++ return; ++ } ++ } ++ /* left-click on right arrow */ ++ w = TEXTW(">"); ++ x = mw - w; ++ if (next && ev->x >= x && ev->x <= x + w) { ++ sel = curr = next; ++ calcoffsets(); ++ drawmenu(); ++ return; ++ } ++ } ++} ++ ++static void ++mousemove(XEvent *e) ++{ ++ struct item *item; ++ XPointerMovedEvent *ev = &e->xmotion; ++ int x = 0, y = 0, h = bh, w; ++ ++ if (lines > 0) { ++ w = mw - x; ++ for (item = curr; item != next; item = item->right) { ++ y += h; ++ if (ev->y >= y && ev->y <= (y + h)) { ++ sel = item; ++ calcoffsets(); ++ drawmenu(); ++ return; ++ } ++ } ++ } else if (matches) { ++ x += inputw + promptw; ++ w = TEXTW("<"); ++ for (item = curr; item != next; item = item->right) { ++ x += w; ++ w = MIN(TEXTW(item->text), mw - x - TEXTW(">")); ++ if (ev->x >= x && ev->x <= x + w) { ++ sel = item; ++ calcoffsets(); ++ drawmenu(); ++ return; ++ } ++ } ++ } ++} ++ + static void + paste(void) + { +@@ -561,6 +711,12 @@ run(void) + break; + cleanup(); + exit(1); ++ case ButtonPress: ++ buttonpress(&ev); ++ break; ++ case MotionNotify: ++ mousemove(&ev); ++ break; + case Expose: + if (ev.xexpose.count == 0) + drw_map(drw, win, 0, 0, mw, mh); +@@ -658,7 +814,8 @@ setup(void) + /* create menu window */ + swa.override_redirect = True; + swa.background_pixel = scheme[SchemeNorm][ColBg].pixel; +- swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask; ++ swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask | ++ ButtonPressMask | PointerMotionMask; + win = XCreateWindow(dpy, parentwin, x, y, mw, mh, 0, + CopyFromParent, CopyFromParent, CopyFromParent, + CWOverrideRedirect | CWBackPixel | CWEventMask, &swa); +-- +2.30.0 + diff --git a/tools.suckless.org/dmenu/patches/mouse-support/index.md b/tools.suckless.org/dmenu/patches/mouse-support/index.md @@ -29,8 +29,9 @@ Download * [dmenu-mousesupport-4.7.diff](dmenu-mousesupport-4.7.diff) * [dmenu-mousesupport-4.6.diff](dmenu-mousesupport-4.6.diff) * [dmenu-mousesupport-20160702-3c91eed.diff](dmenu-mousesupport-20160702-3c91eed.diff) -* [dmenu-mousesupporthoverbgcol-5.0.diff](dmenu-mousesupporthoverbgcol-5.0.diff) +* [dmenu-mousesupporthoverbgcol-20210123-1a13d04.diff](dmenu-mousesupporthoverbgcol-20210123-1a13d04.diff) set selectbg color on hovered item. +* [dmenu-mousesupporthoverbgcol-5.0.diff](dmenu-mousesupporthoverbgcol-5.0.diff) * [dmenu-mousesupportwithgrid-5.0.diff](dmenu-mousesupportwithgrid-5.0.diff) variant compatible with [grid](../grid).