diff options
Diffstat (limited to 'src')
-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 |
4 files changed, 18 insertions, 1 deletions
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]; |