From f3064e0feeb06564b33c99130dbc41ef619f9766 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Sun, 24 Jul 2022 01:08:24 +0200 Subject: [PATCH] [Script] Add new-selection option. Allow you to select an entry (based on view, so might not work in combi mode). fixes: #1248 --- Examples/test_script_mode_color.sh | 1 + source/modes/script.c | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Examples/test_script_mode_color.sh b/Examples/test_script_mode_color.sh index 741a840b..79b5ed15 100755 --- a/Examples/test_script_mode_color.sh +++ b/Examples/test_script_mode_color.sh @@ -10,6 +10,7 @@ then # Override the previously set prompt. echo -en "\0theme\x1felement-text { background-color: "$@";}\n" echo -en "\0keep-selection\x1ftrue\n" + echo -en "\0new-selection\x1f2\n" echo "red" echo "lightgreen" echo "lightblue" diff --git a/source/modes/script.c b/source/modes/script.c index 25d8e852..3bce1a1d 100644 --- a/source/modes/script.c +++ b/source/modes/script.c @@ -68,6 +68,7 @@ typedef struct { char *data; gboolean do_markup; gboolean keep_selection; + int64_t new_selection; char delim; /** no custom */ gboolean no_custom; @@ -138,6 +139,8 @@ static void parse_header_entry(Mode *sw, char *line, ssize_t length) { pd->use_hot_keys = (strcasecmp(value, "true") == 0); } else if (strcasecmp(line, "keep-selection") == 0) { pd->keep_selection = (strcasecmp(value, "true") == 0); + } else if (strcasecmp(line, "new-selection") == 0) { + pd->new_selection = (int64_t)g_ascii_strtoll(value, NULL, 0); } else if (strcasecmp(line, "data") == 0) { g_free(pd->data); pd->data = g_strdup(value); @@ -160,7 +163,9 @@ static DmenuScriptEntry *execute_executor(Mode *sw, char *arg, char **argv = NULL; int argc = 0; *length = 0; - + // Reset these between runs. + pd->new_selection = -1; + pd->keep_selection = -1; // Environment char **env = g_get_environ(); @@ -343,6 +348,11 @@ static ModeMode script_mode_result(Mode *sw, int mretv, char **input, rmpd->cmd_list = new_list; rmpd->cmd_list_length = new_length; if (rmpd->keep_selection) { + if (rmpd->new_selection >= 0 && + rmpd->new_selection < rmpd->cmd_list_length) { + rofi_view_set_selected_line(rofi_view_get_active(), + rmpd->new_selection); + } retv = RELOAD_DIALOG; } else { retv = RESET_DIALOG;