[Xfce4-commits] [xfce/xfce4-session] 02/02: Set logout dialog icons from icon_name

noreply at xfce.org noreply at xfce.org
Sun Apr 28 21:54:57 CEST 2019


This is an automated email from the git hooks/post-receive script.

o   c   h   o   s   i       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository xfce/xfce4-session.

commit 6503852633080caf20905d3a343e099b3457129f
Author: Simon Steinbeiss <simon.steinbeiss at elfenbeinturm.at>
Date:   Sun Apr 28 21:52:48 2019 +0200

    Set logout dialog icons from icon_name
    
    Using pixbufs results in unreliable sizing. While the icon may be
    present in the icon theme, the pixbuf may be in a different size from
    what was defined in the code (32px) and the pixbuf isn't scaled down
    (which would anyway look ugly).
    So the (correct) alternative approach is to use icon names instead and
    check in the icon theme if the icon is present.
---
 xfce4-session/xfsm-logout-dialog.c | 36 +++++++++---------------------------
 1 file changed, 9 insertions(+), 27 deletions(-)

diff --git a/xfce4-session/xfsm-logout-dialog.c b/xfce4-session/xfsm-logout-dialog.c
index 949307d..724f16a 100644
--- a/xfce4-session/xfsm-logout-dialog.c
+++ b/xfce4-session/xfsm-logout-dialog.c
@@ -502,11 +502,8 @@ xfsm_logout_dialog_button (const gchar      *title,
 {
   GtkWidget    *button;
   GtkWidget    *vbox;
-  GdkPixbuf    *pixbuf;
   GtkWidget    *image;
   GtkWidget    *label;
-  static gint   icon_size = 0;
-  gint          w, h;
   gint         *val;
   GtkIconTheme *icon_theme;
 
@@ -525,32 +522,17 @@ xfsm_logout_dialog_button (const gchar      *title,
   gtk_container_add (GTK_CONTAINER (button), vbox);
   gtk_widget_show (vbox);
 
-  if (G_UNLIKELY (icon_size == 0))
-    {
-      if (gtk_icon_size_lookup (GTK_ICON_SIZE_DND, &w, &h))
-        icon_size = MAX (w, h);
-      else
-        icon_size = 32;
-    }
+  icon_theme = gtk_icon_theme_get_default ();
 
-  icon_theme = gtk_icon_theme_get_for_screen (gtk_window_get_screen (GTK_WINDOW (dialog)));
-  pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name, icon_size, 0, NULL);
-
-  if (G_UNLIKELY (pixbuf == NULL))
-    {
-      pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name_fallback,
-                                         icon_size, GTK_ICON_LOOKUP_GENERIC_FALLBACK,
-                                         NULL);
-    }
-
-  if (G_UNLIKELY (pixbuf == NULL))
-    {
-      pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name_fallback2,
-                                         icon_size, GTK_ICON_LOOKUP_GENERIC_FALLBACK,
-                                         NULL);
-    }
+  image = gtk_image_new ();
+  if (gtk_icon_theme_has_icon (icon_theme, icon_name))
+      gtk_image_set_from_icon_name (GTK_IMAGE (image), icon_name, GTK_ICON_SIZE_DND);
+  else if (gtk_icon_theme_has_icon (icon_theme, icon_name_fallback))
+      gtk_image_set_from_icon_name (GTK_IMAGE (image), icon_name_fallback, GTK_ICON_SIZE_DND);
+  else if (gtk_icon_theme_has_icon (icon_theme, icon_name_fallback2))
+      gtk_image_set_from_icon_name (GTK_IMAGE (image), icon_name_fallback2, GTK_ICON_SIZE_DND);
 
-  image = gtk_image_new_from_pixbuf (pixbuf);
+  gtk_image_set_pixel_size (GTK_IMAGE (image), 32);
   gtk_box_pack_start (GTK_BOX (vbox), image, FALSE, FALSE, 0);
   gtk_widget_show (image);
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list