diff --git a/inc/wofi.h b/inc/wofi.h index 39789cf..62ca8c1 100644 --- a/inc/wofi.h +++ b/inc/wofi.h @@ -55,5 +55,7 @@ uint64_t wofi_get_image_size(); bool wofi_run_in_term(); +bool wofi_mod_control(); + void wofi_term_run(const char* cmd); #endif diff --git a/modes/run.c b/modes/run.c index 3d8f280..a5ddb56 100644 --- a/modes/run.c +++ b/modes/run.c @@ -79,11 +79,32 @@ void wofi_run_init() { } void wofi_run_exec(const gchar* cmd) { - wofi_write_cache(MODE, cmd); if(wofi_run_in_term()) { + wofi_write_cache(MODE, cmd); wofi_term_run(cmd); } - execl(cmd, cmd, NULL); + if(wofi_mod_control()) { + char* tmp = strdup(cmd); + size_t space_count = 2; + char* space; + while((space = strchr(tmp, ' ')) != NULL) { + ++space_count; + *space = '\n'; + } + char** args = malloc(space_count * sizeof(char*)); + char* save_ptr; + char* str = strtok_r(tmp, "\n", &save_ptr); + size_t count = 0; + do { + args[count++] = str; + } while((str = strtok_r(NULL, "\n", &save_ptr)) != NULL); + args[space_count - 1] = NULL; + wofi_write_cache(MODE, tmp); + execvp(tmp, args); + } else { + wofi_write_cache(MODE, cmd); + execl(cmd, cmd, NULL); + } fprintf(stderr, "%s cannot be executed\n", cmd); exit(errno); } diff --git a/src/wofi.c b/src/wofi.c index 2036180..fba2e39 100644 --- a/src/wofi.c +++ b/src/wofi.c @@ -32,6 +32,7 @@ static uint64_t image_size; static char* cache_file = NULL; static char* config_dir; static bool run_in_term; +static bool mod_ctrl; static char* terminal; static GtkOrientation outer_orientation; static bool exec_search; @@ -323,6 +324,10 @@ bool wofi_run_in_term() { return run_in_term; } +bool wofi_mod_control() { + return mod_ctrl; +} + void wofi_term_run(const char* cmd) { if(terminal != NULL) { execlp(terminal, terminal, "--", cmd, NULL); @@ -413,9 +418,13 @@ static gboolean key_press(GtkWidget* widget, GdkEvent* event, gpointer data) { break; case GDK_KEY_Return: run_in_term = (event->key.state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK; + mod_ctrl = (event->key.state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK; if(run_in_term) { event->key.state &= ~GDK_SHIFT_MASK; } + if(mod_ctrl) { + event->key.state &= ~GDK_CONTROL_MASK; + } if(gtk_widget_has_focus(scroll)) { gtk_entry_grab_focus_without_selecting(GTK_ENTRY(entry)); } @@ -436,6 +445,7 @@ static gboolean key_press(GtkWidget* widget, GdkEvent* event, gpointer data) { } break; case GDK_KEY_Shift_L:case GDK_KEY_Shift_R: + case GDK_KEY_Control_L:case GDK_KEY_Control_R: break; default: if(!gtk_widget_has_focus(entry)) {