Updating branch refs/heads/master
         to 173fc38553940f4c6807aa5d7a2823882fe780e1 (commit)
       from 85268551b1358c3d4412f4699c2e35f494d8b222 (commit)

commit 173fc38553940f4c6807aa5d7a2823882fe780e1
Author: Nick Schermer <n...@xfce.org>
Date:   Fri Apr 22 11:47:04 2011 +0200

    Libxfce4panel: Add new API to allow plugins to shrink.
    
    This is an alternative to expanding plugins, if there is not
    enough room on the panel, shrink plugins who can.

 libxfce4panel/libxfce4panel.symbols        |    2 +
 libxfce4panel/xfce-panel-plugin-provider.h |    4 +-
 libxfce4panel/xfce-panel-plugin.c          |   90 +++++++++++++++++++++++++++-
 libxfce4panel/xfce-panel-plugin.h          |    5 ++
 4 files changed, 99 insertions(+), 2 deletions(-)

diff --git a/libxfce4panel/libxfce4panel.symbols 
b/libxfce4panel/libxfce4panel.symbols
index 4821b79..494572c 100644
--- a/libxfce4panel/libxfce4panel.symbols
+++ b/libxfce4panel/libxfce4panel.symbols
@@ -108,6 +108,8 @@ xfce_panel_plugin_get_arguments G_GNUC_PURE
 xfce_panel_plugin_get_size G_GNUC_PURE
 xfce_panel_plugin_get_expand G_GNUC_PURE
 xfce_panel_plugin_set_expand
+xfce_panel_plugin_get_shrink G_GNUC_PURE
+xfce_panel_plugin_set_shrink
 xfce_panel_plugin_get_locked
 xfce_panel_plugin_get_orientation G_GNUC_PURE
 xfce_panel_plugin_get_screen_position G_GNUC_PURE
diff --git a/libxfce4panel/xfce-panel-plugin-provider.h 
b/libxfce4panel/xfce-panel-plugin-provider.h
index b5225ac..f4e2a5c 100644
--- a/libxfce4panel/xfce-panel-plugin-provider.h
+++ b/libxfce4panel/xfce-panel-plugin-provider.h
@@ -89,7 +89,9 @@ typedef enum /*< skip >*/
   PROVIDER_SIGNAL_PANEL_HELP,
   PROVIDER_SIGNAL_SHOW_CONFIGURE,
   PROVIDER_SIGNAL_SHOW_ABOUT,
-  PROVIDER_SIGNAL_FOCUS_PLUGIN
+  PROVIDER_SIGNAL_FOCUS_PLUGIN,
+  PROVIDER_SIGNAL_SHRINK_PLUGIN,
+  PROVIDER_SIGNAL_UNSHRINK_PLUGIN
 }
 XfcePanelPluginProviderSignal;
 
diff --git a/libxfce4panel/xfce-panel-plugin.c 
b/libxfce4panel/xfce-panel-plugin.c
index 360ed7d..d85a813 100644
--- a/libxfce4panel/xfce-panel-plugin.c
+++ b/libxfce4panel/xfce-panel-plugin.c
@@ -125,7 +125,8 @@ enum
   PROP_ORIENTATION,
   PROP_SIZE,
   PROP_SCREEN_POSITION,
-  PROP_EXPAND
+  PROP_EXPAND,
+  PROP_SHRINK
 };
 
 enum
@@ -164,6 +165,7 @@ struct _XfcePanelPluginPrivate
   gchar              **arguments;
   gint                 size;
   guint                expand : 1;
+  guint                shrink : 1;
   GtkOrientation       orientation;
   XfceScreenPosition   screen_position;
   guint                locked : 1;
@@ -563,6 +565,24 @@ xfce_panel_plugin_class_init (XfcePanelPluginClass *klass)
                                                          G_PARAM_READWRITE
                                                          | 
G_PARAM_STATIC_STRINGS));
 
+  /**
+   * XfcePanelPlugin:shrink:
+   *
+   * Wether the #XfcePanelPlugin can shrink when there is no space left on the 
panel.
+   * Plugin writes can use it to read or set this property, but 
xfce_panel_plugin_set_shrink()
+   * is recommended.
+   *
+   * Since: 4.10
+   **/
+  g_object_class_install_property (gobject_class,
+                                   PROP_SHRINK,
+                                   g_param_spec_boolean ("shrink",
+                                                         "Shrink",
+                                                         "Whether this plugin 
can shrink",
+                                                         FALSE,
+                                                         G_PARAM_READWRITE
+                                                         | 
G_PARAM_STATIC_STRINGS));
+
   item_properties = g_quark_from_static_string ("item-properties");
   item_about = g_quark_from_static_string ("item-about");
 }
