statusicon: Render as cairo surface

On HiDPI displays, rendering Status Icons as pixbufs results in blurry
icons. By loading them at scale and rendering as a surface, we preserve
both their size and sharpness.
This commit is contained in:
Victor Kareh 2019-10-16 14:40:44 -04:00
parent 9e72ec1c8a
commit 1c09104dc6

View File

@ -1398,13 +1398,16 @@ gtk_status_icon_update_image (GtkStatusIcon *status_icon)
GtkIconHelper *icon_helper;
cairo_surface_t *surface;
GtkWidget *widget;
GdkPixbuf *pixbuf;
GdkPixbuf *pixbuf = NULL;
gint round_size;
gint scale;
#ifdef GDK_WINDOWING_X11
widget = priv->image;
scale = gtk_widget_get_scale_factor (widget);
#else
widget = priv->dummy_widget;
scale = 1;
#endif
if (widget == NULL)
@ -1417,23 +1420,28 @@ gtk_status_icon_update_image (GtkStatusIcon *status_icon)
_gtk_icon_helper_set_definition (icon_helper, priv->image_def);
_gtk_icon_helper_set_icon_size (icon_helper, GTK_ICON_SIZE_SMALL_TOOLBAR);
_gtk_icon_helper_set_pixel_size (icon_helper, round_size);
surface = gtk_icon_helper_load_surface (icon_helper, 1);
surface = gtk_icon_helper_load_surface (icon_helper, scale);
if (surface)
{
#ifdef GDK_WINDOWING_X11
gtk_image_set_from_surface (GTK_IMAGE (priv->image), surface);
#else
pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0,
cairo_image_surface_get_width (surface),
cairo_image_surface_get_height (surface));
#endif
cairo_surface_destroy (surface);
}
else
pixbuf = NULL;
{
#ifdef GDK_WINDOWING_X11
gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), NULL);
#endif
}
g_object_unref (icon_helper);
if (pixbuf != NULL)
{
#ifdef GDK_WINDOWING_X11
gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), pixbuf);
#endif
#ifdef GDK_WINDOWING_WIN32
prev_hicon = priv->nid.hIcon;
priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (pixbuf);
@ -1452,9 +1460,6 @@ gtk_status_icon_update_image (GtkStatusIcon *status_icon)
}
else
{
#ifdef GDK_WINDOWING_X11
gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), NULL);
#endif
#ifdef GDK_WINDOWING_WIN32
priv->nid.uFlags &= ~NIF_ICON;
if (priv->nid.hWnd != NULL && priv->visible)