[Xfce4-commits] <xfce4-panel:master> Move arrow button to plugin widget (bug #6694).

Nick Schermer noreply at xfce.org
Tue Dec 28 20:50:03 CET 2010


Updating branch refs/heads/master
         to 4ea533ef90968e58a0aafd76a9055ac974a92e12 (commit)
       from f04ce15341eb50b8dc739edb761dac7732325ae5 (commit)

commit 4ea533ef90968e58a0aafd76a9055ac974a92e12
Author: Nick Schermer <nick at xfce.org>
Date:   Thu Dec 23 21:28:04 2010 +0100

    Move arrow button to plugin widget (bug #6694).
    
    Also set the relief of the button to none, so it looks better
    on transparent panels. Needs some tweaks but those will land
    with the upcomming commits.

 plugins/systray/systray-box.c |  205 +++++++++++++----------------------------
 plugins/systray/systray-box.h |    5 +
 plugins/systray/systray.c     |   68 +++++++++++++-
 3 files changed, 135 insertions(+), 143 deletions(-)

diff --git a/plugins/systray/systray-box.c b/plugins/systray/systray-box.c
index 7d11ac5..9362044 100644
--- a/plugins/systray/systray-box.c
+++ b/plugins/systray/systray-box.c
@@ -33,7 +33,6 @@
 #include "systray-box.h"
 #include "systray-socket.h"
 
-#define BUTTON_SIZE        (16)
 #define SPACING            (2)
 #define OFFSCREEN          (-9999)
 #define IS_HORIZONTAL(box) ((box)->arrow_type == GTK_ARROW_LEFT \
@@ -65,17 +64,17 @@ static void     systray_box_forall                (GtkContainer    *container,
                                                    GtkCallback      callback,
                                                    gpointer         callback_data);
 static GType    systray_box_child_type            (GtkContainer    *container);
-static void     systray_box_button_set_arrow      (SystrayBox      *box);
-static gboolean systray_box_button_press_event    (GtkWidget       *widget,
-                                                   GdkEventButton  *event,
-                                                   GtkWidget       *box);
-static void     systray_box_button_clicked        (GtkToggleButton *button,
-                                                   SystrayBox      *box);
 static gint     systray_box_compare_function      (gconstpointer    a,
                                                    gconstpointer    b);
 
 
 
+enum
+{
+  PROP_0,
+  PROP_HAS_HIDDEN
+};
+
 struct _SystrayBoxClass
 {
   GtkContainerClass __parent__;
@@ -92,9 +91,6 @@ struct _SystrayBox
    * that represents the hidden bool */
   GHashTable   *names;
 
-  /* expand button */
-  GtkWidget    *button;
-
   /* position of the arrow button */
   GtkArrowType  arrow_type;
 
@@ -152,6 +148,13 @@ systray_box_class_init (SystrayBoxClass *klass)
   gtkcontainer_class->remove = systray_box_remove;
   gtkcontainer_class->forall = systray_box_forall;
   gtkcontainer_class->child_type = systray_box_child_type;
+
+  g_object_class_install_property (gobject_class,
+                                   PROP_HAS_HIDDEN,
+                                   g_param_spec_boolean ("has-hidden",
+                                                         NULL, NULL,
+                                                         FALSE,
+                                                         EXO_PARAM_READABLE));
 }
 
 
@@ -162,22 +165,11 @@ systray_box_init (SystrayBox *box)
   GTK_WIDGET_SET_FLAGS (box, GTK_NO_WINDOW);
 
   box->childeren = NULL;
-  box->button = NULL;
   box->rows = 1;
   box->n_hidden_childeren = 0;
   box->arrow_type = GTK_ARROW_LEFT;
   box->show_hidden = FALSE;
   box->guess_size = 128;
-
-  /* create arrow button */
-  box->button = xfce_arrow_button_new (box->arrow_type);
-  GTK_WIDGET_UNSET_FLAGS (box->button, GTK_CAN_DEFAULT | GTK_CAN_FOCUS);
-  gtk_button_set_focus_on_click (GTK_BUTTON (box->button), FALSE);
-  g_signal_connect (G_OBJECT (box->button), "clicked",
-      G_CALLBACK (systray_box_button_clicked), box);
-  g_signal_connect (G_OBJECT (box->button), "button-press-event",
-      G_CALLBACK (systray_box_button_press_event), box);
-  gtk_widget_set_parent (box->button, GTK_WIDGET (box));
 }
 
 
@@ -188,10 +180,14 @@ systray_box_get_property (GObject      *object,
                           GValue       *value,
                           GParamSpec   *pspec)
 {
-  /*SystrayBox *box = XFCE_SYSTRAY_BOX (object);*/
+  SystrayBox *box = XFCE_SYSTRAY_BOX (object);
 
   switch (prop_id)
     {
+    case PROP_HAS_HIDDEN:
+      g_value_set_boolean (value, box->n_hidden_childeren > 0);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -275,7 +271,11 @@ systray_box_size_request (GtkWidget      *widget,
 
               /* decrease the hidden counter if needed */
               if (systray_socket_get_hidden (XFCE_SYSTRAY_SOCKET (child_info->widget)))
-                box->n_hidden_childeren--;
+                {
+                  box->n_hidden_childeren--;
+                  if (box->n_hidden_childeren == 0)
+                    g_object_notify (G_OBJECT (box), "has-hidden");
+                }
             }
         }
       else
@@ -288,7 +288,11 @@ systray_box_size_request (GtkWidget      *widget,
 
               /* update counter */
               if (systray_socket_get_hidden (XFCE_SYSTRAY_SOCKET (child_info->widget)))
-                box->n_hidden_childeren++;
+                {
+                  box->n_hidden_childeren++;
+                  if (box->n_hidden_childeren == 1)
+                    g_object_notify (G_OBJECT (box), "has-hidden");
+                }
             }
 
           /* count the number of visible childeren */
@@ -325,17 +329,6 @@ systray_box_size_request (GtkWidget      *widget,
       requisition->width = requisition->height = 0;
     }
 
-  /* add the button size if there are hidden icons */
-  if (box->n_hidden_childeren > 0)
-    {
-      /* add the button size */
-      requisition->width += BUTTON_SIZE;
-
-      /* add space */
-      if (n_visible_childeren > 0)
-        requisition->width += SPACING;
-    }
-
   /* swap the sizes if the orientation is vertical */
   if (!IS_HORIZONTAL (box))
     {
@@ -389,8 +382,6 @@ systray_box_size_allocate (GtkWidget     *widget,
   if (box->rows == 1)
     {
       child_size = IS_HORIZONTAL (box) ? width : height;
-      if (box->n_hidden_childeren > 0)
-         child_size -= BUTTON_SIZE + SPACING;
       n = n_children - (box->show_hidden ? 0 : box->n_hidden_childeren);
       child_size -= SPACING * MAX (n - 1, 0);
       if (n > 1)
@@ -412,47 +403,6 @@ systray_box_size_allocate (GtkWidget     *widget,
   if (child_size < 1)
     child_size = 1;
 
-  /* position arrow button */
-  if (box->n_hidden_childeren > 0)
-    {
-      /* initialize allocation */
-      child_allocation.x = allocation->x + GTK_CONTAINER (widget)->border_width;
-      child_allocation.y = allocation->y + GTK_CONTAINER (widget)->border_width;
-
-      /* set the width and height */
-      if (IS_HORIZONTAL (box))
-        {
-          child_allocation.width = BUTTON_SIZE;
-          child_allocation.height = height;
-        }
-      else
-        {
-          child_allocation.width = width;
-          child_allocation.height = BUTTON_SIZE;
-        }
-
-      /* position the button on the other side of the box */
-      if (box->arrow_type == GTK_ARROW_RIGHT)
-        child_allocation.x += width - child_allocation.width;
-      else if (box->arrow_type == GTK_ARROW_DOWN)
-        child_allocation.y += height - child_allocation.height;
-
-      /* set the offset for the icons */
-      offset = BUTTON_SIZE + SPACING;
-
-      /* position the arrow button */
-      gtk_widget_size_allocate (box->button, &child_allocation);
-
-      /* show button if not already visible */
-      if (!GTK_WIDGET_VISIBLE (box->button))
-        gtk_widget_show (box->button);
-    }
-  else if (GTK_WIDGET_VISIBLE (box->button))
-    {
-      /* hide the button */
-      gtk_widget_hide (box->button);
-    }
-
   /* position icons */
   for (li = box->childeren, n = 0; li != NULL; li = li->next)
     {
@@ -564,7 +514,12 @@ systray_box_add (GtkContainer *container,
 
   /* update hidden counter */
   if (systray_socket_get_hidden (XFCE_SYSTRAY_SOCKET (child_info->widget)))
-    box->n_hidden_childeren++;
+    {
+      box->n_hidden_childeren++;
+
+      if (box->n_hidden_childeren == 1)
+        g_object_notify (G_OBJECT (box), "has-hidden");
+    }
 
   /* insert sorted */
   box->childeren = g_slist_insert_sorted (box->childeren, child_info,
@@ -598,7 +553,11 @@ systray_box_remove (GtkContainer *container,
           /* update hidden counter */
           if (systray_socket_get_hidden (XFCE_SYSTRAY_SOCKET (child_info->widget))
               && !child_info->invalid)
-            box->n_hidden_childeren--;
+            {
+              box->n_hidden_childeren--;
+              if (box->n_hidden_childeren == 0)
+                g_object_notify (G_OBJECT (box), "has-hidden");
+            }
 
           /* remove from list */
           box->childeren = g_slist_remove_link (box->childeren, li);
@@ -630,10 +589,6 @@ systray_box_forall (GtkContainer *container,
   SystrayBoxChild *child_info;
   GSList          *li;
 
-  /* for button */
-  if (include_internals)
-    (*callback) (GTK_WIDGET (box->button), callback_data);
-
   /* run callback for all childeren */
   for (li = box->childeren; li != NULL; li = li->next)
     {
@@ -654,58 +609,6 @@ systray_box_child_type (GtkContainer *container)
 
 
 
-static void
-systray_box_button_set_arrow (SystrayBox *box)
-{
-  GtkArrowType arrow_type;
-
-  /* set arrow type */
-  arrow_type = box->arrow_type;
-
-  /* invert the arrow direction when the button is toggled */
-  if (box->show_hidden)
-    {
-      if (IS_HORIZONTAL (box))
-        arrow_type = (arrow_type == GTK_ARROW_LEFT ? GTK_ARROW_RIGHT : GTK_ARROW_LEFT);
-      else
-        arrow_type = (arrow_type == GTK_ARROW_UP ? GTK_ARROW_DOWN : GTK_ARROW_UP);
-    }
-
-  /* set the arrow type */
-  xfce_arrow_button_set_arrow_type (XFCE_ARROW_BUTTON (box->button), arrow_type);
-}
-
-
-
-static gboolean
-systray_box_button_press_event (GtkWidget      *widget,
-                                GdkEventButton *event,
-                                GtkWidget      *box)
-{
-  /* send the event to the box for the panel menu */
-  gtk_widget_event (box, (GdkEvent *) event);
-
-  return FALSE;
-}
-
-
-
-static void
-systray_box_button_clicked (GtkToggleButton *button,
-                            SystrayBox      *box)
-{
-  /* whether to show hidden icons */
-  box->show_hidden = gtk_toggle_button_get_active (button);
-
-  /* update the arrow */
-  systray_box_button_set_arrow (box);
-
-  /* queue a resize */
-  gtk_widget_queue_resize (GTK_WIDGET (box));
-}
-
-
-
 static gint
 systray_box_compare_function (gconstpointer a,
                               gconstpointer b)
@@ -768,9 +671,6 @@ systray_box_set_arrow_type (SystrayBox   *box,
       /* set new setting */
       box->arrow_type = arrow_type;
 
-      /* update button arrow */
-      systray_box_button_set_arrow (box);
-
       /* queue a resize */
       if (box->childeren != NULL)
         gtk_widget_queue_resize (GTK_WIDGET (box));
@@ -809,6 +709,31 @@ systray_box_get_rows (SystrayBox *box)
 
 
 void
+systray_box_set_show_hidden (SystrayBox *box,
+                              gboolean   show_hidden)
+{
+  panel_return_if_fail (XFCE_IS_SYSTRAY_BOX (box));
+
+  if (box->show_hidden != show_hidden)
+    {
+      box->show_hidden = show_hidden;
+      gtk_widget_queue_resize (GTK_WIDGET (box));
+    }
+}
+
+
+
+gboolean
+systray_box_get_show_hidden (SystrayBox *box)
+{
+  panel_return_val_if_fail (XFCE_IS_SYSTRAY_BOX (box), FALSE);
+
+  return box->show_hidden;
+}
+
+
+
+void
 systray_box_update (SystrayBox *box)
 {
   SystrayBoxChild *child_info;
@@ -842,5 +767,7 @@ systray_box_update (SystrayBox *box)
 
       /* update the box */
       gtk_widget_queue_resize (GTK_WIDGET (box));
+
+      g_object_notify (G_OBJECT (box), "has-hidden");
     }
 }
diff --git a/plugins/systray/systray-box.h b/plugins/systray/systray-box.h
index d28c10c..57af888 100644
--- a/plugins/systray/systray-box.h
+++ b/plugins/systray/systray-box.h
@@ -46,6 +46,11 @@ void       systray_box_set_rows        (SystrayBox          *box,
 
 gint       systray_box_get_rows        (SystrayBox          *box);
 
+void       systray_box_set_show_hidden (SystrayBox          *box,
+                                        gboolean             show_hidden);
+
+gboolean   systray_box_get_show_hidden (SystrayBox          *box);
+
 void       systray_box_update          (SystrayBox          *box);
 
 #endif /* !__SYSTRAY_BOX_H__ */
diff --git a/plugins/systray/systray.c b/plugins/systray/systray.c
index c3f964c..c31916e 100644
--- a/plugins/systray/systray.c
+++ b/plugins/systray/systray.c
@@ -34,7 +34,8 @@
 #include "systray-manager.h"
 #include "systray-dialog_ui.h"
 
-#define ICON_SIZE (22)
+#define ICON_SIZE   (22)
+#define BUTTON_SIZE (16)
 
 
 
@@ -55,6 +56,9 @@ static void     systray_plugin_orientation_changed          (XfcePanelPlugin
 static gboolean systray_plugin_size_changed                 (XfcePanelPlugin       *panel_plugin,
                                                              gint                   size);
 static void     systray_plugin_configure_plugin             (XfcePanelPlugin       *panel_plugin);
+static void     systray_plugin_button_toggled               (GtkWidget             *button,
+                                                             SystrayPlugin         *plugin);
+static void     systray_plugin_button_set_arrow             (SystrayPlugin         *plugin);
 static void     systray_plugin_names_collect_visible        (gpointer               key,
                                                              gpointer               value,
                                                              gpointer               user_data);
@@ -102,7 +106,9 @@ struct _SystrayPlugin
 
   /* widgets */
   GtkWidget      *frame;
+  GtkWidget      *hvbox;
   GtkWidget      *box;
+  GtkWidget      *button;
 
   /* settings */
   guint           show_frame : 1;
@@ -208,10 +214,21 @@ systray_plugin_init (SystrayPlugin *plugin)
   gtk_frame_set_shadow_type (GTK_FRAME (plugin->frame), GTK_SHADOW_ETCHED_IN);
   gtk_widget_show (plugin->frame);
 
+  plugin->hvbox = xfce_hvbox_new (GTK_ORIENTATION_HORIZONTAL, FALSE, 2);
+  gtk_container_add (GTK_CONTAINER (plugin->frame), plugin->hvbox);
+  gtk_widget_show (plugin->hvbox);
+
   plugin->box = systray_box_new ();
-  gtk_container_add (GTK_CONTAINER (plugin->frame), plugin->box);
-  xfce_panel_plugin_add_action_widget (XFCE_PANEL_PLUGIN (plugin), plugin->box);
+  gtk_box_pack_start (GTK_BOX (plugin->hvbox), plugin->box, TRUE, TRUE, 0);
   gtk_widget_show (plugin->box);
+
+  plugin->button = xfce_arrow_button_new (GTK_ARROW_RIGHT);
+  gtk_box_pack_start (GTK_BOX (plugin->hvbox), plugin->button, FALSE, FALSE, 0);
+  g_signal_connect (G_OBJECT (plugin->button), "toggled",
+      G_CALLBACK (systray_plugin_button_toggled), plugin);
+  gtk_button_set_relief (GTK_BUTTON (plugin->button), GTK_RELIEF_NONE);
+  exo_binding_new (G_OBJECT (plugin->box), "has-hidden", G_OBJECT (plugin->button), "visible");
+  xfce_panel_plugin_add_action_widget (XFCE_PANEL_PLUGIN (plugin), plugin->button);
 }
 
 
@@ -516,9 +533,16 @@ systray_plugin_orientation_changed (XfcePanelPlugin *panel_plugin,
 {
   SystrayPlugin *plugin = XFCE_SYSTRAY_PLUGIN (panel_plugin);
 
-  /* send the new orientation to the manager */
   if (G_LIKELY (plugin->manager != NULL))
     systray_manager_set_orientation (plugin->manager, orientation);
+  xfce_hvbox_set_orientation (XFCE_HVBOX (plugin->hvbox), orientation);
+
+  if (orientation == GTK_ORIENTATION_HORIZONTAL)
+    gtk_widget_set_size_request (plugin->button, BUTTON_SIZE, -1);
+  else
+    gtk_widget_set_size_request (plugin->button, -1, BUTTON_SIZE);
+
+  systray_plugin_button_set_arrow (plugin);
 }
 
 
@@ -592,6 +616,42 @@ systray_plugin_configure_plugin (XfcePanelPlugin *panel_plugin)
 
 
 static void
+systray_plugin_button_toggled (GtkWidget     *button,
+                               SystrayPlugin *plugin)
+{
+  panel_return_if_fail (XFCE_IS_SYSTRAY_PLUGIN (plugin));
+  panel_return_if_fail (GTK_IS_TOGGLE_BUTTON (button));
+  panel_return_if_fail (plugin->button == button);
+
+  systray_box_set_show_hidden (XFCE_SYSTRAY_BOX (plugin->box),
+      gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)));
+  systray_plugin_button_set_arrow (plugin);
+}
+
+
+
+static void
+systray_plugin_button_set_arrow (SystrayPlugin *plugin)
+{
+  GtkArrowType   arrow_type;
+  gboolean       show_hidden;
+  GtkOrientation orientation;
+
+  panel_return_if_fail (XFCE_IS_SYSTRAY_PLUGIN (plugin));
+
+  show_hidden = systray_box_get_show_hidden (XFCE_SYSTRAY_BOX (plugin->box));
+  orientation = xfce_panel_plugin_get_orientation (XFCE_PANEL_PLUGIN (plugin));
+  if (orientation == GTK_ORIENTATION_HORIZONTAL)
+    arrow_type = show_hidden ? GTK_ARROW_LEFT : GTK_ARROW_RIGHT;
+  else
+    arrow_type = show_hidden ? GTK_ARROW_UP : GTK_ARROW_DOWN;
+
+  xfce_arrow_button_set_arrow_type (XFCE_ARROW_BUTTON (plugin->button), arrow_type);
+}
+
+
+
+static void
 systray_plugin_names_collect (GPtrArray   *array,
                               const gchar *name)
 {



More information about the Xfce4-commits mailing list