[Xfce4-commits] <xfce4-taskbar-plugin:master> Usability tweak.

Gearoid Murphy noreply at xfce.org
Sun Oct 14 13:58:02 CEST 2012


Updating branch refs/heads/master
         to 3d44306b86b5942887e4c1650d3cc21e102bf944 (commit)
       from b8e11daa4411952355c0b555995c58a2cb8507f7 (commit)

commit 3d44306b86b5942887e4c1650d3cc21e102bf944
Author: Gearoid Murphy <gearoid at murphy.com>
Date:   Sun Oct 14 12:55:18 2012 +0100

    Usability tweak.

 taskbar-widget.c |   41 ++++++++++++++++++++++++-----------------
 1 files changed, 24 insertions(+), 17 deletions(-)

diff --git a/taskbar-widget.c b/taskbar-widget.c
index 3ed3e17..2cecb52 100644
--- a/taskbar-widget.c
+++ b/taskbar-widget.c
@@ -73,6 +73,7 @@ enum
 
 
 enum {LEFTMOUSE=1, MIDMOUSE=2, RIGHTMOUSE=3} ;
+enum { HOVER_DISPLAY_COOLOFF=200, GROUP_ICON_HOVER_TIMEOUT=250 } ;
 
 struct _XfceTaskBarClass
 {
@@ -193,6 +194,7 @@ struct _XfceTaskBarGroup
     gboolean      pinned ;
     gchar         *command ;
     guint         hover_timeout ;
+    guint         hover_visible_timestamp ;
 };
 
 #define DISABLE_HOVER_TIMEOUT(group) if(group->hover_timeout != 0) {g_source_remove(group->hover_timeout); group->hover_timeout=0;}
@@ -2254,16 +2256,14 @@ static gboolean xfce_taskbar_group_button_release_event
 {
     GtkWidget *panel_plugin;
     GtkWidget *menu_widget;
-
+    
     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (group->button), FALSE);
     //Disable the timeout, if active
     DISABLE_HOVER_TIMEOUT(group);
     
-    panel_return_val_if_fail (XFCE_IS_taskbar (group->taskbar), FALSE);
-
     if (event->type != GDK_BUTTON_RELEASE || xfce_taskbar_is_locked (group->taskbar))
         return FALSE;
-
+    
     //Some hacky stuff for drag and drop
     if(group->taskbar->dragactive == TRUE)
     {
@@ -2272,18 +2272,6 @@ static gboolean xfce_taskbar_group_button_release_event
         return FALSE ;
     }
     
-    /* send the event to the panel plugin if control is pressed */
-    if (PANEL_HAS_FLAG (event->state, GDK_CONTROL_MASK))
-    {
-        /* send the event to the panel plugin */
-        panel_plugin = xfce_taskbar_get_panel_plugin (group->taskbar);
-        if (G_LIKELY (panel_plugin != NULL))
-        {
-            gtk_widget_event (panel_plugin, (GdkEvent *) 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);
@@ -2292,7 +2280,15 @@ static gboolean xfce_taskbar_group_button_release_event
     if(list_length == 1)
     {
         GtkMenu *menu = attached->data;
+        gint time_diff = (gtk_get_current_event_time() - group->hover_visible_timestamp);
         menu_source = (size_t)(g_object_get_data(G_OBJECT(menu), "menu-source"));
+        //We don't want to dismiss the menu if the user generates a
+        //request for it very shortly after it has appeared
+        if(event->button == LEFTMOUSE && time_diff < HOVER_DISPLAY_COOLOFF)
+        {
+            return TRUE ;
+        }
+        
         gtk_widget_destroy (GTK_WIDGET(menu));
     }
     
@@ -2419,6 +2415,7 @@ static void xfce_taskbar_activate_hover_menu(GtkWidget *menu_widget, XfceTaskBar
     g_signal_connect (G_OBJECT (menu_widget), "selection-done", G_CALLBACK (xfce_taskbar_group_button_menu_destroy), group);
     g_signal_connect (GTK_WINDOW (GTK_MENU(menu_widget)->toplevel), "enter-notify-event", G_CALLBACK (xfce_taskbar_hover_menu_enter), menu_widget);
     g_signal_connect (GTK_WINDOW (GTK_MENU(menu_widget)->toplevel), "leave-notify-event", G_CALLBACK (xfce_taskbar_hover_menu_leave), menu_widget);
+    
     {
         gint x, y ;
         gboolean push_in=TRUE;
@@ -2450,6 +2447,9 @@ static gboolean xfce_taskbar_group_button_hover_timeout(gpointer group_ptr)
     
     //Create and raise the menu
     menu_widget = xfce_taskbar_group_button_menu_show_active (group);
+    //This isn;t a proper event, so we cannot use gtk_get_current_event_time();
+    //Therefore we set hover_visible_timestamp in xfce_taskbar_group_button_enter_event
+    group->hover_visible_timestamp += GROUP_ICON_HOVER_TIMEOUT ;
     
     //Attach the menu widget to the button widget
     xfce_taskbar_activate_hover_menu(menu_widget, group, LEFTMOUSE);
@@ -2488,7 +2488,8 @@ static gboolean xfce_taskbar_group_button_enter_event(GtkWidget *button, GdkEven
     
     if(xfce_taskbar_group_visible_count(group, wnck_screen_get_active_workspace (group->taskbar->screen)) > 0)
     {
-        group->hover_timeout = g_timeout_add(250, xfce_taskbar_group_button_hover_timeout, group);
+        group->hover_timeout = g_timeout_add(GROUP_ICON_HOVER_TIMEOUT, xfce_taskbar_group_button_hover_timeout, group);
+        group->hover_visible_timestamp = gtk_get_current_event_time();
     }
     return TRUE ;
 }
@@ -2615,6 +2616,12 @@ static XfceTaskBarGroup * xfce_taskbar_group_button_new (const char *group_name,
     //The timeout id, used when tracking a mouse hovering over the button
     group->hover_timeout = 0 ;
     
+    //This is a usability tweak, I frequently find that I click the group icon
+    //just after the hover menu appears, causing it to be removed, this timestamp
+    //will be used to ensure that a small window of time has elapsed before destroy
+    //the window based on a user mouse click
+    group->hover_visible_timestamp = 0 ;
+    
     group->button = xfce_arrow_button_new (GTK_ARROW_NONE);
     gtk_widget_set_parent (group->button, GTK_WIDGET (taskbar));
     gtk_widget_set_tooltip_text (group->button, group_name);


More information about the Xfce4-commits mailing list