From faf685ca266d9cd3e2bb42d2ef105a5577cfcaf1 Mon Sep 17 00:00:00 2001 From: Phil Jones Date: Sun, 21 Aug 2022 20:58:10 +0100 Subject: Add --require-match option. --- src/config.c | 2 ++ src/main.c | 22 ++++++++++++++++++---- src/tofi.h | 1 + 3 files changed, 21 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/config.c b/src/config.c index 3cbb18b..5dff7f2 100644 --- a/src/config.c +++ b/src/config.c @@ -324,6 +324,8 @@ bool parse_option(struct tofi *tofi, const char *filename, size_t lineno, const tofi->use_history = parse_bool(filename, lineno, value, &err); } else if (strcasecmp(option, "fuzzy-match") == 0) { tofi->fuzzy_match = parse_bool(filename, lineno, value, &err); + } else if (strcasecmp(option, "require-match") == 0) { + tofi->require_match = parse_bool(filename, lineno, value, &err); } else if (strcasecmp(option, "drun-launch") == 0) { tofi->drun_launch = parse_bool(filename, lineno, value, &err); } else if (strcasecmp(option, "drun-print-exec") == 0) { diff --git a/src/main.c b/src/main.c index 9f244af..62a4e81 100644 --- a/src/main.c +++ b/src/main.c @@ -811,6 +811,7 @@ static void usage() " --horizontal List results horizontally.\n" " --history Sort results by number of usages.\n" " --fuzzy-match Use fuzzy matching for searching.\n" +" --require-match Require a match for selection.\n" " --drun-launch Launch apps directly in drun mode.\n" " --drun-print-exec Print a command line in drun mode.\n" " This is now always the case,\n" @@ -858,6 +859,7 @@ const struct option long_options[] = { {"hide-cursor", required_argument, NULL, 0}, {"history", required_argument, NULL, 0}, {"fuzzy-match", required_argument, NULL, 0}, + {"require-match", required_argument, NULL, 0}, {"drun-launch", required_argument, NULL, 0}, {"drun-print-exec", required_argument, NULL, 0}, {"hint-font", required_argument, NULL, 0}, @@ -933,11 +935,22 @@ static void parse_args(struct tofi *tofi, int argc, char *argv[]) } } -static void do_submit(struct tofi *tofi) +static bool do_submit(struct tofi *tofi) { struct entry *entry = &tofi->window.entry; uint32_t selection = entry->selection + entry->first_result; char *res = entry->results.buf[selection].string; + + if (tofi->window.entry.results.count == 0) { + /* Always require a match in drun mode. */ + if (tofi->require_match || entry->drun) { + return false; + } else { + printf("%ls\n", entry->input); + return true; + } + } + if (entry->drun) { /* * TODO: This is ugly. The list of apps needs to be sorted @@ -948,7 +961,7 @@ static void do_submit(struct tofi *tofi) struct desktop_entry *app = desktop_vec_find(&entry->apps, res); if (app == NULL) { log_error("Couldn't find application file! This shouldn't happen.\n"); - return; + return false; } else { res = app->path; } @@ -966,6 +979,7 @@ static void do_submit(struct tofi *tofi) entry->results.buf[selection].string); history_save(&entry->history, entry->drun); } + return true; } int main(int argc, char *argv[]) @@ -1007,6 +1021,7 @@ int main(int argc, char *argv[]) | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT, .use_history = true, + .require_match = true, }; wl_list_init(&tofi.output_list); @@ -1432,8 +1447,7 @@ int main(int argc, char *argv[]) } if (tofi.submit) { tofi.submit = false; - if (tofi.window.entry.results.count > 0) { - do_submit(&tofi); + if (do_submit(&tofi)) { break; } } diff --git a/src/tofi.h b/src/tofi.h index eb3f0ce..419f86e 100644 --- a/src/tofi.h +++ b/src/tofi.h @@ -84,6 +84,7 @@ struct tofi { bool drun_launch; bool drun_print_exec; bool fuzzy_match; + bool require_match; char target_output_name[MAX_OUTPUT_NAME_LEN]; }; -- cgit v1.2.3