Skip to content
Permalink
Browse files

Convert launcher icons to cairo surfaces

This improves support for HiDPI by loading properly scaled surfaces for
launcher and drawer icons.

It also Fixes the Show Desktop wncklet to show a surface icon. Other
wncklets have their icons determined by libwnck, so they remain as
pixbufs.

Fixes mate-desktop/mate-desktop#314
  • Loading branch information...
vkareh authored and raveit65 committed May 1, 2018
1 parent 6e0188b commit 5c4eb86ea1bb117805cc8fccb4ba3d96a53f2813
@@ -584,11 +584,14 @@ weather_info_setup_tooltip (WeatherInfo *info, ClockLocation *location, GtkToolt
const gchar *sys_timezone;
time_t sunrise_time, sunset_time;
gchar *sunrise_str, *sunset_str;
gint icon_scale;

icon_name = weather_info_get_icon_name (info);
theme = gtk_icon_theme_get_default ();
pixbuf = gtk_icon_theme_load_icon (theme, icon_name, 48,
GTK_ICON_LOOKUP_GENERIC_FALLBACK, NULL);
icon_name = weather_info_get_icon_name (info);
icon_scale = gdk_window_get_scale_factor (gdk_get_default_root_window ());

pixbuf = gtk_icon_theme_load_icon_for_scale (theme, icon_name, 48, icon_scale,
GTK_ICON_LOOKUP_GENERIC_FALLBACK, NULL);
if (pixbuf)
gtk_tooltip_set_icon (tooltip, pixbuf);

@@ -654,7 +657,7 @@ weather_info_setup_tooltip (WeatherInfo *info, ClockLocation *location, GtkToolt
static gboolean
weather_tooltip (GtkWidget *widget,
gint x,
gint y,
gint y,
gboolean keyboard_mode,
GtkTooltip *tooltip,
gpointer data)
@@ -681,20 +684,23 @@ update_weather_icon (ClockLocation *loc, WeatherInfo *info, gpointer data)
{
ClockLocationTile *tile = data;
ClockLocationTilePrivate *priv = PRIVATE (tile);
GdkPixbuf *pixbuf = NULL;
cairo_surface_t *surface = NULL;
GtkIconTheme *theme = NULL;
const gchar *icon_name;
gint icon_scale;

if (!info || !weather_info_is_valid (info))
return;

theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (priv->weather_icon)));
icon_name = weather_info_get_icon_name (info);
theme = gtk_icon_theme_get_default ();
pixbuf = gtk_icon_theme_load_icon (theme, icon_name, 16,
GTK_ICON_LOOKUP_GENERIC_FALLBACK, NULL);
icon_scale = gtk_widget_get_scale_factor (GTK_WIDGET (priv->weather_icon));

surface = gtk_icon_theme_load_surface (theme, icon_name, 16, icon_scale,
NULL, GTK_ICON_LOOKUP_GENERIC_FALLBACK, NULL);

if (pixbuf) {
gtk_image_set_from_pixbuf (GTK_IMAGE (priv->weather_icon), pixbuf);
if (surface) {
gtk_image_set_from_surface (GTK_IMAGE (priv->weather_icon), surface);
gtk_widget_set_margin_end (priv->weather_icon, 6);
}
}
@@ -1975,7 +1975,8 @@ location_weather_updated_cb (ClockLocation *location,
const gchar *icon_name;
const gchar *temp;
GtkIconTheme *theme;
GdkPixbuf *pixbuf;
cairo_surface_t *surface;
gint icon_size, icon_scale;

if (!info || !weather_info_is_valid (info))
return;
@@ -1984,15 +1985,23 @@ location_weather_updated_cb (ClockLocation *location,
return;

icon_name = weather_info_get_icon_name (info);
/* FIXME: mmh, screen please? Also, don't hardcode to 16 */
theme = gtk_icon_theme_get_default ();
pixbuf = gtk_icon_theme_load_icon (theme, icon_name, 16,
GTK_ICON_LOOKUP_GENERIC_FALLBACK, NULL);
if (icon_name == NULL)
return;

theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (cd->applet)));

icon_size = mate_panel_applet_get_size (MATE_PANEL_APPLET (cd->applet));
icon_scale = gtk_widget_get_scale_factor (GTK_WIDGET (cd->applet));

surface = gtk_icon_theme_load_surface (theme, icon_name, icon_size, icon_scale,
NULL, GTK_ICON_LOOKUP_GENERIC_FALLBACK, NULL);

temp = weather_info_get_temp_summary (info);

gtk_image_set_from_pixbuf (GTK_IMAGE (cd->panel_weather_icon), pixbuf);
gtk_image_set_from_surface (GTK_IMAGE (cd->panel_weather_icon), surface);
gtk_label_set_text (GTK_LABEL (cd->panel_temperature_label), temp);

cairo_surface_destroy (surface);
}

