diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index 2c973f713..ddb2d683d 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h @@ -163,6 +163,11 @@ struct sway_container *tiling_container_at( void container_for_each_child(struct sway_container *container, void (*f)(struct sway_container *container, void *data), void *data); +/** + * Returns the fullscreen container obstructing this container if it exists. + */ +struct sway_container *container_obstructing_fullscreen_container(struct sway_container *container); + /** * Returns true if the given container is an ancestor of this container. */ diff --git a/sway/commands/focus.c b/sway/commands/focus.c index 6b4f57c12..6771ca2f7 100644 --- a/sway/commands/focus.c +++ b/sway/commands/focus.c @@ -377,6 +377,13 @@ struct cmd_results *cmd_focus(int argc, char **argv) { if (container_is_scratchpad_hidden_or_child(container)) { root_scratchpad_show(container); } + // if we are switching to a container under a fullscreen window, we first + // need to exit fullscreen so that the newly focused container becomes visible + struct sway_container *obstructing = container_obstructing_fullscreen_container(container); + if (obstructing) { + container_fullscreen_disable(obstructing); + arrange_root(); + } seat_set_focus_container(seat, container); seat_consider_warp_to_focus(seat); container_raise_floating(container); diff --git a/sway/input/seat.c b/sway/input/seat.c index d23525a8a..2d714acd4 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -1139,26 +1139,15 @@ void seat_set_focus(struct sway_seat *seat, struct sway_node *node) { struct sway_container *container = node->type == N_CONTAINER ? node->sway_container : NULL; - // Deny setting focus to a view which is hidden by a fullscreen container - if (new_workspace && new_workspace->fullscreen && container && - !container_is_fullscreen_or_child(container)) { - // Unless it's a transient container - if (!container_is_transient_for(container, new_workspace->fullscreen)) { - return; - } + // Deny setting focus to a view which is hidden by a fullscreen container or global + if (container && container_obstructing_fullscreen_container(container)) { + return; } + // Deny setting focus to a workspace node when using fullscreen global if (root->fullscreen_global && !container && new_workspace) { return; } - // Deny setting focus to a view which is hidden by a fullscreen global - if (root->fullscreen_global && container != root->fullscreen_global && - !container_has_ancestor(container, root->fullscreen_global)) { - // Unless it's a transient container - if (!container_is_transient_for(container, root->fullscreen_global)) { - return; - } - } struct sway_output *new_output = new_workspace ? new_workspace->output : NULL; diff --git a/sway/tree/container.c b/sway/tree/container.c index 6b4c6de2b..e22c5961b 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -418,6 +418,28 @@ void container_for_each_child(struct sway_container *container, } } +struct sway_container *container_obstructing_fullscreen_container(struct sway_container *container) +{ + struct sway_workspace *workspace = container->pending.workspace; + + if (workspace && workspace->fullscreen && !container_is_fullscreen_or_child(container)) { + if (container_is_transient_for(container, workspace->fullscreen)) { + return NULL; + } + return workspace->fullscreen; + } + + struct sway_container *fullscreen_global = root->fullscreen_global; + if (fullscreen_global && container != fullscreen_global && !container_has_ancestor(container, fullscreen_global)) { + if (container_is_transient_for(container, fullscreen_global)) { + return NULL; + } + return fullscreen_global; + } + + return NULL; +} + bool container_has_ancestor(struct sway_container *descendant, struct sway_container *ancestor) { while (descendant) {