From f99cc1d62aefd9aed04fe89c1f4312cbcb8c86a0 Mon Sep 17 00:00:00 2001 From: speedie Date: Mon, 19 Jun 2023 23:16:03 +0200 Subject: [PATCH] significant rewrites to mouse clicks --- libs/wl/wayland.c | 49 +++++++++++++++++++++++++++-------------------- libs/x11/mouse.c | 41 +++++++++++++++++++++------------------ 2 files changed, 50 insertions(+), 40 deletions(-) diff --git a/libs/wl/wayland.c b/libs/wl/wayland.c index 9ca79c0..b537beb 100644 --- a/libs/wl/wayland.c +++ b/libs/wl/wayland.c @@ -219,6 +219,7 @@ void buttonpress_wl(uint32_t button, double ex, double ey) { int h = bh; int xpad = 0; int item_num = 0; + int yp = 0; unsigned int i, click; if (ex == 0 && ey == 0) { @@ -243,21 +244,27 @@ void buttonpress_wl(uint32_t button, double ex, double ey) { if (!hidemode) modeWidth = pango_mode ? TEXTWM(modetext) : TEXTW(modetext); if (!hidecaps) capsWidth = pango_caps ? TEXTWM(capstext) : TEXTW(capstext); - if (!strcmp(capstext, "")) + if (!strcmp(capstext, "")) capsWidth = 0; - click = ClickWindow; // Used as a default, will be overriden. + if ((hideprompt && hideinput && hidemode && hidematchcount && hidecaps) && lines) { + yp = 1; + } else if (lines && ey < h + menumarginv && ey > menumarginv) { + yp = 1; + } + + click = ClickWindow; // clicking anywhere, we use this and override it if we clicked on something specific // check click position and override the value of click - if (ex < x + promptw + powerlineprompt ? plw : 0) { // prompt + if (yp && ex < x + promptw + powerlineprompt ? plw : 0) { // prompt click = ClickPrompt; - } else if ((ex > mw - capsWidth - 2 * sp - 2 * borderwidth - menumarginh) && !hidecaps && capsWidth) { // caps lock indicator + } else if (yp && (ex > mw - capsWidth - 2 * sp - 2 * borderwidth - menumarginh) && !hidecaps && capsWidth) { // caps lock indicator click = ClickCaps; - } else if (ex > mw - modeWidth - capsWidth - 2 * sp - 2 * borderwidth - menumarginh) { // mode indicator + } else if (yp && ex > mw - modeWidth - capsWidth - 2 * sp - 2 * borderwidth - menumarginh) { // mode indicator click = ClickMode; - } else if (ex > mw - modeWidth - numberWidth - capsWidth - 2 * sp - 2 * borderwidth - menumarginh) { // match count + } else if (yp && ex > mw - modeWidth - numberWidth - capsWidth - 2 * sp - 2 * borderwidth - menumarginh) { // match count click = ClickNumber; - } else { // input + } else if (yp && !hideinput) { // input w = (lines > 0 || !matches) ? mw - x : inputw; if ((lines <= 0 && ex >= 0 && ex <= x + w + promptw + @@ -268,29 +275,30 @@ void buttonpress_wl(uint32_t button, double ex, double ey) { } } +#if USEIMAGE + if (!hideimage && longestedge != 0) { + x += MAX((imagegaps * 2) + imagewidth, indentitems ? promptw : 0); + } +#endif + // item click if (lines > 0) { - // vertical list w = mw - x; + + ey -= menumarginv; + for (item = curr; item != next; item = item->right) { if (item_num++ == lines) { item_num = 1; - x += w / columns + (powerlineitems ? plw : 0); + x += w / columns; y = 0; } y += h; -#if USEIMAGE - if (!hideimage && longestedge != 0) { - x += MAX((imagegaps * 2) + imagewidth, indentitems ? promptw : 0); - ex += MAX((imagegaps * 2) + imagewidth, indentitems ? promptw : 0); - } -#endif - // ClickSelItem, called function doesn't matter - if (ey >= y && ey <= (y + h) && ex + (powerlineitems ? plw : 0) >= x + (powerlineitems ? plw : 0) && ex + (powerlineitems ? plw : 0) <= (x + w / columns) + (powerlineitems ? plw : 0)) { - for (i = 0; i < LENGTH(wl_buttons); i++) { + if (ey >= y && ey <= (y + h) && ex >= x + (powerlineitems ? plw : 0) && ex <= (x + w / columns) + (powerlineitems ? plw : 0)) { + for (i = 0; i < LENGTH(buttons); i++) { if (ignoreglobalmouse) break; if (wl_buttons[i].click == ClickSelItem && wl_buttons[i].button == button) { puts(item->text); @@ -299,7 +307,7 @@ void buttonpress_wl(uint32_t button, double ex, double ey) { click = ClickItem; } } - for (i = 0; i < LENGTH(wl_cbuttons); i++) { + for (i = 0; i < LENGTH(cbuttons); i++) { if (ignoreconfmouse) break; if (wl_cbuttons[i].click == ClickSelItem && wl_cbuttons[i].button == button) { puts(item->text); @@ -310,7 +318,7 @@ void buttonpress_wl(uint32_t button, double ex, double ey) { } } } - } else if (matches) { + } else if (matches) { // a single line, meaning it could be arrows too, so we check that here x += inputw; w = larrowWidth; @@ -323,7 +331,6 @@ void buttonpress_wl(uint32_t button, double ex, double ey) { // right arrow w = rarrowWidth; x = mw - w; - if (next && ex >= x && ex <= x + w) { click = ClickRArrow; } diff --git a/libs/x11/mouse.c b/libs/x11/mouse.c index ab8263d..b81055f 100644 --- a/libs/x11/mouse.c +++ b/libs/x11/mouse.c @@ -5,11 +5,7 @@ void buttonpress_x11(XEvent *e) { XButtonPressedEvent *ev = &e->xbutton; int x = 0, y = 0, h = bh, w, item_num = 0; unsigned int i, click; - int xpad = 0; - - if (!hidepowerline) { - x = xpad = plw; - } + int yp = 0; // margin x += menumarginh; @@ -29,20 +25,26 @@ void buttonpress_x11(XEvent *e) { if (!strcmp(capstext, "")) capsWidth = 0; + if ((hideprompt && hideinput && hidemode && hidematchcount && hidecaps) && lines) { + yp = 1; + } else if (lines && ev->y < h + menumarginv && ev->y > menumarginv) { + yp = 1; + } + if (ev->window != win) return; // if incorrect or wrong window, return click = ClickWindow; // clicking anywhere, we use this and override it if we clicked on something specific // check click position and override the value of click - if (ev->x < x + promptw + powerlineprompt ? plw : 0) { // prompt + if (yp && ev->x < x + promptw + powerlineprompt ? plw : 0) { // prompt click = ClickPrompt; - } else if ((ev->x > mw - capsWidth - 2 * sp - 2 * borderwidth - menumarginh) && !hidecaps && capsWidth) { // caps lock indicator + } else if (yp && (ev->x > mw - capsWidth - 2 * sp - 2 * borderwidth - menumarginh) && !hidecaps && capsWidth) { // caps lock indicator click = ClickCaps; - } else if (ev->x > mw - modeWidth - capsWidth - 2 * sp - 2 * borderwidth - menumarginh) { // mode indicator + } else if (yp && ev->x > mw - modeWidth - capsWidth - 2 * sp - 2 * borderwidth - menumarginh) { // mode indicator click = ClickMode; - } else if (ev->x > mw - modeWidth - numberWidth - capsWidth - 2 * sp - 2 * borderwidth - menumarginh) { // match count + } else if (yp && ev->x > mw - modeWidth - numberWidth - capsWidth - 2 * sp - 2 * borderwidth - menumarginh) { // match count click = ClickNumber; - } else { // input + } else if (yp && !hideinput) { // input w = (lines > 0 || !matches) ? mw - x : inputw; if ((lines <= 0 && ev->x >= 0 && ev->x <= x + w + promptw + @@ -53,10 +55,18 @@ void buttonpress_x11(XEvent *e) { } } +#if USEIMAGE + if (!hideimage && longestedge != 0) { + x += MAX((imagegaps * 2) + imagewidth, indentitems ? promptw : 0); + } +#endif + // item click if (lines > 0) { - // vertical list w = mw - x; + + ev->y -= menumarginv; + for (item = curr; item != next; item = item->right) { if (item_num++ == lines) { item_num = 1; @@ -66,15 +76,8 @@ void buttonpress_x11(XEvent *e) { y += h; -#if USEIMAGE - if (!hideimage && longestedge != 0) { - x += MAX((imagegaps * 2) + imagewidth, indentitems ? promptw : 0); - ev->x += MAX((imagegaps * 2) + imagewidth, indentitems ? promptw : 0); - } -#endif - // ClickSelItem, called function doesn't matter - if (ev->y >= y && ev->y <= (y + h) && ev->x + (powerlineitems ? plw : 0) >= x + (powerlineitems ? plw : 0) && ev->x + (powerlineitems ? plw : 0) <= (x + w / columns) + (powerlineitems ? plw : 0)) { + if (ev->y >= y && ev->y <= (y + h) && ev->x >= x + (powerlineitems ? plw : 0) && ev->x <= (x + w / columns) + (powerlineitems ? plw : 0)) { for (i = 0; i < LENGTH(buttons); i++) { if (ignoreglobalmouse) break; if (buttons[i].click == ClickSelItem && buttons[i].button == ev->button) {