From: Marco Pesenti Gritti Date: Mon, 5 Sep 2005 08:57:08 +0000 (+0000) Subject: Delay popup showing. Mirror gtk logic/times. X-Git-Tag: EVINCE_0_5_0~183 X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=ef5061948d20d3fcdefb285c07014954f47dce6d;p=evince.git Delay popup showing. Mirror gtk logic/times. 2005-09-05 Marco Pesenti Gritti * 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. --- diff --git a/ChangeLog b/ChangeLog index 2148ed67..bf854ab2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2005-09-05 Marco Pesenti Gritti + + * 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 * lib/Makefile.am: diff --git a/lib/ev-tooltip.c b/lib/ev-tooltip.c index 14326ab2..5e32c580 100644 --- a/lib/ev-tooltip.c +++ b/lib/ev-tooltip.c @@ -28,8 +28,15 @@ #include +#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) @@ -49,12 +56,24 @@ ev_tooltip_expose_event (GtkWidget *widget, 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)); @@ -115,3 +134,67 @@ ev_tooltip_set_position (EvTooltip *tooltip, int x, int y) 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); +} diff --git a/lib/ev-tooltip.h b/lib/ev-tooltip.h index b57368c3..025a2427 100644 --- a/lib/ev-tooltip.h +++ b/lib/ev-tooltip.h @@ -58,6 +58,8 @@ void ev_tooltip_set_text (EvTooltip *tooltip, void ev_tooltip_set_position (EvTooltip *tooltip, int x, int y); +void ev_tooltip_activate (EvTooltip *tooltip); +void ev_tooltip_deactivate (EvTooltip *tooltip); G_END_DECLS diff --git a/shell/ev-view.c b/shell/ev-view.c index f5b22fd1..2edcd858 100644 --- a/shell/ev-view.c +++ b/shell/ev-view.c @@ -1532,7 +1532,7 @@ ev_view_motion_notify_event (GtkWidget *widget, 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) { @@ -1543,7 +1543,7 @@ ev_view_motion_notify_event (GtkWidget *widget, } 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);