[Xfce4-commits] r26368 - xfce4-panel/trunk/plugins/systray

Nick Schermer nick at xfce.org
Sun Nov 18 16:05:30 CET 2007


Author: nick
Date: 2007-11-18 15:05:30 +0000 (Sun, 18 Nov 2007)
New Revision: 26368

Modified:
   xfce4-panel/trunk/plugins/systray/xfce-tray-dialogs.c
   xfce4-panel/trunk/plugins/systray/xfce-tray-plugin.c
   xfce4-panel/trunk/plugins/systray/xfce-tray-plugin.h
   xfce4-panel/trunk/plugins/systray/xfce-tray-widget.c
   xfce4-panel/trunk/plugins/systray/xfce-tray-widget.h
Log:
* Improve the icons sizing a bit, the initial icon size should be better now.
* Icon spacing is now 2px. The previously 1px was a bit too small for me.


Modified: xfce4-panel/trunk/plugins/systray/xfce-tray-dialogs.c
===================================================================
--- xfce4-panel/trunk/plugins/systray/xfce-tray-dialogs.c	2007-11-18 07:50:36 UTC (rev 26367)
+++ xfce4-panel/trunk/plugins/systray/xfce-tray-dialogs.c	2007-11-18 15:05:30 UTC (rev 26368)
@@ -188,6 +188,9 @@
 
    /* set rows */
    xfce_tray_widget_set_rows (XFCE_TRAY_WIDGET (plugin->tray), value);
+
+   /* reset initial icon size */
+   plugin->initial_size = -1;
 }
 
 

Modified: xfce4-panel/trunk/plugins/systray/xfce-tray-plugin.c
===================================================================
--- xfce4-panel/trunk/plugins/systray/xfce-tray-plugin.c	2007-11-18 07:50:36 UTC (rev 26367)
+++ xfce4-panel/trunk/plugins/systray/xfce-tray-plugin.c	2007-11-18 15:05:30 UTC (rev 26368)
@@ -178,6 +178,13 @@
 {
     gchar *name;
 
+    /* initialize the size when needed */
+    if (G_UNLIKELY (plugin->initial_size == -1))
+       xfce_tray_plugin_size_changed (plugin, xfce_panel_plugin_get_size (plugin->panel_plugin));
+
+    /* set size request */
+    gtk_widget_set_size_request (icon, plugin->initial_size, plugin->initial_size);
+
     /* get the application name */
     name = xfce_tray_manager_get_application_name (icon);
 
@@ -234,6 +241,7 @@
     plugin->panel_plugin = panel_plugin;
     plugin->manager = NULL;
     plugin->show_frame = TRUE;
+    plugin->initial_size = -1;
 
     /* create the frame */
     plugin->frame = gtk_frame_new (NULL);
@@ -281,8 +289,6 @@
         g_error_free (error);
     }
 
-
-
     return plugin;
 }
 
@@ -309,17 +315,25 @@
 
 
 static gboolean
-xfce_tray_plugin_size_changed (XfceTrayPlugin  *plugin,
-                               guint            size)
+xfce_tray_plugin_size_changed (XfceTrayPlugin *plugin,
+                               guint           size)
 {
-    gint border;
+    gint n_rows;
 
     /* set the frame border size */
     gtk_container_set_border_width (GTK_CONTAINER (plugin->frame), size > SMALL_PANEL_SIZE ? 1 : 0);
 
-    /* get the border size */
-    border = size > SMALL_PANEL_SIZE ? 6 : 4;
+    /* get tray rows */
+    n_rows = xfce_tray_widget_get_rows (XFCE_TRAY_WIDGET (plugin->tray));
 
+    /* calculate the initial tray icon size */
+    plugin->initial_size = (size
+                            - 2 * GTK_CONTAINER (plugin->frame)->border_width
+                            - 2 * GTK_CONTAINER (plugin->tray)->border_width
+                            - 2 * MAX (plugin->frame->style->xthickness, plugin->frame->style->ythickness)
+                            - XFCE_TRAY_WIDGET_SPACING * (n_rows - 1))
+                           / n_rows;
+
     /* we handled the size of the plugin */
     return TRUE;
 }

