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

@ -391,8 +391,6 @@ static bool view_has_executed_criteria(struct sway_view *view,
}
void view_execute_criteria(struct sway_view *view) {
struct sway_seat *seat = input_manager_current_seat(input_manager);
struct sway_node *prior_focus = seat_get_focus(seat);
list_t *criterias = criteria_for_view(view, CT_COMMAND);
for (int i = 0; i < criterias->length; i++) {
struct criteria *criteria = criterias->items[i];
@ -403,16 +401,12 @@ void view_execute_criteria(struct sway_view *view) {
}
wlr_log(WLR_DEBUG, "for_window '%s' matches view %p, cmd: '%s'",
criteria->raw, view, criteria->cmdlist);
seat_set_focus_container(seat, view->container);
list_add(view->executed_criteria, criteria);
struct cmd_results *res = execute_command(criteria->cmdlist, NULL);
if (res->status != CMD_SUCCESS) {
wlr_log(WLR_ERROR, "Command '%s' failed: %s", res->input, res->error);
}
struct cmd_results *res = execute_command(
criteria->cmdlist, NULL, view->container);
free_cmd_results(res);
}
list_free(criterias);
seat_set_focus(seat, prior_focus);
}
static struct sway_workspace *select_workspace(struct sway_view *view) {