+2005-09-05 Marco Pesenti Gritti <mpg@redhat.com>
+
+ * lib/ev-tooltip.c: (ev_tooltip_dispose), (ev_tooltip_class_init),
+ (ev_tooltip_set_position), (ev_tooltip_recently_shown),
+ (ev_tooltip_timeout), (ev_tooltip_activate),
+ (ev_tooltip_deactivate):
+ * lib/ev-tooltip.h:
+ * shell/ev-view.c: (ev_view_motion_notify_event):
+
+ Delay popup showing. Mirror gtk logic/times.
+
2005-09-03 Marco Pesenti Gritti <mpg@redhat.com>
* lib/Makefile.am:
#include <gtk/gtklabel.h>
+#define DEFAULT_DELAY 500
+#define STICKY_DELAY 0
+#define STICKY_REVERT_DELAY 1000
+
struct _EvTooltipPrivate {
GtkWidget *label;
+ GTimeVal last_deactivate;
+ int timer_tag;
+ gboolean active;
};
G_DEFINE_TYPE (EvTooltip, ev_tooltip, GTK_TYPE_WINDOW)
return GTK_WIDGET_CLASS (ev_tooltip_parent_class)->expose_event (widget, event);
}
+static void
+ev_tooltip_dispose (GObject *object)
+{
+ EvTooltip *tooltip = EV_TOOLTIP (object);
+
+ if (tooltip->priv->timer_tag) {
+ g_source_remove (tooltip->priv->timer_tag);
+ tooltip->priv->timer_tag = 0;
+ }
+}
+
static void
ev_tooltip_class_init (EvTooltipClass *class)
{
GObjectClass *g_object_class = G_OBJECT_CLASS (class);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
+ g_object_class->dispose = ev_tooltip_dispose;
widget_class->expose_event = ev_tooltip_expose_event;
g_type_class_add_private (g_object_class, sizeof (EvTooltipPrivate));
gtk_window_move (GTK_WINDOW (tooltip), x + root_x, y + root_y);
}
+
+static gboolean
+ev_tooltip_recently_shown (EvTooltip *tooltip)
+{
+ GTimeVal now;
+ glong msec;
+
+ g_get_current_time (&now);
+
+ msec = (now.tv_sec - tooltip->priv->last_deactivate.tv_sec) * 1000 +
+ (now.tv_usec - tooltip->priv->last_deactivate.tv_usec) / 1000;
+
+ return (msec < STICKY_REVERT_DELAY);
+}
+
+static gint
+ev_tooltip_timeout (gpointer data)
+{
+ GtkWidget *tooltip = GTK_WIDGET (data);
+
+ gtk_widget_show (tooltip);
+
+ return FALSE;
+}
+
+void
+ev_tooltip_activate (EvTooltip *tooltip)
+{
+ int delay;
+
+ if (tooltip->priv->active) {
+ return;
+ } else {
+ tooltip->priv->active = TRUE;
+ }
+
+ if (ev_tooltip_recently_shown (tooltip)) {
+ delay = STICKY_DELAY;
+ } else {
+ delay = DEFAULT_DELAY;
+ }
+
+ tooltip->priv->timer_tag = g_timeout_add (delay, ev_tooltip_timeout,
+ (gpointer)tooltip);
+}
+
+void
+ev_tooltip_deactivate (EvTooltip *tooltip)
+{
+ if (!tooltip->priv->active) {
+ return;
+ } else {
+ tooltip->priv->active = FALSE;
+ }
+
+ if (tooltip->priv->timer_tag) {
+ g_source_remove (tooltip->priv->timer_tag);
+ tooltip->priv->timer_tag = 0;
+ }
+
+ gtk_widget_hide (GTK_WIDGET (tooltip));
+
+ g_get_current_time (&tooltip->priv->last_deactivate);
+}
link = get_link_at_location (view, event->x + view->scroll_x, event->y + view->scroll_y);
if (!link && view->link_tooltip) {
- gtk_widget_hide (view->link_tooltip);
+ ev_tooltip_deactivate (EV_TOOLTIP (view->link_tooltip));
}
if (link) {
}
ev_tooltip_set_position (EV_TOOLTIP (view->link_tooltip), event->x, event->y);
ev_tooltip_set_text (EV_TOOLTIP (view->link_tooltip), msg);
- gtk_widget_show (view->link_tooltip);
+ ev_tooltip_activate (EV_TOOLTIP (view->link_tooltip));
g_free (msg);
ev_view_set_cursor (view, EV_VIEW_CURSOR_LINK);