From f7b9c92604d6f17bbc1bdce9313f76cb0fa41603 Mon Sep 17 00:00:00 2001 From: Marius Vlad <marius.vlad@collabora.com> Date: Fri, 5 Mar 2021 21:58:40 +0200 Subject: [PATCH] kiosk-shell: Embed keyboard focus activation code Just like desktop-shell, we shouldn't be dependent on having a keyboard to be present in order to activate a window/surface. Signed-off-by: Marius Vlad <marius.vlad@collabora.com> --- kiosk-shell/kiosk-shell.c | 65 ++++++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 21 deletions(-) diff --git a/kiosk-shell/kiosk-shell.c b/kiosk-shell/kiosk-shell.c index 12c1c279a9..0e6fd32f4f 100644 --- a/kiosk-shell/kiosk-shell.c +++ b/kiosk-shell/kiosk-shell.c @@ -94,6 +94,20 @@ transform_handler(struct wl_listener *listener, void *data) api->send_position(surface, x, y); } +static void +kiosk_shell_surface_deactivate(struct kiosk_shell_surface *shsurf) +{ + if (--shsurf->focus_count == 0) + weston_desktop_surface_set_activated(shsurf->desktop_surface, false); +} + +static void +kiosk_shell_surface_activate(struct kiosk_shell_surface *shsurf) +{ + if (shsurf->focus_count++ == 0) + weston_desktop_surface_set_activated(shsurf->desktop_surface, true); +} + /* * kiosk_shell_surface */ @@ -350,26 +364,8 @@ kiosk_shell_surface_create(struct kiosk_shell *shell, static void kiosk_shell_seat_handle_keyboard_focus(struct wl_listener *listener, void *data) { - struct weston_keyboard *keyboard = data; - struct kiosk_shell_seat *shseat = get_kiosk_shell_seat(keyboard->seat); - - if (shseat->focused_surface) { - struct kiosk_shell_surface *shsurf = - get_kiosk_shell_surface(shseat->focused_surface); - if (shsurf && --shsurf->focus_count == 0) - weston_desktop_surface_set_activated(shsurf->desktop_surface, - false); - } - - shseat->focused_surface = weston_surface_get_main_surface(keyboard->focus); - - if (shseat->focused_surface) { - struct kiosk_shell_surface *shsurf = - get_kiosk_shell_surface(shseat->focused_surface); - if (shsurf && shsurf->focus_count++ == 0) - weston_desktop_surface_set_activated(shsurf->desktop_surface, - true); - } + /* kept for future usage, handle_keyboard_focus() is trigged from + * weston_keyboard_set_focus() */ } static void @@ -662,9 +658,18 @@ desktop_surface_removed(struct weston_desktop_surface *desktop_surface, if (focus_view) { wl_list_for_each(seat, &shell->compositor->seat_list, link) { + struct kiosk_shell_seat *kiosk_seat = + get_kiosk_shell_seat(seat); struct weston_keyboard *keyboard = seat->keyboard_state; + struct kiosk_shell_surface *focus_shsurf = + get_kiosk_shell_surface(focus_view->surface); + if (keyboard && keyboard->focus == surface) weston_view_activate(focus_view, seat, 0); + + kiosk_shell_surface_deactivate(shsurf); + kiosk_seat->focused_surface = focus_view->surface; + kiosk_shell_surface_activate(focus_shsurf); } } @@ -718,8 +723,26 @@ desktop_surface_committed(struct weston_desktop_surface *desktop_surface, shsurf->view->is_mapped = true; surface->is_mapped = true; - wl_list_for_each(seat, &shsurf->shell->compositor->seat_list, link) + wl_list_for_each(seat, &shsurf->shell->compositor->seat_list, link) { + struct kiosk_shell_seat *kiosk_seat = get_kiosk_shell_seat(seat); weston_view_activate(shsurf->view, seat, 0); + + if (kiosk_seat->focused_surface) { + struct kiosk_shell_surface *current_focus = + get_kiosk_shell_surface(kiosk_seat->focused_surface); + if (current_focus) + kiosk_shell_surface_deactivate(current_focus); + } + + kiosk_seat->focused_surface = surface; + + if (kiosk_seat->focused_surface) { + if (shsurf) + kiosk_shell_surface_activate(shsurf); + } + } + + } if (!is_fullscreen && (sx != 0 || sy != 0)) { -- GitLab