Merge branch 'clipboard-demo-improvements' into 'main'

gtk-demo: Small followup fixes

See merge request GNOME/gtk!4239
This commit is contained in:
Matthias Clasen 2021-12-12 18:58:07 +00:00
commit eadc94e0a1
2 changed files with 20 additions and 6 deletions

View File

@ -35,7 +35,12 @@ copy_button_clicked (GtkStack *source_stack,
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (child))) if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (child)))
{ {
GtkWidget *image = gtk_widget_get_first_child (child); GtkWidget *image = gtk_widget_get_first_child (child);
gdk_clipboard_set (clipboard, GDK_TYPE_PAINTABLE, gtk_image_get_paintable (GTK_IMAGE (image))); GdkPaintable *paintable = gtk_image_get_paintable (GTK_IMAGE (image));
if (GDK_IS_TEXTURE (paintable))
gdk_clipboard_set (clipboard, GDK_TYPE_TEXTURE, paintable);
else
gdk_clipboard_set (clipboard, GDK_TYPE_PAINTABLE, paintable);
break; break;
} }
} }
@ -93,7 +98,8 @@ paste_received (GObject *source_object,
color = g_value_get_boxed (value); color = g_value_get_boxed (value);
g_object_set (child, "rgba", color, NULL); g_object_set (child, "rgba", color, NULL);
} }
else if (G_VALUE_HOLDS (value, GDK_TYPE_PAINTABLE)) else if (G_VALUE_HOLDS (value, GDK_TYPE_TEXTURE) ||
G_VALUE_HOLDS (value, GDK_TYPE_PAINTABLE))
{ {
GdkPaintable *paintable; GdkPaintable *paintable;
@ -128,12 +134,14 @@ paste_button_clicked (GtkStack *dest_stack,
clipboard = gtk_widget_get_clipboard (GTK_WIDGET (dest_stack)); clipboard = gtk_widget_get_clipboard (GTK_WIDGET (dest_stack));
formats = gdk_clipboard_get_formats (clipboard); formats = gdk_clipboard_get_formats (clipboard);
if (gdk_content_formats_contain_gtype (formats, G_TYPE_FILE)) if (gdk_content_formats_contain_gtype (formats, GDK_TYPE_TEXTURE))
gdk_clipboard_read_value_async (clipboard, G_TYPE_FILE, 0, NULL, paste_received, dest_stack); gdk_clipboard_read_value_async (clipboard, GDK_TYPE_TEXTURE, 0, NULL, paste_received, dest_stack);
else if (gdk_content_formats_contain_gtype (formats, GDK_TYPE_RGBA))
gdk_clipboard_read_value_async (clipboard, GDK_TYPE_RGBA, 0, NULL, paste_received, dest_stack);
else if (gdk_content_formats_contain_gtype (formats, GDK_TYPE_PAINTABLE)) else if (gdk_content_formats_contain_gtype (formats, GDK_TYPE_PAINTABLE))
gdk_clipboard_read_value_async (clipboard, GDK_TYPE_PAINTABLE, 0, NULL, paste_received, dest_stack); gdk_clipboard_read_value_async (clipboard, GDK_TYPE_PAINTABLE, 0, NULL, paste_received, dest_stack);
else if (gdk_content_formats_contain_gtype (formats, GDK_TYPE_RGBA))
gdk_clipboard_read_value_async (clipboard, GDK_TYPE_RGBA, 0, NULL, paste_received, dest_stack);
else if (gdk_content_formats_contain_gtype (formats, G_TYPE_FILE))
gdk_clipboard_read_value_async (clipboard, G_TYPE_FILE, 0, NULL, paste_received, dest_stack);
else if (gdk_content_formats_contain_gtype (formats, G_TYPE_STRING)) else if (gdk_content_formats_contain_gtype (formats, G_TYPE_STRING))
gdk_clipboard_read_value_async (clipboard, G_TYPE_STRING, 0, NULL, paste_received, dest_stack); gdk_clipboard_read_value_async (clipboard, G_TYPE_STRING, 0, NULL, paste_received, dest_stack);
} }
@ -240,6 +248,7 @@ update_paste_button_sensitivity (GdkClipboard *clipboard,
if (gdk_content_formats_contain_gtype (formats, G_TYPE_FILE) || if (gdk_content_formats_contain_gtype (formats, G_TYPE_FILE) ||
gdk_content_formats_contain_gtype (formats, GDK_TYPE_RGBA) || gdk_content_formats_contain_gtype (formats, GDK_TYPE_RGBA) ||
gdk_content_formats_contain_gtype (formats, GDK_TYPE_TEXTURE) ||
gdk_content_formats_contain_gtype (formats, GDK_TYPE_PAINTABLE) || gdk_content_formats_contain_gtype (formats, GDK_TYPE_PAINTABLE) ||
gdk_content_formats_contain_gtype (formats, G_TYPE_STRING)) gdk_content_formats_contain_gtype (formats, G_TYPE_STRING))
sensitive = TRUE; sensitive = TRUE;

View File

@ -180,6 +180,7 @@
<child> <child>
<object class="GtkStack" id="dest_stack"> <object class="GtkStack" id="dest_stack">
<property name="halign">end</property> <property name="halign">end</property>
<property name="valign">center</property>
<child> <child>
<object class="GtkStackPage"> <object class="GtkStackPage">
<property name="name"></property> <property name="name"></property>
@ -195,6 +196,7 @@
<property name="child"> <property name="child">
<object class="GtkLabel"> <object class="GtkLabel">
<property name="halign">end</property> <property name="halign">end</property>
<property name="valign">center</property>
<property name="xalign">0</property> <property name="xalign">0</property>
<property name="ellipsize">end</property> <property name="ellipsize">end</property>
</object> </object>
@ -207,6 +209,7 @@
<property name="child"> <property name="child">
<object class="GtkImage"> <object class="GtkImage">
<property name="halign">end</property> <property name="halign">end</property>
<property name="valign">center</property>
<style> <style>
<class name="large-icons"/> <class name="large-icons"/>
</style> </style>
@ -220,6 +223,7 @@
<property name="child"> <property name="child">
<object class="GtkBox"> <object class="GtkBox">
<property name="halign">end</property> <property name="halign">end</property>
<property name="valign">center</property>
<child> <child>
<object class="GtkColorSwatch"> <object class="GtkColorSwatch">
<property name="accessible-role">img</property> <property name="accessible-role">img</property>
@ -238,6 +242,7 @@
<property name="child"> <property name="child">
<object class="GtkLabel"> <object class="GtkLabel">
<property name="halign">end</property> <property name="halign">end</property>
<property name="valign">center</property>
<property name="xalign">0</property> <property name="xalign">0</property>
<property name="hexpand">1</property> <property name="hexpand">1</property>
<property name="ellipsize">start</property> <property name="ellipsize">start</property>