[gtk/wip/otte/for-master: 3/3] gtk-demo: Make clipboard demo paste from clipboard
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/for-master: 3/3] gtk-demo: Make clipboard demo paste from clipboard
- Date: Thu, 19 Aug 2021 01:26:59 +0000 (UTC)
commit 6b733d294354c349b4b5ef7d689c0b2ef162f797
Author: Benjamin Otte <otte redhat com>
Date: Thu Aug 19 03:14:59 2021 +0200
gtk-demo: Make clipboard demo paste from clipboard
The old code was just pasting local clipboard data that we put there
ourselves and was causing criticals on remote clipboard data. Now the
code does the proper async paste.
demos/gtk-demo/demoimage.c | 44 +++++++++++++++++++++++++++++++++-----------
1 file changed, 33 insertions(+), 11 deletions(-)
---
diff --git a/demos/gtk-demo/demoimage.c b/demos/gtk-demo/demoimage.c
index 8fdc4257a5..dc5776cc5b 100644
--- a/demos/gtk-demo/demoimage.c
+++ b/demos/gtk-demo/demoimage.c
@@ -146,24 +146,46 @@ copy_image (GtkWidget *widget,
g_object_unref (paintable);
}
+static void
+paste_image_cb (GObject *source,
+ GAsyncResult *result,
+ gpointer data)
+{
+ GdkClipboard *clipboard = GDK_CLIPBOARD (source);
+ DemoImage *demo = DEMO_IMAGE (data);
+ const GValue *value;
+
+ value = gdk_clipboard_read_value_finish (clipboard, result, NULL);
+ if (value == NULL)
+ {
+ gtk_widget_error_bell (GTK_WIDGET (demo));
+ g_object_unref (demo);
+ return;
+ }
+
+ gtk_image_set_from_paintable (GTK_IMAGE (demo->image), g_value_get_object (value));
+ g_object_unref (demo);
+}
+
static void
paste_image (GtkWidget *widget,
const char *action_name,
GVariant *parameter)
{
GdkClipboard *clipboard = gtk_widget_get_clipboard (widget);
- DemoImage *demo = DEMO_IMAGE (widget);
- GdkContentProvider *content = gdk_clipboard_get_content (clipboard);
- GValue value = G_VALUE_INIT;
- GdkPaintable *paintable;
+ GType type;
- g_value_init (&value, GDK_TYPE_PAINTABLE);
- if (!gdk_content_provider_get_value (content, &value, NULL))
- return;
-
- paintable = GDK_PAINTABLE (g_value_get_object (&value));
- gtk_image_set_from_paintable (GTK_IMAGE (demo->image), paintable);
- g_value_unset (&value);
+ if (gdk_content_formats_contain_gtype (gdk_clipboard_get_formats (clipboard), GDK_TYPE_TEXTURE))
+ type = GDK_TYPE_TEXTURE;
+ else
+ type = GDK_TYPE_PAINTABLE;
+
+ gdk_clipboard_read_value_async (clipboard,
+ type,
+ G_PRIORITY_DEFAULT,
+ NULL,
+ paste_image_cb,
+ g_object_ref (widget));
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]