[Xfce4-commits] <xfce4-embed-plugin:master> Add optional handle widget.

David Schneider noreply at xfce.org
Sun Feb 3 07:00:02 CET 2013


Updating branch refs/heads/master
         to 7c111d48d9699d820d5eff7cf749c0b40362787e (commit)
       from a1ae7c2b73cd263700d02f714aa3ccaa1b9e8aaa (commit)

commit 7c111d48d9699d820d5eff7cf749c0b40362787e
Author: David Schneider <dnschneid at gmail.com>
Date:   Sat Feb 2 21:57:43 2013 -0800

    Add optional handle widget.

 panel-plugin/embed-dialogs.c |   17 +++++++++++++
 panel-plugin/embed.c         |   55 ++++++++++++++++++++++++++++++-----------
 panel-plugin/embed.h         |    2 +
 3 files changed, 59 insertions(+), 15 deletions(-)

diff --git a/panel-plugin/embed-dialogs.c b/panel-plugin/embed-dialogs.c
index da56b88..f3869b6 100644
--- a/panel-plugin/embed-dialogs.c
+++ b/panel-plugin/embed-dialogs.c
@@ -196,6 +196,18 @@ embed_expand_toggled (GtkToggleButton *toggle, EmbedPlugin *embed)
 
 
 static void
+embed_handle_toggled (GtkToggleButton *toggle, EmbedPlugin *embed)
+{
+  embed->show_handle = gtk_toggle_button_get_active (toggle);
+  if (embed->show_handle)
+    gtk_widget_show (embed->handle);
+  else
+    gtk_widget_hide (embed->handle);
+}
+
+
+
+static void
 set_tooltips (GtkWidget *widgetA, GtkWidget *widgetB, const gchar *text)
 {
   gtk_widget_set_tooltip_text (widgetA, text);
@@ -395,6 +407,11 @@ embed_configure (XfcePanelPlugin *plugin, EmbedPlugin *embed)
                  _("_Expand"),
                  _("Use up all available panel space"));
 
+  /* show_handle */
+  add_checkbutton (embed, table, 4, embed->show_handle, embed_handle_toggled,
+                 _("Show _handle"),
+                 _("Display a handle at the top of the plugin"));
+
 
   /* center dialog on the screen */
   gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
diff --git a/panel-plugin/embed.c b/panel-plugin/embed.c
index 52f4743..36d75bd 100644
--- a/panel-plugin/embed.c
+++ b/panel-plugin/embed.c
@@ -50,6 +50,7 @@
 #define DEFAULT_POLL_DELAY   0
 #define DEFAULT_MIN_SIZE     EMBED_MIN_SIZE_MATCH_WINDOW
 #define DEFAULT_EXPAND       TRUE
+#define DEFAULT_SHOW_HANDLE  FALSE
 
 
 
@@ -66,6 +67,8 @@ static void
 embed_add_socket (EmbedPlugin *embed, gboolean update_size);
 static void
 embed_add_fake_socket (EmbedPlugin *embed);
+static gint
+embed_handle_expose (GtkWidget *widget, GdkEvent *event, EmbedPlugin *embed);
 
 
 /* register the plugin */
@@ -109,6 +112,7 @@ embed_save (XfcePanelPlugin *plugin, EmbedPlugin *embed)
     xfce_rc_write_int_entry  (rc, "poll_delay",  embed->poll_delay);
     xfce_rc_write_int_entry  (rc, "min_size",    embed->min_size);
     xfce_rc_write_bool_entry (rc, "expand",      embed->expand);
+    xfce_rc_write_bool_entry (rc, "show_handle", embed->show_handle);
 
     /* close the rc file */
     xfce_rc_close (rc);
@@ -154,6 +158,8 @@ embed_read (EmbedPlugin *embed)
                               "min_size", DEFAULT_MIN_SIZE);
       embed->expand = xfce_rc_read_bool_entry (rc,
                               "expand", DEFAULT_EXPAND);
+      embed->show_handle = xfce_rc_read_bool_entry (rc,
+                              "show_handle", DEFAULT_SHOW_HANDLE);
 
       /* cleanup */
       xfce_rc_close (rc);
