From a37044f36cd9421d7deb66f7c8d1253f774f044b Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 7 Feb 2021 01:30:50 -0500 Subject: [PATCH 1/3] x11: Some code cleanups Fix some glaring misindentation. --- gdk/x11/gdkdrag-x11.c | 52 +++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/gdk/x11/gdkdrag-x11.c b/gdk/x11/gdkdrag-x11.c index 606cef0f0c..c0706cbe74 100644 --- a/gdk/x11/gdkdrag-x11.c +++ b/gdk/x11/gdkdrag-x11.c @@ -1334,7 +1334,7 @@ _gdk_x11_display_get_drag_protocol (GdkDisplay *display, static GdkSurfaceCache * drag_find_window_cache (GdkX11Drag *drag_x11, - GdkDisplay *display) + GdkDisplay *display) { if (!drag_x11->cache) drag_x11->cache = gdk_surface_cache_get (display); @@ -1365,7 +1365,7 @@ gdk_x11_drag_find_surface (GdkDrag *drag, drag_surface && GDK_IS_X11_SURFACE (drag_surface) ? GDK_SURFACE_XID (drag_surface) : None, x_root * screen_x11->surface_scale, - y_root * screen_x11->surface_scale); + y_root * screen_x11->surface_scale); if (drag_x11->dest_xid != dest) { @@ -1395,8 +1395,8 @@ gdk_x11_drag_find_surface (GdkDrag *drag, static void move_drag_surface (GdkDrag *drag, - guint x_root, - guint y_root) + guint x_root, + guint y_root) { GdkX11Drag *drag_x11 = GDK_X11_DRAG (drag); @@ -1407,14 +1407,14 @@ move_drag_surface (GdkDrag *drag, } static gboolean -gdk_x11_drag_drag_motion (GdkDrag *drag, - Window proxy_xid, - GdkDragProtocol protocol, - int x_root, - int y_root, - GdkDragAction suggested_action, - GdkDragAction possible_actions, - guint32 time) +gdk_x11_drag_drag_motion (GdkDrag *drag, + Window proxy_xid, + GdkDragProtocol protocol, + int x_root, + int y_root, + GdkDragAction suggested_action, + GdkDragAction possible_actions, + guint32 time) { GdkX11Drag *drag_x11 = GDK_X11_DRAG (drag); @@ -1606,8 +1606,8 @@ gdk_x11_drag_get_drag_surface (GdkDrag *drag) static void gdk_x11_drag_set_hotspot (GdkDrag *drag, - int hot_x, - int hot_y) + int hot_x, + int hot_y) { GdkX11Drag *x11_drag = GDK_X11_DRAG (drag); @@ -1623,8 +1623,8 @@ gdk_x11_drag_set_hotspot (GdkDrag *drag, static void gdk_x11_drag_default_output_done (GObject *drag, - GAsyncResult *result, - gpointer user_data) + GAsyncResult *result, + gpointer user_data) { GError *error = NULL; @@ -1636,17 +1636,17 @@ gdk_x11_drag_default_output_done (GObject *drag, } static void -gdk_x11_drag_default_output_handler (GOutputStream *stream, - const char *mime_type, - gpointer user_data) +gdk_x11_drag_default_output_handler (GOutputStream *stream, + const char *mime_type, + gpointer user_data) { gdk_drag_write_async (GDK_DRAG (user_data), - mime_type, - stream, - G_PRIORITY_DEFAULT, - NULL, - gdk_x11_drag_default_output_done, - NULL); + mime_type, + stream, + G_PRIORITY_DEFAULT, + NULL, + gdk_x11_drag_default_output_done, + NULL); g_object_unref (stream); } @@ -1675,7 +1675,7 @@ gdk_x11_drag_xevent (GdkDisplay *display, if (xevent->xselectionclear.time < x11_drag->timestamp) { GDK_DISPLAY_NOTE (display, CLIPBOARD, g_printerr ("ignoring SelectionClear with too old timestamp (%lu vs %lu)\n", - xevent->xselectionclear.time, x11_drag->timestamp)); + xevent->xselectionclear.time, x11_drag->timestamp)); return FALSE; } From f26f15fcedef760d7dd3612859a5fc73dcb3160e Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 7 Feb 2021 01:31:40 -0500 Subject: [PATCH 2/3] x11: Fix a memory leak We ref the content formats here, so we better unref it when done. --- gdk/x11/gdkdrag-x11.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gdk/x11/gdkdrag-x11.c b/gdk/x11/gdkdrag-x11.c index c0706cbe74..00e9a104ab 100644 --- a/gdk/x11/gdkdrag-x11.c +++ b/gdk/x11/gdkdrag-x11.c @@ -1095,6 +1095,8 @@ xdnd_send_enter (GdkX11Drag *drag_x11) } xdnd_send_xevent (drag_x11, &xev); + + gdk_content_formats_unref (formats); } static void From 5b45f267d65419869608693499a78e9fe288bde5 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 7 Feb 2021 01:32:39 -0500 Subject: [PATCH 3/3] x11: Pass mimetypes when creating output stream When creating the output stream for a drop, we must pass the mimetypes we support, otherwise the picking of the right handler does not work. Fixes: #3652 --- gdk/x11/gdkdrag-x11.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/gdk/x11/gdkdrag-x11.c b/gdk/x11/gdkdrag-x11.c index 00e9a104ab..05e1c58377 100644 --- a/gdk/x11/gdkdrag-x11.c +++ b/gdk/x11/gdkdrag-x11.c @@ -1687,6 +1687,7 @@ gdk_x11_drag_xevent (GdkDisplay *display, case SelectionRequest: { + GdkContentFormats *formats; #ifdef G_ENABLE_DEBUG const char *target, *property; #endif @@ -1705,23 +1706,30 @@ gdk_x11_drag_xevent (GdkDisplay *display, if (xevent->xselectionrequest.requestor == None) { GDK_DISPLAY_NOTE (display, CLIPBOARD, g_printerr ("got SelectionRequest for %s @ %s with NULL window, ignoring\n", - target, property)); + target, property)); return TRUE; } GDK_DISPLAY_NOTE (display, CLIPBOARD, g_printerr ("got SelectionRequest for %s @ %s\n", - target, property)); + target, property)); + + formats = gdk_content_formats_ref (gdk_drag_get_formats (drag)); + formats = gdk_content_formats_union_serialize_mime_types (formats); gdk_x11_selection_output_streams_create (display, - gdk_drag_get_formats (drag), + formats, xevent->xselectionrequest.requestor, xevent->xselectionrequest.selection, xevent->xselectionrequest.target, - xevent->xselectionrequest.property ? xevent->xselectionrequest.property - : xevent->xselectionrequest.target, + xevent->xselectionrequest.property + ? xevent->xselectionrequest.property + : xevent->xselectionrequest.target, xevent->xselectionrequest.time, gdk_x11_drag_default_output_handler, drag); + + gdk_content_formats_unref (formats); + return TRUE; }