[x11] Add backend-specific get_current_event_time()
The clutter_get_current_event_time() function will return the event timestamp coming from a Clutter event. Clutter might synthesize or throttle events, so the function cannot be used when dealing with backend-specific use cases. The X11 backend is the only backend supported by Clutter that makes use of timestamps, so it's altogether fitting that it should come with a specific function to deal with the timestamps of the X events.
This commit is contained in:
parent
747233a8ac
commit
2fe0228f92
@ -355,6 +355,8 @@ clutter_backend_x11_init (ClutterBackendX11 *backend_x11)
|
||||
clutter_backend_set_double_click_time (backend, 250);
|
||||
clutter_backend_set_double_click_distance (backend, 5);
|
||||
clutter_backend_set_resolution (backend, 96.0);
|
||||
|
||||
backend_x11->last_event_time = CurrentTime;
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -84,6 +84,7 @@ struct _ClutterBackendX11
|
||||
gboolean have_xinput;
|
||||
#endif
|
||||
|
||||
Time last_event_time;
|
||||
};
|
||||
|
||||
struct _ClutterBackendX11Class
|
||||
|
@ -204,6 +204,50 @@ _clutter_backend_x11_events_uninit (ClutterBackend *backend)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
update_last_event_time (ClutterBackendX11 *backend_x11,
|
||||
XEvent *xevent)
|
||||
{
|
||||
Time current_time = CurrentTime;
|
||||
Time last_time = backend_x11->last_event_time;
|
||||
|
||||
switch (xevent->type)
|
||||
{
|
||||
case KeyPress:
|
||||
case KeyRelease:
|
||||
current_time = xevent->xkey.time;
|
||||
break;
|
||||
|
||||
case ButtonPress:
|
||||
case ButtonRelease:
|
||||
current_time = xevent->xbutton.time;
|
||||
break;
|
||||
|
||||
case MotionNotify:
|
||||
current_time = xevent->xmotion.time;
|
||||
break;
|
||||
|
||||
case EnterNotify:
|
||||
case LeaveNotify:
|
||||
current_time = xevent->xcrossing.time;
|
||||
break;
|
||||
|
||||
case PropertyNotify:
|
||||
current_time = xevent->xproperty.time;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/* only change the current event time if it's after the previous event
|
||||
* time, or if it is at least 30 seconds earlier - in case the system
|
||||
* clock was changed
|
||||
*/
|
||||
if (current_time > last_time || (last_time - current_time > (30 * 1000)))
|
||||
backend_x11->last_event_time = current_time;
|
||||
}
|
||||
|
||||
static void
|
||||
set_user_time (ClutterBackendX11 *backend_x11,
|
||||
Window *xwindow,
|
||||
@ -419,9 +463,10 @@ event_translate (ClutterBackend *backend,
|
||||
|
||||
event->any.stage = stage;
|
||||
|
||||
|
||||
res = TRUE;
|
||||
|
||||
update_last_event_time (backend_x11, xevent);
|
||||
|
||||
switch (xevent->type)
|
||||
{
|
||||
case ConfigureNotify:
|
||||
@ -1002,3 +1047,23 @@ clutter_event_dispatch (GSource *source,
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* clutter_x11_get_current_event_time:
|
||||
*
|
||||
* Retrieves the timestamp of the last X11 event processed by
|
||||
* Clutter. This might be different from the timestamp returned
|
||||
* by clutter_get_current_event_time(), as Clutter may synthesize
|
||||
* or throttle events.
|
||||
*
|
||||
* Return value: a timestamp, in milliseconds
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
Time
|
||||
clutter_x11_get_current_event_time (void)
|
||||
{
|
||||
ClutterBackend *backend = clutter_get_default_backend ();
|
||||
|
||||
return CLUTTER_BACKEND_X11 (backend)->last_event_time;
|
||||
}
|
||||
|
@ -132,6 +132,8 @@ gboolean clutter_x11_has_xinput (void);
|
||||
|
||||
gboolean clutter_x11_has_composite_extension (void);
|
||||
|
||||
Time clutter_x11_get_current_event_time (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __CLUTTER_X11_H__ */
|
||||
|
Loading…
Reference in New Issue
Block a user