[Xfce4-commits] <xfce4-indicator-plugin:master> Moved button-related event handlers to buttons

Andrzej noreply at xfce.org
Thu Apr 4 17:44:13 CEST 2013


Updating branch refs/heads/master
         to 2cb73e6d4175c5d693e91cc5357ac4564912e18f (commit)
       from c9785b9b7beb502e6b7bd03cbfbc6cd765040a29 (commit)

commit 2cb73e6d4175c5d693e91cc5357ac4564912e18f
Author: Andrzej <ndrwrdck at gmail.com>
Date:   Sat Apr 28 19:03:13 2012 +0900

    Moved button-related event handlers to buttons

 panel-plugin/indicator-box.c    |   16 +++++++++-
 panel-plugin/indicator-box.h    |    5 +++
 panel-plugin/indicator-button.c |   65 ++++++++++++++++++++++++++++++++++++++-
 panel-plugin/indicator.c        |   55 +--------------------------------
 panel-plugin/indicator.h        |    4 --
 5 files changed, 85 insertions(+), 60 deletions(-)

diff --git a/panel-plugin/indicator-box.c b/panel-plugin/indicator-box.c
index 37248c4..78567b4 100644
--- a/panel-plugin/indicator-box.c
+++ b/panel-plugin/indicator-box.c
@@ -292,9 +292,14 @@ xfce_indicator_box_set_size (XfceIndicatorBox *box,
 
 
 GtkWidget *
-xfce_indicator_box_new ()
+xfce_indicator_box_new (XfcePanelPlugin *plugin)
 {
   XfceIndicatorBox *box = g_object_new (XFCE_TYPE_INDICATOR_BOX, NULL);
+
+  box->plugin = plugin;
+  if (box->plugin != NULL)
+    g_object_ref (G_OBJECT (box->plugin));
+
   return GTK_WIDGET (box);
 }
 
@@ -633,3 +638,12 @@ xfce_indicator_box_get_align_left (XfceIndicatorBox *box)
 
   return box->align_left;
 }
+
+
+XfcePanelPlugin *
+xfce_indicator_box_get_plugin (XfceIndicatorBox *box)
+{
+  g_return_val_if_fail (XFCE_IS_INDICATOR_BOX (box), NULL);
+
+  return box->plugin;
+}
diff --git a/panel-plugin/indicator-box.h b/panel-plugin/indicator-box.h
index e4ee8c9..d0746c8 100644
--- a/panel-plugin/indicator-box.h
+++ b/panel-plugin/indicator-box.h
@@ -21,6 +21,7 @@
 #include <glib.h>
 #include <gtk/gtk.h>
 #include <libindicator/indicator-object.h>
+#include <libxfce4panel/libxfce4panel.h>
 
 G_BEGIN_DECLS
 
