diff options
author | Victor Kareh <vkareh@redhat.com> | 2019-11-28 07:06:30 -0500 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2020-02-14 18:23:09 +0100 |
commit | 1e88c5509d371640802513ff6921276c7456435c (patch) | |
tree | 84f5831f2ce5c64c80cd3eda9a8620792cb8f0f5 | |
parent | 360ad330ed2dc4c34a40e418a2a8c642459dd4f9 (diff) | |
download | network-manager-applet-1e88c5509d371640802513ff6921276c7456435c.tar.gz |
menu-item: Render network icons as cairo surfaces
This converts menu items from GdkPixbuf to a correctly scaled
cairo_surface_t so that it can render properly on HiDPI displays. This
change only applies to the GtkStatusIcon version of nm-applet, since
appindicator icon-data is currently set to handle GdkPixbuf.
-rw-r--r-- | src/ap-menu-item.c | 29 | ||||
-rw-r--r-- | src/mb-menu-item.c | 15 |
2 files changed, 39 insertions, 5 deletions
diff --git a/src/ap-menu-item.c b/src/ap-menu-item.c index 0fdb4483..0f4d32b8 100644 --- a/src/ap-menu-item.c +++ b/src/ap-menu-item.c @@ -86,6 +86,8 @@ update_icon (NMNetworkMenuItem *item, NMApplet *applet) NMNetworkMenuItemPrivate *priv = NM_NETWORK_MENU_ITEM_GET_PRIVATE (item); gs_unref_object GdkPixbuf *icon_free = NULL, *icon_free2 = NULL; GdkPixbuf *icon; + cairo_surface_t *surface; + int icon_size, scale; const char *icon_name = NULL; if (priv->is_adhoc) @@ -93,6 +95,17 @@ update_icon (NMNetworkMenuItem *item, NMApplet *applet) else icon_name = mobile_helper_get_quality_icon_name (priv->int_strength); + scale = gtk_widget_get_scale_factor (GTK_WIDGET (item)); +#ifdef WITH_APPINDICATOR + /* Since app_indicator relies on GdkPixbuf, we should not scale it */ + if (applet->app_indicator) + icon_size = 24; + else +#endif /* WITH_APPINDICATOR */ + { + icon_size = 24 * scale; + } + icon = nma_icon_check_and_load (icon_name, applet); if (icon) { if (priv->is_encrypted) { @@ -110,11 +123,21 @@ update_icon (NMNetworkMenuItem *item, NMApplet *applet) } /* Scale to menu size if larger so the menu doesn't look awful */ - if (gdk_pixbuf_get_height (icon) > 24 || gdk_pixbuf_get_width (icon) > 24) - icon = icon_free2 = gdk_pixbuf_scale_simple (icon, 24, 24, GDK_INTERP_BILINEAR); + if (gdk_pixbuf_get_height (icon) > icon_size || gdk_pixbuf_get_width (icon) > icon_size) + icon = icon_free2 = gdk_pixbuf_scale_simple (icon, icon_size, icon_size, GDK_INTERP_BILINEAR); } - gtk_image_set_from_pixbuf (GTK_IMAGE (priv->strength), icon); +#ifdef WITH_APPINDICATOR + /* app_indicator only uses GdkPixbuf */ + if (applet->app_indicator) + gtk_image_set_from_pixbuf (GTK_IMAGE (priv->strength), icon); + else +#endif /* WITH_APPINDICATOR */ + { + surface = gdk_cairo_surface_create_from_pixbuf (icon, scale, NULL); + gtk_image_set_from_surface (GTK_IMAGE (priv->strength), surface); + cairo_surface_destroy (surface); + } } void diff --git a/src/mb-menu-item.c b/src/mb-menu-item.c index e82735b0..db802e95 100644 --- a/src/mb-menu-item.c +++ b/src/mb-menu-item.c @@ -166,8 +166,19 @@ nm_mb_menu_item_new (const char *connection_name, /* And the strength icon, if we have strength information at all */ if (enabled && strength) { const char *icon_name = mobile_helper_get_quality_icon_name (strength); - - gtk_image_set_from_pixbuf (GTK_IMAGE (priv->strength), nma_icon_check_and_load (icon_name, applet)); + GdkPixbuf *icon = nma_icon_check_and_load (icon_name, applet); +#ifdef WITH_APPINDICATOR + /* app_indicator only uses GdkPixbuf */ + if (applet->app_indicator) + gtk_image_set_from_pixbuf (GTK_IMAGE (priv->strength), icon); + else +#endif /* WITH_APPINDICATOR */ + { + int scale = gtk_widget_get_scale_factor (GTK_WIDGET (priv->strength)); + cairo_surface_t *surface = gdk_cairo_surface_create_from_pixbuf (icon, scale, NULL); + gtk_image_set_from_surface (GTK_IMAGE (priv->strength), surface); + cairo_surface_destroy (surface); + } } return GTK_WIDGET (item); |