From 539f4bdca28ba959dd631dd2e90fded528cfc942 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Wed, 8 Jul 2020 15:53:01 +0200 Subject: [PATCH] X11: Fix race in window hovered query The window decoration window can go away between calls to XQueryPointer, for example if the GLFW_DECORATED window attribute was just cleared. (cherry picked from commit ceb20c7f97994106db17cc66bd8abad331bc355e) --- src/x11_window.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/x11_window.c b/src/x11_window.c index 9df28973..9ffb5e9e 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -2591,11 +2591,19 @@ int _glfwPlatformWindowHovered(_GLFWwindow* window) int rootX, rootY, childX, childY; unsigned int mask; - if (!XQueryPointer(_glfw.x11.display, w, - &root, &w, &rootX, &rootY, &childX, &childY, &mask)) - { + _glfwGrabErrorHandlerX11(); + + const Bool result = XQueryPointer(_glfw.x11.display, w, + &root, &w, &rootX, &rootY, + &childX, &childY, &mask); + + _glfwReleaseErrorHandlerX11(); + + if (_glfw.x11.errorCode == BadWindow) + w = _glfw.x11.root; + + if (!result) return GLFW_FALSE; - } if (w == window->x11.handle) return GLFW_TRUE;