[Xfce4-commits] <xfce4-indicator-plugin:master> Fixed #9040.

Andrzej noreply at xfce.org
Thu Apr 4 17:44:35 CEST 2013


Updating branch refs/heads/master
         to f60f6d59702faef79cb3c346002395cbd0696c86 (commit)
       from 985d34925075ffd8ea020cec1fd2e849d47aff83 (commit)

commit f60f6d59702faef79cb3c346002395cbd0696c86
Author: Andrzej <ndrwrdck at gmail.com>
Date:   Wed Apr 3 01:46:26 2013 +0100

    Fixed #9040.
    
    This required getting replacing XfcePanelImage with GtkImage. The former
    does not work reliably with non-square icons and added automatization
    is not needed in this case.
    
    Only horizontal non-square icons are supported (vertical will be squeezed
    into a square shape). Non-square icons are rendered in a single row
    (like indicators with labels).

 panel-plugin/indicator-box.c    |   16 +++++----
 panel-plugin/indicator-button.c |   63 ++++++++++++++++++++++++++------------
 panel-plugin/indicator-button.h |    2 +
 3 files changed, 54 insertions(+), 27 deletions(-)

diff --git a/panel-plugin/indicator-box.c b/panel-plugin/indicator-box.c
index 4c9ae90..c181009 100644
--- a/panel-plugin/indicator-box.c
+++ b/panel-plugin/indicator-box.c
@@ -336,7 +336,7 @@ xfce_indicator_box_size_request (GtkWidget      *widget,
   gint                 row;
   gint                 nrows;
   gint                 x;
-  gboolean             has_label;
+  gboolean             has_label, rectangular_icon;
   GtkOrientation       panel_orientation;
 
   panel_size = indicator_config_get_panel_size (box->config);
@@ -359,9 +359,10 @@ xfce_indicator_box_size_request (GtkWidget      *widget,
 
           gtk_widget_size_request (GTK_WIDGET (button), &child_req);
           has_label = (xfce_indicator_button_get_label (button) != NULL);
+          rectangular_icon = xfce_indicator_button_is_icon_rectangular (button);
 
           /* wrap rows if column is overflowing or a label is encountered */
-          if (row > 0 && (has_label || row >= nrows))
+          if (row > 0 && (has_label || row >= nrows || rectangular_icon))
             {
               x += length;
               row = 0;
@@ -371,7 +372,7 @@ xfce_indicator_box_size_request (GtkWidget      *widget,
           length =
             MAX (length, (panel_orientation == GTK_ORIENTATION_HORIZONTAL) ? child_req.width :child_req.height);
 
-          if (has_label || row >= nrows)
+          if (has_label || row >= nrows || rectangular_icon)
             {
               x += length;
               row = 0;
@@ -416,7 +417,7 @@ xfce_indicator_box_size_allocate (GtkWidget     *widget,
   gint                 length, width;
   gint                 row;
   gint                 nrows;
-  gboolean             has_label;
+  gboolean             has_label, rectangular_icon;
   GtkOrientation       panel_orientation;
 
   row = 0;
@@ -445,9 +446,10 @@ xfce_indicator_box_size_allocate (GtkWidget     *widget,
           gtk_widget_get_child_requisition (GTK_WIDGET (button), &child_req);
 
           has_label = (xfce_indicator_button_get_label (button) != NULL);
+          rectangular_icon = xfce_indicator_button_is_icon_rectangular (button);
 
           /* wrap rows if column is overflowing or a label is encountered */
-          if (row > 0 && (has_label || row >= nrows))
+          if (row > 0 && (has_label || row >= nrows || rectangular_icon))
             {
               x += length;
               y = 0;
@@ -455,7 +457,7 @@ xfce_indicator_box_size_allocate (GtkWidget     *widget,
               length = 0;
             }
 
-          width = (has_label) ? panel_size : size;
+          width = (has_label || rectangular_icon) ? panel_size : size;
           length = MAX (length,
                         (panel_orientation == GTK_ORIENTATION_HORIZONTAL) ? child_req.width :child_req.height);
 
@@ -479,7 +481,7 @@ xfce_indicator_box_size_allocate (GtkWidget     *widget,
 
           gtk_widget_size_allocate (GTK_WIDGET (button), &child_alloc);
 
-          if (has_label || row >= nrows)
+          if (has_label || row >= nrows || rectangular_icon)
             {
               x += length;
               y = 0;
diff --git a/panel-plugin/indicator-button.c b/panel-plugin/indicator-button.c
index 74ed022..25a3572 100644
--- a/panel-plugin/indicator-button.c
+++ b/panel-plugin/indicator-button.c
@@ -67,6 +67,7 @@ struct _XfceIndicatorButton
   GtkWidget            *label;
   GtkWidget            *icon;
   GtkWidget            *orig_icon;
+  gboolean              rectangular_icon;
 
   gulong                orig_icon_changed_id;
   gulong                configuration_changed_id;
@@ -119,6 +120,7 @@ xfce_indicator_button_init (XfceIndicatorButton *button)
   button->icon = NULL;
   button->orig_icon_changed_id = 0;
   button->configuration_changed_id = 0;
+  button->rectangular_icon = FALSE;
 
   button->align_box = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
   gtk_container_add (GTK_CONTAINER (button), button->align_box);
@@ -214,8 +216,6 @@ xfce_indicator_button_update_layout (XfceIndicatorButton *button)
     gtk_label_set_angle (GTK_LABEL (button->label),
                          (indicator_config_get_orientation (button->config) == GTK_ORIENTATION_VERTICAL)
                          ? -90 : 0);
-  if (button->icon != NULL)
-    xfce_panel_image_set_size (XFCE_PANEL_IMAGE (button->icon), xfce_indicator_button_get_icon_size (button));
 }
 
 
@@ -226,10 +226,12 @@ xfce_indicator_button_update_icon (XfceIndicatorButton *button)
 {
   GdkPixbuf    *pixbuf_s, *pixbuf_d;
   gdouble       aspect;
-  gint          size;
+  gint          w, h, size;
+  gint          border_thickness;
+  GtkStyle     *style;
 
   g_return_if_fail (GTK_IS_IMAGE (button->orig_icon));
-  g_return_if_fail (XFCE_IS_PANEL_IMAGE (button->icon));
+  g_return_if_fail (GTK_IS_IMAGE (button->icon));
 
   size = xfce_indicator_button_get_icon_size (button);
 
@@ -246,25 +248,34 @@ xfce_indicator_button_update_icon (XfceIndicatorButton *button)
 
   if (pixbuf_s != NULL)
     {
-      aspect = (gdouble) gdk_pixbuf_get_width (pixbuf_s) /
-        (gdouble) gdk_pixbuf_get_height (pixbuf_s);
-      if (aspect > 1.0)
-        pixbuf_d = gdk_pixbuf_scale_simple
-          (pixbuf_s, size, (gint) (size / aspect),
-           GDK_INTERP_BILINEAR);
+      w = gdk_pixbuf_get_width (pixbuf_s);
+      h = gdk_pixbuf_get_height (pixbuf_s);
+      aspect = (gdouble) w / (gdouble) h;
+
+      button->rectangular_icon = (w != h);
+
+      if (indicator_config_get_panel_orientation (button->config) == GTK_ORIENTATION_VERTICAL &&
+          size * aspect > indicator_config_get_panel_size (button->config))
+        {
+          style = gtk_widget_get_style (GTK_WIDGET (button->plugin));
+          border_thickness = 2 * MAX (style->xthickness, style->ythickness);
+          w = indicator_config_get_panel_size (button->config) - border_thickness;
+          h = (gint) (w / aspect);
+        }
       else
-        pixbuf_d = gdk_pixbuf_scale_simple
-          (pixbuf_s, (gint) (size * aspect), size,
-           GDK_INTERP_BILINEAR);
-      xfce_panel_image_set_from_pixbuf (XFCE_PANEL_IMAGE (button->icon), pixbuf_d);
+        {
+          h = size;
+          w = (gint) (h * aspect);
+        }
+      pixbuf_d = gdk_pixbuf_scale_simple (pixbuf_s, w, h, GDK_INTERP_BILINEAR);
+      gtk_image_set_from_pixbuf (GTK_IMAGE (button->icon), pixbuf_d);
       g_object_unref (G_OBJECT (pixbuf_d));
     }
   else
     {
-      xfce_panel_image_set_from_source (XFCE_PANEL_IMAGE (button->icon), "image-missing");
+      gtk_image_set_from_icon_name (GTK_IMAGE (button->icon),
+                                    "image-missing", GTK_ICON_SIZE_MENU);
     }
-
-  xfce_panel_image_set_size (XFCE_PANEL_IMAGE (button->icon), size);
 }
 
 
@@ -310,7 +321,7 @@ on_pixbuf_changed (GtkImage *image, GParamSpec *pspec, XfceIndicatorButton *butt
 {
   g_return_if_fail (XFCE_IS_INDICATOR_BUTTON (button));
   g_return_if_fail (GTK_IS_IMAGE (image));
-  g_return_if_fail (XFCE_IS_PANEL_IMAGE (button->icon));
+  g_return_if_fail (GTK_IS_IMAGE (button->icon));
 
   xfce_indicator_button_update_icon (button);
 }
@@ -350,8 +361,7 @@ xfce_indicator_button_set_image (XfceIndicatorButton *button,
       button->orig_icon_changed_id = g_signal_connect
         (G_OBJECT (image), "notify::pixbuf", G_CALLBACK (on_pixbuf_changed), button);
 
-
-      button->icon = xfce_panel_image_new ();
+      button->icon = gtk_image_new ();
       xfce_indicator_button_update_icon (button);
 
       gtk_box_pack_start (GTK_BOX (button->box), button->icon, TRUE, FALSE, 1);
@@ -458,6 +468,19 @@ xfce_indicator_button_get_menu (XfceIndicatorButton *button)
 
 
 
+
+
+gboolean
+xfce_indicator_button_is_icon_rectangular (XfceIndicatorButton *button)
+{
+  g_return_val_if_fail (XFCE_IS_INDICATOR_BUTTON (button), FALSE);
+
+  return button->rectangular_icon;
+}
+
+
+
+
 static gint
 xfce_indicator_button_get_icon_size (XfceIndicatorButton *button)
 {
diff --git a/panel-plugin/indicator-button.h b/panel-plugin/indicator-button.h
index b25efa6..427d1e6 100644
--- a/panel-plugin/indicator-button.h
+++ b/panel-plugin/indicator-button.h
@@ -63,6 +63,8 @@ guint                   xfce_indicator_button_get_pos     (XfceIndicatorButton
 
 GtkMenu                *xfce_indicator_button_get_menu    (XfceIndicatorButton        *button);
 
+gboolean                xfce_indicator_button_is_icon_rectangular (XfceIndicatorButton *button);
+
 GtkWidget              *xfce_indicator_button_new         (IndicatorObject            *io,
                                                            const gchar                *io_name,
                                                            IndicatorObjectEntry       *entry,


More information about the Xfce4-commits mailing list