From 79cf52e5566742bdbf98bce7ad7f61a5e0106448 Mon Sep 17 00:00:00 2001
From: Marius Vlad <marius.vlad@collabora.com>
Date: Fri, 12 Nov 2021 15:15:20 +0200
Subject: [PATCH] kiosk-shell: Handle child top-level windows at destruction

With the seperation of surface activation and keyboard input, a special
corner case arose for child top-level windows when surfaces are being
destroyed. To make sure we never pick the wrong window to activate upon
destruction, we verify if the current focused surface is different than
the one being destroyed.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
---
 kiosk-shell/kiosk-shell.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/kiosk-shell/kiosk-shell.c b/kiosk-shell/kiosk-shell.c
index a2de28ec78..eed0f0aa1c 100644
--- a/kiosk-shell/kiosk-shell.c
+++ b/kiosk-shell/kiosk-shell.c
@@ -652,6 +652,14 @@ find_focus_successor(struct weston_layer *layer,
 	struct weston_view *top_view = NULL;
 	struct weston_view *view;
 
+	/* we need to take into account that the surface being destroyed it not
+	 * always the same as the focus_surface, which could result in picking
+	 * and *activating* the wrong window, so avoid returning a view for
+	 * that case. A particular case is when a top-level child window, would
+	 * pick a parent window below the focused_surface. */
+	if (focused_surface != shsurf->view->surface)
+		return top_view;
+
 	wl_list_for_each(view, &layer->view_list.link, layer_link.link) {
 		struct kiosk_shell_surface *view_shsurf;
 		struct kiosk_shell_surface *root;
-- 
GitLab