From 5ac970120a5d276692e3f931db4a37f3d73ebdc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Thu, 3 Nov 2022 21:51:29 +0100 Subject: [PATCH] Wayland: Use tags to verify proxy ownership This is in preparation for adding support for libdecor, which creates its own proxies on our display. It will likely also be helpful to some people using native access on Wayland. This is partly based on the implementation of libdecor support in PR #1693 by @ christianrauch. (cherry picked from commit 91c837ace563cb2bf188dc8ac8e0ae60f616ffe3) --- src/wl_init.c | 2 ++ src/wl_monitor.c | 1 + src/wl_platform.h | 2 ++ src/wl_window.c | 26 ++++++++++++++++++++++++-- 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/wl_init.c b/src/wl_init.c index 90ec449f..3f359e81 100644 --- a/src/wl_init.c +++ b/src/wl_init.c @@ -341,6 +341,8 @@ int _glfwPlatformInit(void) _glfw.wl.keyRepeatTimerfd = -1; _glfw.wl.cursorTimerfd = -1; + _glfw.wl.tag = glfwGetVersionString(); + _glfw.wl.cursor.handle = _glfw_dlopen("libwayland-cursor.so.0"); if (!_glfw.wl.cursor.handle) { diff --git a/src/wl_monitor.c b/src/wl_monitor.c index 99de8933..4792fd6b 100644 --- a/src/wl_monitor.c +++ b/src/wl_monitor.c @@ -187,6 +187,7 @@ void _glfwAddOutputWayland(uint32_t name, uint32_t version) monitor->wl.output = output; monitor->wl.name = name; + wl_proxy_set_tag((struct wl_proxy*) output, &_glfw.wl.tag); wl_output_add_listener(output, &outputListener, monitor); } diff --git a/src/wl_platform.h b/src/wl_platform.h index 8e5714bb..ade4454a 100644 --- a/src/wl_platform.h +++ b/src/wl_platform.h @@ -257,6 +257,8 @@ typedef struct _GLFWlibraryWayland _GLFWwindow* dragFocus; uint32_t dragSerial; + const char* tag; + struct wl_cursor_theme* cursorTheme; struct wl_cursor_theme* cursorThemeHiDPI; struct wl_surface* cursorSurface; diff --git a/src/wl_window.c b/src/wl_window.c index fc5ea2d6..4efef7b6 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -238,6 +238,7 @@ static void createFallbackDecoration(_GLFWdecorationWayland* decoration, int width, int height) { decoration->surface = wl_compositor_create_surface(_glfw.wl.compositor); + wl_proxy_set_tag((struct wl_proxy*) decoration->surface, &_glfw.wl.tag); decoration->subsurface = wl_subcompositor_get_subsurface(_glfw.wl.subcompositor, decoration->surface, parent); @@ -410,6 +411,9 @@ static void surfaceHandleEnter(void* userData, struct wl_surface* surface, struct wl_output* output) { + if (wl_proxy_get_tag((struct wl_proxy*) output) != &_glfw.wl.tag) + return; + _GLFWwindow* window = userData; _GLFWmonitor* monitor = wl_output_get_user_data(output); @@ -430,6 +434,9 @@ static void surfaceHandleLeave(void* userData, struct wl_surface* surface, struct wl_output* output) { + if (wl_proxy_get_tag((struct wl_proxy*) output) != &_glfw.wl.tag) + return; + _GLFWwindow* window = userData; _GLFWmonitor* monitor = wl_output_get_user_data(output); GLFWbool found; @@ -766,6 +773,7 @@ static GLFWbool createNativeSurface(_GLFWwindow* window, return GLFW_FALSE; } + wl_proxy_set_tag((struct wl_proxy*) window->wl.surface, &_glfw.wl.tag); wl_surface_add_listener(window->wl.surface, &surfaceListener, window); @@ -1099,6 +1107,9 @@ static void pointerHandleEnter(void* userData, if (!surface) return; + if (wl_proxy_get_tag((struct wl_proxy*) surface) != &_glfw.wl.tag) + return; + _GLFWdecorationSideWayland focus = mainWindow; _GLFWwindow* window = wl_surface_get_user_data(surface); if (!window) @@ -1124,8 +1135,13 @@ static void pointerHandleLeave(void* userData, uint32_t serial, struct wl_surface* surface) { - _GLFWwindow* window = _glfw.wl.pointerFocus; + if (!surface) + return; + if (wl_proxy_get_tag((struct wl_proxy*) surface) != &_glfw.wl.tag) + return; + + _GLFWwindow* window = _glfw.wl.pointerFocus; if (!window) return; @@ -1719,7 +1735,10 @@ static void dataDeviceHandleEnter(void* userData, _GLFWwindow* window = NULL; if (surface) - window = wl_surface_get_user_data(surface); + { + if (wl_proxy_get_tag((struct wl_proxy*) surface) == &_glfw.wl.tag) + window = wl_surface_get_user_data(surface); + } if (window && _glfw.wl.offers[i].text_uri_list) { @@ -1734,6 +1753,9 @@ static void dataDeviceHandleEnter(void* userData, } } + if (wl_proxy_get_tag((struct wl_proxy*) surface) != &_glfw.wl.tag) + return; + if (_glfw.wl.dragOffer) wl_data_offer_accept(offer, serial, "text/uri-list"); else