[Xfce4-commits] <xfce4-panel:nick/desktop-mode> Add small property for plugins.

Nick Schermer noreply at xfce.org
Sun Dec 11 16:36:01 CET 2011


Updating branch refs/heads/nick/desktop-mode
         to 8b66f2aaa92aaf81c2992880b73283d49b76f88b (commit)
       from 53544a44f488abf30b877af47310fc38c08a4eda (commit)

commit 8b66f2aaa92aaf81c2992880b73283d49b76f88b
Author: Andrzej <ndrwrdck at gmail.com>
Date:   Sun Dec 11 15:38:36 2011 +0100

    Add small property for plugins.
    
    This properly will be used to pack a plugin only on a single row instead
    of the whole panel height.

 libxfce4panel/xfce-panel-plugin-provider.h |    2 +
 libxfce4panel/xfce-panel-plugin.c          |   90 ++++++++++++++++++++++++++++
 libxfce4panel/xfce-panel-plugin.h          |    5 ++
 panel/panel-application.c                  |   10 +++
 panel/panel-itembar.c                      |   22 +++++++-
 5 files changed, 128 insertions(+), 1 deletions(-)

diff --git a/libxfce4panel/xfce-panel-plugin-provider.h b/libxfce4panel/xfce-panel-plugin-provider.h
index 5408fec..ed300c0 100644
--- a/libxfce4panel/xfce-panel-plugin-provider.h
+++ b/libxfce4panel/xfce-panel-plugin-provider.h
@@ -81,6 +81,8 @@ typedef enum /*< skip >*/
   PROVIDER_SIGNAL_COLLAPSE_PLUGIN,
   PROVIDER_SIGNAL_WRAP_PLUGIN,
   PROVIDER_SIGNAL_UNWRAP_PLUGIN,
+  PROVIDER_SIGNAL_SMALL_PLUGIN,
+  PROVIDER_SIGNAL_UNSMALL_PLUGIN,
   PROVIDER_SIGNAL_LOCK_PANEL,
   PROVIDER_SIGNAL_UNLOCK_PANEL,
   PROVIDER_SIGNAL_REMOVE_PLUGIN,
diff --git a/libxfce4panel/xfce-panel-plugin.c b/libxfce4panel/xfce-panel-plugin.c
index 52f28f8..6356b1e 100644
--- a/libxfce4panel/xfce-panel-plugin.c
+++ b/libxfce4panel/xfce-panel-plugin.c
@@ -126,6 +126,7 @@ enum
   PROP_UNIQUE_ID,
   PROP_ORIENTATION,
   PROP_SIZE,
+  PROP_SMALL,
   PROP_SCREEN_POSITION,
   PROP_EXPAND,
   PROP_MODE,
@@ -174,6 +175,7 @@ struct _XfcePanelPluginPrivate
   guint                shrink : 1;
   guint                nrows;
   XfcePanelPluginMode  mode;
+  guint                small : 1;
   XfceScreenPosition   screen_position;
   guint                locked : 1;
   GSList              *menu_items;
