From eca445672a48ac4a870790efa63339f8d974c2fd Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Wed, 7 Dec 2022 00:35:37 +0100 Subject: [PATCH] gdk/wayland: Convert selection mimetypes back to atoms, if needed Commit 0c1ea922197 took care of converting STRING/UTF8_STRING to mimetype strings when letting selection targets known to the outer world through wl_data_source/zwp_primary_selection_source_v1, but it missed the conversion of those mimetypes back to the old atom strings, depending on the application, the mimetype counterparts might not be known or handled, so requests to paste from this app could go ignored. Fixes: 0c1ea922197 - wayland: Translate STRING/UTF8_STRING selection atoms to mimetypes Closes: https://gitlab.gnome.org/GNOME/gtk/-/issues/5397 --- gdk/wayland/gdkselection-wayland.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/gdk/wayland/gdkselection-wayland.c b/gdk/wayland/gdkselection-wayland.c index 6fbdb5e50d..656e3e67da 100644 --- a/gdk/wayland/gdkselection-wayland.c +++ b/gdk/wayland/gdkselection-wayland.c @@ -941,20 +941,41 @@ gdk_wayland_selection_lookup_requestor_buffer (GdkWindow *requestor) static gboolean gdk_wayland_selection_source_handles_target (GdkWaylandSelection *wayland_selection, - GdkAtom target) + GdkAtom *target) { GdkAtom atom; + GdkAtom string_atom, utf8_string_atom; + GdkAtom string_mimetype, utf8_string_mimetype; guint i; - if (target == GDK_NONE) + if (*target == GDK_NONE) return FALSE; + string_atom = gdk_atom_intern ("STRING", FALSE); + utf8_string_atom = gdk_atom_intern ("UTF8_STRING", FALSE); + string_mimetype = gdk_atom_intern (STRING_MIMETYPE, FALSE); + utf8_string_mimetype = gdk_atom_intern (UTF8_STRING_MIMETYPE, FALSE); + for (i = 0; i < wayland_selection->source_targets->len; i++) { atom = g_array_index (wayland_selection->source_targets, GdkAtom, i); - if (atom == target) + if (atom == *target) return TRUE; + + /* We might have converted (UTF8_)STRING to mimetypes when issuing + * the source.target requests, convert them back if needed. + */ + if (atom == string_atom && *target == string_mimetype) + { + *target = string_atom; + return TRUE; + } + else if (atom == utf8_string_atom && *target == utf8_string_mimetype) + { + *target = utf8_string_atom; + return TRUE; + } } return FALSE; @@ -993,7 +1014,7 @@ gdk_wayland_selection_request_target (GdkWaylandSelection *wayland_selection, AsyncWriteData *write_data; if (!window || - !gdk_wayland_selection_source_handles_target (wayland_selection, target)) + !gdk_wayland_selection_source_handles_target (wayland_selection, &target)) { close (fd); return FALSE;