diff --git a/hw/xwayland/xwayland-input.c b/hw/xwayland/xwayland-input.c
index 3d4e51d9e693b549c203ed9daff9bf1e7be02055..0be81c21d408d9d6c699014f11992e80d3de80b2 100644
--- a/hw/xwayland/xwayland-input.c
+++ b/hw/xwayland/xwayland-input.c
@@ -2544,8 +2544,15 @@ sprite_check_lost_focus(SpritePtr sprite, WindowPtr window)
      * devices so we can find out the xwl_seat, but those don't actually own
      * their sprite, so the match doesn't mean a lot.
      */
-    if (master->lastSlave == xwl_seat->pointer &&
-        xwl_seat->focus_window == NULL &&
+    if (master->lastSlave != xwl_seat->pointer)
+        return FALSE;
+
+    if (xwl_seat->focus_window != NULL &&
+        xwl_seat->cursor_confinement_window != NULL &&
+        xwl_seat->focus_window != xwl_seat->cursor_confinement_window)
+        return TRUE;
+
+    if (xwl_seat->focus_window == NULL &&
         xwl_seat->last_xwindow != NullWindow &&
         IsParent(xwl_seat->last_xwindow, window))
         return TRUE;