Improve selecthover() function, add markhover() function

This commit is contained in:
speedie 2023-07-25 00:19:58 +02:00
parent 92ce25077a
commit 0ec1c73053
5 changed files with 61 additions and 1 deletions

View file

@ -1061,6 +1061,8 @@ bind:
- Switch between Normal mode and Insert mode - Switch between Normal mode and Insert mode
- `selecthover` - `selecthover`
- Output the item clicked on - Output the item clicked on
- `markhover`
- Mark the item clicked on
- `screenshot` - `screenshot`
- Take a screenshot of spmenu - Take a screenshot of spmenu

View file

@ -619,11 +619,61 @@ void switchmode(Arg *arg) {
drawmenu(); drawmenu();
} }
/* This function is basically a copy of the selectitem function.
* The only difference is "selectitem" was replaced with "mouseitem" and tx.text output
* was removed.
*/
void selecthover(Arg *arg) { void selecthover(Arg *arg) {
puts(mouseitem->text); char *selection;
if (printindex && mouseitem && arg->i) {
fprintf(stdout, "%d\n", mouseitem->index);
cleanup();
exit(0); exit(0);
} }
selection = mouseitem->text;
for (int i = 0; i < sel_size; i++) {
if (sel_index[i] != -1 && (!mouseitem || mouseitem->index != sel_index[i])) {
puts(items[sel_index[i]].text);
}
}
if (!selection)
return;
puts(selection);
savehistory(selection);
cleanup();
exit(0);
}
void markhover(Arg *arg) {
if (!mark) return;
if (mouseitem && is_selected(mouseitem->index)) {
for (int i = 0; i < sel_size; i++) {
if (sel_index[i] == mouseitem->index) {
sel_index[i] = -1;
}
}
} else {
for (int i = 0; i < sel_size; i++) {
if (sel_index[i] == -1) {
sel_index[i] = mouseitem->index;
return;
}
}
sel_size++;
sel_index = realloc(sel_index, (sel_size + 1) * sizeof(int));
sel_index[sel_size - 1] = mouseitem->index;
}
drawmenu();
}
void screenshot(Arg *arg) { void screenshot(Arg *arg) {
char *file = NULL; char *file = NULL;
char *home = NULL; char *home = NULL;

View file

@ -77,3 +77,4 @@ static void toggleimg(Arg *arg);
/* hover */ /* hover */
static void selecthover(Arg *arg); static void selecthover(Arg *arg);
static void markhover(Arg *arg);

View file

@ -396,6 +396,7 @@ static FuncList fl[] = {
{ "setlineheight", setlineheight }, { "setlineheight", setlineheight },
{ "switchmode", switchmode }, { "switchmode", switchmode },
{ "selecthover", selecthover }, { "selecthover", selecthover },
{ "markhover", markhover },
{ "spawn", spawn }, { "spawn", spawn },
}; };

View file

@ -1975,6 +1975,12 @@ Switch between Normal mode and Insert mode
Output the item clicked on Output the item clicked on
.RE .RE
.IP \[bu] 2 .IP \[bu] 2
\f[V]markhover\f[R]
.RS 2
.IP \[bu] 2
Mark 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