x11: Explicitly close_async() the output stream
authorBenjamin Otte <otte@redhat.com>
Mon, 13 Dec 2021 00:43:24 +0000 (01:43 +0100)
committerBenjamin Otte <otte@redhat.com>
Mon, 13 Dec 2021 00:51:35 +0000 (01:51 +0100)
We need to be very careful when writing data, because if we aren't, sync
functions will be called on the output stream and X11 does not like that
at all.

gdk/x11/gdkclipboard-x11.c
gdk/x11/gdkdrag-x11.c

index 404c8c7cd6f933e1174f17845327f42876c7d2d1..4335674102834982e6b949897ad8754f6cab7d31 100644 (file)
@@ -76,11 +76,30 @@ print_atoms (GdkX11Clipboard *cb,
   });
 }
 
+static void
+gdk_x11_clipboard_default_output_closed (GObject      *stream,
+                                         GAsyncResult *result,
+                                         gpointer      user_data)
+{
+  GError *error = NULL;
+
+  if (!g_output_stream_close_finish (G_OUTPUT_STREAM (stream), result, &error))
+    {
+      GDK_NOTE (CLIPBOARD,
+                g_printerr ("-------: failed to close stream: %s\n",
+                            error->message));
+      g_error_free (error);
+    }
+
+  g_object_unref (stream);
+}
+
 static void
 gdk_x11_clipboard_default_output_done (GObject      *clipboard,
                                        GAsyncResult *result,
                                        gpointer      user_data)
 {
+  GOutputStream *stream = user_data;
   GError *error = NULL;
 
   if (!gdk_clipboard_write_finish (GDK_CLIPBOARD (clipboard), result, &error))
@@ -90,6 +109,12 @@ gdk_x11_clipboard_default_output_done (GObject      *clipboard,
                             GDK_X11_CLIPBOARD (clipboard)->selection, error->message));
       g_error_free (error);
     }
+
+  g_output_stream_close_async (stream,
+                               G_PRIORITY_DEFAULT,
+                               NULL, 
+                               gdk_x11_clipboard_default_output_closed,
+                               NULL);
 }
 
 static void
@@ -103,8 +128,7 @@ gdk_x11_clipboard_default_output_handler (GOutputStream   *stream,
                              G_PRIORITY_DEFAULT,
                              NULL,
                              gdk_x11_clipboard_default_output_done,
-                             NULL);
-  g_object_unref (stream);
+                             stream);
 }
 
 static GInputStream * 
index 5804085a5694e3101956277bf355923ef8a776e2..7e7904904b7219b8de24ed45d34c27ea5837f157 100644 (file)
@@ -1612,11 +1612,30 @@ gdk_x11_drag_set_hotspot (GdkDrag *drag,
     }
 }
 
+static void
+gdk_x11_drag_default_output_closed (GObject      *stream,
+                                    GAsyncResult *result,
+                                    gpointer      user_data)
+{
+  GError *error = NULL;
+
+  if (!g_output_stream_close_finish (G_OUTPUT_STREAM (stream), result, &error))
+    {
+      GDK_NOTE (DND,
+                g_printerr ("failed to close stream: %s\n",
+                            error->message));
+      g_error_free (error);
+    }
+
+  g_object_unref (stream);
+}
+
 static void
 gdk_x11_drag_default_output_done (GObject      *drag,
                                   GAsyncResult *result,
                                   gpointer      user_data)
 {
+  GOutputStream *stream = user_data;
   GError *error = NULL;
 
   if (!gdk_drag_write_finish (GDK_DRAG (drag), result, &error))
@@ -1624,6 +1643,12 @@ gdk_x11_drag_default_output_done (GObject      *drag,
       GDK_DISPLAY_NOTE (gdk_drag_get_display (GDK_DRAG (drag)), DND, g_printerr ("failed to write stream: %s\n", error->message));
       g_error_free (error);
     }
+
+  g_output_stream_close_async (stream,
+                               G_PRIORITY_DEFAULT,
+                               NULL, 
+                               gdk_x11_drag_default_output_closed,
+                               NULL);
 }
 
 static void
@@ -1637,8 +1662,7 @@ gdk_x11_drag_default_output_handler (GOutputStream *stream,
                         G_PRIORITY_DEFAULT,
                         NULL,
                         gdk_x11_drag_default_output_done,
-                        NULL);
-  g_object_unref (stream);
+                        stream);
 }
 
 static gboolean