From 74799937cf95205c2ff16da9dc7dcaea47ce7116 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Mon, 4 Jun 2018 11:30:26 +1000 Subject: [PATCH 1/4] Restore focus when unmapping unmanaged xwayland surfaces --- sway/desktop/xwayland.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index 75bfb7b26..55c42227e 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -77,6 +77,18 @@ static void unmanaged_handle_unmap(struct wl_listener *listener, void *data) { desktop_damage_surface(xsurface->surface, xsurface->x, xsurface->y, true); wl_list_remove(&surface->link); wl_list_remove(&surface->commit.link); + + if (!wlr_xwayland_surface_is_unmanaged(xsurface)) { + // Restore focus + struct sway_seat *seat = input_manager_current_seat(input_manager); + struct sway_container *previous = + seat_get_focus_inactive(seat, &root_container); + if (previous) { + // Hack to get seat to re-focus the return value of get_focus + seat_set_focus(seat, previous->parent); + seat_set_focus(seat, previous); + } + } } static void unmanaged_handle_destroy(struct wl_listener *listener, void *data) { From 9253278328524e4f483a66aa54ed11fd8538ace8 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Mon, 4 Jun 2018 11:31:07 +1000 Subject: [PATCH 2/4] Restore focus when unmapping layer shell surfaces --- sway/desktop/layer_shell.c | 5 +++++ sway/input/seat.c | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/sway/desktop/layer_shell.c b/sway/desktop/layer_shell.c index b60aa4873..2d355b74d 100644 --- a/sway/desktop/layer_shell.c +++ b/sway/desktop/layer_shell.c @@ -257,6 +257,11 @@ static void unmap(struct sway_layer_surface *sway_layer) { } output_damage_surface(output, sway_layer->geo.x, sway_layer->geo.y, sway_layer->layer_surface->surface, true); + + struct sway_seat *seat = input_manager_current_seat(input_manager); + if (seat->focused_layer == sway_layer->layer_surface) { + seat_set_focus_layer(seat, NULL); + } } static void handle_destroy(struct wl_listener *listener, void *data) { diff --git a/sway/input/seat.c b/sway/input/seat.c index 0e539b707..071ef0202 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -658,7 +658,8 @@ void seat_set_focus_layer(struct sway_seat *seat, struct wlr_layer_surface *layer) { if (!layer && seat->focused_layer) { seat->focused_layer = NULL; - struct sway_container *previous = seat_get_focus(seat); + struct sway_container *previous = + seat_get_focus_inactive(seat, &root_container); if (previous) { wlr_log(L_DEBUG, "Returning focus to %p %s '%s'", previous, container_type_to_str(previous->type), previous->name); From bcdb676abb34de49c57a11059658427f675ccec4 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Mon, 4 Jun 2018 11:31:25 +1000 Subject: [PATCH 3/4] Don't set focus to NULL when clicking a surface which has no container --- sway/input/cursor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 16e5427be..d6e17ae14 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -264,7 +264,7 @@ void dispatch_cursor_button(struct sway_cursor *cursor, if (new_ws != old_ws) { seat_set_focus(cursor->seat, cont); } - } else { + } else if (cont) { seat_set_focus(cursor->seat, cont); } From 1206a6097711556b22418db5043dc7c22d8b9a3e Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Mon, 4 Jun 2018 13:31:09 +1000 Subject: [PATCH 4/4] Don't restore focus if unmapping surface wasn't focused --- sway/desktop/xwayland.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index 55c42227e..6447b711e 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -79,14 +79,17 @@ static void unmanaged_handle_unmap(struct wl_listener *listener, void *data) { wl_list_remove(&surface->commit.link); if (!wlr_xwayland_surface_is_unmanaged(xsurface)) { - // Restore focus struct sway_seat *seat = input_manager_current_seat(input_manager); - struct sway_container *previous = - seat_get_focus_inactive(seat, &root_container); - if (previous) { - // Hack to get seat to re-focus the return value of get_focus - seat_set_focus(seat, previous->parent); - seat_set_focus(seat, previous); + if (seat->wlr_seat->keyboard_state.focused_surface == + xsurface->surface) { + // Restore focus + struct sway_container *previous = + seat_get_focus_inactive(seat, &root_container); + if (previous) { + // Hack to get seat to re-focus the return value of get_focus + seat_set_focus(seat, previous->parent); + seat_set_focus(seat, previous); + } } } }