[network-manager-applet: 1/4] menu-item: Render network icons as cairo surfaces
- From: Thomas Haller <thaller src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-applet: 1/4] menu-item: Render network icons as cairo surfaces
- Date: Fri, 14 Feb 2020 17:57:10 +0000 (UTC)
commit 1e88c5509d371640802513ff6921276c7456435c
Author: Victor Kareh <vkareh redhat com>
Date: Thu Nov 28 07:06:30 2019 -0500
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.
src/ap-menu-item.c | 29 ++++++++++++++++++++++++++---
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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]