From 628ed1dc4081c80a1e8ed85c9815e4f780422122 Mon Sep 17 00:00:00 2001 From: speedie Date: Tue, 4 Apr 2023 02:28:05 +0200 Subject: [PATCH] rewrite the way clicking on items work --- libs/mouse.c | 28 ++++++++++++++++------------ libs/mouse.h | 2 ++ mouse.h | 27 +++++++++++++++------------ 3 files changed, 33 insertions(+), 24 deletions(-) diff --git a/libs/mouse.c b/libs/mouse.c index 2fbdcfd..37350c5 100644 --- a/libs/mouse.c +++ b/libs/mouse.c @@ -114,13 +114,14 @@ buttonpress(XEvent *e) y += h; if (ev->y >= y && ev->y <= (y + h) && ev->x >= x && ev->x <= (x + w / columns)) { - - // TODO: make clickitem a thing - if (ev->button != Button1) - return; - - puts(item->text); - exit(0); + for (i = 0; i < LENGTH(buttons); i++) { + if (buttons[i].click == clickselitem && buttons[i].button == ev->button && CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state)) { + puts(item->text); + exit(0); + } else if (buttons[i].click == clickitem) { + click = clickitem; + } + } } } } else if (matches) { @@ -138,12 +139,15 @@ buttonpress(XEvent *e) x += w; w = MIN(TEXTW(item->text), mw - x - rarrowWidth); if (ev->x >= x && ev->x <= x + w) { - // TODO: make clickitem a thing - if (ev->button != Button1) - return; + for (i = 0; i < LENGTH(buttons); i++) { + if (buttons[i].click == clickselitem && buttons[i].button == ev->button && CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state)) { + puts(item->text); + exit(0); + } else if (buttons[i].click == clickitem) { + click = clickitem; + } + } - puts(item->text); - exit(0); } } // left-click on right arrow diff --git a/libs/mouse.h b/libs/mouse.h index edb826d..086a48c 100644 --- a/libs/mouse.h +++ b/libs/mouse.h @@ -12,6 +12,8 @@ enum { clickprompt, clickinput, clicklarrow, + clickitem, + clickselitem, clickrarrow, clicknumber, clickmode, diff --git a/mouse.h b/mouse.h index 10fe124..9264d8c 100644 --- a/mouse.h +++ b/mouse.h @@ -3,19 +3,21 @@ * This header contains mouse binds. * Change them or remove them if you prefer. You can also add more if you want. * - * clickwindow: - spmenu window/client - * clickinput: - Input box - * clickprompt: - Prompt - * clicklarrow: - Left arrow - * clickrarrow: - Right arrow - * clicknumber: - Match count - * clickmode: - Mode indicator + * clickwindow: - spmenu window/client + * clickinput: - Input box + * clickprompt: - Prompt + * clicklarrow: - Left arrow + * clickitem: - Item + * clickselitem: - Item hovered over (function doesn't matter, this will always select the item) + * clickrarrow: - Right arrow + * clicknumber: - Match count + * clickmode: - Mode indicator * - * Button1 - Left click - * Button2 - Middle click - * Button3 - Right click - * Button4 - Scroll up - * Button5 - Scroll down + * Button1 - Left click + * Button2 - Middle click + * Button3 - Right click + * Button4 - Scroll up + * Button5 - Scroll down * * Note that clicking on an item will select it, as of now it's hardcoded. */ @@ -25,4 +27,5 @@ static Mouse buttons[] = { { clickprompt, 0, Button1, clear, {0} }, { clickmode, 0, Button1, switchmode, {0} }, { clicknumber, 0, Button1, viewhist, {0} }, + { clickselitem, 0, Button1, NULL, {0} }, };