From ea48ea69ed99e6d80f0180ad7c48818d6ad02fac Mon Sep 17 00:00:00 2001 From: speedie Date: Sat, 22 Jul 2023 02:02:03 +0200 Subject: [PATCH] Fix issue #14 by replacing bad code. I don't know what I was thinking to be honest. --- libs/arg.c | 2 +- libs/wl/wayland.c | 7 ++----- libs/x11/mouse.c | 7 ++----- spmenu.c | 3 +-- 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/libs/arg.c b/libs/arg.c index 3b424ff..894ca2f 100644 --- a/libs/arg.c +++ b/libs/arg.c @@ -607,7 +607,7 @@ void switchmode(Arg *arg) { } void selecthover(Arg *arg) { - puts(items[sp.clickitemindex].text); + puts(mouseitem->text); exit(0); } diff --git a/libs/wl/wayland.c b/libs/wl/wayland.c index 5a5a55e..d0e0f4d 100644 --- a/libs/wl/wayland.c +++ b/libs/wl/wayland.c @@ -289,8 +289,6 @@ void buttonpress_wl(uint32_t button, double ex, double ey) { ey += h; } - i = 0; - for (item = currentitem; item != nextitem; item = item->right) { if (item_num++ == lines) { item_num = 1; @@ -301,15 +299,14 @@ void buttonpress_wl(uint32_t button, double ex, double ey) { y += h; if (ey >= y && ey <= (y + h) && ex >= x + (powerlineitems ? sp.plw : 0) && ex <= (x + w / columns) + (powerlineitems ? sp.plw : 0)) { - sp.clickitemindex = i; click = ClickItem; + mouseitem = item; #if USEIMAGE } else if (ey >= y && ey <= (y + h) && ex >= x + (powerlineitems ? sp.plw : 0) - MAX((img.imagegaps * 2) + img.imagewidth, indentitems ? sp.promptw : 0) && ex <= (x - MAX((img.imagegaps * 2) + img.imagewidth, indentitems ? sp.promptw : 0) + w / columns) + (powerlineitems ? sp.plw : 0)) { click = ClickImage; + mouseitem = item; #endif } - - i++; } } else if (matches) { // a single line, meaning it could be arrows too, so we check that here x += sp.inputw; diff --git a/libs/x11/mouse.c b/libs/x11/mouse.c index c58325b..646cdef 100644 --- a/libs/x11/mouse.c +++ b/libs/x11/mouse.c @@ -73,8 +73,6 @@ void buttonpress_x11(XEvent *e) { ev->y += h; } - i = 0; - for (item = currentitem; item != nextitem; item = item->right) { if (item_num++ == lines) { item_num = 1; @@ -87,14 +85,13 @@ void buttonpress_x11(XEvent *e) { // ClickSelItem, called function doesn't matter if (ev->y >= y && ev->y <= (y + h) && ev->x >= x + (powerlineitems ? sp.plw : 0) && ev->x <= (x + w / columns) + (powerlineitems ? sp.plw : 0)) { click = ClickItem; - sp.clickitemindex = i; + mouseitem = item; #if USEIMAGE } else if (ev->y >= y && ev->y <= (y + h) && ev->x >= x + (powerlineitems ? sp.plw : 0) - MAX((img.imagegaps * 2) + img.imagewidth, indentitems ? sp.promptw : 0) && ev->x <= (x - MAX((img.imagegaps * 2) + img.imagewidth, indentitems ? sp.promptw : 0) + w / columns) + (powerlineitems ? sp.plw : 0)) { click = ClickImage; + mouseitem = item; #endif } - - i++; } } else if (matches) { // a single line, meaning it could be arrows too, so we check that here x += sp.inputw; diff --git a/spmenu.c b/spmenu.c index b0cd62c..45b7e0f 100644 --- a/spmenu.c +++ b/spmenu.c @@ -140,8 +140,6 @@ struct sp { int listcount; int listchanged; - int clickitemindex; - size_t cursor; // cursor width int ignoreconfkeys; // can be set globally if you don't want to override keybinds with config file keys @@ -206,6 +204,7 @@ static struct item *previousitem; // previous item static struct item *currentitem; // current item static struct item *nextitem; // next item static struct item *selecteditem; // selected item +static struct item *mouseitem; // clicked item // various headers #include "libs/draw/draw.h"