@@ -595,6 +597,24 @@ xfce_panel_plugin_class_init (XfcePanelPluginClass *klass)
                                                        | G_PARAM_STATIC_STRINGS));
 
   /**
+   * XfcePanelPlugin:small:
+   *
+   * Wether the #XfcePanelPlugin is small enough to fit a single row of a multi-row panel.
+   * Plugin writes can use it to read or set this property, but xfce_panel_plugin_set_small()
+   * is recommended.
+   *
+   * Since: 4.10
+   **/
+  g_object_class_install_property (gobject_class,
+                                   PROP_SMALL,
+                                   g_param_spec_boolean ("small",
+                                                         "Small",
+                                                         "Is this plugin small, e.g. a single button?",
+                                                         FALSE,
+                                                         G_PARAM_READWRITE
+                                                         | G_PARAM_STATIC_STRINGS));
+
+  /**
    * XfcePanelPlugin:expand:
    *
    * Wether the #XfcePanelPlugin expands on the panel. Plugin writes can use it
@@ -679,6 +699,7 @@ xfce_panel_plugin_init (XfcePanelPlugin *plugin)
   plugin->priv->property_base = NULL;
   plugin->priv->arguments = NULL;
   plugin->priv->size = 0;
+  plugin->priv->small = FALSE;
   plugin->priv->expand = FALSE;
   plugin->priv->shrink = FALSE;
   plugin->priv->mode = XFCE_PANEL_PLUGIN_MODE_HORIZONTAL;
@@ -781,6 +802,14 @@ xfce_panel_plugin_get_property (GObject    *object,
       g_value_set_int (value, private->size);
       break;
 
+    case PROP_NROWS:
+      g_value_set_uint (value, private->nrows);
+      break;
+
+    case PROP_SMALL:
+      g_value_set_boolean (value, private->small);
+      break;
+
     case PROP_SCREEN_POSITION:
       g_value_set_enum (value, private->screen_position);
       break;
@@ -840,6 +869,11 @@ xfce_panel_plugin_set_property (GObject      *object,
       private->arguments = g_value_dup_boxed (value);
       break;
 
+    case PROP_SMALL:
+      xfce_panel_plugin_set_small (XFCE_PANEL_PLUGIN (object),
+                                   g_value_get_boolean (value));
+      break;
+
     case PROP_EXPAND:
       xfce_panel_plugin_set_expand (XFCE_PANEL_PLUGIN (object),
                                     g_value_get_boolean (value));
@@ -1856,6 +1890,62 @@ xfce_panel_plugin_set_shrink (XfcePanelPlugin *plugin,
 }
 
 
+/**
+ * xfce_panel_plugin_get_small:
+ * @plugin : an #XfcePanelPlugin.
+ *
+ * Whether the plugin is small enough to fit in a single row of
+ * a multi-row panel. E.g. if it is a button-like applet.
+ *
+ * Returns: %TRUE when the plugin is small,
+ *          %FALSE otherwise.
+ *
+ * Since: 4.10
+ **/
+gboolean
+xfce_panel_plugin_get_small (XfcePanelPlugin *plugin)
+{
+  g_return_val_if_fail (XFCE_IS_PANEL_PLUGIN (plugin), FALSE);
+  g_return_val_if_fail (XFCE_PANEL_PLUGIN_CONSTRUCTED (plugin), FALSE);
+
+  return plugin->priv->small;
+}
+
+
+
+/**
+ * xfce_panel_plugin_set_small:
+ * @plugin : an #XfcePanelPlugin.
+ * @small : whether the plugin is a small button-like applet.
+ *
+ * Whether the plugin is small enough to fit in a single row of
+ * a multi-row panel. E.g. if it is a button-like applet.
+ **/
+void
+xfce_panel_plugin_set_small (XfcePanelPlugin *plugin,
+                             gboolean         small)
+{
+  g_return_if_fail (XFCE_IS_PANEL_PLUGIN (plugin));
+  g_return_if_fail (XFCE_PANEL_PLUGIN_CONSTRUCTED (plugin));
+
+  /* normalize the value */
+  small = !!small;
+
+  /* check if update is required */
+  if (G_LIKELY (xfce_panel_plugin_get_small (plugin) != small))
+    {
+      plugin->priv->small = small;
+
+      /* emit signal (in provider) */
+      xfce_panel_plugin_provider_emit_signal (XFCE_PANEL_PLUGIN_PROVIDER (plugin),
+                                              small ? PROVIDER_SIGNAL_SMALL_PLUGIN :
+                                              PROVIDER_SIGNAL_UNSMALL_PLUGIN);
+
+      g_object_notify (G_OBJECT (plugin), "small");
+    }
+}
+
+
 
 /**
  * xfce_panel_plugin_get_mode:
diff --git a/libxfce4panel/xfce-panel-plugin.h b/libxfce4panel/xfce-panel-plugin.h
index 8dcc787..37c3a63 100644
--- a/libxfce4panel/xfce-panel-plugin.h
+++ b/libxfce4panel/xfce-panel-plugin.h
@@ -182,6 +182,11 @@ gboolean              xfce_panel_plugin_get_shrink          (XfcePanelPlugin   *
 void                  xfce_panel_plugin_set_shrink          (XfcePanelPlugin   *plugin,
                                                              gboolean           shrink);
 
+gboolean              xfce_panel_plugin_get_small           (XfcePanelPlugin   *plugin) G_GNUC_PURE;
+
+void                  xfce_panel_plugin_set_small           (XfcePanelPlugin   *plugin,
+                                                             gboolean           small);
+
 GtkOrientation        xfce_panel_plugin_get_orientation     (XfcePanelPlugin   *plugin) G_GNUC_PURE;
 
 XfcePanelPluginMode   xfce_panel_plugin_get_mode            (XfcePanelPlugin   *plugin) G_GNUC_PURE;
diff --git a/panel/panel-application.c b/panel/panel-application.c
index 631550f..2680e25 100644
--- a/panel/panel-application.c
+++ b/panel/panel-application.c
@@ -643,6 +643,16 @@ panel_application_plugin_provider_signal (XfcePanelPluginProvider       *provide
                                NULL);
       break;
 
+    case PROVIDER_SIGNAL_SMALL_PLUGIN:
+    case PROVIDER_SIGNAL_UNSMALL_PLUGIN:
+      itembar = gtk_bin_get_child (GTK_BIN (window));
+      gtk_container_child_set (GTK_CONTAINER (itembar),
+                               GTK_WIDGET (provider),
+                               "small",
+                               provider_signal == PROVIDER_SIGNAL_SMALL_PLUGIN,
+                               NULL);
+      break;
+
     case PROVIDER_SIGNAL_LOCK_PANEL:
       /* increase window's autohide counter */
       panel_window_freeze_autohide (window);