Modified: xfce4-panel/trunk/plugins/systray/xfce-tray-plugin.h
===================================================================
--- xfce4-panel/trunk/plugins/systray/xfce-tray-plugin.h	2007-11-18 07:50:36 UTC (rev 26367)
+++ xfce4-panel/trunk/plugins/systray/xfce-tray-plugin.h	2007-11-18 15:05:30 UTC (rev 26368)
@@ -34,6 +34,9 @@
     GtkWidget       *frame;
     GtkWidget       *tray;
 
+    /* initial icon size */
+    gint             initial_size;
+
     /* properties */
     guint            show_frame : 1;
 };

Modified: xfce4-panel/trunk/plugins/systray/xfce-tray-widget.c
===================================================================
--- xfce4-panel/trunk/plugins/systray/xfce-tray-widget.c	2007-11-18 07:50:36 UTC (rev 26367)
+++ xfce4-panel/trunk/plugins/systray/xfce-tray-widget.c	2007-11-18 15:05:30 UTC (rev 26368)
@@ -96,9 +96,6 @@
     /* whether hidden icons are visible */
     guint         show_hidden : 1;
 
-    /* spacing between the childeren */
-    gint          spacing;
-
     /* number of rows */
     gint          rows;
 };
@@ -178,7 +175,6 @@
     /* initialize */
     tray->childeren = NULL;
     tray->button = NULL;
-    tray->spacing = 1;
     tray->rows = 1;
     tray->n_hidden_childeren = 0;
     tray->arrow_type = GTK_ARROW_LEFT;
@@ -227,8 +223,9 @@
     XfceTrayWidget      *tray = XFCE_TRAY_WIDGET (widget);
     GSList              *li;
     XfceTrayWidgetChild *child_info;
-    gint                 child_size = 1;
+    gint                 child_size = 128;
     gint                 n_columns;
+    GtkRequisition       child_requisition;
     gint                 n_visible_childeren = 0;
 
     _panel_return_if_fail (XFCE_IS_TRAY_WIDGET (widget));
@@ -241,11 +238,12 @@
         /* ship hidden icons if needed */
         if (child_info->hidden == FALSE || tray->show_hidden == TRUE)
         {
-            /* we use the child allocation for size request here, this is not entirely legal, but
-             * it seems to work better for tray icons since they request weird sizes sometimes */
-            child_size = MAX (child_size, MAX (child_info->widget->allocation.width,
-                                               child_info->widget->allocation.height));
+            /* get the icons size request */
+            gtk_widget_size_request (child_info->widget, &child_requisition);
 
+            /* get the child size (smallest icon) */
+            child_size = MIN (child_size, MAX (child_requisition.width, child_requisition.height));
+
             /* number of visible childeren */
             n_visible_childeren++;
         }
@@ -259,8 +257,8 @@
     /* set the width and height needed for the icons */
     if (n_visible_childeren > 0)
     {
-        requisition->width = ((child_size + tray->spacing) * n_columns) - tray->spacing;
-        requisition->height = ((child_size + tray->spacing) * tray->rows) - tray->spacing;
+        requisition->width = ((child_size + XFCE_TRAY_WIDGET_SPACING) * n_columns) - XFCE_TRAY_WIDGET_SPACING;
+        requisition->height = ((child_size + XFCE_TRAY_WIDGET_SPACING) * tray->rows) - XFCE_TRAY_WIDGET_SPACING;
     }
     else
     {
@@ -275,7 +273,7 @@
 
         /* add space */
         if (n_visible_childeren > 0)
-             requisition->width += tray->spacing;
+             requisition->width += XFCE_TRAY_WIDGET_SPACING;
     }
 
     /* swap the sizes if the orientation is vertical */
@@ -319,7 +317,7 @@
 
     /* child size */
     child_size = XFCE_TRAY_WIDGET_IS_HORIZONTAL (tray) ? height : width;
-    child_size -= tray->spacing * (tray->rows - 1);
+    child_size -= XFCE_TRAY_WIDGET_SPACING * (tray->rows - 1);
     child_size /= tray->rows;
 
     /* position arrow button */
@@ -348,7 +346,7 @@
             child_allocation.y += height - child_allocation.height;
 
         /* set the offset for the icons */
