From 2f3deec245f958a19edd808cc7366b7e98736399 Mon Sep 17 00:00:00 2001
From: Frank Praznik <[EMAIL REDACTED]>
Date: Wed, 20 Sep 2023 14:42:10 -0400
Subject: [PATCH] wayland: Don't process drag & drop events from surfaces not
owned by SDL
Libdecor creates subsurfaces of the primary SDL surface, but events from these surfaces should be ignored, or applications will get drag & drop events when dragged over drop shadows and such.
---
src/video/wayland/SDL_waylandevents.c | 23 ++++++++++++++---------
1 file changed, 14 insertions(+), 9 deletions(-)
diff --git a/src/video/wayland/SDL_waylandevents.c b/src/video/wayland/SDL_waylandevents.c
index d3d087665f52..ea2c8a2296d4 100644
--- a/src/video/wayland/SDL_waylandevents.c
+++ b/src/video/wayland/SDL_waylandevents.c
@@ -1873,11 +1873,15 @@ static void data_device_handle_enter(void *data, struct wl_data_device *wl_data_
}
/* find the current window */
- if (surface && SDL_WAYLAND_own_surface(surface)) {
- SDL_WindowData *window = (SDL_WindowData *)wl_surface_get_user_data(surface);
- if (window) {
- data_device->dnd_window = window->sdlwindow;
- }
+ if (surface) {
+ if (SDL_WAYLAND_own_surface(surface)) {
+ SDL_WindowData *window = (SDL_WindowData *)wl_surface_get_user_data(surface);
+ if (window) {
+ data_device->dnd_window = window->sdlwindow;
+ }
+ } else {
+ data_device->dnd_window = NULL;
+ }
}
}
}
@@ -1897,7 +1901,7 @@ static void data_device_handle_motion(void *data, struct wl_data_device *wl_data
{
SDL_WaylandDataDevice *data_device = data;
- if (data_device->drag_offer != NULL) {
+ if (data_device->drag_offer != NULL && data_device->dnd_window) {
/* TODO: SDL Support more mime types */
size_t length;
void *buffer = Wayland_data_offer_receive(data_device->drag_offer,
@@ -2046,7 +2050,7 @@ static void data_device_handle_drop(void *data, struct wl_data_device *wl_data_d
{
SDL_WaylandDataDevice *data_device = data;
- if (data_device->drag_offer != NULL) {
+ if (data_device->drag_offer != NULL && data_device->dnd_window) {
/* TODO: SDL Support more mime types */
size_t length;
SDL_bool drop_handled = SDL_FALSE;
@@ -2102,9 +2106,10 @@ static void data_device_handle_drop(void *data, struct wl_data_device *wl_data_d
WL_DATA_OFFER_FINISH_SINCE_VERSION) {
wl_data_offer_finish(data_device->drag_offer->offer);
}
- Wayland_data_offer_destroy(data_device->drag_offer);
- data_device->drag_offer = NULL;
}
+
+ Wayland_data_offer_destroy(data_device->drag_offer);
+ data_device->drag_offer = NULL;
}
static void data_device_handle_selection(void *data, struct wl_data_device *wl_data_device,