@@ -582,6 +602,7 @@ xfce_panel_plugin_init (XfcePanelPlugin *plugin)
   plugin->priv->arguments = NULL;
   plugin->priv->size = 0;
   plugin->priv->expand = FALSE;
+  plugin->priv->shrink = FALSE;
   plugin->priv->orientation = GTK_ORIENTATION_HORIZONTAL;
   plugin->priv->screen_position = XFCE_SCREEN_POSITION_NONE;
   plugin->priv->menu = NULL;
@@ -688,6 +709,10 @@ xfce_panel_plugin_get_property (GObject    *object,
       g_value_set_boolean (value, private->expand);
       break;
 
+    case PROP_SHRINK:
+      g_value_set_boolean (value, private->shrink);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -740,6 +765,11 @@ xfce_panel_plugin_set_property (GObject      *object,
                                     g_value_get_boolean (value));
       break;
 
+    case PROP_SHRINK:
+      xfce_panel_plugin_set_shrink (XFCE_PANEL_PLUGIN (object),
+                                    g_value_get_boolean (value));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -1654,6 +1684,64 @@ xfce_panel_plugin_set_expand (XfcePanelPlugin *plugin,
 
 
 /**
+ * xfce_panel_plugin_get_shrink:
+ * @plugin : an #XfcePanelPlugin.
+ *
+ * Whether the plugin can shrink if the size on the panel is limited. This
+ * is effective with plugins that do not have expand set, but can accept
+ * a smaller size when needed.
+ *
+ * Returns: %TRUE when the plugin can shrink,
+ *          %FALSE otherwise.
+ *
+ * Since: 4.10
+ **/
+gboolean
+xfce_panel_plugin_get_shrink (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->shrink;
+}
+
+
+
+/**
+ * xfce_panel_plugin_set_shrink:
+ * @plugin : an #XfcePanelPlugin.
+ * @shrink : whether the plugin can shrink.
+ *
+ * Wether the plugin can shrink if the size on the panel
+ * is limited. This does not work if the plugin is expanded.
+ **/
+void
+xfce_panel_plugin_set_shrink (XfcePanelPlugin *plugin,
+                              gboolean         shrink)
+{
+  g_return_if_fail (XFCE_IS_PANEL_PLUGIN (plugin));
+  g_return_if_fail (XFCE_PANEL_PLUGIN_CONSTRUCTED (plugin));
+
+  /* normalize the value */
+  shrink = !!shrink;
+
+  /* check if update is required */
+  if (G_LIKELY (xfce_panel_plugin_get_shrink (plugin) != shrink))
+    {
+      plugin->priv->shrink = shrink;
+
+      /* emit signal (in provider) */
+      xfce_panel_plugin_provider_emit_signal (XFCE_PANEL_PLUGIN_PROVIDER 
(plugin),
+                                              shrink ? 
PROVIDER_SIGNAL_SHRINK_PLUGIN :
+                                                  
PROVIDER_SIGNAL_UNSHRINK_PLUGIN);
+
+      g_object_notify (G_OBJECT (plugin), "shrink");
+    }
+}
+
+
+
+/**
  * xfce_panel_plugin_get_orientation:
  * @plugin : an #XfcePanelPlugin.
  *
diff --git a/libxfce4panel/xfce-panel-plugin.h 
b/libxfce4panel/xfce-panel-plugin.h
index 6f802ec..b905120 100644
--- a/libxfce4panel/xfce-panel-plugin.h
+++ b/libxfce4panel/xfce-panel-plugin.h
@@ -174,6 +174,11 @@ gboolean              xfce_panel_plugin_get_expand         
 (XfcePanelPlugin   *
 void                  xfce_panel_plugin_set_expand          (XfcePanelPlugin   
*plugin,
                                                              gboolean          
 expand);
 
+gboolean              xfce_panel_plugin_get_shrink          (XfcePanelPlugin   
*plugin) G_GNUC_PURE;
+
+void                  xfce_panel_plugin_set_shrink          (XfcePanelPlugin   
*plugin,
+                                                             gboolean          
 shrink);
+
 GtkOrientation        xfce_panel_plugin_get_orientation     (XfcePanelPlugin   
*plugin) G_GNUC_PURE;
 
 XfceScreenPosition    xfce_panel_plugin_get_screen_position (XfcePanelPlugin   
*plugin) G_GNUC_PURE;
_______________________________________________
Xfce4-commits mailing list
Xfce4-commits@xfce.org
http://foo-projects.org/mailman/listinfo/xfce4-commits

Reply via email to