@@ -40,6 +41,8 @@ struct _XfceIndicatorBox
 {
   GtkContainer          __parent__;
 
+  XfcePanelPlugin      *plugin;
+
   GSList               *children;
 
   gint                  panel_size;
@@ -82,6 +85,8 @@ gboolean xfce_indicator_box_get_align_left (XfceIndicatorBox *box);
 void xfce_indicator_box_remove_entry (XfceIndicatorBox     *box,
                                       IndicatorObjectEntry *entry);
 
+XfcePanelPlugin *xfce_indicator_box_get_plugin (XfceIndicatorBox *box);
+
 GtkWidget *xfce_indicator_box_new ();
 
 G_END_DECLS
diff --git a/panel-plugin/indicator-button.c b/panel-plugin/indicator-button.c
index 58ff3cc..ac0f432 100644
--- a/panel-plugin/indicator-button.c
+++ b/panel-plugin/indicator-button.c
@@ -32,8 +32,21 @@
 
 #include "indicator-button.h"
 
+
+#include <libindicator/indicator-object.h>
+//#ifndef INDICATOR_OBJECT_SIGNAL_ENTRY_SCROLLED
+//#define INDICATOR_OBJECT_SIGNAL_ENTRY_SCROLLED "scroll-entry"
+//#endif
+
+
 static void                 xfce_indicator_button_finalize        (GObject                *object);
 static gint                 xfce_indicator_button_get_icon_size   (XfceIndicatorButton    *button);
+static gboolean             xfce_indicator_button_button_press    (GtkWidget              *widget,
+                                                                   GdkEventButton         *event);
+static gboolean             xfce_indicator_button_scroll          (GtkWidget              *widget,
+                                                                   GdkEventScroll         *event);
+static void                 xfce_indicator_button_menu_deactivate (XfceIndicatorButton    *button,
+                                                                   GtkMenu                *menu);
 
 
 G_DEFINE_TYPE (XfceIndicatorButton, xfce_indicator_button, GTK_TYPE_TOGGLE_BUTTON)
@@ -41,10 +54,16 @@ G_DEFINE_TYPE (XfceIndicatorButton, xfce_indicator_button, GTK_TYPE_TOGGLE_BUTTO
 static void
 xfce_indicator_button_class_init (XfceIndicatorButtonClass *klass)
 {
-  GObjectClass   *gobject_class;
+  GObjectClass      *gobject_class;
+  GtkWidgetClass    *widget_class;
 
   gobject_class = G_OBJECT_CLASS (klass);
   gobject_class->finalize = xfce_indicator_button_finalize;
+
+  widget_class = GTK_WIDGET_CLASS (klass);
+  widget_class->button_press_event = xfce_indicator_button_button_press;
+  widget_class->scroll_event = xfce_indicator_button_scroll;
+
 }
 
 
@@ -314,6 +333,8 @@ xfce_indicator_button_set_menu (XfceIndicatorButton *button,
         g_object_unref (G_OBJECT (button->menu));
       button->menu = menu;
       g_object_ref (G_OBJECT (button->menu));
+      g_signal_connect_swapped (G_OBJECT (button->menu), "deactivate",
+                                G_CALLBACK (xfce_indicator_button_menu_deactivate), button);
       gtk_menu_attach_to_widget(menu, GTK_WIDGET (button), NULL);
     }
 }
@@ -454,3 +475,45 @@ xfce_indicator_button_disconnect_signals (XfceIndicatorButton *button)
 
 }
 
+
+static gboolean
+xfce_indicator_button_button_press (GtkWidget      *widget,
+                                    GdkEventButton *event)
+{
+  XfceIndicatorButton *button = XFCE_INDICATOR_BUTTON (widget);
+
+  if( event->button == 1) /* left click only */
+    {
+      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),TRUE);
+      gtk_menu_popup (button->menu, NULL, NULL,
+                      xfce_panel_plugin_position_menu,
+                      xfce_indicator_box_get_plugin (button->buttonbox),
+                      1, gtk_get_current_event_time ());
+      return TRUE;
+    }
+
+  return FALSE;
+}
+
+
+static gboolean
+xfce_indicator_button_scroll (GtkWidget *widget, GdkEventScroll *event)
+{
+  XfceIndicatorButton *button = XFCE_INDICATOR_BUTTON (widget);
+
+  g_signal_emit_by_name (button->io, INDICATOR_OBJECT_SIGNAL_ENTRY_SCROLLED,
+                         button->entry, 1, event->direction);
+
+  return TRUE;
+}
+
+
+static void
+xfce_indicator_button_menu_deactivate (XfceIndicatorButton *button,
+                                       GtkMenu             *menu)
+{
+  g_return_if_fail (XFCE_IS_INDICATOR_BUTTON (button));
+  g_return_if_fail (GTK_IS_MENU (menu));
+
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), FALSE);
+}
diff --git a/panel-plugin/indicator.c b/panel-plugin/indicator.c
index e122aea..f152a02 100644
--- a/panel-plugin/indicator.c
+++ b/panel-plugin/indicator.c
@@ -182,7 +182,7 @@ indicator_init (IndicatorPlugin *indicator)
   indicator->ebox = gtk_event_box_new();
   gtk_widget_set_can_focus(GTK_WIDGET(indicator->ebox), TRUE);
 
