[Xfce4-commits] <xfce4-taskbar-plugin:master> Replaced the primary popup menu with a hover menu, still some instabilties in the code.

Gearoid Murphy noreply at xfce.org
Wed Oct 10 15:58:01 CEST 2012


Updating branch refs/heads/master
         to cce5b5e9b27f4e057ab50d1f57c88afe0861d4f3 (commit)
       from 8ec01766e0861a2cccaab6c2b390c2fe7b2547bb (commit)

commit cce5b5e9b27f4e057ab50d1f57c88afe0861d4f3
Author: Gearoid Murphy <gearoid.murphy at hp.com>
Date:   Wed Oct 10 14:53:14 2012 +0100

    Replaced the primary popup menu with a hover menu, still some instabilties in the code.

 README           |    1 -
 taskbar-widget.c |  110 +++++++++++++++++++++++++++++-------------------------
 2 files changed, 59 insertions(+), 52 deletions(-)

diff --git a/README b/README
index 0ebfa35..3bc9c56 100644
--- a/README
+++ b/README
@@ -37,7 +37,6 @@
         
         3) If there are multiple application instances running, a list to
         the application windows is shown
-    
 
 ** Known Issues ***
     
diff --git a/taskbar-widget.c b/taskbar-widget.c
index 476e14f..1a3be0a 100644
--- a/taskbar-widget.c
+++ b/taskbar-widget.c
@@ -243,8 +243,7 @@ static void         xfce_taskbar_group_button_add_window        (XfceTaskBarGrou
 static gboolean     xfce_taskbar_group_button_enter_event       (GtkWidget *button, GdkEvent *event, XfceTaskBarGroup *group);
 static gboolean     xfce_taskbar_group_button_leave_event       (GtkWidget *button, GdkEvent *event, XfceTaskBarGroup *group);
 
-static XfceTaskBarGroup* 
-                xfce_taskbar_group_button_new               (const char *, XfceTaskBar *taskbar);
+static XfceTaskBarGroup* xfce_taskbar_group_button_new (const char *, XfceTaskBar *taskbar);
 
 // pinning functions
 static void     xfce_taskbar_group_button_toggle_pinned     (XfceTaskBarGroup *group);
@@ -254,7 +253,13 @@ static void     xfce_taskbar_group_button_build_pin_menu    (XfceTaskBarGroup *g
 static void     cache_pinned_configuration                  (XfceTaskBar *taskbar);
 
 //hover menu functions
-static gboolean     trigger_hover_menu_timeout(GtkWidget *widget, GdkEvent  *event, gpointer menu_ptr);
+static gboolean trigger_hover_menu_timeout(GtkWidget *widget, GdkEvent  *event, gpointer menu_ptr);
+static gboolean trigger_hover_menu_timeout(GtkWidget *widget, GdkEvent  *event, gpointer menu_ptr);
+static gboolean hover_menu_leave(GtkWidget *widget, GdkEvent  *event, gpointer menu_ptr);
+static gboolean hover_menu_enter(GtkWidget *widget, GdkEvent  *event, gpointer menu_ptr);
+static gboolean xfce_taskbar_hover_menu_timeout(gpointer menu_ptr);
+static gboolean xfce_taskbar_group_button_hover_timeout(gpointer group_ptr);
+static void    xfce_taskbar_activate_hover_menu(GtkWidget *widget, XfceTaskBarGroup *group, size_t mouse_button);
 
 // potential public functions
 static void xfce_taskbar_set_include_all_workspaces     (XfceTaskBar *taskbar, gboolean all_workspaces);
@@ -2235,7 +2240,7 @@ static gboolean xfce_taskbar_group_button_release_event
 (GtkWidget *button, GdkEventButton *event, XfceTaskBarGroup *group)
 {
     GtkWidget *panel_plugin;
-    GtkWidget *menu;
+    GtkWidget *menu_widget;
 
     //Disable the timeout, if active
     DISABLE_HOVER_TIMEOUT(group);
@@ -2264,6 +2269,20 @@ static gboolean xfce_taskbar_group_button_release_event
         return TRUE;
     }
     
+    //Check if there's a hover menu active, if so, disable it
+    GList *attached = gtk_menu_get_for_attach_widget(group->button);
+    guint list_length = g_list_length(attached);
+    size_t menu_source = 0 ;
+    panel_assert (list_length <= 1 && "There should only be at most one menu attached to the icon!");
+    if(list_length == 1)
+    {
+        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));
+    }
+    
     //Middle mouse click on the taskbar icon launchs the icon
     if(event->button == MIDMOUSE)
     {
@@ -2271,7 +2290,7 @@ static gboolean xfce_taskbar_group_button_release_event
         return TRUE ;
     }
     
-    //This is trying to do too much, need to prune it
+    
     if (event->button == LEFTMOUSE || event->button == RIGHTMOUSE)
     {
         GSList *li;
@@ -2291,17 +2310,22 @@ static gboolean xfce_taskbar_group_button_release_event
                 }
             }
         }