-        offset = XFCE_TRAY_WIDGET_BUTTON_SIZE + tray->spacing;
+        offset = XFCE_TRAY_WIDGET_BUTTON_SIZE + XFCE_TRAY_WIDGET_SPACING;
 
         /* position the arrow button */
         gtk_widget_size_allocate (tray->button, &child_allocation);
@@ -376,8 +374,8 @@
         else
         {
             /* set coordinates */
-            child_allocation.x = (child_size + tray->spacing) * (n / tray->rows) + offset;
-            child_allocation.y = (child_size + tray->spacing) * (n % tray->rows);
+            child_allocation.x = (child_size + XFCE_TRAY_WIDGET_SPACING) * (n / tray->rows) + offset;
+            child_allocation.y = (child_size + XFCE_TRAY_WIDGET_SPACING) * (n % tray->rows);
 
             /* increase item counter */
             n++;
@@ -403,6 +401,7 @@
 
         /* allocate widget size */
         gtk_widget_size_allocate (child_info->widget, &child_allocation);
+        gtk_widget_set_size_request (child_info->widget, child_size, child_size);
     }
 }
 
@@ -628,7 +627,8 @@
         xfce_tray_widget_button_set_arrow (tray);
 
         /* queue a resize */
-        gtk_widget_queue_resize (GTK_WIDGET (tray));
+        if (tray->childeren != NULL)
+            gtk_widget_queue_resize (GTK_WIDGET (tray));
     }
 }
 
@@ -645,34 +645,6 @@
 
 
 void
-xfce_tray_widget_set_spacing (XfceTrayWidget *tray,
-                              gint            spacing)
-{
-    _panel_return_if_fail (XFCE_IS_TRAY_WIDGET (tray));
-
-    if (G_LIKELY (spacing != tray->spacing))
-    {
-        /* set new setting */
-        tray->spacing = spacing;
-
-        /* queue a resize */
-        gtk_widget_queue_resize (GTK_WIDGET (tray));
-    }
-}
-
-
-
-gint
-xfce_tray_widget_get_spacing (XfceTrayWidget *tray)
-{
-    _panel_return_val_if_fail (XFCE_IS_TRAY_WIDGET (tray), 0);
-
-    return tray->spacing;
-}
-
-
-
-void
 xfce_tray_widget_set_rows (XfceTrayWidget *tray,
                            gint            rows)
 {
@@ -684,7 +656,8 @@
         tray->rows = MAX (1, rows);
 
         /* queue a resize */
-        gtk_widget_queue_resize (GTK_WIDGET (tray));
+        if (tray->childeren != NULL)
+            gtk_widget_queue_resize (GTK_WIDGET (tray));
     }
 }
 

Modified: xfce4-panel/trunk/plugins/systray/xfce-tray-widget.h
===================================================================
--- xfce4-panel/trunk/plugins/systray/xfce-tray-widget.h	2007-11-18 07:50:36 UTC (rev 26367)
+++ xfce4-panel/trunk/plugins/systray/xfce-tray-widget.h	2007-11-18 15:05:30 UTC (rev 26368)
@@ -24,6 +24,8 @@
 typedef struct _XfceTrayWidget      XfceTrayWidget;
 typedef struct _XfceTrayWidgetChild XfceTrayWidgetChild;
 
+#define XFCE_TRAY_WIDGET_SPACING (2)
+
 #define XFCE_TYPE_TRAY_WIDGET            (xfce_tray_widget_get_type ())
 #define XFCE_TRAY_WIDGET(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), XFCE_TYPE_TRAY_WIDGET, XfceTrayWidget))
 #define XFCE_TRAY_WIDGET_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), XFCE_TYPE_TRAY_WIDGET, XfceTrayWidgetClass))
@@ -44,11 +46,6 @@
 
 GtkArrowType     xfce_tray_widget_get_arrow_type     (XfceTrayWidget *tray) G_GNUC_INTERNAL;
 
-void             xfce_tray_widget_set_spacing        (XfceTrayWidget *tray,
-                                                      gint            spacing) G_GNUC_INTERNAL;
-
-gint             xfce_tray_widget_get_spacing        (XfceTrayWidget *tray) G_GNUC_INTERNAL;
-
 void             xfce_tray_widget_set_rows           (XfceTrayWidget *tray,
                                                       gint            rows) G_GNUC_INTERNAL;
 



More information about the Xfce4-commits mailing list