GTK3 re-uses wl_data_source
When adding a new mime type to a wl_data_source, GTK3 re-uses the data source and attaches it again to the wl_data_device by calling wl_data_device_set_selection. This is problematic due to unavoidable race conditions with wl_data_source::cancelled. In GTK4, a new wl_data_source is created whenever the mime types change.
See also this issue and the linked chromium bug: https://gitlab.freedesktop.org/wayland/wayland/-/merge_requests/5
The following patch might be enough to fix the issue. I have not tested it yet:
diff --git a/gdk/wayland/gdkselection-wayland.c b/gdk/wayland/gdkselection-wayland.c
index d7f3332fa2..73f96dc27f 100644
--- a/gdk/wayland/gdkselection-wayland.c
+++ b/gdk/wayland/gdkselection-wayland.c
@@ -1774,6 +1774,12 @@ gdk_wayland_selection_add_targets (GdkWindow *window,
data_source = gdk_wayland_selection_get_data_source (window, selection);
+ if (!data_source)
+ return;
+
+ gdk_wayland_selection_unset_data_source(display, selection);
+ data_source = gdk_wayland_selection_get_data_source (window, selection);
+
if (!data_source)
return;
Edited by Julian Orth