From a9ff224ba1eadeaede216a8d7c903dfe2735f802 Mon Sep 17 00:00:00 2001 From: Tomas Frydrych Date: Thu, 21 Feb 2008 15:18:14 +0000 Subject: [PATCH] 2008-02-21 Tomas Frydrych * clutter/x11/clutter-backend-x11.h: * clutter/x11/clutter-event-x11.c: * clutter/x11/clutter-x11.h: (clutter_x11_handle_event): (clutter_x11_disable_event_retrieval): Functions to allow to hook into external XEvent retrieval (for example when using clutter with gtk); NB: this API is tentative. --- ChangeLog | 10 ++++ clutter/x11/clutter-backend-x11.h | 2 + clutter/x11/clutter-event-x11.c | 76 +++++++++++++++++++++++++++++++ clutter/x11/clutter-x11.h | 8 +++- 4 files changed, 94 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index b2d1da305..543b60376 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2008-02-21 Tomas Frydrych + + * clutter/x11/clutter-backend-x11.h: + * clutter/x11/clutter-event-x11.c: + * clutter/x11/clutter-x11.h: + (clutter_x11_handle_event): + (clutter_x11_disable_event_retrieval): + Functions to allow to hook into external XEvent retrieval (for + example when using clutter with gtk); NB: this API is tentative. + 2008-02-21 Emmanuele Bassi * clutter/x11/clutter-event-x11.c (event_translate): Ignore diff --git a/clutter/x11/clutter-backend-x11.h b/clutter/x11/clutter-backend-x11.h index 4a55eef8a..357da8028 100644 --- a/clutter/x11/clutter-backend-x11.h +++ b/clutter/x11/clutter-backend-x11.h @@ -66,6 +66,8 @@ struct _ClutterBackendX11 GSource *event_source; GSList *event_filters; + gboolean no_xevent_retrieval; + /* props */ Atom atom_NET_WM_PING; Atom atom_NET_WM_STATE; diff --git a/clutter/x11/clutter-event-x11.c b/clutter/x11/clutter-event-x11.c index ff7c1c53d..e6e86d272 100644 --- a/clutter/x11/clutter-event-x11.c +++ b/clutter/x11/clutter-event-x11.c @@ -163,6 +163,9 @@ _clutter_backend_x11_events_init (ClutterBackend *backend) ClutterEventSource *event_source; int connection_number; + if (backend_x11->no_xevent_retrieval) + return; + connection_number = ConnectionNumber (backend_x11->xdpy); CLUTTER_NOTE (EVENT, "Connection number: %d", connection_number); @@ -654,6 +657,79 @@ events_queue (ClutterBackend *backend) } } +/** + * clutter_x11_handle_event + * @xevent: pointer to XEvent structure + * + * This function processes a single X event; it can be used to hook + * into external X event retrieval (for example that done by GDK). + * + * Return: #ClutterX11FilterReturn indicating what the caller should + * do with the original event. + * + * Since: 0.8 + */ +ClutterX11FilterReturn +clutter_x11_handle_event (XEvent *xevent) +{ + ClutterBackend *backend; + ClutterEvent *event; + ClutterMainContext *clutter_context; + + clutter_threads_enter (); + + clutter_context = clutter_context_get_default (); + backend = clutter_context->backend; + + event = clutter_event_new (CLUTTER_NOTHING); + + if (event_translate (backend, event, xevent)) + { + /* push directly here to avoid copy of queue_put */ + g_queue_push_head (clutter_context->events_queue, event); + } + else + { + clutter_event_free (event); + } + + event = clutter_event_get (); + + if (event) + { + /* forward the event into clutter for emission etc. */ + clutter_do_event (event); + clutter_event_free (event); + } + + clutter_threads_leave (); + + return CLUTTER_X11_FILTER_CONTINUE; +} + +/** + * clutter_x11_disable_event_retrieval + * + * Disables retrieval of X events in the main loop. Use to create event-less + * canvas or in conjunction with clutter_x11_handle_event. + * + * This function can only be called before calling clutter_init(). + * + * Since: 0.8 + */ +void +clutter_x11_disable_event_retrieval (void) +{ + ClutterBackendX11 *backend; + ClutterMainContext *clutter_context; + + clutter_context = clutter_context_get_default (); + backend = CLUTTER_BACKEND_X11 (clutter_context->backend); + + backend->no_xevent_retrieval = TRUE; +} + + static gboolean clutter_event_prepare (GSource *source, gint *timeout) diff --git a/clutter/x11/clutter-x11.h b/clutter/x11/clutter-x11.h index 996c0a79a..28a5e5a0b 100644 --- a/clutter/x11/clutter-x11.h +++ b/clutter/x11/clutter-x11.h @@ -75,7 +75,7 @@ typedef enum { * * Since: 0.6 */ -typedef ClutterX11FilterReturn (*ClutterX11FilterFunc) (XEvent *xev, +typedef ClutterX11FilterReturn (*ClutterX11FilterFunc) (XEvent *xev, ClutterEvent *cev, gpointer data); @@ -94,9 +94,13 @@ gboolean clutter_x11_set_stage_foreign (ClutterStage *stage, void clutter_x11_add_filter (ClutterX11FilterFunc func, gpointer data); -void clutter_x11_remove_filter (ClutterX11FilterFunc func, +void clutter_x11_remove_filter (ClutterX11FilterFunc func, gpointer data); +ClutterX11FilterReturn clutter_x11_handle_event (XEvent *xevent); + +void clutter_x11_disable_event_retrieval (void); + G_END_DECLS #endif /* __CLUTTER_X11_H__ */