From 59a697f773e856776887c6e11e452fe4b2cefed0 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Thu, 10 Oct 2019 12:16:58 +0200 Subject: [PATCH] x11: Translate well known selection atoms to mimetypes Some antediluvian x11 clients only bother to set atoms like UTF8_STRING/STRING/TEXT/... and no matching mimetypes. Cover for them and add the well known mimetypes if they are missing. Reported at https://bugzilla.redhat.com/show_bug.cgi?id=1758873 https://gitlab.gnome.org/GNOME/mutter/merge_requests/842 --- src/x11/meta-selection-source-x11.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/x11/meta-selection-source-x11.c b/src/x11/meta-selection-source-x11.c index 15a763651..1a0369ab0 100644 --- a/src/x11/meta-selection-source-x11.c +++ b/src/x11/meta-selection-source-x11.c @@ -139,6 +139,8 @@ atoms_to_mimetypes (MetaX11Display *display, const Atom *atoms; gsize size; guint i, n_atoms; + gboolean utf8_string_found = FALSE, utf8_text_plain_found = FALSE; + gboolean string_found = FALSE, text_plain_found = FALSE; atoms = g_bytes_get_data (bytes, &size); n_atoms = size / sizeof (Atom); @@ -149,8 +151,19 @@ atoms_to_mimetypes (MetaX11Display *display, mimetype = gdk_x11_get_xatom_name (atoms[i]); mimetypes = g_list_prepend (mimetypes, g_strdup (mimetype)); + + utf8_text_plain_found |= strcmp (mimetype, "text/plain;charset=utf-8") == 0; + text_plain_found |= strcmp (mimetype, "text/plain") == 0; + utf8_string_found |= strcmp (mimetype, "UTF8_STRING") == 0; + string_found |= strcmp (mimetype, "STRING") == 0; } + /* Ensure non-x11 clients get well-known mimetypes */ + if (string_found && !text_plain_found) + mimetypes = g_list_prepend (mimetypes, g_strdup ("text/plain")); + if (utf8_string_found && !utf8_text_plain_found) + mimetypes = g_list_prepend (mimetypes, g_strdup ("text/plain;charset=utf-8")); + return mimetypes; }