[Xfce4-commits] <xfce4-taskbar-plugin:master> Tidied up the hover menu timeout logic.

Gearoid Murphy noreply at xfce.org
Sat Oct 13 16:52:01 CEST 2012


Updating branch refs/heads/master
         to c7178568dc3a4a4c0399b49bf65dcc8ea817e986 (commit)
       from aa7b850f8ef45a0879bec62f50933f02a9841613 (commit)

commit c7178568dc3a4a4c0399b49bf65dcc8ea817e986
Author: Gearoid Murphy <gearoid at murphy.com>
Date:   Sat Oct 13 15:44:51 2012 +0100

    Tidied up the hover menu timeout logic.

 taskbar-widget.c |   63 ++++++++++++++++++++++++------------------------------
 1 files changed, 28 insertions(+), 35 deletions(-)

diff --git a/taskbar-widget.c b/taskbar-widget.c
index 75d0cfc..c1a8ce2 100644
--- a/taskbar-widget.c
+++ b/taskbar-widget.c
@@ -2277,7 +2277,6 @@ static gboolean xfce_taskbar_group_button_release_event
         GtkMenu *menu = attached->data;
         menu_source = (size_t)(g_object_get_data(G_OBJECT(menu), "menu-source"));
         printf("menu_source: %zu\n", menu_source);
-        g_signal_handlers_disconnect_by_func(group->button, trigger_hover_menu_timeout, menu);
         gtk_widget_destroy (GTK_WIDGET(menu));
     }
     
@@ -2363,14 +2362,7 @@ static gboolean xfce_taskbar_group_button_release_event
 static gboolean xfce_taskbar_hover_menu_timeout(gpointer menu_ptr)
 {
     GtkWidget *menu_widget = (GtkWidget *)menu_ptr;
-    
-    if((GTK_MENU_SHELL (menu_widget))->active == FALSE)
-    {
-        GtkWidget *button_widget = gtk_menu_get_attach_widget(GTK_MENU(menu_widget));
-        g_signal_handlers_disconnect_by_func(button_widget, trigger_hover_menu_timeout, menu_ptr);
-        gtk_widget_destroy (menu_widget);
-    }
-    
+    gtk_widget_destroy (menu_widget);
     return FALSE ;
 }
 
