[PATCH] Tooltip delays for adjacent widgets



This patch implements the "proximity delay" when displaying tooltips.
The rationale for this patch has been posted in my message to gtk-list
with Message-ID <87zp6h37bs.fsf@pc-hrvoje.srce.hr>.  Here is a
summary:

    Gtk lets the application specify the delay parameter of a tooltip
    object.  The delay is the time the mouse needs to hover over the
    object for the tooltip to appear, the default delay being half a
    second.

    However, when a tooltip object encompasses several close widgets (e.g.
    a toolbar), and you want to see the tooltip of each button, you have
    to wait for the delay period to pass over every widget, which tends to
    get annoying.  Many other windowing systems (e.g. Windows) show the
    following tooltip immediately.

This patch implements that behaviour by introducing the notion of
"proximity delay".  If less than 200 msecs pass after a tooltip has
been destroyed, the next tooltip within the same tooltip object will
be shown immediately.  The proximity delay can be changed using the
new function gtk_tooltips_set_proximity_delay().

I have uploaded the patch to ftp.gimp.org:/incoming/ under the names
`gtk-hniksic-990224-0.patch.gz' and `gtk-hniksic-990224-0.patch.README'.

1999-02-24  Hrvoje Niksic  <hniksic@srce.hr>

	* gtk/gtktooltips.c (gtk_tooltips_set_proximity_delay): New
 	function.
	(gtk_tooltips_proximity_timeout): Ditto.
	(gtk_tooltips_set_active_widget): Setup the timeout when hiding
 	tip_window.
	(gtk_tooltips_event_handler): If a tooltip was recently destroyed, 
	draw the new one immediately.

	* gtk/gtktooltips.h (struct _GtkTooltips): New members
	proximity_delay and proximity_timer_tag.

--- gtk/gtktooltips.h.orig	Wed Feb 24 00:34:26 1999
+++ gtk/gtktooltips.h	Wed Feb 24 02:44:52 1999
@@ -61,8 +61,11 @@
   GdkColor *background;
 
   guint   delay : 30;
-  guint	  enabled : 1;
   gint	  timer_tag;
+  guint   proximity_delay : 30;
+  gint    proximity_timer_tag;
+
+  guint	  enabled : 1;
 };
 
 struct _GtkTooltipsClass
@@ -77,6 +80,8 @@
 void		 gtk_tooltips_disable	   (GtkTooltips   *tooltips);
 void		 gtk_tooltips_set_delay	   (GtkTooltips   *tooltips,
 					    guint	   delay);
+void		 gtk_tooltips_set_proximity_delay (GtkTooltips   *tooltips,
+						   guint	  proximity_delay);
 void		 gtk_tooltips_set_tip	   (GtkTooltips   *tooltips,
 					    GtkWidget	  *widget,
 					    const gchar   *tip_text,
--- gtk/gtktooltips.c.orig	Wed Feb 24 00:27:52 1999
+++ gtk/gtktooltips.c	Wed Feb 24 02:45:09 1999
@@ -28,7 +28,8 @@
 #include "gtktooltips.h"
 
 
-#define DEFAULT_DELAY 500           /* Default delay in ms */
+#define DEFAULT_DELAY           500 /* Default delay in ms */
+#define DEFAULT_PROXIMITY_DELAY 200
 
 static void gtk_tooltips_class_init        (GtkTooltipsClass *klass);
 static void gtk_tooltips_init              (GtkTooltips      *tooltips);
@@ -43,6 +44,7 @@
 static void gtk_tooltips_set_active_widget (GtkTooltips *tooltips,
                                             GtkWidget   *widget);
 static gint gtk_tooltips_timeout           (gpointer     data);
+static gint gtk_tooltips_proximity_timeout (gpointer     data);
 static gint gtk_tooltips_expose            (GtkTooltips    *tooltips, 
 					    GdkEventExpose *event);
 
@@ -98,6 +100,7 @@
   tooltips->background = NULL;
   
   tooltips->delay = DEFAULT_DELAY;
+  tooltips->proximity_delay = DEFAULT_PROXIMITY_DELAY;
   tooltips->enabled = TRUE;
   tooltips->timer_tag = 0;
 }
@@ -316,6 +319,15 @@
   tooltips->delay = delay;
 }
 
+void
+gtk_tooltips_set_proximity_delay (GtkTooltips *tooltips,
+				  guint        proximity_delay)
+{
+  g_return_if_fail (tooltips != NULL);
+
+  tooltips->proximity_delay = proximity_delay;
+}
+
 GtkTooltipsData*
 gtk_tooltips_data_get (GtkWidget       *widget)
 {
@@ -511,12 +523,39 @@
   return FALSE;
 }
 
+static gint
+gtk_tooltips_proximity_timeout (gpointer data)
+{
+  GtkTooltips *tooltips = (GtkTooltips *) data;
+
+  GDK_THREADS_ENTER ();
+  
+  tooltips->proximity_timer_tag = 0;
+
+  GDK_THREADS_LEAVE ();
+
+  return FALSE;
+}
+
 static void
 gtk_tooltips_set_active_widget (GtkTooltips *tooltips,
                                 GtkWidget   *widget)
 {
   if (tooltips->tip_window)
-    gtk_widget_hide (tooltips->tip_window);
+    {
+      gtk_widget_hide (tooltips->tip_window);
+      if (!widget)
+	{
+	  if (tooltips->proximity_timer_tag)
+	    gtk_timeout_remove (tooltips->proximity_timer_tag);
+	  
+	  tooltips->proximity_timer_tag =
+	    gtk_timeout_add (tooltips->proximity_delay,
+			     gtk_tooltips_proximity_timeout,
+			     (gpointer) tooltips);
+	}
+    }
+  
   if (tooltips->timer_tag)
     {
       gtk_timeout_remove (tooltips->timer_tag);
@@ -577,10 +616,19 @@
 	  (!old_tips_data || old_tips_data->widget != widget))
 	{
 	  gtk_tooltips_set_active_widget (tooltips, widget);
-	  
-	  tooltips->timer_tag = gtk_timeout_add (tooltips->delay,
-						 gtk_tooltips_timeout,
-						 (gpointer) tooltips);
+
+	  if (!tooltips->proximity_timer_tag)
+	    {
+	      tooltips->timer_tag = gtk_timeout_add (tooltips->delay,
+						     gtk_tooltips_timeout,
+						     (gpointer) tooltips);
+	    }
+	  else
+	    {
+	      if (tooltips->active_tips_data != NULL &&
+		  GTK_WIDGET_DRAWABLE (tooltips->active_tips_data->widget))
+		gtk_tooltips_draw_tips (tooltips);
+	    }
 	}
       break;
 



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