diff --git a/docs/docs.md b/docs/docs.md index 84e2287..06db61b 100644 --- a/docs/docs.md +++ b/docs/docs.md @@ -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 diff --git a/libs/arg.c b/libs/arg.c index e250441..40d82e2 100644 --- a/libs/arg.c +++ b/libs/arg.c @@ -619,11 +619,61 @@ 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) { char *file = NULL; char *home = NULL; diff --git a/libs/arg.h b/libs/arg.h index bc91c08..d8aa919 100644 --- a/libs/arg.h +++ b/libs/arg.h @@ -77,3 +77,4 @@ static void toggleimg(Arg *arg); /* hover */ static void selecthover(Arg *arg); +static void markhover(Arg *arg); diff --git a/libs/conf/config.h b/libs/conf/config.h index c8173a8..3181acf 100644 --- a/libs/conf/config.h +++ b/libs/conf/config.h @@ -396,6 +396,7 @@ static FuncList fl[] = { { "setlineheight", setlineheight }, { "switchmode", switchmode }, { "selecthover", selecthover }, + { "markhover", markhover }, { "spawn", spawn }, }; diff --git a/spmenu.1 b/spmenu.1 index 9d77c7b..3633e05 100644 --- a/spmenu.1 +++ b/spmenu.1 @@ -1975,6 +1975,12 @@ Switch between Normal mode and Insert mode Output the item clicked on .RE .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] .RS 2 .IP \[bu] 2