@@ -2380,13 +2372,12 @@ static gboolean hover_menu_enter(GtkWidget *widget, GdkEvent  *event, gpointer m
     void *counter;
     GtkWidget *menu_widget = (GtkWidget *)menu_ptr;
     
-    //We leave the menu shell in an inactive state until the user transfers mouse focus to it
-    //When mouse focus is recv'd, we disanle the pending timeout and activate the hover menu shell
-    if((GTK_MENU_SHELL (menu_widget))->active == FALSE)
+    size_t timeout_id = (size_t)(g_object_get_data(G_OBJECT(menu_widget), "timeout_id"));
+    if(timeout_id != 0)
     {
-        GtkWidget *button_widget = gtk_menu_get_attach_widget(GTK_MENU(menu_widget));
-        g_signal_handlers_disconnect_by_func(button_widget, trigger_hover_menu_timeout, menu_ptr);
-        (GTK_MENU_SHELL (menu_widget))->active = TRUE;
+        g_source_remove(timeout_id);
+        timeout_id = 0 ;
+        g_object_set_data(G_OBJECT(menu_widget), "timeout_id", (void *)timeout_id);
     }
     
     return FALSE ;
@@ -2395,26 +2386,8 @@ static gboolean hover_menu_enter(GtkWidget *widget, GdkEvent  *event, gpointer m
 //Triggered when mouse focus leaves the hover menu
 static gboolean hover_menu_leave(GtkWidget *widget, GdkEvent  *event, gpointer menu_ptr)
 {
-    void *counter;
     GtkWidget *menu_widget = (GtkWidget *)menu_ptr;
     gtk_widget_destroy (menu_widget);
-    
-    return FALSE ;
-}
-
-//When the mouse moves away from the group icon, we trigger a timeout, during which the hover menu will remain
-//if the user moves into the hover menu scope, we disable the timeout, otherwise the timeout triggers
-//and removes the hover menu
-static gboolean trigger_hover_menu_timeout(GtkWidget *widget, GdkEvent  *event, gpointer menu_ptr)
-{
-    GtkWidget *menu_widget = (GtkWidget *)menu_ptr;
-    
-    //We don't want to kill the hover menu immediately, so we wait 100ms
-    g_timeout_add(100, xfce_taskbar_hover_menu_timeout, menu_widget);
-    
-    g_signal_connect (GTK_WINDOW (GTK_MENU(menu_widget)->toplevel), "enter-notify-event", G_CALLBACK (hover_menu_enter), menu_widget);
-    g_signal_connect (GTK_WINDOW (GTK_MENU(menu_widget)->toplevel), "leave-notify-event", G_CALLBACK (hover_menu_leave), menu_widget);
-    
     return FALSE ;
 }
 
@@ -2423,7 +2396,6 @@ static void xfce_taskbar_activate_hover_menu(GtkWidget *menu_widget, XfceTaskBar
     gtk_menu_attach_to_widget (GTK_MENU (menu_widget), group->button, NULL);
     g_object_set_data(G_OBJECT(menu_widget), "menu-source", (void *)mouse_button);
     g_signal_connect (G_OBJECT (menu_widget), "selection-done", G_CALLBACK (xfce_taskbar_group_button_menu_destroy), group);
-    g_signal_connect_after (G_OBJECT (group->button), "leave-notify-event", G_CALLBACK (trigger_hover_menu_timeout), menu_widget);
     {
         gint x, y ;
         gboolean push_in=TRUE;
@@ -2435,6 +2407,8 @@ static void xfce_taskbar_activate_hover_menu(GtkWidget *menu_widget, XfceTaskBar
         menu->position_func = xfce_panel_plugin_position_menu;
         menu->position_func_data = xfce_taskbar_get_panel_plugin(group->taskbar);
         
+        (GTK_MENU_SHELL (menu_widget))->active = TRUE;
+        
         gtk_widget_show (menu->toplevel);
         gtk_window_move(menu_window, x, y);
         gtk_widget_show (menu_widget);
@@ -2462,9 +2436,28 @@ static gboolean xfce_taskbar_group_button_hover_timeout(gpointer group_ptr)
 }
 
 //Triggered when the mouse exits the group button icon
-static gboolean xfce_taskbar_group_button_leave_event(GtkWidget *button, GdkEvent *event, XfceTaskBarGroup *group)
+static gboolean xfce_taskbar_group_button_leave_event(GtkWidget *button_widget, GdkEvent *event, XfceTaskBarGroup *group)
 {
     DISABLE_HOVER_TIMEOUT(group);
+    
+    {
+        GList *attachlist = gtk_menu_get_for_attach_widget(button_widget);
+        guint attachcount = g_list_length(attachlist);
+        panel_assert (attachcount <= 1 && "button widget should only ever have a single widget attached!");
+        if(attachcount == 1)
+        {
+            //We;ve got a hover menu attached, trigger a timeout for destroying it
+            GtkWidget *menu_widget = (GtkWidget *)(attachlist->data);
+            
+            //We don't want to kill the hover menu immediately, so we wait a small time
+            size_t timeout_id = (size_t)g_timeout_add(300, xfce_taskbar_hover_menu_timeout, menu_widget);
+            g_object_set_data(G_OBJECT(menu_widget), "timeout_id", (void *)timeout_id);
+            
+            g_signal_connect (GTK_WINDOW (GTK_MENU(menu_widget)->toplevel), "enter-notify-event", G_CALLBACK (hover_menu_enter), menu_widget);
+            g_signal_connect (GTK_WINDOW (GTK_MENU(menu_widget)->toplevel), "leave-notify-event", G_CALLBACK (hover_menu_leave), menu_widget);
+        }
+    }
+    
     return FALSE ;
 }
 


More information about the Xfce4-commits mailing list