Tooltips - reduce delay when browsing.



Hi,

I've made a proof of concept implementation of a tooltip feature which
I understand MS-Office and IE have: Let the tooltip pop up without
delay if a tooltip has been shown within the last - say - 500 msec.

So if you want to find out what each widget does, you can browse the
tooltips very quickly.

In normal use, you would experience the normal delay.

I aired the proposal on gnome-gui-list, and reactions were
favourable. I use it myself, and like it. E.g. when hunting for the
right widget in glade, it is a boon.

Below's a primitive patch (against 1.2.7). It's very simple. Where the
tooltip timer is normally set, we check how long it's been since last
time a tooltip popped down. If it's below a certain limit, the tooltip
pops up without delay.

To avoid changing the API, I simply use the normal tooltip delay as
the limit. 

I am aware that this should really be an attribute of a group of
tooltips. But it's probably OK to have a common delay for the
class. There should probably be an API call to set the delay, and may
be to turn the feature off.

Regards

Jon Kåre

--- old/gtk/gtktooltips.c
+++ new/gtk/gtktooltips.c
@@ -58,6 +58,9 @@
 static GtkDataClass *parent_class;
 static const gchar  *tooltips_data_key = "_GtkTooltipsData";
 
+/* FIXME: Make this a class variable if people like the feature */
+static GTimeVal last_popdown = { -1, -1 };
+
 GtkType
 gtk_tooltips_get_type (void)
 {
@@ -472,7 +475,10 @@
   if (!tooltips->tip_window)
     gtk_tooltips_force_window (tooltips);
   else if (GTK_WIDGET_VISIBLE (tooltips->tip_window))
-    gtk_widget_hide (tooltips->tip_window);
+    {
+      gtk_widget_hide (tooltips->tip_window);
+      g_get_current_time (&last_popdown);
+    }
 
   gtk_widget_ensure_style (tooltips->tip_window);
   style = tooltips->tip_window->style;
@@ -544,7 +550,11 @@
                                 GtkWidget   *widget)
 {
   if (tooltips->tip_window)
-    gtk_widget_hide (tooltips->tip_window);
+    {
+      if (GTK_WIDGET_VISIBLE (tooltips->tip_window))
+	g_get_current_time (&last_popdown);
+      gtk_widget_hide (tooltips->tip_window);
+    }
   if (tooltips->timer_tag)
     {
       gtk_timeout_remove (tooltips->timer_tag);
@@ -574,6 +584,23 @@
 }
 
 static gint
+gtk_tooltips_recently_shown (GtkTooltips *tooltips)
+{
+	GTimeVal now;
+	glong msec;
+
+	g_get_current_time (&now);
+	msec = (now.tv_sec  - last_popdown.tv_sec) * 1000 +
+		(now.tv_usec - last_popdown.tv_usec) / 1000;
+
+/*  	g_message ("%s\t%s: %ld\t%s: %d", __PRETTY_FUNCTION__, */
+/*  		   "msec", msec, */
+/*  		   "(msec <= tooltips->delay)", (msec <= tooltips->delay)); */
+	return (msec <= tooltips->delay);
+	
+}
+
+static gint
 gtk_tooltips_event_handler (GtkWidget *widget,
                             GdkEvent  *event)
 {
@@ -606,9 +633,12 @@
 	{
 	  gtk_tooltips_set_active_widget (tooltips, widget);
 	  
-	  tooltips->timer_tag = gtk_timeout_add (tooltips->delay,
-						 gtk_tooltips_timeout,
-						 (gpointer) tooltips);
+	  if (gtk_tooltips_recently_shown (tooltips))
+	    gtk_tooltips_timeout ((gpointer) tooltips);
+	  else
+  	    tooltips->timer_tag = gtk_timeout_add (tooltips->delay,
+						   gtk_tooltips_timeout,
+						   (gpointer) tooltips);
 	}
       break;
 




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]