Holding ctrl when pressing enter will now parse args in run mode

This commit is contained in:
Scoopta 2019-11-18 22:13:14 -08:00
parent c85f6a7209
commit 750cdd0167
3 changed files with 35 additions and 2 deletions

View File

@ -55,5 +55,7 @@ uint64_t wofi_get_image_size();
bool wofi_run_in_term(); bool wofi_run_in_term();
bool wofi_mod_control();
void wofi_term_run(const char* cmd); void wofi_term_run(const char* cmd);
#endif #endif

View File

@ -79,11 +79,32 @@ void wofi_run_init() {
} }
void wofi_run_exec(const gchar* cmd) { void wofi_run_exec(const gchar* cmd) {
wofi_write_cache(MODE, cmd);
if(wofi_run_in_term()) { if(wofi_run_in_term()) {
wofi_write_cache(MODE, cmd);
wofi_term_run(cmd); wofi_term_run(cmd);
} }
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); execl(cmd, cmd, NULL);
}
fprintf(stderr, "%s cannot be executed\n", cmd); fprintf(stderr, "%s cannot be executed\n", cmd);
exit(errno); exit(errno);
} }

View File

@ -32,6 +32,7 @@ static uint64_t image_size;
static char* cache_file = NULL; static char* cache_file = NULL;
static char* config_dir; static char* config_dir;
static bool run_in_term; static bool run_in_term;
static bool mod_ctrl;
static char* terminal; static char* terminal;
static GtkOrientation outer_orientation; static GtkOrientation outer_orientation;
static bool exec_search; static bool exec_search;
@ -323,6 +324,10 @@ bool wofi_run_in_term() {
return run_in_term; return run_in_term;
} }
bool wofi_mod_control() {
return mod_ctrl;
}
void wofi_term_run(const char* cmd) { void wofi_term_run(const char* cmd) {
if(terminal != NULL) { if(terminal != NULL) {
execlp(terminal, terminal, "--", cmd, NULL); execlp(terminal, terminal, "--", cmd, NULL);
@ -413,9 +418,13 @@ static gboolean key_press(GtkWidget* widget, GdkEvent* event, gpointer data) {
break; break;
case GDK_KEY_Return: case GDK_KEY_Return:
run_in_term = (event->key.state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK; 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) { if(run_in_term) {
event->key.state &= ~GDK_SHIFT_MASK; event->key.state &= ~GDK_SHIFT_MASK;
} }
if(mod_ctrl) {
event->key.state &= ~GDK_CONTROL_MASK;
}
if(gtk_widget_has_focus(scroll)) { if(gtk_widget_has_focus(scroll)) {
gtk_entry_grab_focus_without_selecting(GTK_ENTRY(entry)); gtk_entry_grab_focus_without_selecting(GTK_ENTRY(entry));
} }
@ -436,6 +445,7 @@ static gboolean key_press(GtkWidget* widget, GdkEvent* event, gpointer data) {
} }
break; break;
case GDK_KEY_Shift_L:case GDK_KEY_Shift_R: case GDK_KEY_Shift_L:case GDK_KEY_Shift_R:
case GDK_KEY_Control_L:case GDK_KEY_Control_R:
break; break;
default: default:
if(!gtk_widget_has_focus(entry)) { if(!gtk_widget_has_focus(entry)) {