From 9da564b391fc860492c08ff4a779c4d6163e28d2 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Sat, 14 Feb 2009 11:38:16 +0000 Subject: [PATCH] Bug 1440 - Add clutter_get_current_event_time() The clutter_get_current_event_time() is a global function for retrieving the timestamp of the current event being propagated by Clutter. Such function avoids the need to propagate the timestamp from within user code. --- clutter/clutter-event.c | 22 ++++++++++++++++++++++ clutter/clutter-event.h | 2 ++ clutter/clutter-main.c | 2 ++ clutter/clutter-private.h | 2 ++ 4 files changed, 28 insertions(+) diff --git a/clutter/clutter-event.c b/clutter/clutter-event.c index b03b0dfc7..0c3899ef0 100644 --- a/clutter/clutter-event.c +++ b/clutter/clutter-event.c @@ -529,3 +529,25 @@ clutter_events_pending (void) return g_queue_is_empty (context->events_queue) == FALSE; } +/** + * clutter_get_current_event_time: + * + * Retrieves the timestamp of the last event, if there is an + * event or if the event has a timestamp. + * + * Return value: the event timestamp, or %CLUTTER_CURRENT_TIME + * + * Since: 1.0 + */ +guint32 +clutter_get_current_event_time (void) +{ + ClutterMainContext *context = clutter_context_get_default (); + + g_return_val_if_fail (context != NULL, FALSE); + + if (context->last_event_time != 0) + return context->last_event_time; + + return CLUTTER_CURRENT_TIME; +} diff --git a/clutter/clutter-event.h b/clutter/clutter-event.h index 0fb6c2408..34583e7ee 100644 --- a/clutter/clutter-event.h +++ b/clutter/clutter-event.h @@ -466,6 +466,8 @@ guint32 clutter_keysym_to_unicode (guint keyval); ClutterStage* clutter_event_get_stage (ClutterEvent *event); +guint32 clutter_get_current_event_time (void); + G_END_DECLS #endif /* __CLUTTER_EVENT_H__ */ diff --git a/clutter/clutter-main.c b/clutter/clutter-main.c index a1eaceb21..67e99833a 100644 --- a/clutter/clutter-main.c +++ b/clutter/clutter-main.c @@ -1957,6 +1957,8 @@ clutter_do_event (ClutterEvent *event) CLUTTER_TIMESTAMP (EVENT, "Event received"); + context->last_event_time = clutter_event_get_time (event); + switch (event->type) { case CLUTTER_NOTHING: diff --git a/clutter/clutter-private.h b/clutter/clutter-private.h index c7345c832..741820187 100644 --- a/clutter/clutter-private.h +++ b/clutter/clutter-private.h @@ -131,6 +131,8 @@ struct _ClutterMainContext GSList *input_devices; /* For extra input devices, i.e MultiTouch */ + + guint32 last_event_time; }; #define CLUTTER_CONTEXT() (clutter_context_get_default ())