-        /*
-            if a single instance of a class window is visible to the taskbar,
-            activate that instance instead of showing the associated group menus,
-            when a left mouse click falls on the icon
-        */
+        
+        // If a single instance of a class window is visible to the taskbar,
+        // activate that instance instead of showing the associated group menus,
+        // when a left mouse click falls on the icon
         if(active_child && event->button == LEFTMOUSE)
         {
             xfce_taskbar_button_activate (active_child, event->time);
             return TRUE ;
         }
         
+        //2nd click of same button dismisses the menu
+        if(menu_source == event->button)
+        {
+            return TRUE ;
+        }
+        
         if(visible_count == 0)
         {
             panel_return_val_if_fail ((group->pinned == TRUE), FALSE);
@@ -2313,44 +2337,23 @@ static gboolean xfce_taskbar_group_button_release_event
             }
             else
             {
-                menu = xfce_taskbar_group_button_menu_launcher (group);
+                menu_widget = xfce_taskbar_group_button_menu_launcher (group);
             }
         }
         else
         {
-            /* Split the particular menu use cases into separate functions*/
+            // Split the particular menu use cases into separate functions
             if(event->button == LEFTMOUSE)
             {
-                //We need to check if the hover menu is active
-                if(visible_count > 1)
-                {
-                    GList *attached = gtk_menu_get_for_attach_widget(group->button);
-                    guint list_length = g_list_length(attached);
-                    panel_assert (list_length <= 1 && "There should only be at most one menu attached to the icon!");
-                    if(list_length == 1)
-                    {
-                        GtkMenu *menu = attached->data;
-                        g_signal_handlers_disconnect_by_func(group->button, trigger_hover_menu_timeout, menu);
-                        gtk_widget_destroy (GTK_WIDGET(menu));
-                        return TRUE ;
-                    }
-                }
-                
-                menu = xfce_taskbar_group_button_menu_show_active (group);
+                menu_widget = xfce_taskbar_group_button_menu_show_active (group);
             }
             else
             {
-                menu = xfce_taskbar_group_button_menu_group_actions (group);
+                menu_widget = xfce_taskbar_group_button_menu_group_actions (group);
             }
         }
         
-        g_signal_connect (G_OBJECT (menu), "selection-done", G_CALLBACK (xfce_taskbar_group_button_menu_destroy), group);
-        gtk_menu_attach_to_widget (GTK_MENU (menu), button, NULL);
-        gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
-                        xfce_panel_plugin_position_menu,
-                        xfce_taskbar_get_panel_plugin(group->taskbar),
-                        event->button,
-                        event->time);
+        xfce_taskbar_activate_hover_menu(menu_widget, group, event->button);
         
         return TRUE;
     }
@@ -2417,25 +2420,12 @@ static gboolean trigger_hover_menu_timeout(GtkWidget *widget, GdkEvent  *event,
     return FALSE ;
 }
 
-//Triggered when the mouse has hovered over the group icon for duration of time
-static gboolean xfce_taskbar_group_button_hover_timeout(gpointer group_ptr)
+static void xfce_taskbar_activate_hover_menu(GtkWidget *menu_widget, XfceTaskBarGroup *group, size_t mouse_button)
 {
-    GtkWidget *menu_widget;
-    XfceTaskBarGroup *group = (XfceTaskBarGroup *)group_ptr ;
-    
-    //printf("xfce_taskbar_group_button_hover_timeout %s\n", group->window_class_name);
-    
-    //Disable the hover timeout
-    DISABLE_HOVER_TIMEOUT(group);
-    
-    //Create and raise the menu
-    menu_widget = xfce_taskbar_group_button_menu_show_active (group);
-    //Attach the menu widget to the button widget
     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;
@@ -2451,6 +2441,24 @@ static gboolean xfce_taskbar_group_button_hover_timeout(gpointer group_ptr)
         gtk_window_move(menu_window, x, y);
         gtk_widget_show (menu_widget);
     }
+}
+
+//Triggered when the mouse has hovered over the group icon for duration of time
+static gboolean xfce_taskbar_group_button_hover_timeout(gpointer group_ptr)
+{
+    GtkWidget *menu_widget;
+    XfceTaskBarGroup *group = (XfceTaskBarGroup *)group_ptr ;
+    
+    //printf("xfce_taskbar_group_button_hover_timeout %s\n", group->window_class_name);
+    
+    //Disable the hover timeout
+    DISABLE_HOVER_TIMEOUT(group);
+    
+    //Create and raise the menu
+    menu_widget = xfce_taskbar_group_button_menu_show_active (group);
+    
+    //Attach the menu widget to the button widget
+    xfce_taskbar_activate_hover_menu(menu_widget, group, LEFTMOUSE);
     
     return FALSE ;
 }


More information about the Xfce4-commits mailing list