rewrite the way clicking on items work

This commit is contained in:
speedie 2023-04-04 02:28:05 +02:00
parent 39b166bf17
commit 628ed1dc40
3 changed files with 33 additions and 24 deletions

View file

@ -114,13 +114,14 @@ buttonpress(XEvent *e)
y += h; y += h;
if (ev->y >= y && ev->y <= (y + h) && ev->x >= x && ev->x <= (x + w / columns)) { if (ev->y >= y && ev->y <= (y + h) && ev->x >= x && ev->x <= (x + w / columns)) {
for (i = 0; i < LENGTH(buttons); i++) {
// TODO: make clickitem a thing if (buttons[i].click == clickselitem && buttons[i].button == ev->button && CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state)) {
if (ev->button != Button1) puts(item->text);
return; exit(0);
} else if (buttons[i].click == clickitem) {
puts(item->text); click = clickitem;
exit(0); }
}
} }
} }
} else if (matches) { } else if (matches) {
@ -138,12 +139,15 @@ buttonpress(XEvent *e)
x += w; x += w;
w = MIN(TEXTW(item->text), mw - x - rarrowWidth); w = MIN(TEXTW(item->text), mw - x - rarrowWidth);
if (ev->x >= x && ev->x <= x + w) { if (ev->x >= x && ev->x <= x + w) {
// TODO: make clickitem a thing for (i = 0; i < LENGTH(buttons); i++) {
if (ev->button != Button1) if (buttons[i].click == clickselitem && buttons[i].button == ev->button && CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state)) {
return; puts(item->text);
exit(0);
} else if (buttons[i].click == clickitem) {
click = clickitem;
}
}
puts(item->text);
exit(0);
} }
} }
// left-click on right arrow // left-click on right arrow

View file

@ -12,6 +12,8 @@ enum {
clickprompt, clickprompt,
clickinput, clickinput,
clicklarrow, clicklarrow,
clickitem,
clickselitem,
clickrarrow, clickrarrow,
clicknumber, clicknumber,
clickmode, clickmode,

27
mouse.h
View file

@ -3,19 +3,21 @@
* This header contains mouse binds. * This header contains mouse binds.
* Change them or remove them if you prefer. You can also add more if you want. * Change them or remove them if you prefer. You can also add more if you want.
* *
* clickwindow: - spmenu window/client * clickwindow: - spmenu window/client
* clickinput: - Input box * clickinput: - Input box
* clickprompt: - Prompt * clickprompt: - Prompt
* clicklarrow: - Left arrow * clicklarrow: - Left arrow
* clickrarrow: - Right arrow * clickitem: - Item
* clicknumber: - Match count * clickselitem: - Item hovered over (function doesn't matter, this will always select the item)
* clickmode: - Mode indicator * clickrarrow: - Right arrow
* clicknumber: - Match count
* clickmode: - Mode indicator
* *
* Button1 - Left click * Button1 - Left click
* Button2 - Middle click * Button2 - Middle click
* Button3 - Right click * Button3 - Right click
* Button4 - Scroll up * Button4 - Scroll up
* Button5 - Scroll down * Button5 - Scroll down
* *
* Note that clicking on an item will select it, as of now it's hardcoded. * 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} }, { clickprompt, 0, Button1, clear, {0} },
{ clickmode, 0, Button1, switchmode, {0} }, { clickmode, 0, Button1, switchmode, {0} },
{ clicknumber, 0, Button1, viewhist, {0} }, { clicknumber, 0, Button1, viewhist, {0} },
{ clickselitem, 0, Button1, NULL, {0} },
}; };