kiosk-shell: Embed keyboard focus activation code

Just like desktop-shell, we shouldn't be dependent on having a keyboard
be present in order to activate a window/surface.

This adds a libweston helper to retrieve the first available seat, and
to use it in order to avoid going over the seat list.

We also encapsulate the activation of the surface in one place, and use
it on surface removal, when the surface has been committed, or for
touch/pointer events. With it we also deal with the keyboard focus and
shell activation in one place.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
dev
Marius Vlad 4 years ago
parent 742a0232b0
commit 365f445eab
  1. 105
      kiosk-shell/kiosk-shell.c

@ -65,6 +65,20 @@ get_kiosk_shell_seat(struct weston_seat *seat)
struct kiosk_shell_seat, seat_destroy_listener); struct kiosk_shell_seat, seat_destroy_listener);
} }
static struct weston_seat *
get_kiosk_shell_first_seat(struct kiosk_shell *shell)
{
struct wl_list *node;
struct weston_compositor *compositor = shell->compositor;
if (wl_list_empty(&compositor->seat_list))
return NULL;
node = compositor->seat_list.next;
return container_of(node, struct weston_seat, link);
}
static void static void
transform_handler(struct wl_listener *listener, void *data) transform_handler(struct wl_listener *listener, void *data)
{ {
@ -343,6 +357,36 @@ kiosk_shell_surface_create(struct kiosk_shell *shell,
return shsurf; return shsurf;
} }
static void
kiosk_shell_surface_activate(struct kiosk_shell_surface *shsurf,
struct kiosk_shell_seat *kiosk_seat,
uint32_t activate_flags)
{
struct weston_desktop_surface *dsurface = shsurf->desktop_surface;
struct weston_surface *surface =
weston_desktop_surface_get_surface(dsurface);
/* keyboard focus */
weston_view_activate_input(shsurf->view, kiosk_seat->seat, activate_flags);
/* xdg-shell deactivation if there's a focused one */
if (kiosk_seat->focused_surface) {
struct kiosk_shell_surface *current_focus =
get_kiosk_shell_surface(kiosk_seat->focused_surface);
struct weston_desktop_surface *dsurface_focus;
assert(current_focus);
dsurface_focus = current_focus->desktop_surface;
if (--current_focus->focus_count == 0)
weston_desktop_surface_set_activated(dsurface_focus, false);
}
/* xdg-shell activation for the new one */
kiosk_seat->focused_surface = surface;
if (shsurf->focus_count++ == 0)
weston_desktop_surface_set_activated(dsurface, true);
}
/* /*
* kiosk_shell_seat * kiosk_shell_seat
*/ */
@ -350,26 +394,7 @@ kiosk_shell_surface_create(struct kiosk_shell *shell,
static void static void
kiosk_shell_seat_handle_keyboard_focus(struct wl_listener *listener, void *data) kiosk_shell_seat_handle_keyboard_focus(struct wl_listener *listener, void *data)
{ {
struct weston_keyboard *keyboard = data; /* FIXME: To be removed later. */
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);
}
} }
static void static void
@ -619,7 +644,8 @@ desktop_surface_added(struct weston_desktop_surface *desktop_surface,
* parentage. */ * parentage. */
static struct weston_view * static struct weston_view *
find_focus_successor(struct weston_layer *layer, find_focus_successor(struct weston_layer *layer,
struct kiosk_shell_surface *shsurf) struct kiosk_shell_surface *shsurf,
struct weston_surface *focused_surface)
{ {
struct kiosk_shell_surface *parent_root = struct kiosk_shell_surface *parent_root =
kiosk_shell_surface_get_parent_root(shsurf); kiosk_shell_surface_get_parent_root(shsurf);
@ -659,17 +685,27 @@ desktop_surface_removed(struct weston_desktop_surface *desktop_surface,
weston_desktop_surface_get_surface(desktop_surface); weston_desktop_surface_get_surface(desktop_surface);
struct weston_view *focus_view; struct weston_view *focus_view;
struct weston_seat *seat; struct weston_seat *seat;
struct kiosk_shell_seat* kiosk_seat;
if (!shsurf) if (!shsurf)
return; return;
focus_view = find_focus_successor(&shell->normal_layer, shsurf); seat = get_kiosk_shell_first_seat(shell);
kiosk_seat = get_kiosk_shell_seat(seat);
if (seat && kiosk_seat) {
focus_view = find_focus_successor(&shell->normal_layer, shsurf,
kiosk_seat->focused_surface);
if (focus_view) { if (focus_view) {
wl_list_for_each(seat, &shell->compositor->seat_list, link) { struct kiosk_shell_surface *focus_shsurf =
struct weston_keyboard *keyboard = seat->keyboard_state; get_kiosk_shell_surface(focus_view->surface);
if (keyboard && keyboard->focus == surface)
weston_view_activate_input(focus_view, seat, 0); kiosk_shell_surface_activate(focus_shsurf, kiosk_seat,
WESTON_ACTIVATE_FLAG_NONE);
} else {
if (kiosk_seat->focused_surface == surface)
kiosk_seat->focused_surface = NULL;
} }
} }
@ -687,6 +723,8 @@ desktop_surface_committed(struct weston_desktop_surface *desktop_surface,
bool is_resized; bool is_resized;
bool is_fullscreen; bool is_fullscreen;
assert(shsurf);
if (surface->width == 0) if (surface->width == 0)
return; return;
@ -716,15 +754,19 @@ desktop_surface_committed(struct weston_desktop_surface *desktop_surface,
} }
if (!weston_surface_is_mapped(surface)) { if (!weston_surface_is_mapped(surface)) {
struct weston_seat *seat; struct weston_seat *seat =
get_kiosk_shell_first_seat(shsurf->shell);
struct kiosk_shell_seat *kiosk_seat;
weston_layer_entry_insert(&shsurf->shell->normal_layer.view_list, weston_layer_entry_insert(&shsurf->shell->normal_layer.view_list,
&shsurf->view->layer_link); &shsurf->view->layer_link);
shsurf->view->is_mapped = true; shsurf->view->is_mapped = true;
surface->is_mapped = true; surface->is_mapped = true;
wl_list_for_each(seat, &shsurf->shell->compositor->seat_list, link) kiosk_seat = get_kiosk_shell_seat(seat);
weston_view_activate_input(shsurf->view, seat, 0); if (seat && kiosk_seat)
kiosk_shell_surface_activate(shsurf, kiosk_seat,
WESTON_ACTIVATE_FLAG_NONE);
} }
if (!is_fullscreen && (sx != 0 || sy != 0)) { if (!is_fullscreen && (sx != 0 || sy != 0)) {
@ -916,6 +958,8 @@ kiosk_shell_activate_view(struct kiosk_shell *shell,
weston_surface_get_main_surface(view->surface); weston_surface_get_main_surface(view->surface);
struct kiosk_shell_surface *shsurf = struct kiosk_shell_surface *shsurf =
get_kiosk_shell_surface(main_surface); get_kiosk_shell_surface(main_surface);
struct kiosk_shell_seat *kiosk_seat =
get_kiosk_shell_seat(seat);
if (!shsurf) if (!shsurf)
return; return;
@ -932,7 +976,8 @@ kiosk_shell_activate_view(struct kiosk_shell *shell,
weston_surface_damage(view->surface); weston_surface_damage(view->surface);
} }
weston_view_activate_input(view, seat, flags); if (kiosk_seat)
kiosk_shell_surface_activate(shsurf, kiosk_seat, flags);
} }
static void static void

Loading…
Cancel
Save