static void
@@ -134,9 +134,9 @@ static void update_icon(ShowDesktopData* sdd)
GtkStateFlags state;
GtkBorder padding;
int width, height;
GdkPixbuf* icon;
GdkPixbuf* scaled;
int icon_size;
cairo_surface_t* icon;
cairo_surface_t* scaled;
int icon_size, icon_scale;
GError* error;
int thickness = 0;

@@ -156,17 +156,24 @@ static void update_icon(ShowDesktopData* sdd)
break;
}

icon_size = sdd->size - thickness;
icon_scale = gtk_widget_get_scale_factor (sdd->button);
icon_size = sdd->size * icon_scale - thickness;

if (icon_size < 22)
icon_size = 16;
else if (icon_size < 32)
else if (icon_size < 24)
icon_size = 22;
else if (icon_size < 32)
icon_size = 24;
else if (icon_size < 48)
icon_size = 32;
else if (icon_size < 64)
icon_size = 48;
else if (icon_size < 128)
icon_size = 64;

error = NULL;
icon = gtk_icon_theme_load_icon (sdd->icon_theme, SHOW_DESKTOP_ICON, icon_size, 0, &error);
icon = gtk_icon_theme_load_surface (sdd->icon_theme, SHOW_DESKTOP_ICON, icon_size, icon_scale, NULL, 0, &error);

if (icon == NULL)
{
@@ -182,37 +189,45 @@ static void update_icon(ShowDesktopData* sdd)
return;
}

width = gdk_pixbuf_get_width(icon);
height = gdk_pixbuf_get_height(icon);
width = cairo_image_surface_get_width (icon);
height = cairo_image_surface_get_height (icon);

scaled = NULL;

/* Make it fit on the given panel */
switch (sdd->orient)
{
case GTK_ORIENTATION_HORIZONTAL:
width = (icon_size * width) / height;
height = icon_size;
width = (icon_size / icon_scale * width) / height;
height = icon_size / icon_scale;
break;
case GTK_ORIENTATION_VERTICAL:
height = (icon_size * height) / width;
width = icon_size;
height = (icon_size / icon_scale * height) / width;
width = icon_size / icon_scale;
break;
}

scaled = gdk_pixbuf_scale_simple(icon, width, height, GDK_INTERP_BILINEAR);
scaled = cairo_surface_create_similar (icon,
cairo_surface_get_content (icon),
width,
height);

if (scaled != NULL)
{
gtk_image_set_from_pixbuf(GTK_IMAGE(sdd->image), scaled);
g_object_unref(scaled);
cairo_t *cr;
cr = cairo_create (scaled);
cairo_scale (cr, (double) width / icon_size, (double) height / icon_size);
cairo_set_source_surface (cr, icon, 0, 0);
cairo_paint (cr);
gtk_image_set_from_surface (GTK_IMAGE(sdd->image), scaled);
cairo_surface_destroy (scaled);
}
else
{
gtk_image_set_from_pixbuf (GTK_IMAGE (sdd->image), icon);
gtk_image_set_from_surface (GTK_IMAGE (sdd->image), icon);
}

g_object_unref (icon);
cairo_surface_destroy (icon);
}

static const GtkActionEntry show_desktop_menu_actions[] = {
Oops, something went wrong.

0 comments on commit 5c4eb86

Please sign in to comment.
You can’t perform that action at this time.