diff --git a/docs/docs.md b/docs/docs.md index 706f876..ae1b0f4 100644 --- a/docs/docs.md +++ b/docs/docs.md @@ -849,9 +849,7 @@ spmenu supports mouse clicks. The following parts can be clicked on: - `ClickRArrow` - Clicking on the right arrow - `ClickItem` - - Clicking on the item area -- `ClickSelItem` - - Clicking on an item, function here doesn't matter, it will always be selected + - Clicking on an item - `ClickImage` - Clicking on an image - `ClickNumber` @@ -883,7 +881,7 @@ These are the default mouse binds. Mode does not apply for mouse binds. | ClickPrompt | Left Click | clear | 0 | | ClickMode | Left Click | switchmode | 0 | | ClickNumber | Left Click | viewhist | 0 | -| ClickSelItem | Left Click | Outputs the item | 0 | +| ClickItem | Left Click | selecthover | 0 | | None | Scroll Up | moveprev | 0 | | None | Scroll Down | movenext | 0 | @@ -1021,6 +1019,8 @@ bind: - Open profile menu if available - `switchmode` - Switch between Normal mode and Insert mode +- `selecthover` + - Output the item clicked on - `screenshot` - Take a screenshot of spmenu diff --git a/libs/arg.c b/libs/arg.c index 52691cc..3b424ff 100644 --- a/libs/arg.c +++ b/libs/arg.c @@ -606,6 +606,11 @@ void switchmode(Arg *arg) { drawmenu(); } +void selecthover(Arg *arg) { + puts(items[sp.clickitemindex].text); + exit(0); +} + void screenshot(Arg *arg) { char *file = NULL; char *home = NULL; diff --git a/libs/arg.h b/libs/arg.h index 5d73d39..1e27f85 100644 --- a/libs/arg.h +++ b/libs/arg.h @@ -73,3 +73,6 @@ static void togglemode(Arg *arg); static void togglehighlight(Arg *arg); static void toggleregex(Arg *arg); static void toggleimg(Arg *arg); + +/* hover */ +static void selecthover(Arg *arg); diff --git a/libs/conf/config.h b/libs/conf/config.h index 68053fc..1b86fe0 100644 --- a/libs/conf/config.h +++ b/libs/conf/config.h @@ -394,6 +394,7 @@ static FuncList fl[] = { { "setprofile", setprofile }, { "setlineheight", setlineheight }, { "switchmode", switchmode }, + { "selecthover", selecthover }, { "spawn", spawn }, }; @@ -687,7 +688,6 @@ static ClickType ctp[] = { { "ClickInput", ClickInput }, { "ClickLArrow", ClickLArrow }, { "ClickItem", ClickItem }, - { "ClickSelItem", ClickSelItem }, { "ClickRArrow", ClickRArrow }, { "ClickNumber", ClickNumber }, { "ClickCaps", ClickCaps }, diff --git a/libs/mouse.h b/libs/mouse.h index 6eca6a7..ba2e80b 100644 --- a/libs/mouse.h +++ b/libs/mouse.h @@ -9,7 +9,7 @@ static Mouse buttons[] = { { ClickPrompt, Button1, clear, {0} }, { ClickMode, Button1, switchmode, {0} }, { ClickNumber, Button1, viewhist, {0} }, - { ClickSelItem, Button1, NULL, {0} }, + { ClickItem, Button1, selecthover, {0} }, { ClickNone, Button5, movenext, {0} }, { ClickNone, Button4, moveprev, {0} }, }; @@ -22,7 +22,7 @@ static WlMouse wl_buttons[] = { { ClickPrompt, WL_Left, clear, {0} }, { ClickMode, WL_Left, switchmode, {0} }, { ClickNumber, WL_Left, viewhist, {0} }, - { ClickSelItem, WL_Left, NULL, {0} }, + { ClickItem, WL_Left, selecthover, {0} }, { ClickNone, WL_Down, movenext, {0} }, { ClickNone, WL_Up, moveprev, {0} }, }; diff --git a/libs/wl/wayland.c b/libs/wl/wayland.c index a2d672c..5a5a55e 100644 --- a/libs/wl/wayland.c +++ b/libs/wl/wayland.c @@ -289,6 +289,8 @@ 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; @@ -298,31 +300,16 @@ void buttonpress_wl(uint32_t button, double ex, double ey) { y += h; - // ClickSelItem, called function doesn't matter if (ey >= y && ey <= (y + h) && ex >= x + (powerlineitems ? sp.plw : 0) && ex <= (x + w / columns) + (powerlineitems ? sp.plw : 0)) { - for (i = 0; i < LENGTH(wl_buttons); i++) { - if (sp.ignoreglobalmouse) break; - if (wl_buttons[i].click == ClickSelItem && wl_buttons[i].button == button) { - puts(item->text); - exit(0); - } else if (wl_buttons[i].click == ClickItem) { - click = ClickItem; - } - } - for (i = 0; i < LENGTH(wl_cbuttons); i++) { - if (sp.ignoreconfmouse) break; - if (wl_cbuttons[i].click == ClickSelItem && wl_cbuttons[i].button == button) { - puts(item->text); - exit(0); - } else if (wl_cbuttons[i].click == ClickItem) { - click = ClickItem; - } - } + sp.clickitemindex = i; + click = ClickItem; #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; #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 346afe9..c58325b 100644 --- a/libs/x11/mouse.c +++ b/libs/x11/mouse.c @@ -73,6 +73,8 @@ 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; @@ -84,29 +86,15 @@ 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)) { - for (i = 0; i < LENGTH(buttons); i++) { - if (sp.ignoreglobalmouse) break; - if (buttons[i].click == ClickSelItem && buttons[i].button == ev->button) { - puts(item->text); - exit(0); - } else if (buttons[i].click == ClickItem) { - click = ClickItem; - } - } - for (i = 0; i < LENGTH(cbuttons); i++) { - if (sp.ignoreconfmouse) break; - if (cbuttons[i].click == ClickSelItem && cbuttons[i].button == ev->button) { - puts(item->text); - exit(0); - } else if (cbuttons[i].click == ClickItem) { - click = ClickItem; - } - } + click = ClickItem; + sp.clickitemindex = i; #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; #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.1 b/spmenu.1 index 0967914..ba7d39a 100644 --- a/spmenu.1 +++ b/spmenu.1 @@ -1407,14 +1407,7 @@ Clicking on the right arrow \f[V]ClickItem\f[R] .RS 2 .IP \[bu] 2 -Clicking on the item area -.RE -.IP \[bu] 2 -\f[V]ClickSelItem\f[R] -.RS 2 -.IP \[bu] 2 -Clicking on an item, function here doesn\[cq]t matter, it will always be -selected +Clicking on an item .RE .IP \[bu] 2 \f[V]ClickImage\f[R] @@ -1512,11 +1505,11 @@ T}@T{ 0 T} T{ -ClickSelItem +ClickItem T}@T{ Left Click T}@T{ -Outputs the item +selecthover T}@T{ 0 T} @@ -1844,6 +1837,12 @@ Set lines to passed argument Set columns to passed argument .RE .IP \[bu] 2 +\f[V]setlineheight\f[R] +.RS 2 +.IP \[bu] 2 +Set line height to passed argument +.RE +.IP \[bu] 2 \f[V]setprofile\f[R] .RS 2 .IP \[bu] 2 @@ -1856,6 +1855,12 @@ Open profile menu if available Switch between Normal mode and Insert mode .RE .IP \[bu] 2 +\f[V]selecthover\f[R] +.RS 2 +.IP \[bu] 2 +Output the item clicked on +.RE +.IP \[bu] 2 \f[V]screenshot\f[R] .RS 2 .IP \[bu] 2 diff --git a/spmenu.c b/spmenu.c index 3f3bebf..b0cd62c 100644 --- a/spmenu.c +++ b/spmenu.c @@ -101,7 +101,6 @@ enum { // click enum ClickInput, ClickLArrow, ClickItem, - ClickSelItem, ClickRArrow, ClickNumber, ClickCaps, @@ -141,6 +140,8 @@ 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