Convert trivial users of icon theme loading to use info as paintable

This commit is contained in:
Alexander Larsson 2020-01-27 15:40:58 +01:00
parent aefd8443de
commit c42977af04
6 changed files with 18 additions and 30 deletions

View File

@ -110,7 +110,7 @@ get_image_paintable (GtkImage *image)
icon_info = gtk_icon_theme_lookup_icon (icon_theme, icon_name, 48, GTK_ICON_LOOKUP_GENERIC_FALLBACK); icon_info = gtk_icon_theme_lookup_icon (icon_theme, icon_name, 48, GTK_ICON_LOOKUP_GENERIC_FALLBACK);
if (icon_info == NULL) if (icon_info == NULL)
return NULL; return NULL;
return gtk_icon_info_load_icon (icon_info, NULL); return GDK_PAINTABLE (icon_info);
default: default:
g_warning ("Image storage type %d not handled", g_warning ("Image storage type %d not handled",
gtk_image_get_storage_type (image)); gtk_image_get_storage_type (image));

View File

@ -363,7 +363,7 @@ get_image_paintable (GtkImage *image)
GTK_ICON_LOOKUP_FORCE_SIZE | GTK_ICON_LOOKUP_GENERIC_FALLBACK); GTK_ICON_LOOKUP_FORCE_SIZE | GTK_ICON_LOOKUP_GENERIC_FALLBACK);
if (icon_info == NULL) if (icon_info == NULL)
return NULL; return NULL;
return gtk_icon_info_load_icon (icon_info, NULL); return GDK_PAINTABLE (icon_info);
default: default:
g_warning ("Image storage type %d not handled", g_warning ("Image storage type %d not handled",
gtk_image_get_storage_type (image)); gtk_image_get_storage_type (image));

View File

@ -2585,7 +2585,7 @@ gtk_calendar_drag_update (GtkGestureDrag *gesture,
GdkDevice *device; GdkDevice *device;
GdkDrag *drag; GdkDrag *drag;
GtkIconTheme *theme; GtkIconTheme *theme;
GdkPaintable *paintable; GtkIconInfo *icon;
GdkSurface *surface; GdkSurface *surface;
if (!priv->in_drag) if (!priv->in_drag)
@ -2604,9 +2604,9 @@ gtk_calendar_drag_update (GtkGestureDrag *gesture,
drag = gdk_drag_begin (surface, device, content, GDK_ACTION_COPY, start_x, start_y); drag = gdk_drag_begin (surface, device, content, GDK_ACTION_COPY, start_x, start_y);
theme = gtk_icon_theme_get_for_display (gtk_widget_get_display (widget)); theme = gtk_icon_theme_get_for_display (gtk_widget_get_display (widget));
paintable = gtk_icon_theme_load_icon (theme, "text-x-generic", 32, 0, NULL); icon = gtk_icon_theme_lookup_icon (theme, "text-x-generic", 32, 0);
gtk_drag_icon_set_from_paintable (drag, paintable, 0, 0); gtk_drag_icon_set_from_paintable (drag, GDK_PAINTABLE (icon), 0, 0);
g_clear_object (&paintable); g_clear_object (&icon);
g_object_unref (content); g_object_unref (content);
g_object_unref (drag); g_object_unref (drag);

View File

@ -484,9 +484,9 @@ gtk_drag_source_drag_begin (GtkDragSource *source)
if (!source->paintable) if (!source->paintable)
{ {
GtkIconTheme *theme; GtkIconTheme *theme;
theme = gtk_icon_theme_get_for_display (gtk_widget_get_display (widget)); theme = gtk_icon_theme_get_for_display (gtk_widget_get_display (widget));
source->paintable = gtk_icon_theme_load_icon (theme, "text-x-generic", 32, 0, NULL); source->paintable = GDK_PAINTABLE(gtk_icon_theme_lookup_icon (theme, "text-x-generic", 32, 0));
source->hot_x = 0; source->hot_x = 0;
source->hot_y = 0; source->hot_y = 0;
} }

View File

@ -4102,7 +4102,6 @@ gtk_window_get_icon_for_size (GtkWindow *window,
{ {
const char *name; const char *name;
GtkIconInfo *info; GtkIconInfo *info;
GdkPaintable *paintable;
name = gtk_window_get_icon_name (window); name = gtk_window_get_icon_name (window);
@ -4117,10 +4116,7 @@ gtk_window_get_icon_for_size (GtkWindow *window,
if (info == NULL) if (info == NULL)
return NULL; return NULL;
paintable = gtk_icon_info_load_icon (info, NULL); return GDK_PAINTABLE (info);
g_object_unref (info);
return paintable;
} }
static void static void

View File

@ -90,8 +90,7 @@ main (int argc, char *argv[])
if (strcmp (argv[1], "display") == 0) if (strcmp (argv[1], "display") == 0)
{ {
GError *error; GtkIconInfo *icon;
GdkPaintable *paintable;
GtkWidget *window, *image; GtkWidget *window, *image;
if (argc < 4) if (argc < 4)
@ -107,22 +106,21 @@ main (int argc, char *argv[])
if (argc >= 6) if (argc >= 6)
scale = atoi (argv[5]); scale = atoi (argv[5]);
error = NULL; icon = gtk_icon_theme_lookup_icon_for_scale (icon_theme, argv[3], size, scale, flags);
paintable = gtk_icon_theme_load_icon_for_scale (icon_theme, argv[3], size, scale, flags, &error); if (!icon)
if (!paintable)
{ {
g_print ("%s\n", error->message); g_print ("Icon '%s' not found\n", argv[3]);
return 1; return 1;
} }
window = gtk_window_new (GTK_WINDOW_TOPLEVEL); window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
image = gtk_image_new (); image = gtk_image_new ();
gtk_image_set_from_paintable (GTK_IMAGE (image), paintable); gtk_image_set_from_paintable (GTK_IMAGE (image), GDK_PAINTABLE (icon));
g_object_unref (paintable); g_object_unref (icon);
gtk_container_add (GTK_CONTAINER (window), image); gtk_container_add (GTK_CONTAINER (window), image);
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
gtk_widget_show (window); gtk_widget_show (window);
gtk_main (); gtk_main ();
} }
else if (strcmp (argv[1], "display-async") == 0) else if (strcmp (argv[1], "display-async") == 0)
@ -199,16 +197,10 @@ main (int argc, char *argv[])
if (icon_info) if (icon_info)
{ {
GdkTexture *texture; GdkPaintable *paintable = GDK_PAINTABLE (icon_info);
g_print ("Base size: %d, Scale: %d\n", gtk_icon_info_get_base_size (icon_info), gtk_icon_info_get_base_scale (icon_info)); g_print ("Base size: %d, Scale: %d\n", gtk_icon_info_get_base_size (icon_info), gtk_icon_info_get_base_scale (icon_info));
g_print ("texture size: %dx%d\n", gdk_paintable_get_intrinsic_width (paintable), gdk_paintable_get_intrinsic_height (paintable));
texture = GDK_TEXTURE (gtk_icon_info_load_icon (icon_info, NULL));
if (texture != NULL)
{
g_print ("texture size: %dx%d\n", gdk_texture_get_width (texture), gdk_texture_get_height (texture));
g_object_unref (texture);
}
g_object_unref (icon_info); g_object_unref (icon_info);
} }