[Xfce4-commits] <xfce4-panel:andrzejr/deskbar-length-adjust> panel-itembar: added support for length_adjust in the itembar.

Andrzej noreply at xfce.org
Mon Dec 19 18:18:04 CET 2011


Updating branch refs/heads/andrzejr/deskbar-length-adjust
         to a072867401762c7a6c0b3a1a5b881d9eb4e91476 (commit)
       from f284ad33fe00ed3d9cdb5b14040e7d282b13ee38 (commit)

commit a072867401762c7a6c0b3a1a5b881d9eb4e91476
Author: Andrzej <ndrwrdck at gmail.com>
Date:   Tue Dec 20 02:09:26 2011 +0900

    panel-itembar: added support for length_adjust in the itembar.
    
    Had to move the handling of shrinking plugins to a separate loop. This is because the shrinking process may now produce some excess space, which should be added back to expand_len_avail.
    
    Also fixed some bugs in calculating expand_len_avail (previously expanding separators had invalid minimum size in some cases).

 panel/panel-itembar.c |   56 ++++++++++++++++++++++++++++++++----------------
 1 files changed, 37 insertions(+), 19 deletions(-)

diff --git a/panel/panel-itembar.c b/panel/panel-itembar.c
index fbd42bc..34115d4 100644
--- a/panel/panel-itembar.c
+++ b/panel/panel-itembar.c
@@ -111,6 +111,7 @@ struct _PanelItembarChild
 {
   GtkWidget    *widget;
   ChildOptions  option;
+  gint          length;
 };
 
 enum
@@ -443,6 +444,8 @@ panel_itembar_size_allocate (GtkWidget     *widget,
   for (lp = itembar->children; lp != NULL; lp = lp->next)
     {
       child = lp->data;
+      child->length = 0;
+
       if (G_LIKELY (child != NULL))
         {
           if (!GTK_WIDGET_VISIBLE (child->widget))
@@ -502,13 +505,40 @@ panel_itembar_size_allocate (GtkWidget     *widget,
    * not the length set by the user) */
   expand_children_fit = expand_len_req == expand_len_avail;
 
-  if (expand_len_avail < 0)
+  /* are we short of space */
+  if (expand_len_avail < expand_len_req)
     {
-      /* check if there are plugins on the panel we can shrink */
+      /* are there any plugins on the panel we can shrink */
       if (shrink_len_avail > 0)
-        shrink_len_req = ABS (expand_len_avail);
+        {
+          shrink_len_req = expand_len_req - expand_len_avail;
+          /* go over shrinkable children on this row and shrink them before allocating other children */
+          for (lp = itembar->children; lp != NULL; lp = lp->next)
+            {
+              child = lp->data;
+              if (child->option == CHILD_OPTION_SHRINK && GTK_WIDGET_VISIBLE (child->widget))
+                {
+                  gtk_widget_get_child_requisition (child->widget, &child_req);
+                  child_len = CHILD_LENGTH (child_req, itembar);
+                  /* equally shrink all shrinking plugins */
+                  panel_assert (shrink_len_avail > 0);
+                  new_len = shrink_len_req * child_len / shrink_len_avail;              
+
+                  new_len = child_len - xfce_panel_plugin_length_adjust(XFCE_PANEL_PLUGIN (child->widget), child_len - new_len);
+
+                  shrink_len_req -= new_len;
+                  shrink_len_avail -= child_len;
+
+                  /* the size we decrease can never be more then the actual length,
+                   * if this is the case the size allocation is lacking behind,
+                   * which happens on panel startup with a expanding panel */
+                  if (new_len < child_len)
+                    child->length = child_len - new_len;
+                }
+            }
+          expand_len_avail = -shrink_len_req + expand_len_req;
+        }
 
-      expand_len_avail = 0;
     }
 
   /* init coordinates for first child */
@@ -562,28 +592,16 @@ panel_itembar_size_allocate (GtkWidget     *widget,
         {
           /* equally share the length between the expanding plugins */
           panel_assert (expand_len_req > 0);
-          new_len = expand_len_avail * child_len / expand_len_req;
+          new_len = MAX (expand_len_avail * child_len / expand_len_req, child_len);
 
           expand_len_req -= child_len;
           expand_len_avail -= new_len;
 
           child_len = new_len;
         }
-      else if (child->option == CHILD_OPTION_SHRINK
-               && shrink_len_req > 0)
+      else if (child->length != 0)
         {
-          /* equally shrink all shrinking plugins */
-          panel_assert (shrink_len_avail > 0);
-          new_len = shrink_len_req * child_len / shrink_len_avail;
-
-          shrink_len_req -= new_len;
-          shrink_len_avail -= child_len;
-
-          /* the size we decrease can never be more then the actual length,
-           * if this is the case the size allocation is lacking behind,
-           * which happens on panel startup with a expanding panel */
-          if (new_len < child_len)
-            child_len -= new_len;
+          child_len = child->length;
         }
 
       if (G_UNLIKELY (child_len < 1))


More information about the Xfce4-commits mailing list