Updating branch refs/heads/master to 9003be9a2ba233c68c706e691741c3dea09a44c2 (commit) from 11fbd8c67c272706dbde3ca9fa0722b4691ec817 (commit)
commit 9003be9a2ba233c68c706e691741c3dea09a44c2 Author: Andrzej <ndrwr...@gmail.com> Date: Wed Jan 22 21:44:00 2014 +0000 Improved handling of popup menus _set_menu should clean up/disactivate previous menu, Menus should only be attached once (and detached when needed), _deactivate function should only be called once. panel-plugin/indicator-box.c | 3 +-- panel-plugin/indicator-button.c | 48 ++++++++++++++++++--------------------- panel-plugin/indicator-button.h | 2 +- panel-plugin/indicator.c | 6 +++-- 4 files changed, 28 insertions(+), 31 deletions(-) diff --git a/panel-plugin/indicator-box.c b/panel-plugin/indicator-box.c index c0fa328..66523d6 100644 --- a/panel-plugin/indicator-box.c +++ b/panel-plugin/indicator-box.c @@ -595,8 +595,7 @@ xfce_indicator_box_remove_entry (XfceIndicatorBox *box, button = XFCE_INDICATOR_BUTTON (li_tmp->data); if (xfce_indicator_button_get_entry (button) == entry) { - xfce_indicator_button_disconnect_signals (button); - gtk_widget_destroy (GTK_WIDGET (button)); + xfce_indicator_button_destroy (button); return; } } diff --git a/panel-plugin/indicator-button.c b/panel-plugin/indicator-button.c index 2963e84..8440c62 100644 --- a/panel-plugin/indicator-button.c +++ b/panel-plugin/indicator-button.c @@ -43,7 +43,6 @@ //#define INDICATOR_OBJECT_SIGNAL_ENTRY_SCROLLED "scroll-entry" //#endif -static void xfce_indicator_button_finalize (GObject *object); static gboolean xfce_indicator_button_button_press (GtkWidget *widget, GdkEventButton *event); static gboolean xfce_indicator_button_button_release (GtkWidget *widget, @@ -73,6 +72,7 @@ struct _XfceIndicatorButton GtkWidget *align_box; GtkWidget *box; + gulong deactivate_id; }; struct _XfceIndicatorButtonClass @@ -88,12 +88,8 @@ G_DEFINE_TYPE (XfceIndicatorButton, xfce_indicator_button, GTK_TYPE_TOGGLE_BUTTO static void xfce_indicator_button_class_init (XfceIndicatorButtonClass *klass) { - 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->button_release_event = xfce_indicator_button_button_release; @@ -122,6 +118,7 @@ xfce_indicator_button_init (XfceIndicatorButton *button) button->plugin = NULL; button->config = NULL; button->menu = NULL; + button->deactivate_id = 0; button->align_box = gtk_alignment_new (0.5, 0.5, 1.0, 1.0); gtk_container_add (GTK_CONTAINER (button), button->align_box); @@ -130,18 +127,6 @@ xfce_indicator_button_init (XfceIndicatorButton *button) -static void -xfce_indicator_button_finalize (GObject *object) -{ - XfceIndicatorButton *button = XFCE_INDICATOR_BUTTON (object); - - xfce_indicator_button_disconnect_signals (button); - - G_OBJECT_CLASS (xfce_indicator_button_parent_class)->finalize (object); -} - - - void xfce_indicator_button_set_label (XfceIndicatorButton *button, GtkLabel *label) @@ -174,13 +159,15 @@ xfce_indicator_button_set_menu (XfceIndicatorButton *button, g_return_if_fail (XFCE_IS_INDICATOR_BUTTON (button)); g_return_if_fail (GTK_IS_MENU (menu)); - if (button->menu != menu) + if (button->menu != NULL) { - button->menu = 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); + gtk_menu_detach (button->menu); + gtk_menu_popdown (button->menu); + button->menu = NULL; } + + button->menu = menu; + gtk_menu_attach_to_widget(menu, GTK_WIDGET (button), NULL); } @@ -297,14 +284,17 @@ xfce_indicator_button_new (IndicatorObject *io, void -xfce_indicator_button_disconnect_signals (XfceIndicatorButton *button) +xfce_indicator_button_destroy (XfceIndicatorButton *button) { g_return_if_fail (XFCE_IS_INDICATOR_BUTTON (button)); - if (button->menu != 0) + if (button->menu != NULL) { + gtk_menu_detach (button->menu); gtk_menu_popdown (button->menu); + button->menu = NULL; } + gtk_widget_destroy (GTK_WIDGET (button)); } @@ -316,13 +306,14 @@ xfce_indicator_button_button_press (GtkWidget *widget, if(event->button == 1 && button->menu != NULL) /* left click only */ { - //gtk_menu_attach_to_widget(button->menu, GTK_WIDGET (button), NULL); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),TRUE); + button->deactivate_id = g_signal_connect_swapped + (G_OBJECT (button->menu), "deactivate", + G_CALLBACK (xfce_indicator_button_menu_deactivate), button); gtk_menu_reposition (GTK_MENU (button->menu)); gtk_menu_popup (button->menu, NULL, NULL, xfce_panel_plugin_position_menu, button->plugin, event->button, event->time); - //gtk_menu_detach(button->menu); return TRUE; } @@ -366,6 +357,11 @@ xfce_indicator_button_menu_deactivate (XfceIndicatorButton *button, g_return_if_fail (XFCE_IS_INDICATOR_BUTTON (button)); g_return_if_fail (GTK_IS_MENU (menu)); + if (button->deactivate_id) + { + g_signal_handler_disconnect (menu, button->deactivate_id); + button->deactivate_id = 0; + } gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), FALSE); } diff --git a/panel-plugin/indicator-button.h b/panel-plugin/indicator-button.h index 9347838..f0f1610 100644 --- a/panel-plugin/indicator-button.h +++ b/panel-plugin/indicator-button.h @@ -69,7 +69,7 @@ GtkWidget *xfce_indicator_button_new (IndicatorObject XfcePanelPlugin *plugin, IndicatorConfig *config); -void xfce_indicator_button_disconnect_signals (XfceIndicatorButton *button); +void xfce_indicator_button_destroy (XfceIndicatorButton *button); G_END_DECLS diff --git a/panel-plugin/indicator.c b/panel-plugin/indicator.c index f4b60cb..b921046 100644 --- a/panel-plugin/indicator.c +++ b/panel-plugin/indicator.c @@ -341,8 +341,7 @@ entry_added (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_d /* remove placeholder item when there are real entries to be added */ if (indicator->item != NULL) { - xfce_indicator_button_disconnect_signals (XFCE_INDICATOR_BUTTON (indicator->item)); - gtk_widget_destroy (GTK_WIDGET (indicator->item)); + xfce_indicator_button_destroy (XFCE_INDICATOR_BUTTON (indicator->item)); indicator->item = NULL; } @@ -367,6 +366,9 @@ entry_added (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_d static void entry_removed (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_data) { + const gchar *io_name = g_object_get_data (G_OBJECT (io), "io-name"); + + g_debug("Entry removed for io=%s", io_name); xfce_indicator_box_remove_entry (XFCE_INDICATOR_BOX (user_data), entry); } _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org https://mail.xfce.org/mailman/listinfo/xfce4-commits