diff --git a/panel/panel-itembar.c b/panel/panel-itembar.c
index 2e6e177..cbf845e 100644
--- a/panel/panel-itembar.c
+++ b/panel/panel-itembar.c
@@ -102,6 +102,7 @@ struct _PanelItembarChild
   guint      expand : 1;
   guint      shrink : 1;
   guint      wrap : 1;
+  guint      small : 1;
 };
 
 enum
@@ -117,7 +118,8 @@ enum
   CHILD_PROP_0,
   CHILD_PROP_EXPAND,
   CHILD_PROP_SHRINK,
-  CHILD_PROP_WRAP
+  CHILD_PROP_WRAP,
+  CHILD_PROP_SMALL
 };
 
 enum
@@ -211,6 +213,13 @@ panel_itembar_class_init (PanelItembarClass *klass)
                                                                     NULL, NULL,
                                                                     FALSE,
                                                                     EXO_PARAM_READWRITE));
+
+  gtk_container_class_install_child_property (gtkcontainer_class,
+                                              CHILD_PROP_SMALL,
+                                              g_param_spec_boolean ("small",
+                                                                    NULL, NULL,
+                                                                    FALSE,
+                                                                    EXO_PARAM_READWRITE));
 }
 
 
@@ -704,6 +713,13 @@ panel_itembar_set_child_property (GtkContainer *container,
       child->wrap = boolean;
       break;
 
+    case CHILD_PROP_SMALL:
+      boolean = g_value_get_boolean (value);
+      if (child->small == boolean)
+        return;
+      child->small = boolean;
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (container, prop_id, pspec);
       break;
@@ -741,6 +757,10 @@ panel_itembar_get_child_property (GtkContainer *container,
       g_value_set_boolean (value, child->wrap);
       break;
 
+    case CHILD_PROP_SMALL:
+      g_value_set_boolean (value, child->small);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (container, prop_id, pspec);
       break;


More information about the Xfce4-commits mailing list