From 51a3e49c8228a22c1fbcd42971ad27d26d83991b Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Wed, 17 Feb 2010 18:21:50 +0000 Subject: [PATCH] device: Allow updating devices from embedding toolkits MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Embedding toolkits most likely will disable the event handling, so all the input device code will not be executed. Unfortunately, the newly added synthetic event generation of ENTER and LEAVE event pairs depends on having input devices. In order to unbreak things without reintroducing the madness of the previous code we should allow embedding toolkits to just update the state of an InputDevice by using the data contained inside the ClutterEvent. This strategy has two obvious reasons: • the embedding toolkit is creating a ClutterEvent by translating a toolkit-native event anyway • this is exactly what ClutterStage does when processing events We are, essentially, deferring input device handling to the embedding toolkits, just like we're deferring event handling to them. --- clutter/clutter-event.h | 2 - clutter/clutter-input-device.c | 59 ++++++++++++++++++++++ clutter/clutter-input-device.h | 5 ++ clutter/clutter-types.h | 2 + doc/reference/clutter/clutter-sections.txt | 2 + 5 files changed, 68 insertions(+), 2 deletions(-) diff --git a/clutter/clutter-event.h b/clutter/clutter-event.h index 947536461..f0dc8a357 100644 --- a/clutter/clutter-event.h +++ b/clutter/clutter-event.h @@ -192,8 +192,6 @@ typedef enum CLUTTER_STAGE_STATE_ACTIVATED = (1<<3) } ClutterStageState; -typedef union _ClutterEvent ClutterEvent; - typedef struct _ClutterAnyEvent ClutterAnyEvent; typedef struct _ClutterButtonEvent ClutterButtonEvent; typedef struct _ClutterKeyEvent ClutterKeyEvent; diff --git a/clutter/clutter-input-device.c b/clutter/clutter-input-device.c index 1567a41b5..0f93e9329 100644 --- a/clutter/clutter-input-device.c +++ b/clutter/clutter-input-device.c @@ -526,6 +526,25 @@ clutter_input_device_get_pointer_actor (ClutterInputDevice *device) return device->cursor_actor; } +/** + * clutter_input_device_get_pointer_stage: + * @device: a #ClutterInputDevice of type %CLUTTER_POINTER_DEVICE + * + * Retrieves the #ClutterStage underneath the pointer of @device + * + * Return value: (transfer none): a pointer to the #ClutterStage or %NULL + * + * Since: 1.2 + */ +ClutterStage * +clutter_input_device_get_pointer_stage (ClutterInputDevice *device) +{ + g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), NULL); + g_return_val_if_fail (device->device_type == CLUTTER_POINTER_DEVICE, NULL); + + return device->stage; +} + /** * clutter_input_device_get_device_name: * @device: a #ClutterInputDevice @@ -545,3 +564,43 @@ clutter_input_device_get_device_name (ClutterInputDevice *device) return device->device_name; } + +/** + * clutter_input_device_update_from_event: + * @device: a #ClutterInputDevice + * @event: a #ClutterEvent + * @update_stage: whether to update the #ClutterStage of the @device + * using the stage of the event + * + * Forcibly updates the state of the @device using a #ClutterEvent + * + * This function should never be used by applications: it is meant + * for integration with embedding toolkits, like clutter-gtk + * + * Since: 1.2 + */ +void +clutter_input_device_update_from_event (ClutterInputDevice *device, + ClutterEvent *event, + gboolean update_stage) +{ + ClutterModifierType event_state; + ClutterStage *event_stage; + gfloat event_x, event_y; + guint32 event_time; + + g_return_if_fail (CLUTTER_IS_INPUT_DEVICE (device)); + g_return_if_fail (event != NULL); + + event_state = clutter_event_get_state (event); + event_time = clutter_event_get_time (event); + event_stage = clutter_event_get_stage (event); + clutter_event_get_coords (event, &event_x, &event_y); + + _clutter_input_device_set_coords (device, event_x, event_y); + _clutter_input_device_set_state (device, event_state); + _clutter_input_device_set_time (device, event_time); + + if (update_stage) + _clutter_input_device_set_stage (device, event_stage); +} diff --git a/clutter/clutter-input-device.h b/clutter/clutter-input-device.h index 4b8cc9470..85ee592f5 100644 --- a/clutter/clutter-input-device.h +++ b/clutter/clutter-input-device.h @@ -92,8 +92,13 @@ void clutter_input_device_get_device_coords (ClutterInputDevic gint *x, gint *y); ClutterActor * clutter_input_device_get_pointer_actor (ClutterInputDevice *device); +ClutterStage * clutter_input_device_get_pointer_stage (ClutterInputDevice *device); G_CONST_RETURN gchar * clutter_input_device_get_device_name (ClutterInputDevice *device); +void clutter_input_device_update_from_event (ClutterInputDevice *device, + ClutterEvent *event, + gboolean update_stage); + G_END_DECLS #endif /* __CLUTTER_INPUT_DEVICE_H__ */ diff --git a/clutter/clutter-types.h b/clutter/clutter-types.h index 84f364462..119ff1d8a 100644 --- a/clutter/clutter-types.h +++ b/clutter/clutter-types.h @@ -46,6 +46,8 @@ typedef struct _ClutterChildMeta ClutterChildMeta; typedef struct _ClutterLayoutMeta ClutterLayoutMeta; typedef struct _ClutterAnimator ClutterAnimator; +typedef union _ClutterEvent ClutterEvent; + /** * ClutterGravity: * @CLUTTER_GRAVITY_NONE: Do not apply any gravity diff --git a/doc/reference/clutter/clutter-sections.txt b/doc/reference/clutter/clutter-sections.txt index 8e3891640..59d61fac2 100644 --- a/doc/reference/clutter/clutter-sections.txt +++ b/doc/reference/clutter/clutter-sections.txt @@ -1005,6 +1005,8 @@ clutter_input_device_get_device_type clutter_input_device_get_device_name clutter_input_device_get_device_coords clutter_input_device_get_pointer_actor +clutter_input_device_get_pointer_stage +clutter_input_device_update_from_event CLUTTER_TYPE_INPUT_DEVICE