Holding ctrl when pressing enter will now parse args in run mode
This commit is contained in:
parent
c85f6a7209
commit
750cdd0167
@ -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
|
||||
|
25
modes/run.c
25
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);
|
||||
}
|
||||
|
10
src/wofi.c
10
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)) {
|
||||
|
Loading…
Reference in New Issue
Block a user