forked from speedie/spmenu
Improve selecthover() function, add markhover() function
This commit is contained in:
parent
92ce25077a
commit
0ec1c73053
|
@ -1061,6 +1061,8 @@ bind:
|
|||
- Switch between Normal mode and Insert mode
|
||||
- `selecthover`
|
||||
- Output the item clicked on
|
||||
- `markhover`
|
||||
- Mark the item clicked on
|
||||
- `screenshot`
|
||||
- Take a screenshot of spmenu
|
||||
|
||||
|
|
52
libs/arg.c
52
libs/arg.c
|
@ -619,9 +619,59 @@ void switchmode(Arg *arg) {
|
|||
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) {
|
||||
puts(mouseitem->text);
|
||||
char *selection;
|
||||
|
||||
if (printindex && mouseitem && arg->i) {
|
||||
fprintf(stdout, "%d\n", mouseitem->index);
|
||||
cleanup();
|
||||
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) {
|
||||
|
|
|
@ -77,3 +77,4 @@ static void toggleimg(Arg *arg);
|
|||
|
||||
/* hover */
|
||||
static void selecthover(Arg *arg);
|
||||
static void markhover(Arg *arg);
|
||||
|
|
|
@ -396,6 +396,7 @@ static FuncList fl[] = {
|
|||
{ "setlineheight", setlineheight },
|
||||
{ "switchmode", switchmode },
|
||||
{ "selecthover", selecthover },
|
||||
{ "markhover", markhover },
|
||||
{ "spawn", spawn },
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue