Allow running commands on containers without focusing them

This adds a `con` argument to `execute_command` which allows you to
specify the container to execute the command on. In most cases it leaves
it as `NULL` which makes it use the focused node. We only set it when
executing `for_window` criteria such as when a view maps. This means we
don't send unnecessary IPC focus events, and fixes a crash when the
criteria command is `move scratchpad` (because we can't give focus to a
hidden scratchpad container).

Each of the shell map handlers now check to see if the view has a
workspace. It won't have a workspace if criteria has moved it to the
scratchpad.
This commit is contained in:
Ryan Dwyer 2018-09-23 08:38:15 +10:00
parent 082488a81c
commit cb66bbea42
9 changed files with 28 additions and 19 deletions

View file

@ -237,7 +237,8 @@ static void set_config_node(struct sway_node *node) {
}
}
struct cmd_results *execute_command(char *_exec, struct sway_seat *seat) {
struct cmd_results *execute_command(char *_exec, struct sway_seat *seat,
struct sway_container *con) {
// Even though this function will process multiple commands we will only
// return the last error, if any (for now). (Since we have access to an
// error string we could e.g. concatenate all errors there.)
@ -256,6 +257,15 @@ struct cmd_results *execute_command(char *_exec, struct sway_seat *seat) {
}
}
// This is the container or workspace which this command will run on.
// Ignored if the command string contains criteria.
struct sway_node *node;
if (con) {
node = &con->node;
} else {
node = seat_get_focus_inactive(seat, &root->node);
}
config->handler_context.seat = seat;
head = exec;
@ -318,9 +328,7 @@ struct cmd_results *execute_command(char *_exec, struct sway_seat *seat) {
}
if (!config->handler_context.using_criteria) {
// without criteria, the command acts upon the focused
// container
set_config_node(seat_get_focus_inactive(seat, &root->node));
set_config_node(node);
struct cmd_results *res = handler->handle(argc-1, argv+1);
if (res->status != CMD_SUCCESS) {
free_argv(argc, argv);