@@ -175,23 +181,13 @@ embed_read (EmbedPlugin *embed)
   embed->poll_delay  = DEFAULT_POLL_DELAY;
   embed->min_size    = DEFAULT_MIN_SIZE;
   embed->expand      = DEFAULT_EXPAND;
+  embed->show_handle = DEFAULT_SHOW_HANDLE;
 
   embed_configure (embed->plugin, embed);
 }
 
 
 
-/* Remove any old separator and add a new one, if necessary.
- * This is used to add a separator widget, although currently as there is no
- * separator widget, nothing happens.  The function is still called in the
- * correct places though, so it is trivial to add. */
-static void
-embed_update_separator (EmbedPlugin* embed, GtkOrientation orientation)
-{
-}
-
-
-
 /* Creates a new EmbedPlugin structure and initializes everything. */
 static EmbedPlugin *
 embed_new (XfcePanelPlugin *plugin)
@@ -230,8 +226,15 @@ embed_new (XfcePanelPlugin *plugin)
   embed->hvbox = xfce_hvbox_new (orientation, FALSE, 2);
   gtk_widget_show (embed->hvbox);
 
-  /* separator */
-  embed_update_separator (embed, orientation);
+  /* handle */
+  embed->handle = gtk_alignment_new (0.0f, 0.0f, 0.0f, 0.0f);
+  gtk_box_pack_start (GTK_BOX (embed->hvbox), embed->handle, FALSE, FALSE, 0);
+  g_signal_connect (G_OBJECT (embed->handle), "expose-event",
+                    G_CALLBACK (embed_handle_expose), plugin);
+  gtk_widget_set_size_request (embed->handle, 8, 8);
+  xfce_panel_plugin_add_action_widget (embed->plugin, embed->handle);
+  if (embed->show_handle)
+    gtk_widget_show (embed->handle);
 
   /* label */
   embed->label = gtk_label_new (NULL);
@@ -337,7 +340,6 @@ embed_mode_changed (XfcePanelPlugin     *plugin,
 
   embed_update_label (embed);
   xfce_hvbox_set_orientation (XFCE_HVBOX (embed->hvbox), orientation);
-  embed_update_separator (embed, orientation);
 }
 
 #else  // libxfce4panel < 4.9.0
@@ -350,7 +352,6 @@ embed_orientation_changed (XfcePanelPlugin *plugin,
 {
   /* change the orientation of the box */
   xfce_hvbox_set_orientation (XFCE_HVBOX (embed->hvbox), orientation);
-  embed_update_separator (embed, orientation);
 }
 #endif
 
@@ -857,6 +858,30 @@ embed_expose (GtkWidget *widget, GdkEvent *event, EmbedPlugin *embed)
 
 
 
+/* Callback used when the handle needs to be painted.
+ */
+static gint
+embed_handle_expose (GtkWidget *widget, GdkEvent *event, EmbedPlugin *embed)
+{
+  GtkOrientation orientation = GTK_ORIENTATION_HORIZONTAL;
+  if (xfce_panel_plugin_get_orientation (XFCE_PANEL_PLUGIN (embed)) ==
+      GTK_ORIENTATION_HORIZONTAL)
+    orientation = GTK_ORIENTATION_VERTICAL;
+
+  gtk_paint_handle (widget->style, widget->window,
+                    GTK_WIDGET_STATE (widget), GTK_SHADOW_NONE,
+                    &(event->expose.area), widget, "handlebox",
+                    widget->allocation.x,
+                    widget->allocation.y,
+                    widget->allocation.width,
+                    widget->allocation.height,
+                    orientation);
+
+  return TRUE;
+}
+
+
+
 /* Callback for when the gtksocket is realized.
  * Set the window settings.
  */
diff --git a/panel-plugin/embed.h b/panel-plugin/embed.h
index 9343437..3725ce5 100644
--- a/panel-plugin/embed.h
+++ b/panel-plugin/embed.h
@@ -29,6 +29,7 @@ typedef struct
 
     /* panel widgets */
     GtkWidget       *hvbox;
+    GtkWidget       *handle;
     GtkWidget       *label;
     GtkWidget       *socket;
     GtkWidget       *embed_menu;
@@ -66,6 +67,7 @@ typedef struct
     gint             poll_delay;
     gint             min_size;
     gboolean         expand;
+    gboolean         show_handle;
 }
 EmbedPlugin;
 


More information about the Xfce4-commits mailing list