Remove ClickSelItem

This commit removes ClickSelItem. It doesn't make very much sense to
keep a separate click for the click and output functionality.
This commit is contained in:
Jacob 2023-07-19 17:50:50 +02:00
parent 4bd225b32f
commit 4e716ee80c
9 changed files with 44 additions and 55 deletions

View file

@ -849,9 +849,7 @@ spmenu supports mouse clicks. The following parts can be clicked on:
- `ClickRArrow` - `ClickRArrow`
- Clicking on the right arrow - Clicking on the right arrow
- `ClickItem` - `ClickItem`
- Clicking on the item area - Clicking on an item
- `ClickSelItem`
- Clicking on an item, function here doesn't matter, it will always be selected
- `ClickImage` - `ClickImage`
- Clicking on an image - Clicking on an image
- `ClickNumber` - `ClickNumber`
@ -883,7 +881,7 @@ These are the default mouse binds. Mode does not apply for mouse binds.
| ClickPrompt | Left Click | clear | 0 | | ClickPrompt | Left Click | clear | 0 |
| ClickMode | Left Click | switchmode | 0 | | ClickMode | Left Click | switchmode | 0 |
| ClickNumber | Left Click | viewhist | 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 Up | moveprev | 0 |
| None | Scroll Down | movenext | 0 | | None | Scroll Down | movenext | 0 |
@ -1021,6 +1019,8 @@ bind:
- Open profile menu if available - Open profile menu if available
- `switchmode` - `switchmode`
- Switch between Normal mode and Insert mode - Switch between Normal mode and Insert mode
- `selecthover`
- Output the item clicked on
- `screenshot` - `screenshot`
- Take a screenshot of spmenu - Take a screenshot of spmenu

View file

@ -606,6 +606,11 @@ void switchmode(Arg *arg) {
drawmenu(); drawmenu();
} }
void selecthover(Arg *arg) {
puts(items[sp.clickitemindex].text);
exit(0);
}
void screenshot(Arg *arg) { void screenshot(Arg *arg) {
char *file = NULL; char *file = NULL;
char *home = NULL; char *home = NULL;

View file

@ -73,3 +73,6 @@ static void togglemode(Arg *arg);
static void togglehighlight(Arg *arg); static void togglehighlight(Arg *arg);
static void toggleregex(Arg *arg); static void toggleregex(Arg *arg);
static void toggleimg(Arg *arg); static void toggleimg(Arg *arg);
/* hover */
static void selecthover(Arg *arg);

View file

@ -394,6 +394,7 @@ static FuncList fl[] = {
{ "setprofile", setprofile }, { "setprofile", setprofile },
{ "setlineheight", setlineheight }, { "setlineheight", setlineheight },
{ "switchmode", switchmode }, { "switchmode", switchmode },
{ "selecthover", selecthover },
{ "spawn", spawn }, { "spawn", spawn },
}; };
@ -687,7 +688,6 @@ static ClickType ctp[] = {
{ "ClickInput", ClickInput }, { "ClickInput", ClickInput },
{ "ClickLArrow", ClickLArrow }, { "ClickLArrow", ClickLArrow },
{ "ClickItem", ClickItem }, { "ClickItem", ClickItem },
{ "ClickSelItem", ClickSelItem },
{ "ClickRArrow", ClickRArrow }, { "ClickRArrow", ClickRArrow },
{ "ClickNumber", ClickNumber }, { "ClickNumber", ClickNumber },
{ "ClickCaps", ClickCaps }, { "ClickCaps", ClickCaps },

View file

@ -9,7 +9,7 @@ static Mouse buttons[] = {
{ ClickPrompt, Button1, clear, {0} }, { ClickPrompt, Button1, clear, {0} },
{ ClickMode, Button1, switchmode, {0} }, { ClickMode, Button1, switchmode, {0} },
{ ClickNumber, Button1, viewhist, {0} }, { ClickNumber, Button1, viewhist, {0} },
{ ClickSelItem, Button1, NULL, {0} }, { ClickItem, Button1, selecthover, {0} },
{ ClickNone, Button5, movenext, {0} }, { ClickNone, Button5, movenext, {0} },
{ ClickNone, Button4, moveprev, {0} }, { ClickNone, Button4, moveprev, {0} },
}; };
@ -22,7 +22,7 @@ static WlMouse wl_buttons[] = {
{ ClickPrompt, WL_Left, clear, {0} }, { ClickPrompt, WL_Left, clear, {0} },
{ ClickMode, WL_Left, switchmode, {0} }, { ClickMode, WL_Left, switchmode, {0} },
{ ClickNumber, WL_Left, viewhist, {0} }, { ClickNumber, WL_Left, viewhist, {0} },
{ ClickSelItem, WL_Left, NULL, {0} }, { ClickItem, WL_Left, selecthover, {0} },
{ ClickNone, WL_Down, movenext, {0} }, { ClickNone, WL_Down, movenext, {0} },
{ ClickNone, WL_Up, moveprev, {0} }, { ClickNone, WL_Up, moveprev, {0} },
}; };

