From eb42f82f23c4cba72f12a3a9857672fd985ba2ce Mon Sep 17 00:00:00 2001 From: Matthew Allum Date: Wed, 9 May 2007 23:31:08 +0000 Subject: [PATCH] 2007-05-10 Matthew Allum * clutter/clutter-backend.c: * clutter/clutter-backend.h: * clutter/clutter-event.c: * clutter/clutter-main.c: * clutter/clutter-private.h: * clutter/glx/clutter-backend-glx.c: * clutter/glx/clutter-backend-glx.h: * clutter/glx/clutter-event-glx.c: Rejig backend event code as to simplify a little. NOTE: This breaks non glx backends. * tests/Makefile.am: * tests/test-events.c: Add a very simple event test. * tests/test-textures.c: (main): Add some more sizes to the test. --- ChangeLog | 20 +++ clutter/clutter-backend.c | 255 ++++++------------------------ clutter/clutter-backend.h | 35 +--- clutter/clutter-event.c | 165 ++++++++----------- clutter/clutter-main.c | 15 +- clutter/clutter-private.h | 68 +++----- clutter/glx/clutter-backend-glx.c | 31 +--- clutter/glx/clutter-backend-glx.h | 3 + clutter/glx/clutter-event-glx.c | 101 ++++-------- tests/Makefile.am | 4 +- tests/test-events.c | 63 ++++++++ tests/test-textures.c | 54 ++++--- 12 files changed, 306 insertions(+), 508 deletions(-) create mode 100644 tests/test-events.c diff --git a/ChangeLog b/ChangeLog index 243ec4daa..8b3b6ee7f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2007-05-10 Matthew Allum + + * clutter/clutter-backend.c: + * clutter/clutter-backend.h: + * clutter/clutter-event.c: + * clutter/clutter-main.c: + * clutter/clutter-private.h: + * clutter/glx/clutter-backend-glx.c: + * clutter/glx/clutter-backend-glx.h: + * clutter/glx/clutter-event-glx.c: + Rejig backend event code as to simplify a little. + NOTE: This breaks non glx backends. + + * tests/Makefile.am: + * tests/test-events.c: + Add a very simple event test. + + * tests/test-textures.c: (main): + Add some more sizes to the test. + 2007-05-05 Matthew Allum * clutter/clutter-texture.c: diff --git a/clutter/clutter-backend.c b/clutter/clutter-backend.c index 9e0f2eeb6..221192b24 100644 --- a/clutter/clutter-backend.c +++ b/clutter/clutter-backend.c @@ -34,16 +34,30 @@ G_DEFINE_ABSTRACT_TYPE (ClutterBackend, clutter_backend, G_TYPE_OBJECT); +#define CLUTTER_BACKEND_GET_PRIVATE(obj) \ +(G_TYPE_INSTANCE_GET_PRIVATE ((obj), CLUTTER_TYPE_BACKEND, ClutterBackendPrivate)) + +struct _ClutterBackendPrivate +{ + /* settings */ + guint double_click_time; + guint double_click_distance; + + +}; + static void clutter_backend_dispose (GObject *gobject) { - ClutterBackend *backend = CLUTTER_BACKEND (gobject); + ClutterMainContext *clutter_context; - if (backend->events_queue) + clutter_context = clutter_context_get_default (); + + if (clutter_context && clutter_context->events_queue) { - g_queue_foreach (backend->events_queue, (GFunc) clutter_event_free, NULL); - g_queue_free (backend->events_queue); - backend->events_queue = NULL; + g_queue_foreach (clutter_context->events_queue, (GFunc) clutter_event_free, NULL); + g_queue_free (clutter_context->events_queue); + clutter_context->events_queue = NULL; } G_OBJECT_CLASS (clutter_backend_parent_class)->dispose (gobject); @@ -55,12 +69,16 @@ clutter_backend_class_init (ClutterBackendClass *klass) GObjectClass *gobject_class = G_OBJECT_CLASS (klass); gobject_class->dispose = clutter_backend_dispose; + + g_type_class_add_private (gobject_class, sizeof (ClutterBackendPrivate)); } static void clutter_backend_init (ClutterBackend *backend) { + ClutterBackendPrivate *priv; + priv = backend->priv = CLUTTER_BACKEND_GET_PRIVATE(backend); } ClutterActor * @@ -125,18 +143,6 @@ _clutter_backend_init_stage (ClutterBackend *backend, return TRUE; } -void -_clutter_backend_init_events (ClutterBackend *backend) -{ - ClutterBackendClass *klass; - - g_return_if_fail (CLUTTER_IS_BACKEND (backend)); - - klass = CLUTTER_BACKEND_GET_CLASS (backend); - if (klass->init_events) - klass->init_events (backend); -} - void _clutter_backend_init_features (ClutterBackend *backend) { @@ -149,14 +155,34 @@ _clutter_backend_init_features (ClutterBackend *backend) klass->init_features (backend); } +void +_clutter_backend_init_events (ClutterBackend *backend) +{ + ClutterBackendClass *klass; + ClutterMainContext *clutter_context; + + clutter_context = clutter_context_get_default (); + + g_return_if_fail (CLUTTER_IS_BACKEND (backend)); + g_return_if_fail (clutter_context != NULL); + + clutter_context->events_queue = g_queue_new (); + + klass = CLUTTER_BACKEND_GET_CLASS (backend); + if (klass->init_events) + klass->init_events (backend); +} + + /** * clutter_get_default_backend: * * FIXME * * Return value: the default backend. You should not ref or - * unref the returned object - * + * unref the returned object. Applications should not rarely need + * to use this. + * * Since: 0.4 */ ClutterBackend * @@ -169,188 +195,7 @@ clutter_get_default_backend (void) return clutter_context->backend; } -/** - * clutter_backend_get_event: - * @backend: a #ClutterBackend - * - * FIXME - * - * Return value: the #ClutterEvent removed from the queue - * - * Since: 0.4 - */ -ClutterEvent * -clutter_backend_get_event (ClutterBackend *backend) -{ - g_return_val_if_fail (CLUTTER_IS_BACKEND (backend), NULL); - - _clutter_events_queue (backend); - return _clutter_event_queue_pop (backend); -} - -/** - * clutter_backend_peek_event: - * @backend: a #ClutterBackend - * - * FIXME - * - * Return value: a copy of the first #ClutterEvent in the queue - * - * Since: 0.4 - */ -ClutterEvent * -clutter_backend_peek_event (ClutterBackend *backend) -{ - g_return_val_if_fail (CLUTTER_IS_BACKEND (backend), NULL); - - return _clutter_event_queue_peek (backend); -} - -/** - * clutter_backend_put_event: - * @backend: a #ClutterBackend - * @event: a #ClutterEvent - * - * FIXME - * - * Since: 0.4 - */ -void -clutter_backend_put_event (ClutterBackend *backend, - ClutterEvent *event) -{ - g_return_if_fail (CLUTTER_IS_BACKEND (backend)); - g_return_if_fail (event != NULL); - - _clutter_event_queue_push (backend, clutter_event_copy (event)); -} - -/** - * clutter_backend_get_width: - * @backend: a #ClutterBackend - * - * Gets the width of the screen used by @backend in pixels. - * - * Return value: the width of the screen - * - * Since: 0.4 - */ -gint -clutter_backend_get_width (ClutterBackend *backend) -{ - g_return_val_if_fail (CLUTTER_IS_BACKEND (backend), -1); - - return backend->res_width; -} - -/** - * clutter_backend_get_height: - * @backend: a #ClutterBackend - * - * Gets the height of the screen used by @backend in pixels. - * - * Return value: the height of the screen - * - * Since: 0.4 - */ -gint -clutter_backend_get_height (ClutterBackend *backend) -{ - g_return_val_if_fail (CLUTTER_IS_BACKEND (backend), -1); - - return backend->res_height; -} - -/** - * clutter_backend_get_width_mm: - * @backend: a #ClutterBackend - * - * Gets the width of the screen used by @backend in millimiters. - * - * Return value: the width of the screen - * - * Since: 0.4 - */ -gint -clutter_backend_get_width_mm (ClutterBackend *backend) -{ - g_return_val_if_fail (CLUTTER_IS_BACKEND (backend), -1); - - return backend->mm_width; -} - -/** - * clutter_backend_get_height_mm: - * @backend: a #ClutterBackend - * - * Gets the height of the screen used by @backend in millimiters. - * - * Return value: the height of the screen - * - * Since: 0.4 - */ -gint -clutter_backend_get_height_mm (ClutterBackend *backend) -{ - g_return_val_if_fail (CLUTTER_IS_BACKEND (backend), -1); - - return backend->mm_height; -} - -/** - * clutter_backend_get_screen_number: - * @backend: a #ClutterBackend - * - * Gets the number of screens available for @backend. - * - * Return value: the number of screens. - * - * Since: 0.4 - */ -gint -clutter_backend_get_screen_number (ClutterBackend *backend) -{ - g_return_val_if_fail (CLUTTER_IS_BACKEND (backend), -1); - - return backend->screen_num; -} - -/** - * clutter_backend_get_n_screens: - * @backend: a #ClutterBackend - * - * Gets the number of screens managed by @backend. - * - * Return value: the number of screens - * - * Since: 0.4 - */ -gint -clutter_backend_get_n_screens (ClutterBackend *backend) -{ - g_return_val_if_fail (CLUTTER_IS_BACKEND (backend), 0); - - return backend->n_screens; -} - -/** - * clutter_backend_get_resolution: - * @backend: a #ClutterBackend - * - * Gets the resolution of the screen used by @backend. - * - * Return value: the resolution of the screen - * - * Since: 0.4 - */ -gdouble -clutter_backend_get_resolution (ClutterBackend *backend) -{ - g_return_val_if_fail (CLUTTER_IS_BACKEND (backend), 0.0); - - return (((gdouble) backend->res_height * 25.4) / - (gdouble) backend->mm_height); -} +/* FIXME: below should probably be moved into clutter_main */ /** * clutter_backend_set_double_click_time: @@ -368,7 +213,7 @@ clutter_backend_set_double_click_time (ClutterBackend *backend, { g_return_if_fail (CLUTTER_IS_BACKEND (backend)); - backend->double_click_time = msec; + backend->priv->double_click_time = msec; } /** @@ -387,7 +232,7 @@ clutter_backend_get_double_click_time (ClutterBackend *backend) { g_return_val_if_fail (CLUTTER_IS_BACKEND (backend), 0); - return backend->double_click_time; + return backend->priv->double_click_time; } /** @@ -405,7 +250,7 @@ clutter_backend_set_double_click_distance (ClutterBackend *backend, { g_return_if_fail (CLUTTER_IS_BACKEND (backend)); - backend->double_click_distance = distance; + backend->priv->double_click_distance = distance; } /** @@ -423,5 +268,5 @@ clutter_backend_get_double_click_distance (ClutterBackend *backend) { g_return_val_if_fail (CLUTTER_IS_BACKEND (backend), 0); - return backend->double_click_distance; + return backend->priv->double_click_distance; } diff --git a/clutter/clutter-backend.h b/clutter/clutter-backend.h index 7ab7f23cd..6a75d482f 100644 --- a/clutter/clutter-backend.h +++ b/clutter/clutter-backend.h @@ -40,34 +40,14 @@ G_BEGIN_DECLS #define CLUTTER_BACKEND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CLUTTER_TYPE_BACKEND, ClutterBackendClass)) typedef struct _ClutterBackend ClutterBackend; +typedef struct _ClutterBackendPrivate ClutterBackendPrivate; typedef struct _ClutterBackendClass ClutterBackendClass; struct _ClutterBackend { - GObject parent_instance; + GObject parent_instance; + ClutterBackendPrivate *priv; - /*< private >*/ - gint mm_width; - gint mm_height; - gint res_width; - gint res_height; - - gint screen_num; - gint n_screens; - - /* events queue: every backend must implement one */ - GQueue *events_queue; - gpointer queue_head; - - /* settings */ - guint double_click_time; - guint double_click_distance; - - /* multiple button click detection */ - guint32 button_click_time[2]; - guint32 button_number[2]; - gint button_x[2]; - gint button_y[2]; }; struct _ClutterBackendClass @@ -92,17 +72,12 @@ GType clutter_backend_get_type (void) G_GNUC_CONST; ClutterBackend *clutter_get_default_backend (void); +#if 0 ClutterEvent *clutter_backend_get_event (ClutterBackend *backend); ClutterEvent *clutter_backend_peek_event (ClutterBackend *backend); void clutter_backend_put_event (ClutterBackend *backend, ClutterEvent *event); - -gint clutter_backend_get_width (ClutterBackend *backend); -gint clutter_backend_get_height (ClutterBackend *backend); -gint clutter_backend_get_width_mm (ClutterBackend *backend); -gint clutter_backend_get_height_mm (ClutterBackend *backend); -gint clutter_backend_get_screen_number (ClutterBackend *backend); -gint clutter_backend_get_n_screens (ClutterBackend *backend); +#endif void clutter_backend_set_double_click_time (ClutterBackend *backend, guint msec); diff --git a/clutter/clutter-event.c b/clutter/clutter-event.c index af9a2fd86..1a47482d7 100644 --- a/clutter/clutter-event.c +++ b/clutter/clutter-event.c @@ -32,10 +32,11 @@ #include "clutter-private.h" #include "clutter-debug.h" -/* main event handler */ -ClutterEventFunc _clutter_event_func = NULL; -gpointer _clutter_event_data = NULL; -GDestroyNotify _clutter_event_destroy = NULL; +/* multiple button click detection */ +static guint32 button_click_time[2] = {0, 0}; +static guint32 button_number[2] = {0, -1}; +static gint button_x[2] = {0, 0}; +static gint button_y[2] = {0, 0};; /** * clutter_event_type: @@ -320,6 +321,7 @@ clutter_event_new (ClutterEventType type) new_event = g_slice_new0 (ClutterEvent); new_event->type = new_event->any.type = type; + /* FIXME: why do we put in a hash ? */ g_hash_table_insert (event_hash, new_event, GUINT_TO_POINTER (1)); return new_event; @@ -375,10 +377,8 @@ ClutterEvent * clutter_event_get (void) { ClutterMainContext *context = clutter_context_get_default (); - ClutterBackend *backend = context->backend; - _clutter_events_queue (backend); - return _clutter_event_queue_pop (backend); + return g_queue_pop_tail (context->events_queue); } /** @@ -394,8 +394,13 @@ ClutterEvent * clutter_event_peek (void) { ClutterMainContext *context = clutter_context_get_default (); + + g_return_val_if_fail (context != NULL, NULL); - return _clutter_event_queue_peek (context->backend); + if (context->events_queue == NULL) + return NULL; + + return g_queue_peek_tail (context->events_queue); } /** @@ -410,74 +415,32 @@ void clutter_event_put (ClutterEvent *event) { ClutterMainContext *context = clutter_context_get_default (); - ClutterBackend *backend = context->backend; - _clutter_event_queue_push (backend, clutter_event_copy (event)); -} + /* FIXME: check queue is valid */ + g_return_if_fail (context != NULL); -void -_clutter_event_queue_push (ClutterBackend *backend, - ClutterEvent *event) -{ - if (!backend->events_queue) - backend->events_queue = g_queue_new (); - - g_queue_push_head (backend->events_queue, event); -} - -ClutterEvent * -_clutter_event_queue_pop (ClutterBackend *backend) -{ - if (!backend->events_queue) - return NULL; - - return g_queue_pop_tail (backend->events_queue); -} - -ClutterEvent * -_clutter_event_queue_peek (ClutterBackend *backend) -{ - if (!backend->events_queue) - return NULL; - - return g_queue_peek_tail (backend->events_queue); + g_queue_push_head (context->events_queue, clutter_event_copy (event)); } gboolean -_clutter_event_queue_check_pending (ClutterBackend *backend) +clutter_events_pending (void) { - if (!backend->events_queue) + ClutterMainContext *context = clutter_context_get_default (); + + g_return_val_if_fail (context != NULL, FALSE); + + if (!context->events_queue) return FALSE; - return g_queue_is_empty (backend->events_queue) == FALSE; + return g_queue_is_empty (context->events_queue) == FALSE; } -void -_clutter_set_events_handler (ClutterEventFunc func, - gpointer data, - GDestroyNotify destroy) -{ - if (_clutter_event_destroy) - (* _clutter_event_destroy) (_clutter_event_data); +/* Backend helpers (private) */ - _clutter_event_func = func; - _clutter_event_data = data; - _clutter_event_destroy = destroy; -} - -void -_clutter_synthetise_stage_state (ClutterBackend *backend, - ClutterEvent *event, - ClutterStageState set_flags, - ClutterStageState unset_flags) -{ - -} - -void -_clutter_synthesize_click (ClutterBackend *backend, - ClutterEvent *event, - gint n_clicks) +static void +synthesize_click (ClutterBackend *backend, + ClutterEvent *event, + gint n_clicks) { ClutterEvent temp_event; @@ -485,52 +448,58 @@ _clutter_synthesize_click (ClutterBackend *backend, temp_event.type = (n_clicks == 2) ? CLUTTER_2BUTTON_PRESS : CLUTTER_3BUTTON_PRESS; - clutter_backend_put_event (backend, &temp_event); + clutter_event_put (&temp_event); } +/* post process a button to synthesize double clicks etc */ void _clutter_event_button_generate (ClutterBackend *backend, ClutterEvent *event) { - if ((event->button.time < (backend->button_click_time[1] + 2 * backend->double_click_time)) && - (event->button.button == backend->button_number[1]) && - (ABS (event->button.x - backend->button_x[1]) <= backend->double_click_distance) && - (ABS (event->button.y - backend->button_y[1]) <= backend->double_click_distance)) + guint double_click_time, double_click_distance; + + double_click_distance = clutter_backend_get_double_click_distance (backend); + double_click_time = clutter_backend_get_double_click_time (backend); + + if ((event->button.time < (button_click_time[1] + 2 * double_click_time)) + && (event->button.button == button_number[1]) + && (ABS (event->button.x - button_x[1]) <= double_click_distance) + && (ABS (event->button.y - button_y[1]) <= double_click_distance)) { - _clutter_synthesize_click (backend, event, 3); + synthesize_click (backend, event, 3); - backend->button_click_time[1] = 0; - backend->button_click_time[0] = 0; - backend->button_number[1] = -1; - backend->button_number[0] = -1; - backend->button_x[0] = backend->button_x[1] = 0; - backend->button_y[0] = backend->button_y[1] = 0; + button_click_time[1] = 0; + button_click_time[0] = 0; + button_number[1] = -1; + button_number[0] = -1; + button_x[0] = button_x[1] = 0; + button_y[0] = button_y[1] = 0; } - else if ((event->button.time < (backend->button_click_time[0] + backend->double_click_time)) && - (event->button.button == backend->button_number[0]) && - (ABS (event->button.x - backend->button_x[0]) <= backend->double_click_distance) && - (ABS (event->button.y - backend->button_y[0]) <= backend->double_click_distance)) + else if ((event->button.time < (button_click_time[0] + double_click_time)) && + (event->button.button == button_number[0]) && + (ABS (event->button.x - button_x[0]) <= double_click_distance) && + (ABS (event->button.y - button_y[0]) <= double_click_distance)) { - _clutter_synthesize_click (backend, event, 2); + synthesize_click (backend, event, 2); - backend->button_click_time[1] = backend->button_click_time[0]; - backend->button_click_time[0] = event->button.time; - backend->button_number[1] = backend->button_number[0]; - backend->button_number[0] = event->button.button; - backend->button_x[1] = backend->button_x[0]; - backend->button_x[0] = event->button.x; - backend->button_y[1] = backend->button_y[0]; - backend->button_y[0] = event->button.y; + button_click_time[1] = button_click_time[0]; + button_click_time[0] = event->button.time; + button_number[1] = button_number[0]; + button_number[0] = event->button.button; + button_x[1] = button_x[0]; + button_x[0] = event->button.x; + button_y[1] = button_y[0]; + button_y[0] = event->button.y; } else { - backend->button_click_time[1] = 0; - backend->button_click_time[0] = event->button.time; - backend->button_number[1] = -1; - backend->button_number[0] = event->button.button; - backend->button_x[1] = 0; - backend->button_x[0] = event->button.x; - backend->button_y[1] = 0; - backend->button_y[0] = event->button.y; + button_click_time[1] = 0; + button_click_time[0] = event->button.time; + button_number[1] = -1; + button_number[0] = event->button.button; + button_x[1] = 0; + button_x[0] = event->button.x; + button_y[1] = 0; + button_y[0] = event->button.y; } } diff --git a/clutter/clutter-main.c b/clutter/clutter-main.c index e28104333..bb601fec7 100644 --- a/clutter/clutter-main.c +++ b/clutter/clutter-main.c @@ -70,7 +70,6 @@ static const GDebugKey clutter_debug_keys[] = { }; #endif /* CLUTTER_ENABLE_DEBUG */ - /** * clutter_get_show_fps: * @@ -116,9 +115,13 @@ clutter_redraw (void) clutter_actor_paint (_clutter_backend_get_stage (ctx->backend)); } -static void -clutter_main_do_event (ClutterEvent *event, - gpointer dummy) +/** + * clutter_do_event + * + * This function should never be called by applications. + */ +void +clutter_do_event (ClutterEvent *event) { ClutterMainContext *context; ClutterBackend *backend; @@ -367,8 +370,6 @@ pre_parse_hook (GOptionContext *context, backend = clutter_context->backend; g_assert (CLUTTER_IS_BACKEND (backend)); - _clutter_set_events_handler (clutter_main_do_event, NULL, NULL); - #ifdef CLUTTER_ENABLE_DEBUG env_string = g_getenv ("CLUTTER_DEBUG"); if (env_string != NULL) @@ -631,7 +632,7 @@ clutter_init (int *argc, return CLUTTER_INIT_ERROR_INTERNAL; } - _clutter_events_init (context->backend); + _clutter_backend_init_events (context->backend); return CLUTTER_INIT_SUCCESS; } diff --git a/clutter/clutter-private.h b/clutter/clutter-private.h index 453e496ba..47d3fed2b 100644 --- a/clutter/clutter-private.h +++ b/clutter/clutter-private.h @@ -47,17 +47,14 @@ typedef struct _ClutterMainContext ClutterMainContext; struct _ClutterMainContext { /* holds a pointer to the stage */ - ClutterBackend *backend; - + ClutterBackend *backend; + GQueue *events_queue; PangoFT2FontMap *font_map; - - GMutex *gl_lock; - guint update_idle; - - guint main_loop_level; - GSList *main_loops; - - guint is_initialized : 1; + GMutex *gl_lock; + guint update_idle; + guint main_loop_level; + GSList *main_loops; + guint is_initialized : 1; }; #define CLUTTER_CONTEXT() (clutter_context_get_default ()) @@ -84,19 +81,18 @@ typedef enum { #define CLUTTER_PARAM_READWRITE \ G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK |G_PARAM_STATIC_BLURB +/* signal accumulators */ +gboolean _clutter_boolean_accumulator (GSignalInvocationHint *ihint, + GValue *return_accu, + const GValue *handler_return, + gpointer dummy); + +/* vfuncs implemnted by backend */ + GType _clutter_backend_impl_get_type (void); -/* backend-specific private functions */ -void _clutter_events_init (ClutterBackend *backend); -void _clutter_events_uninit (ClutterBackend *backend); -void _clutter_events_queue (ClutterBackend *backend); -void _clutter_event_queue_push (ClutterBackend *backend, - ClutterEvent *event); -ClutterEvent *_clutter_event_queue_pop (ClutterBackend *backend); -ClutterEvent *_clutter_event_queue_peek (ClutterBackend *backend); -gboolean _clutter_event_queue_check_pending (ClutterBackend *backend); - ClutterActor *_clutter_backend_get_stage (ClutterBackend *backend); + void _clutter_backend_add_options (ClutterBackend *backend, GOptionGroup *group); gboolean _clutter_backend_pre_parse (ClutterBackend *backend, @@ -106,39 +102,19 @@ gboolean _clutter_backend_post_parse (ClutterBackend *backend, gboolean _clutter_backend_init_stage (ClutterBackend *backend, GError **error); void _clutter_backend_init_events (ClutterBackend *backend); + void _clutter_backend_init_features (ClutterBackend *backend); - -/* signal accumulators */ -gboolean _clutter_boolean_accumulator (GSignalInvocationHint *ihint, - GValue *return_accu, - const GValue *handler_return, - gpointer dummy); - -typedef void (* ClutterEventFunc) (ClutterEvent *event, - gpointer data); - -/* the event dispatcher function */ -extern ClutterEventFunc _clutter_event_func; -extern gpointer _clutter_event_data; -extern GDestroyNotify _clutter_event_destroy; - -void _clutter_set_events_handler (ClutterEventFunc func, - gpointer data, - GDestroyNotify destroy); - +/* backend helpers */ void _clutter_event_button_generate (ClutterBackend *backend, ClutterEvent *event); -void _clutter_synthetise_click (ClutterBackend *backend, - ClutterEvent *event, - gint n_clicks); -void _clutter_synthetise_stage_state (ClutterBackend *backend, - ClutterEvent *event, - ClutterStageState set_flags, - ClutterStageState unset_flags); +/* FIXME: move elsewhere via ClutterAudience */ void _clutter_stage_sync_viewport (ClutterStage *stage); +/* Does this need to be private ? */ +void clutter_do_event (ClutterEvent *event); + G_END_DECLS #endif /* _HAVE_CLUTTER_PRIVATE_H */ diff --git a/clutter/glx/clutter-backend-glx.c b/clutter/glx/clutter-backend-glx.c index b575bff0b..721c2a1b3 100644 --- a/clutter/glx/clutter-backend-glx.c +++ b/clutter/glx/clutter-backend-glx.c @@ -107,13 +107,6 @@ clutter_backend_glx_post_parse (ClutterBackend *backend, backend_glx->display_name = g_strdup (clutter_display_name); - /* generic backend properties */ - backend->res_width = WidthOfScreen (backend_glx->xscreen); - backend->res_height = HeightOfScreen (backend_glx->xscreen); - backend->mm_width = WidthMMOfScreen (backend_glx->xscreen); - backend->mm_height = HeightMMOfScreen (backend_glx->xscreen); - backend->screen_num = backend_glx->xscreen_num; - backend->n_screens = ScreenCount (backend_glx->xdpy); } g_free (clutter_display_name); @@ -130,7 +123,7 @@ clutter_backend_glx_post_parse (ClutterBackend *backend, static gboolean is_gl_version_at_least_12 (void) { - /* FIXME: This likely needs to live elsewhere in features */ + /* FIXME: This likely needs to live elsewhere in features or cogl */ return (g_ascii_strtod ((const gchar*) glGetString (GL_VERSION), NULL) >= 1.2); } @@ -189,7 +182,8 @@ static void clutter_backend_glx_init_events (ClutterBackend *backend) { CLUTTER_NOTE (EVENT, "initialising the event loop"); - _clutter_events_init (backend); + + _clutter_backend_glx_events_init (backend); } static ClutterActor * @@ -244,7 +238,7 @@ clutter_backend_glx_dispose (GObject *gobject) { ClutterBackendGlx *backend_glx = CLUTTER_BACKEND_GLX (gobject); - _clutter_events_uninit (CLUTTER_BACKEND (backend_glx)); + _clutter_backend_glx_events_uninit (CLUTTER_BACKEND(backend_glx)); if (backend_glx->stage) { @@ -301,21 +295,10 @@ static void clutter_backend_glx_init (ClutterBackendGlx *backend_glx) { ClutterBackend *backend = CLUTTER_BACKEND (backend_glx); - backend->events_queue = g_queue_new (); - backend->button_click_time[0] = backend->button_click_time[1] = 0; - backend->button_number[0] = backend->button_number[1] = -1; - backend->button_x[0] = backend->button_x[1] = 0; - backend->button_y[0] = backend->button_y[1] = 0; - - backend->res_width = backend->res_height = -1; - backend->mm_width = backend->mm_height = -1; - backend->screen_num = 0; - backend->n_screens = 0; - - /* FIXME - find a way to set this stuff from XSettings */ - backend->double_click_time = 250; - backend->double_click_distance = 5; + /* FIXME: get from xsettings */ + clutter_backend_set_double_click_time (backend, 250); + clutter_backend_set_double_click_distance (backend, 5); } /* every backend must implement this function */ diff --git a/clutter/glx/clutter-backend-glx.h b/clutter/glx/clutter-backend-glx.h index 6496d4bc8..947667578 100644 --- a/clutter/glx/clutter-backend-glx.h +++ b/clutter/glx/clutter-backend-glx.h @@ -64,6 +64,9 @@ struct _ClutterBackendGlxClass ClutterBackendClass parent_class; }; +void _clutter_backend_glx_events_init (ClutterBackend *backend); +void _clutter_backend_glx_events_uninit (ClutterBackend *backend); + GType clutter_backend_glx_get_type (void) G_GNUC_CONST; G_END_DECLS diff --git a/clutter/glx/clutter-event-glx.c b/clutter/glx/clutter-event-glx.c index fd3d9ba48..088c9f2d2 100644 --- a/clutter/glx/clutter-event-glx.c +++ b/clutter/glx/clutter-event-glx.c @@ -103,7 +103,7 @@ clutter_event_source_new (ClutterBackend *backend) } static gboolean -clutter_check_xpending (ClutterBackend *backend) +check_xpending (ClutterBackend *backend) { return XPending (CLUTTER_BACKEND_GLX (backend)->xdpy); } @@ -163,7 +163,7 @@ xembed_set_info (Display *xdisplay, } void -_clutter_events_init (ClutterBackend *backend) +_clutter_backend_glx_events_init (ClutterBackend *backend) { GSource *source; ClutterEventSource *event_source; @@ -195,7 +195,7 @@ _clutter_events_init (ClutterBackend *backend) } void -_clutter_events_uninit (ClutterBackend *backend) +_clutter_backend_glx_events_uninit (ClutterBackend *backend) { ClutterBackendGlx *backend_glx = CLUTTER_BACKEND_GLX (backend); @@ -231,41 +231,6 @@ set_user_time (Display *display, } } -/** - * clutter_events_pending: - * - * FIXME - * - * Return value: FIXME - * - * Since: 0.4 - */ -gboolean -clutter_events_pending (void) -{ - GList *i; - - for (i = event_sources; i != NULL; i = i->next) - { - ClutterEventSource *source = i->data; - ClutterBackend *backend = source->backend; - - if (_clutter_event_queue_check_pending (backend)) - return TRUE; - } - - for (i = event_sources; i != NULL; i = i->next) - { - ClutterEventSource *source = i->data; - ClutterBackend *backend = source->backend; - - if (clutter_check_xpending (backend)) - return TRUE; - } - - return FALSE; -} - static void translate_key_event (ClutterBackend *backend, ClutterEvent *event, @@ -381,9 +346,9 @@ handle_xembed_event (ClutterBackendGlx *backend_glx, } static gboolean -clutter_event_translate (ClutterBackend *backend, - ClutterEvent *event, - XEvent *xevent) +event_translate (ClutterBackend *backend, + ClutterEvent *event, + XEvent *xevent) { ClutterBackendGlx *backend_glx; ClutterStage *stage; @@ -518,32 +483,27 @@ clutter_event_translate (ClutterBackend *backend, return res; } -void -_clutter_events_queue (ClutterBackend *backend) +static void +events_queue (ClutterBackend *backend) { ClutterBackendGlx *backend_glx = CLUTTER_BACKEND_GLX (backend); - ClutterEvent *event; - XEvent xevent; - Display *xdisplay = backend_glx->xdpy; + ClutterEvent *event; + Display *xdisplay = backend_glx->xdpy; + XEvent xevent; + ClutterMainContext *clutter_context; - while (!_clutter_event_queue_check_pending (backend) && XPending (xdisplay)) + clutter_context = clutter_context_get_default (); + + while (!clutter_events_pending () && XPending (xdisplay)) { XNextEvent (xdisplay, &xevent); - switch (xevent.type) - { - case KeyPress: - case KeyRelease: - break; - default: - if (XFilterEvent (&xevent, None)) - continue; - } - event = clutter_event_new (CLUTTER_NOTHING); - if (clutter_event_translate (backend, event, &xevent)) + + if (event_translate (backend, event, &xevent)) { - _clutter_event_queue_push (backend, event); + /* push directly here to avoid copy of queue_put */ + g_queue_push_head (clutter_context->events_queue, event); } else { @@ -560,8 +520,7 @@ clutter_event_prepare (GSource *source, gboolean retval; *timeout = -1; - retval = (_clutter_event_queue_check_pending (backend) || - clutter_check_xpending (backend)); + retval = (clutter_events_pending () || check_xpending (backend)); return retval; } @@ -574,8 +533,7 @@ clutter_event_check (GSource *source) gboolean retval; if (event_source->event_poll_fd.revents & G_IO_IN) - retval = (_clutter_event_queue_check_pending (backend) || - clutter_check_xpending (backend)); + retval = (clutter_events_pending () || check_xpending (backend)); else retval = FALSE; @@ -590,17 +548,18 @@ clutter_event_dispatch (GSource *source, ClutterBackend *backend = ((ClutterEventSource *) source)->backend; ClutterEvent *event; - _clutter_events_queue (backend); - event = _clutter_event_queue_pop (backend); + /* Grab the event(s), translate and figure out double click. + * The push onto queue (stack) if valid. + */ + events_queue (backend); + + /* Pop an event off the queue if any */ + event = clutter_event_get (); if (event) { - if (_clutter_event_func) - { - CLUTTER_NOTE (EVENT, "Dispatching _clutter_event_func"); - (* _clutter_event_func) (event, _clutter_event_data); - } - + /* forward the event into clutter for emission etc. */ + clutter_do_event (event); clutter_event_free (event); } diff --git a/tests/Makefile.am b/tests/Makefile.am index cebfa5cbc..c92da6b7d 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,4 +1,4 @@ -noinst_PROGRAMS = test-textures +noinst_PROGRAMS = test-textures test-events INCLUDES = -I$(top_srcdir)/ LDADD = $(top_builddir)/clutter/libclutter-@CLUTTER_FLAVOUR@-@CLUTTER_MAJORMINOR@.la @@ -6,3 +6,5 @@ AM_CFLAGS = $(CLUTTER_CFLAGS) LDFLAGS = $(CLUTTER_LIBS) test_textures_SOURCES = test-textures.c + +test_events_SOURCES = test-events.c diff --git a/tests/test-events.c b/tests/test-events.c new file mode 100644 index 000000000..51c515abd --- /dev/null +++ b/tests/test-events.c @@ -0,0 +1,63 @@ +#include + +static void +input_cb (ClutterStage *stage, + ClutterEvent *event, + gpointer data) +{ + switch (event->type) + { + case CLUTTER_KEY_PRESS: + printf("- KEY PRESS\n"); + break; + case CLUTTER_KEY_RELEASE: + printf("- KEY RELEASE\n"); + break; + case CLUTTER_MOTION: + printf("- MOTION\n"); + break; + case CLUTTER_BUTTON_PRESS: + printf("- BUTTON PRESS\n"); + break; + case CLUTTER_2BUTTON_PRESS: + printf("- BUTTON 2 PRESS\n"); + break; + case CLUTTER_3BUTTON_PRESS: + printf("- BUTTON 3 PRESS\n"); + break; + case CLUTTER_BUTTON_RELEASE: + printf("- BUTTON RELEASE\n"); + break; + case CLUTTER_SCROLL: + printf("- BUTTON SCROLL\n"); + break; + case CLUTTER_STAGE_STATE: + printf("- STAGE STATE\n"); + break; + case CLUTTER_DESTROY_NOTIFY: + printf("- DESTROY NOTIFY\n"); + break; + case CLUTTER_CLIENT_MESSAGE: + printf("- CLIENT MESSAGE\n"); + break; + case CLUTTER_DELETE: + printf("- DELETE\n"); + break; + } +} + +int +main (int argc, char *argv[]) +{ + ClutterActor *stage; + + clutter_init (&argc, &argv); + + stage = clutter_stage_get_default (); + g_signal_connect (stage, "event", G_CALLBACK (input_cb), NULL); + clutter_actor_show_all (CLUTTER_ACTOR (stage)); + + clutter_main(); + + return 0; +} diff --git a/tests/test-textures.c b/tests/test-textures.c index 20b278fd3..972a6f21a 100644 --- a/tests/test-textures.c +++ b/tests/test-textures.c @@ -56,7 +56,7 @@ main (int argc, char *argv[]) ClutterActor *texture; ClutterActor *stage; GdkPixbuf *pixbuf; - gint i, cols, rows; + gint i, j, cols, rows; clutter_init (&argc, &argv); @@ -66,31 +66,33 @@ main (int argc, char *argv[]) SPIN(); for (i=100; i<5000; i += 100) - { - pixbuf = make_pixbuf (i, i, 4, TRUE); - - if (!pixbuf) - g_error("%ix%i pixbuf creation failed", i, i); - - printf("o %ix%i pixbuf... ", i, i); - - texture = clutter_texture_new_from_pixbuf (pixbuf); - - g_object_unref (pixbuf); - - if (!texture) - g_error("Pixbuf creation failed"); - - printf("uploaded to texture... ", i, i); - - clutter_group_add (CLUTTER_GROUP (stage), texture); - clutter_actor_set_size (texture, 400, 400); - clutter_actor_show (texture); - - clutter_texture_get_n_tiles(CLUTTER_TEXTURE(texture), &cols, &rows); - printf("with tiles: %i x %i\n", cols, rows); - - SPIN(); + for (j=0; j<4; j++) + { + pixbuf = make_pixbuf (i+j, i+j, 4, TRUE); + + if (!pixbuf) + g_error("%ix%i pixbuf creation failed", i+j, i+j); + + printf("o %ix%i pixbuf... ", i+j, i+j); + + texture = clutter_texture_new_from_pixbuf (pixbuf); + + g_object_unref (pixbuf); + + if (!texture) + g_error("Pixbuf creation failed"); + + printf("uploaded to texture... "); + + clutter_group_add (CLUTTER_GROUP (stage), texture); + clutter_actor_set_size (texture, 400, 400); + clutter_actor_show (texture); + + clutter_texture_get_n_tiles(CLUTTER_TEXTURE(texture), &cols, &rows); + + printf("with tiles: %i x %i\n", cols, rows); + + SPIN(); clutter_group_remove (CLUTTER_GROUP (stage), texture); }