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 91c837ace5)
This commit is contained in:
Camilla Löwy 2022-11-03 21:51:29 +01:00
parent 677fbb0f82
commit 5ac970120a
4 changed files with 29 additions and 2 deletions

View File

@ -341,6 +341,8 @@ int _glfwPlatformInit(void)
_glfw.wl.keyRepeatTimerfd = -1; _glfw.wl.keyRepeatTimerfd = -1;
_glfw.wl.cursorTimerfd = -1; _glfw.wl.cursorTimerfd = -1;
_glfw.wl.tag = glfwGetVersionString();
_glfw.wl.cursor.handle = _glfw_dlopen("libwayland-cursor.so.0"); _glfw.wl.cursor.handle = _glfw_dlopen("libwayland-cursor.so.0");
if (!_glfw.wl.cursor.handle) if (!_glfw.wl.cursor.handle)
{ {

View File

@ -187,6 +187,7 @@ void _glfwAddOutputWayland(uint32_t name, uint32_t version)
monitor->wl.output = output; monitor->wl.output = output;
monitor->wl.name = name; monitor->wl.name = name;
wl_proxy_set_tag((struct wl_proxy*) output, &_glfw.wl.tag);
wl_output_add_listener(output, &outputListener, monitor); wl_output_add_listener(output, &outputListener, monitor);
} }

View File

@ -257,6 +257,8 @@ typedef struct _GLFWlibraryWayland
_GLFWwindow* dragFocus; _GLFWwindow* dragFocus;
uint32_t dragSerial; uint32_t dragSerial;
const char* tag;
struct wl_cursor_theme* cursorTheme; struct wl_cursor_theme* cursorTheme;
struct wl_cursor_theme* cursorThemeHiDPI; struct wl_cursor_theme* cursorThemeHiDPI;
struct wl_surface* cursorSurface; struct wl_surface* cursorSurface;

View File

@ -238,6 +238,7 @@ static void createFallbackDecoration(_GLFWdecorationWayland* decoration,
int width, int height) int width, int height)
{ {
decoration->surface = wl_compositor_create_surface(_glfw.wl.compositor); decoration->surface = wl_compositor_create_surface(_glfw.wl.compositor);
wl_proxy_set_tag((struct wl_proxy*) decoration->surface, &_glfw.wl.tag);
decoration->subsurface = decoration->subsurface =
wl_subcompositor_get_subsurface(_glfw.wl.subcompositor, wl_subcompositor_get_subsurface(_glfw.wl.subcompositor,
decoration->surface, parent); decoration->surface, parent);
@ -410,6 +411,9 @@ static void surfaceHandleEnter(void* userData,
struct wl_surface* surface, struct wl_surface* surface,
struct wl_output* output) struct wl_output* output)
{ {
if (wl_proxy_get_tag((struct wl_proxy*) output) != &_glfw.wl.tag)
return;
_GLFWwindow* window = userData; _GLFWwindow* window = userData;
_GLFWmonitor* monitor = wl_output_get_user_data(output); _GLFWmonitor* monitor = wl_output_get_user_data(output);
@ -430,6 +434,9 @@ static void surfaceHandleLeave(void* userData,
struct wl_surface* surface, struct wl_surface* surface,
struct wl_output* output) struct wl_output* output)
{ {
if (wl_proxy_get_tag((struct wl_proxy*) output) != &_glfw.wl.tag)
return;
_GLFWwindow* window = userData; _GLFWwindow* window = userData;
_GLFWmonitor* monitor = wl_output_get_user_data(output); _GLFWmonitor* monitor = wl_output_get_user_data(output);
GLFWbool found; GLFWbool found;
@ -766,6 +773,7 @@ static GLFWbool createNativeSurface(_GLFWwindow* window,
return GLFW_FALSE; return GLFW_FALSE;
} }
wl_proxy_set_tag((struct wl_proxy*) window->wl.surface, &_glfw.wl.tag);
wl_surface_add_listener(window->wl.surface, wl_surface_add_listener(window->wl.surface,
&surfaceListener, &surfaceListener,
window); window);
@ -1099,6 +1107,9 @@ static void pointerHandleEnter(void* userData,
if (!surface) if (!surface)
return; return;
if (wl_proxy_get_tag((struct wl_proxy*) surface) != &_glfw.wl.tag)
return;
_GLFWdecorationSideWayland focus = mainWindow; _GLFWdecorationSideWayland focus = mainWindow;
_GLFWwindow* window = wl_surface_get_user_data(surface); _GLFWwindow* window = wl_surface_get_user_data(surface);
if (!window) if (!window)
@ -1124,8 +1135,13 @@ static void pointerHandleLeave(void* userData,
uint32_t serial, uint32_t serial,
struct wl_surface* surface) 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) if (!window)
return; return;
@ -1719,7 +1735,10 @@ static void dataDeviceHandleEnter(void* userData,
_GLFWwindow* window = NULL; _GLFWwindow* window = NULL;
if (surface) if (surface)
{
if (wl_proxy_get_tag((struct wl_proxy*) surface) == &_glfw.wl.tag)
window = wl_surface_get_user_data(surface); window = wl_surface_get_user_data(surface);
}
if (window && _glfw.wl.offers[i].text_uri_list) 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) if (_glfw.wl.dragOffer)
wl_data_offer_accept(offer, serial, "text/uri-list"); wl_data_offer_accept(offer, serial, "text/uri-list");
else else