View file

@ -289,6 +289,8 @@ void buttonpress_wl(uint32_t button, double ex, double ey) {
ey += h; ey += h;
} }
i = 0;
for (item = currentitem; item != nextitem; item = item->right) { for (item = currentitem; item != nextitem; item = item->right) {
if (item_num++ == lines) { if (item_num++ == lines) {
item_num = 1; item_num = 1;
@ -298,31 +300,16 @@ void buttonpress_wl(uint32_t button, double ex, double ey) {
y += h; 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)) { 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++) { sp.clickitemindex = i;
if (sp.ignoreglobalmouse) break; click = ClickItem;
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;
}
}
#if USEIMAGE #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)) { } 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; click = ClickImage;
#endif #endif
} }
i++;
} }
} else if (matches) { // a single line, meaning it could be arrows too, so we check that here } else if (matches) { // a single line, meaning it could be arrows too, so we check that here
x += sp.inputw; x += sp.inputw;

View file

@ -73,6 +73,8 @@ void buttonpress_x11(XEvent *e) {
ev->y += h; ev->y += h;
} }
i = 0;
for (item = currentitem; item != nextitem; item = item->right) { for (item = currentitem; item != nextitem; item = item->right) {
if (item_num++ == lines) { if (item_num++ == lines) {
item_num = 1; item_num = 1;
@ -84,29 +86,15 @@ void buttonpress_x11(XEvent *e) {
// ClickSelItem, called function doesn't matter // 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)) { 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++) { click = ClickItem;
if (sp.ignoreglobalmouse) break; sp.clickitemindex = i;
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;
}
}
#if USEIMAGE #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)) { } 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; click = ClickImage;
#endif #endif
} }
i++;
} }
} else if (matches) { // a single line, meaning it could be arrows too, so we check that here } else if (matches) { // a single line, meaning it could be arrows too, so we check that here
x += sp.inputw; x += sp.inputw;

View file

@ -1407,14 +1407,7 @@ Clicking on the right arrow
\f[V]ClickItem\f[R] \f[V]ClickItem\f[R]
.RS 2 .RS 2
.IP \[bu] 2 .IP \[bu] 2
Clicking on the item area Clicking on an item
.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
.RE .RE
.IP \[bu] 2 .IP \[bu] 2
\f[V]ClickImage\f[R] \f[V]ClickImage\f[R]
@ -1512,11 +1505,11 @@ T}@T{
0 0
T} T}
T{ T{
ClickSelItem ClickItem
T}@T{ T}@T{
Left Click Left Click
T}@T{ T}@T{
Outputs the item selecthover
T}@T{ T}@T{
0 0
T} T}
@ -1844,6 +1837,12 @@ Set lines to passed argument
Set columns to passed argument Set columns to passed argument
.RE .RE
.IP \[bu] 2 .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] \f[V]setprofile\f[R]
.RS 2 .RS 2
.IP \[bu] 2 .IP \[bu] 2
@ -1856,6 +1855,12 @@ Open profile menu if available
Switch between Normal mode and Insert mode Switch between Normal mode and Insert mode
.RE .RE
.IP \[bu] 2 .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] \f[V]screenshot\f[R]
.RS 2 .RS 2
.IP \[bu] 2 .IP \[bu] 2

View file

@ -101,7 +101,6 @@ enum { // click enum
ClickInput, ClickInput,
ClickLArrow, ClickLArrow,
ClickItem, ClickItem,
ClickSelItem,
ClickRArrow, ClickRArrow,
ClickNumber, ClickNumber,
ClickCaps, ClickCaps,
@ -141,6 +140,8 @@ struct sp {
int listcount; int listcount;
int listchanged; int listchanged;
int clickitemindex;
size_t cursor; // cursor width size_t cursor; // cursor width
int ignoreconfkeys; // can be set globally if you don't want to override keybinds with config file keys int ignoreconfkeys; // can be set globally if you don't want to override keybinds with config file keys