-  indicator->buttonbox = xfce_indicator_box_new ();
+  indicator->buttonbox = xfce_indicator_box_new (plugin);
   gtk_container_add (GTK_CONTAINER (indicator->ebox), GTK_WIDGET(indicator->buttonbox));
   gtk_container_add (GTK_CONTAINER (plugin), GTK_WIDGET(indicator->ebox));
   gtk_widget_show(GTK_WIDGET(indicator->buttonbox));
@@ -270,36 +270,6 @@ indicator_size_changed (XfcePanelPlugin *plugin,
 }
 
 
-
-static gboolean
-on_button_press (GtkWidget *widget, GdkEventButton *event, IndicatorPlugin *indicator)
-{
-  XfcePanelPlugin  *plugin = XFCE_PANEL_PLUGIN (indicator);
-
-  if (indicator != NULL)
-  {
-    if( event->button == 1) /* left click only */
-    {
-      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),TRUE);
-      gtk_menu_popup (xfce_indicator_button_get_menu (XFCE_INDICATOR_BUTTON(widget)), NULL, NULL,
-                      xfce_panel_plugin_position_menu,
-                      plugin, 1, gtk_get_current_event_time ());
-      
-      return TRUE;
-    }
-    /* event doesn't make it to the ebox, so I just push it. */
-    gtk_widget_event (indicator->ebox, (GdkEvent*)event);
-  }
-  return FALSE;
-}
-
-static void
-menu_deactivate (GtkMenu *menu,
-                 gpointer      user_data)
-{
-  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gtk_menu_get_attach_widget (menu)), FALSE);
-}
-
 static void
 indicator_construct (XfcePanelPlugin *plugin)
 {
@@ -359,21 +329,6 @@ indicator_construct (XfcePanelPlugin *plugin)
 }
 
 
-static gboolean
-entry_scrolled (GtkWidget *menuitem, GdkEventScroll *event, IndicatorPlugin *indicator)
-{
-  IndicatorObject *io = xfce_indicator_button_get_io (XFCE_INDICATOR_BUTTON (menuitem));
-  IndicatorObjectEntry *entry = xfce_indicator_button_get_entry (XFCE_INDICATOR_BUTTON (menuitem));
-
-  g_return_val_if_fail(INDICATOR_IS_OBJECT(io), FALSE);
-  g_return_val_if_fail(indicator != NULL, FALSE);
-
-  g_signal_emit_by_name (io, INDICATOR_OBJECT_SIGNAL_ENTRY_SCROLLED, entry, 1, event->direction);
-
-  return TRUE;
-}
-
-
 static void
 entry_added (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_data)
 {
@@ -391,15 +346,7 @@ entry_added (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_d
     xfce_indicator_button_set_label(XFCE_INDICATOR_BUTTON(button), entry->label);
 
   if (entry->menu != NULL)
-  {
     xfce_indicator_button_set_menu (XFCE_INDICATOR_BUTTON(button), entry->menu);
-    g_signal_connect(G_OBJECT(entry->menu), "deactivate", G_CALLBACK(menu_deactivate),NULL);
-  }
-
-  g_signal_connect(button, "button-press-event", G_CALLBACK(on_button_press),
-                   user_data);
-  g_signal_connect(button, "scroll-event", G_CALLBACK(entry_scrolled),
-                   user_data);
 
   gtk_container_add(GTK_CONTAINER (indicator->buttonbox), button);
   gtk_widget_show(button);
diff --git a/panel-plugin/indicator.h b/panel-plugin/indicator.h
index dfe2b47..488bb5f 100644
--- a/panel-plugin/indicator.h
+++ b/panel-plugin/indicator.h
@@ -38,10 +38,6 @@ GType indicator_get_type      (void) G_GNUC_CONST;
 
 void  indicator_register_type (XfcePanelTypeModule *type_module);
 
-#ifndef INDICATOR_OBJECT_SIGNAL_ENTRY_SCROLLED
-#define INDICATOR_OBJECT_SIGNAL_ENTRY_SCROLLED "scroll-entry"
-#endif
-
 void                indicator_save             (XfcePanelPlugin    *plugin,
                                                 IndicatorPlugin    *indicator);
 


More information about the Xfce4-commits mailing list