[Xfce4-commits] <xfce4-panel:master> Panel: Implement shrink plugin size allocation.

Nick Schermer noreply at xfce.org
Fri Apr 22 12:56:02 CEST 2011


Updating branch refs/heads/master
         to 9703cf78e25e0641b8ea1307b77e639279f55718 (commit)
       from 173fc38553940f4c6807aa5d7a2823882fe780e1 (commit)

commit 9703cf78e25e0641b8ea1307b77e639279f55718
Author: Nick Schermer <nick at xfce.org>
Date:   Fri Apr 22 11:48:23 2011 +0200

    Panel: Implement shrink plugin size allocation.

 panel/panel-application.c |   10 ++++++++
 panel/panel-itembar.c     |   55 ++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 64 insertions(+), 1 deletions(-)

diff --git a/panel/panel-application.c b/panel/panel-application.c
index 03a6004..2e78eb9 100644
--- a/panel/panel-application.c
+++ b/panel/panel-application.c
@@ -535,6 +535,16 @@ panel_application_plugin_provider_signal (XfcePanelPluginProvider       *provide
                                NULL);
       break;
 
+    case PROVIDER_SIGNAL_SHRINK_PLUGIN:
+    case PROVIDER_SIGNAL_UNSHRINK_PLUGIN:
+      itembar = gtk_bin_get_child (GTK_BIN (window));
+      gtk_container_child_set (GTK_CONTAINER (itembar),
+                               GTK_WIDGET (provider),
+                               "shrink",
+                               provider_signal == PROVIDER_SIGNAL_SHRINK_PLUGIN,
+                               NULL);
+      break;
+
     case PROVIDER_SIGNAL_WRAP_PLUGIN:
     case PROVIDER_SIGNAL_UNWRAP_PLUGIN:
       itembar = gtk_bin_get_child (GTK_BIN (window));
diff --git a/panel/panel-itembar.c b/panel/panel-itembar.c
index add31e2..afecdd7 100644
--- a/panel/panel-itembar.c
+++ b/panel/panel-itembar.c
@@ -97,6 +97,7 @@ struct _PanelItembarChild
 {
   GtkWidget *widget;
   guint      expand : 1;
+  guint      shrink : 1;
   guint      wrap : 1;
 };
 
@@ -111,6 +112,7 @@ enum
 {
   CHILD_PROP_0,
   CHILD_PROP_EXPAND,
+  CHILD_PROP_SHRINK,
   CHILD_PROP_WRAP
 };
 
@@ -185,6 +187,13 @@ panel_itembar_class_init (PanelItembarClass *klass)
                                                                     EXO_PARAM_READWRITE));
 
   gtk_container_class_install_child_property (gtkcontainer_class,
+                                              CHILD_PROP_SHRINK,
+                                              g_param_spec_boolean ("shrink",
+                                                                    NULL, NULL,
+                                                                    FALSE,
+                                                                    EXO_PARAM_READWRITE));
+
+  gtk_container_class_install_child_property (gtkcontainer_class,
                                               CHILD_PROP_WRAP,
                                               g_param_spec_boolean ("wrap",
                                                                     NULL, NULL,
@@ -358,6 +367,8 @@ panel_itembar_size_allocate (GtkWidget     *widget,
   gint               expand_length, border_width;
   gint               expand_length_avail;
   gint               expand_length_req;
+  gint               shrink_length;
+  gint               shrink_length_req;
   gint               length_req, length;
   gint               alloc_length;
   gint               x, y;
@@ -378,6 +389,8 @@ panel_itembar_size_allocate (GtkWidget     *widget,
       expand_length_avail = expand_length;
       expand_length_req = 0;
       n_expand_children = 0;
+      shrink_length = 0;
+      shrink_length_req = 0;
 
       /* get information about the expandable lengths */
       for (lp = li; lp != NULL; lp = g_slist_next (lp))
@@ -403,6 +416,9 @@ panel_itembar_size_allocate (GtkWidget     *widget,
               else
                 {
                   expand_length_avail -= length;
+
+                  if (child->shrink)
+                    shrink_length += length;
                 }
             }
           else
@@ -425,7 +441,13 @@ panel_itembar_size_allocate (GtkWidget     *widget,
        * not the length set by the user) */
       expand_children_fit = expand_length_req == expand_length_avail;
       if (expand_length_avail < 0)
-        expand_length_avail = 0;
+        {
+          /* check if there are plugins on the panel we can shrink */
+          if (shrink_length > 0)
+            shrink_length_req = ABS (expand_length_avail);
+
+          expand_length_avail = 0;
+        }
 
       /* allocate the children on this row */
       for (; li != NULL; li = g_slist_next (li))
@@ -503,6 +525,26 @@ panel_itembar_size_allocate (GtkWidget     *widget,
               expand_length_req -= length_req;
               expand_length_avail -= alloc_length;
             }
+          else if (child->shrink && shrink_length_req > 0)
+            {
+              /* equally shrink all shrinking plugins */
+              length_req = itembar->horizontal ? child_req.width : child_req.height;
+              alloc_length = shrink_length_req * length_req / shrink_length;
+
+              shrink_length_req -= alloc_length;
+              shrink_length -= length_req;
+
+              alloc_length = length_req - alloc_length;
+              if (alloc_length < 1)
+                alloc_length = 1;
+
+              if (itembar->horizontal)
+                child_alloc.width = alloc_length;
+              else
+                child_alloc.height = alloc_length;
+
+
+            }
           else
             {
               if (itembar->horizontal)
@@ -647,6 +689,13 @@ panel_itembar_set_child_property (GtkContainer *container,
       child->expand = boolean;
       break;
 
+    case CHILD_PROP_SHRINK:
+      boolean = g_value_get_boolean (value);
+      if (child->shrink == boolean)
+        return;
+      child->shrink = boolean;
+      break;
+
     case CHILD_PROP_WRAP:
       boolean = g_value_get_boolean (value);
       if (child->wrap == boolean)
@@ -683,6 +732,10 @@ panel_itembar_get_child_property (GtkContainer *container,
       g_value_set_boolean (value, child->expand);
       break;
 
+    case CHILD_PROP_SHRINK:
+      g_value_set_boolean (value, child->shrink);
+      break;
+
     case CHILD_PROP_WRAP:
       g_value_set_boolean (value, child->wrap);
       break;



More information about the Xfce4-commits mailing list