summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Davenport <qball@blame.services>2022-07-09 14:12:28 +0200
committerDave Davenport <qball@blame.services>2022-07-09 14:12:28 +0200
commitdaf3127d3a79602112fca747ad71ca06fb8a6f05 (patch)
tree43b026a1c2745293e80dac1160b68ba552cf0a85
parent96027decd9100d72d5aeac10682cb45e9c74005e (diff)
[Script] Add keep-selection flag that keeps the current selection.
Fixes: #1064
-rwxr-xr-xExamples/test_script_mode_color.sh6
-rw-r--r--doc/rofi-script.52
-rw-r--r--doc/rofi-script.5.markdown1
-rw-r--r--source/modes/script.c9
4 files changed, 17 insertions, 1 deletions
diff --git a/Examples/test_script_mode_color.sh b/Examples/test_script_mode_color.sh
index 4b0b19db..741a840b 100755
--- a/Examples/test_script_mode_color.sh
+++ b/Examples/test_script_mode_color.sh
@@ -9,6 +9,7 @@ if [ "$@" ]
then
# Override the previously set prompt.
echo -en "\0theme\x1felement-text { background-color: "$@";}\n"
+ echo -en "\0keep-selection\x1ftrue\n"
echo "red"
echo "lightgreen"
echo "lightblue"
@@ -18,11 +19,16 @@ else
echo -en "\x00prompt\x1ftesting\n"
echo -en "\0urgent\x1f0,2\n"
echo -en "\0active\x1f1\n"
+ echo -en "\0keep-selection\x1ftrue\n"
echo -en "\0message\x1fSpecial <b>bold</b>message\n"
echo "red"
echo "lightgreen"
echo "lightblue"
echo "lightyellow"
+ echo "pink"
+ echo "green"
+ echo "blue"
+ echo "gold"
echo "quit"
fi
diff --git a/doc/rofi-script.5 b/doc/rofi-script.5
index fc1daa13..689f4155 100644
--- a/doc/rofi-script.5
+++ b/doc/rofi-script.5
@@ -124,6 +124,8 @@ The following extra options exists:
.IP \(bu 2
\fBuse-hot-keys\fP: If set to true, it enabled the Custom keybindings for script. Warning this breaks the normal rofi flow.
.IP \(bu 2
+\fBkeep-selection\fP: If set, the selection is not moved to the first entry, but the current position is maintained.
+.IP \(bu 2
\fBdata\fP: Passed data to the next execution of the script via \fBROFI_DATA\fP\&.
.IP \(bu 2
\fBtheme\fP: Small theme snippet to f.e. change the background color of a widget.
diff --git a/doc/rofi-script.5.markdown b/doc/rofi-script.5.markdown
index 55d16731..805886d0 100644
--- a/doc/rofi-script.5.markdown
+++ b/doc/rofi-script.5.markdown
@@ -88,6 +88,7 @@ The following extra options exists:
* **delim**: Set the delimiter for for next rows. Default is '\n' and this option should finish with this. Only call this on first call of script, it is remembered for consecutive calls.
* **no-custom**: If set to 'true'; only accept listed entries, ignore custom input.
* **use-hot-keys**: If set to true, it enabled the Custom keybindings for script. Warning this breaks the normal rofi flow.
+ * **keep-selection**: If set, the selection is not moved to the first entry, but the current position is maintained.
* **data**: Passed data to the next execution of the script via **ROFI_DATA**.
* **theme**: Small theme snippet to f.e. change the background color of a widget.
diff --git a/source/modes/script.c b/source/modes/script.c
index 462e86f3..c67ed263 100644
--- a/source/modes/script.c
+++ b/source/modes/script.c
@@ -67,6 +67,7 @@ typedef struct {
char *prompt;
char *data;
gboolean do_markup;
+ gboolean keep_selection;
char delim;
/** no custom */
gboolean no_custom;
@@ -135,6 +136,8 @@ static void parse_header_entry(Mode *sw, char *line, ssize_t length) {
pd->no_custom = (strcasecmp(value, "true") == 0);
} else if (strcasecmp(line, "use-hot-keys") == 0) {
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, "data") == 0) {
g_free(pd->data);
pd->data = g_strdup(value);
@@ -339,7 +342,11 @@ static ModeMode script_mode_result(Mode *sw, int mretv, char **input,
rmpd->cmd_list = new_list;
rmpd->cmd_list_length = new_length;
- retv = RESET_DIALOG;
+ if (rmpd->keep_selection) {
+ retv = RELOAD_DIALOG;
+ } else {
+ retv = RESET_DIALOG;
+ }
}
return retv;
}