From ea056d261fdf5d2a2d242efd9f2e77eb57c88bca Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Wed, 14 Dec 2022 02:26:49 +0100 Subject: [PATCH] contentserializer: Serialize to file:// if possible Try to get a native file:// URI instead of any other GVFS scheme, for interoperability with apps only handling file:// URIs. This is what GTK3 Nautilus and Thunar do, so apps should be tuned for this behavior. See also https://bugzilla.xfce.org/show_bug.cgi?id=13845 Fixes: #5422 --- gdk/gdkcontentserializer.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/gdk/gdkcontentserializer.c b/gdk/gdkcontentserializer.c index 2ffbbf5ae5..da9f668d8c 100644 --- a/gdk/gdkcontentserializer.c +++ b/gdk/gdkcontentserializer.c @@ -795,6 +795,22 @@ file_serializer_finish (GObject *source, gdk_content_serializer_return_success (serializer); } +static char * +file_get_native_uri (GFile *file) +{ + char *path; + + path = g_file_get_path (file); + if (path != NULL) + { + char *uri = g_filename_to_uri (path, NULL, NULL); + g_free (path); + return uri; + } + + return g_file_get_uri (file); +} + static void file_uri_serializer (GdkContentSerializer *serializer) { @@ -811,7 +827,7 @@ file_uri_serializer (GdkContentSerializer *serializer) file = g_value_get_object (gdk_content_serializer_get_value (serializer)); if (file) { - uri = g_file_get_uri (file); + uri = file_get_native_uri (file); g_string_append (str, uri); g_free (uri); } @@ -827,7 +843,7 @@ file_uri_serializer (GdkContentSerializer *serializer) for (l = g_value_get_boxed (value); l; l = l->next) { - uri = g_file_get_uri (l->data); + uri = file_get_native_uri (l->data); g_string_append (str, uri); g_free (uri); g_string_append (str, "\r\n");