From 73050c358d55bf56cf5d0efcffb903618a3fd93c Mon Sep 17 00:00:00 2001 From: Daniel Stone Date: Wed, 12 Jul 2023 11:03:21 +0100 Subject: [PATCH] desktop-shell: Don't open-code animate_focus_change() It already does what we want, so just use it when we're losing focus. Signed-off-by: Daniel Stone --- desktop-shell/shell.c | 78 ++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 42 deletions(-) diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c index 80369004..8aacdd17 100644 --- a/desktop-shell/shell.c +++ b/desktop-shell/shell.c @@ -678,6 +678,39 @@ focus_animation_done(struct weston_view_animation *animation, void *data) ws->focus_animation = NULL; } +static void +animate_focus_change(struct desktop_shell *shell, struct workspace *ws, + struct weston_view *from, struct weston_view *to) +{ + struct weston_view *front = ws->fsurf_front->curtain->view; + struct weston_view *back = ws->fsurf_back->curtain->view; + if ((from && from == to) || shell->focus_animation_type == ANIMATION_NONE) + return; + + if (ws->focus_animation) { + weston_view_animation_destroy(ws->focus_animation); + ws->focus_animation = NULL; + } + + if (to) { + weston_view_move_to_layer(front, &to->layer_link); + if (from) + weston_view_move_to_layer(back, &from->layer_link); + else + weston_view_move_to_layer(back, &ws->layer.view_list); + + ws->focus_animation = + weston_stable_fade_run(front, 0.0, back, 0.4, + focus_animation_done, ws); + } else { + weston_view_move_to_layer(front, &ws->layer.view_list); + weston_view_move_to_layer(back, NULL); + ws->focus_animation = + weston_fade_run(front, front->alpha, 0.0, 300, + focus_animation_done, ws); + } +} + static void focus_state_destroy(struct focus_state *state) { @@ -736,14 +769,9 @@ focus_state_surface_destroy(struct wl_listener *listener, void *data) activate(state->shell, next, state->seat, WESTON_ACTIVATE_FLAG_CONFIGURE); } else { - if (state->shell->focus_animation_type == ANIMATION_DIM_LAYER) { - if (state->ws->focus_animation) - weston_view_animation_destroy(state->ws->focus_animation); - - state->ws->focus_animation = weston_fade_run( - state->ws->fsurf_front->curtain->view, - state->ws->fsurf_front->curtain->view->alpha, 0.0, 300, - focus_animation_done, state->ws); + if (state->shell->focus_animation_type != ANIMATION_NONE) { + animate_focus_change(state->shell, state->ws, + get_default_view(main_surface), NULL); } wl_list_remove(&state->link); @@ -863,40 +891,6 @@ drop_focus_state(struct desktop_shell *shell, struct workspace *ws, focus_state_set_focus(state, NULL); } -static void -animate_focus_change(struct desktop_shell *shell, struct workspace *ws, - struct weston_view *from, struct weston_view *to) -{ - struct weston_view *front = ws->fsurf_front->curtain->view; - struct weston_view *back = ws->fsurf_back->curtain->view; - - if ((from && from == to) || shell->focus_animation_type == ANIMATION_NONE) - return; - - if (ws->focus_animation) { - weston_view_animation_destroy(ws->focus_animation); - ws->focus_animation = NULL; - } - - if (to) { - weston_view_move_to_layer(front, &to->layer_link); - if (from) - weston_view_move_to_layer(back, &from->layer_link); - else - weston_view_move_to_layer(back, &ws->layer.view_list); - - ws->focus_animation = - weston_stable_fade_run(front, 0.0, back, 0.4, - focus_animation_done, ws); - } else { - weston_view_move_to_layer(front, &ws->layer.view_list); - weston_view_move_to_layer(back, NULL); - ws->focus_animation = - weston_fade_run(front, front->alpha, 0.0, 300, - focus_animation_done, ws); - } -} - static void desktop_shell_destroy_layer(struct weston_layer *layer);