diff --git a/modes/dmenu.c b/modes/dmenu.c index eb41add..27d9935 100644 --- a/modes/dmenu.c +++ b/modes/dmenu.c @@ -52,7 +52,3 @@ void wofi_dmenu_exec(const gchar* cmd) { printf("%s\n", cmd); exit(0); } - -bool wofi_dmenu_exec_search() { - return true; -} diff --git a/src/main.c b/src/main.c index 255c992..868b852 100644 --- a/src/main.c +++ b/src/main.c @@ -66,6 +66,7 @@ static void print_usage(char** argv) { printf("--cache-file\t-k\tSets the cache file to use\n"); printf("--term\t\t-t\tSpecifies the terminal to use when running in a term\n"); printf("--password\t-P\tRuns in password mode\n"); + printf("--exec-search\t-e\tMakes enter always use the search contents not the first result\n"); exit(0); } @@ -277,6 +278,12 @@ int main(int argc, char** argv) { .flag = NULL, .val = 'P' }, + { + .name = "exec-search", + .has_arg = no_argument, + .flag = NULL, + .val = 'e' + }, { .name = NULL, .has_arg = 0, @@ -300,8 +307,9 @@ int main(int argc, char** argv) { char* cache_file = NULL; char* terminal = NULL; char* password_char = "false"; + char* exec_search = NULL; int opt; - while((opt = getopt_long(argc, argv, "hfc:s:C:dS:W:H:p:x:y:nimk:t:P::", opts, NULL)) != -1) { + while((opt = getopt_long(argc, argv, "hfc:s:C:dS:W:H:p:x:y:nimk:t:P::e", opts, NULL)) != -1) { switch(opt) { case 'h': print_usage(argv); @@ -362,6 +370,9 @@ int main(int argc, char** argv) { case 'P': password_char = optarg; break; + case 'e': + exec_search = "true"; + break; } } @@ -491,6 +502,9 @@ int main(int argc, char** argv) { } map_put(config, "password_char", password_char); } + if(exec_search != NULL) { + map_put(config, "exec_search", exec_search); + } gtk_init(&argc, &argv); diff --git a/src/wofi.c b/src/wofi.c index eb24d50..8cea358 100644 --- a/src/wofi.c +++ b/src/wofi.c @@ -34,8 +34,8 @@ static char* config_dir; static bool run_in_term; static char* terminal; static GtkOrientation outer_orientation; +static bool exec_search; static void (*mode_exec)(const gchar* cmd); -static bool (*exec_search)(); struct node { char* text, *search_text, *action; @@ -311,7 +311,7 @@ static GtkWidget* get_first_child(GtkContainer* container) { GtkWidget* child = list->data; GtkAllocation alloc; gtk_widget_get_allocation(child, &alloc); - if(alloc.x <= x && alloc.y <= y && alloc.x != -1 && alloc.y != -1 && alloc.width != 1 && alloc.height != 1) { + if(alloc.x <= x && alloc.y <= y && alloc.x != -1 && alloc.y != -1 && alloc.width != 1 && alloc.height != 1 && gtk_widget_get_child_visible(child)) { x = alloc.x; y = alloc.y; min_child = child; @@ -323,10 +323,10 @@ static GtkWidget* get_first_child(GtkContainer* container) { static void activate_search(GtkEntry* entry, gpointer data) { (void) data; - if(exec_search != NULL && exec_search()) { + GtkWidget* child = get_first_child(GTK_CONTAINER(inner_box)); + if(exec_search || child == NULL) { execute_action(mode, gtk_entry_get_text(entry)); } else { - GtkWidget* child = get_first_child(GTK_CONTAINER(inner_box)); GtkWidget* box = gtk_bin_get_child(GTK_BIN(child)); execute_action(mode, wofi_property_box_get_property(WOFI_PROPERTY_BOX(box), "action")); } @@ -408,7 +408,6 @@ static void* start_thread(void* data) { if(dso == NULL) { init = get_plugin_proc(mode, "_init"); mode_exec = get_plugin_proc(mode, "_exec"); - exec_search = get_plugin_proc(mode, "_exec_search"); } else { char* plugins_dir = utils_concat(2, config_dir, "/plugins/"); char* full_name = utils_concat(2, plugins_dir, mode); @@ -417,7 +416,6 @@ static void* start_thread(void* data) { free(plugins_dir); init = dlsym(plugin, "init"); mode_exec = dlsym(plugin, "exec"); - exec_search = dlsym(plugin, "exec_search"); } if(init != NULL) { @@ -455,6 +453,7 @@ void wofi_init(struct map* config) { config_dir = map_get(config, "config_dir"); terminal = map_get(config, "term"); char* password_char = map_get(config, "password_char"); + exec_search = strcmp(config_get(config, "exec_search", "false"), "true") == 0; window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_widget_realize(window);