diff options
author | Phil Jones <philj56@gmail.com> | 2023-04-09 18:26:52 +0100 |
---|---|---|
committer | Phil Jones <philj56@gmail.com> | 2023-04-09 18:26:52 +0100 |
commit | cfab8efa406c7ff1063cb6ef89cb41028d0e826e (patch) | |
tree | 35f5931295bcd430189002fc68abf1acdc03bf9c | |
parent | 0fe8548a6534a80aa81c288629799a752f0060c2 (diff) |
Add --auto-accept-single option.
-rw-r--r-- | completions/tofi | 1 | ||||
-rw-r--r-- | doc/config | 5 | ||||
-rw-r--r-- | doc/tofi.5.md | 8 | ||||
-rw-r--r-- | doc/tofi.5.scd | 7 | ||||
-rw-r--r-- | src/config.c | 5 | ||||
-rw-r--r-- | src/input.c | 4 | ||||
-rw-r--r-- | src/main.c | 9 | ||||
-rw-r--r-- | src/tofi.h | 1 |
8 files changed, 39 insertions, 1 deletions
diff --git a/completions/tofi b/completions/tofi index d0025f4..3983090 100644 --- a/completions/tofi +++ b/completions/tofi @@ -78,6 +78,7 @@ _tofi() --history-file --fuzzy-match --require-match + --auto-accept-single --hide-input --hidden-character --drun-launch @@ -257,6 +257,11 @@ # In drun mode, this is always true. require-match = true + # If true, automatically accept a result if it is the only one + # remaining. If there's only one result on startup, window creation is + # skipped altogether. + auto-accept-single = false + # If true, typed input will be hidden, and what is displayed (if # anything) is determined by the hidden-character option. hide-input = false diff --git a/doc/tofi.5.md b/doc/tofi.5.md index e4aaf7b..e976ef7 100644 --- a/doc/tofi.5.md +++ b/doc/tofi.5.md @@ -89,6 +89,14 @@ options. > > Default: true +**auto-accept-single**=*true\|false* + +> If true, automatically accept a result if it is the only one +> remaining. If there's only one result on startup, window creation is +> skipped altogether. +> +> Default: false + **hide-input**=*true\|false* > If true, typed input will be hidden, and what is displayed (if diff --git a/doc/tofi.5.scd b/doc/tofi.5.scd index 6e97ae3..29547e0 100644 --- a/doc/tofi.5.scd +++ b/doc/tofi.5.scd @@ -76,6 +76,13 @@ options. Default: true +*auto-accept-single*=_true|false_ + If true, automatically accept a result if it is the only one remaining. + If there's only one result on startup, window creation is skipped + altogether. + + Default: false + *hide-input*=_true|false_ If true, typed input will be hidden, and what is displayed (if anything) is determined by the *hidden-character* option. diff --git a/src/config.c b/src/config.c index d831267..b78e3af 100644 --- a/src/config.c +++ b/src/config.c @@ -693,6 +693,11 @@ bool parse_option(struct tofi *tofi, const char *filename, size_t lineno, const if (!err) { tofi->require_match = val; } + } else if (strcasecmp(option, "auto-accept-single") == 0) { + bool val = parse_bool(filename, lineno, value, &err); + if (!err) { + tofi->auto_accept_single = val; + } } else if (strcasecmp(option, "hide-input") == 0) { bool val = parse_bool(filename, lineno, value, &err); if (!err) { diff --git a/src/input.c b/src/input.c index 0ccdead..1049fa9 100644 --- a/src/input.c +++ b/src/input.c @@ -110,6 +110,10 @@ void input_handle_keypress(struct tofi *tofi, xkb_keycode_t keycode) return; } + if (tofi->auto_accept_single && tofi->window.entry.results.count == 1) { + tofi->submit = true; + } + tofi->window.surface.redraw = true; } @@ -913,6 +913,7 @@ const struct option long_options[] = { {"history-file", required_argument, NULL, 0}, {"fuzzy-match", required_argument, NULL, 0}, {"require-match", required_argument, NULL, 0}, + {"auto-accept-single", required_argument, NULL, 0}, {"hide-input", required_argument, NULL, 0}, {"hidden-character", required_argument, NULL, 0}, {"drun-launch", required_argument, NULL, 0}, @@ -1198,7 +1199,7 @@ int main(int argc, char *argv[]) } parse_args(&tofi, argc, argv); - log_debug("Config done\n"); + log_debug("Config done.\n"); if (!tofi.multiple_instance && lock_check()) { log_error("Another instance of tofi is already running.\n"); @@ -1498,6 +1499,12 @@ int main(int argc, char *argv[]) } tofi.window.entry.results = string_ref_vec_copy(&tofi.window.entry.commands); + if (tofi.auto_accept_single && tofi.window.entry.results.count == 1) { + log_debug("Only one result, exiting.\n"); + do_submit(&tofi); + return EXIT_SUCCESS; + } + /* * Next, we create the Wayland surface, which takes on the * layer shell role. @@ -99,6 +99,7 @@ struct tofi { bool drun_print_exec; bool fuzzy_match; bool require_match; + bool auto_accept_single; bool multiple_instance; char target_output_name[MAX_OUTPUT_NAME_LEN]; char default_terminal[MAX_TERMINAL_NAME_LEN]; |