event: Add setters for ClutterEvent members

Creating a synthetic event requires direct access to the ClutterEvent
union members; this access does not map in bindings to high-level
languages, especially run-time bindings using GObject-Introspection.
It's also midly annoying from C, as it unnecessarily exposes the guts of
ClutterEvent - something we might want to fix in the future.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2575
This commit is contained in:
Emmanuele Bassi 2011-02-22 17:12:34 +00:00
parent 26ec3efbff
commit d3a7b7502e
6 changed files with 433 additions and 120 deletions

View File

@ -18,10 +18,6 @@ gpointer _clutter_event_get_platform_data (const ClutterEvent *eve
void _clutter_event_push (const ClutterEvent *event,
gboolean do_copy);
void _clutter_event_set_device (ClutterEvent *event,
ClutterInputDevice *device);
void _clutter_event_set_source_device (ClutterEvent *event,
ClutterInputDevice *device);
G_END_DECLS

View File

@ -87,6 +87,15 @@ _clutter_event_get_platform_data (const ClutterEvent *event)
return ((ClutterEventPrivate *) event)->platform_data;
}
/*< private >
* _clutter_event_set_platform_data:
* @event: a #ClutterEvent
* @data: a pointer to platform-specific data
*
* Sets the pointer to platform-specific data inside an event
*
* Since: 1.4
*/
void
_clutter_event_set_platform_data (ClutterEvent *event,
gpointer data)
@ -131,6 +140,24 @@ clutter_event_get_time (const ClutterEvent *event)
return event->any.time;
}
/**
* clutter_event_set_time:
* @event: a #ClutterEvent
* @time_: the time of the event
*
* Sets the time of the event.
*
* Since: 1.8
*/
void
clutter_event_set_time (ClutterEvent *event,
guint32 time_)
{
g_return_if_fail (event != NULL);
event->any.time = time_;
}
/**
* clutter_event_get_state:
* @event: a #ClutterEvent
@ -169,6 +196,46 @@ clutter_event_get_state (const ClutterEvent *event)
return 0;
}
/**
* clutter_event_set_state:
* @event: a #ClutterEvent
* @state: the modifier state to set
*
* Sets the modifier state of the event.
*
* Since: 1.8
*/
void
clutter_event_set_state (ClutterEvent *event,
ClutterModifierType state)
{
g_return_if_fail (event != NULL);
switch (event->type)
{
case CLUTTER_KEY_PRESS:
case CLUTTER_KEY_RELEASE:
event->key.modifier_state = state;
break;
case CLUTTER_BUTTON_PRESS:
case CLUTTER_BUTTON_RELEASE:
event->button.modifier_state = state;
break;
case CLUTTER_MOTION:
event->motion.modifier_state = state;
break;
case CLUTTER_SCROLL:
event->scroll.modifier_state = state;
break;
default:
break;
}
}
/**
* clutter_event_get_coords:
* @event: a #ClutterEvent
@ -231,6 +298,58 @@ clutter_event_get_coords (const ClutterEvent *event,
*y = event_y;
}
/**
* clutter_event_set_coords:
* @event: a #ClutterEvent
* @x: the X coordinate of the event
* @y: the Y coordinate of the event
*
* Sets the coordinates of the @event.
*
* Since: 1.8
*/
void
clutter_event_set_coords (ClutterEvent *event,
gfloat x,
gfloat y)
{
g_return_if_fail (event != NULL);
switch (event->type)
{
case CLUTTER_NOTHING:
case CLUTTER_KEY_PRESS:
case CLUTTER_KEY_RELEASE:
case CLUTTER_STAGE_STATE:
case CLUTTER_DESTROY_NOTIFY:
case CLUTTER_CLIENT_MESSAGE:
case CLUTTER_DELETE:
break;
case CLUTTER_ENTER:
case CLUTTER_LEAVE:
event->crossing.x = x;
event->crossing.y = y;
break;
case CLUTTER_BUTTON_PRESS:
case CLUTTER_BUTTON_RELEASE:
event->button.x = x;
event->button.y = y;
break;
case CLUTTER_MOTION:
event->motion.x = x;
event->motion.y = y;
break;
case CLUTTER_SCROLL:
event->scroll.x = x;
event->scroll.y = y;
break;
}
}
/**
* clutter_event_get_source:
* @event: a #ClutterEvent
@ -250,6 +369,25 @@ clutter_event_get_source (const ClutterEvent *event)
return event->any.source;
}
/**
* clutter_event_set_source:
* @event: a #ClutterEvent
* @actor: (allow-none): a #ClutterActor, or %NULL
*
* Sets the source #ClutterActor of @event.
*
* Since: 1.8
*/
void
clutter_event_set_source (ClutterEvent *event,
ClutterActor *actor)
{
g_return_if_fail (event != NULL);
g_return_if_fail (actor == NULL || CLUTTER_IS_ACTOR (actor));
event->any.source = actor;
}
/**
* clutter_event_get_stage:
* @event: a #ClutterEvent
@ -269,6 +407,28 @@ clutter_event_get_stage (const ClutterEvent *event)
return event->any.stage;
}
/**
* clutter_event_set_stage:
* @event: a #ClutterEvent
* @stage: (allow-none): a #ClutterStage, or %NULL
*
* Sets the source #ClutterStage of the event.
*
* Since: 1.8
*/
void
clutter_event_set_stage (ClutterEvent *event,
ClutterStage *stage)
{
g_return_if_fail (event != NULL);
g_return_if_fail (stage == NULL || CLUTTER_IS_STAGE (stage));
if (event->any.stage == stage)
return;
event->any.stage = stage;
}
/**
* clutter_event_get_flags:
* @event: a #ClutterEvent
@ -287,6 +447,28 @@ clutter_event_get_flags (const ClutterEvent *event)
return event->any.flags;
}
/**
* clutter_event_set_flags:
* @event: a #ClutterEvent
* @flags: a binary OR of #ClutterEventFlags values
*
* Sets the #ClutterEventFlags of @event
*
* Since: 1.8
*/
void
clutter_event_set_flags (ClutterEvent *event,
ClutterEventFlags flags)
{
g_return_if_fail (event != NULL);
if (event->any.flags == flags)
return;
event->any.flags = flags;
event->any.flags |= CLUTTER_EVENT_FLAG_SYNTHETIC;
}
/**
* clutter_event_get_related:
* @event: a #ClutterEvent of type %CLUTTER_ENTER or of
@ -308,6 +490,30 @@ clutter_event_get_related (const ClutterEvent *event)
return event->crossing.related;
}
/**
* clutter_event_set_related
* @event: a #ClutterEvent of type %CLUTTER_ENTER or %CLUTTER_LEAVE
* @actor: (allow-none): a #ClutterActor or %NULL
*
* Sets the related actor of a crossing event
*
* Since: 1.8
*/
void
clutter_event_set_related (ClutterEvent *event,
ClutterActor *actor)
{
g_return_if_fail (event != NULL);
g_return_if_fail (event->type == CLUTTER_ENTER ||
event->type == CLUTTER_LEAVE);
g_return_if_fail (actor == NULL || CLUTTER_IS_ACTOR (actor));
if (event->crossing.related == actor)
return;
event->crossing.related = actor;
}
/**
* clutter_event_get_scroll_direction:
* @event: a #ClutterEvent of type %CLUTTER_SCROLL
@ -327,6 +533,25 @@ clutter_event_get_scroll_direction (const ClutterEvent *event)
return event->scroll.direction;
}
/**
* clutter_event_set_scroll_direction:
* @event: a #ClutterEvent
* @direction: the scrolling direction
*
* Sets the direction of the scrolling of @event
*
* Since: 1.8
*/
void
clutter_event_set_scroll_direction (ClutterEvent *event,
ClutterScrollDirection direction)
{
g_return_if_fail (event != NULL);
g_return_if_fail (event->type == CLUTTER_SCROLL);
event->scroll.direction = direction;
}
/**
* clutter_event_get_button:
* @event: a #ClutterEvent of type %CLUTTER_BUTTON_PRESS or
@ -348,6 +573,27 @@ clutter_event_get_button (const ClutterEvent *event)
return event->button.button;
}
/**
* clutter_event_set_button:
* @event: a #ClutterEvent or type %CLUTTER_BUTTON_PRESS or
* of type %CLUTTER_BUTTON_RELEASE
* @button: the button number
*
* Sets the button number of @event
*
* Since: 1.8
*/
void
clutter_event_set_button (ClutterEvent *event,
guint32 button)
{
g_return_if_fail (event != NULL);
g_return_if_fail (event->type == CLUTTER_BUTTON_PRESS ||
event->type == CLUTTER_BUTTON_RELEASE);
event->button.button = button;
}
/**
* clutter_event_get_click_count:
* @event: a #ClutterEvent of type %CLUTTER_BUTTON_PRESS or
@ -392,6 +638,27 @@ clutter_event_get_key_symbol (const ClutterEvent *event)
return event->key.keyval;
}
/**
* clutter_event_set_key_symbol:
* @event: a #ClutterEvent of type %CLUTTER_KEY_PRESS
* or %CLUTTER_KEY_RELEASE
* @key_sym: the key symbol representing the key
*
* Sets the key symbol of @event.
*
* Since: 1.8
*/
void
clutter_event_set_key_symbol (ClutterEvent *event,
guint key_sym)
{
g_return_if_fail (event != NULL);
g_return_if_fail (event->type == CLUTTER_KEY_PRESS ||
event->type == CLUTTER_KEY_RELEASE);
event->key.keyval = key_sym;
}
/**
* clutter_event_get_key_code:
* @event: a #ClutterEvent of type %CLUTTER_KEY_PRESS or
@ -413,9 +680,31 @@ clutter_event_get_key_code (const ClutterEvent *event)
return event->key.hardware_keycode;
}
/**
* clutter_event_set_key_code:
* @event: a #ClutterEvent of type %CLUTTER_KEY_PRESS
* or %CLUTTER_KEY_RELEASE
* @key_code: the keycode representing the key
*
* Sets the keycode of the @event.
*
* Since: 1.8
*/
void
clutter_event_set_key_code (ClutterEvent *event,
guint16 key_code)
{
g_return_if_fail (event != NULL);
g_return_if_fail (event->type == CLUTTER_KEY_PRESS ||
event->type == CLUTTER_KEY_RELEASE);
event->key.hardware_keycode = key_code;
}
/**
* clutter_event_get_key_unicode:
* @event: A #ClutterKeyEvent
* @event: a #ClutterEvent of type %CLUTTER_KEY_PRESS
* or %CLUTTER_KEY_RELEASE
*
* Retrieves the unicode value for the key that caused @keyev.
*
@ -434,6 +723,27 @@ clutter_event_get_key_unicode (const ClutterEvent *event)
return clutter_keysym_to_unicode (event->key.keyval);
}
/**
* clutter_event_set_key_unicode:
* @event: a #ClutterEvent of type %CLUTTER_KEY_PRESS
* or %CLUTTER_KEY_RELEASE
* @key_unicode: the Unicode value representing the key
*
* Sets the Unicode value of @event.
*
* Since: 1.8
*/
void
clutter_event_set_key_unicode (ClutterEvent *event,
guint32 key_unicode)
{
g_return_if_fail (event != NULL);
g_return_if_fail (event->type == CLUTTER_KEY_PRESS ||
event->type == CLUTTER_KEY_RELEASE);
event->key.unicode_value = key_unicode;
}
/**
* clutter_keysym_to_unicode:
* @keyval: a key symbol
@ -532,7 +842,7 @@ clutter_event_get_device_type (const ClutterEvent *event)
/**
* clutter_event_set_device:
* @event: a #ClutterEvent
* @device: a #ClutterInputDevice
* @device: (allow-none): a #ClutterInputDevice, or %NULL
*
* Sets the device for @event.
*
@ -652,7 +962,7 @@ clutter_event_get_device (const ClutterEvent *event)
*
* Creates a new #ClutterEvent of the specified type.
*
* Return value: A newly allocated #ClutterEvent.
* Return value: (transfer full): A newly allocated #ClutterEvent.
*/
ClutterEvent *
clutter_event_new (ClutterEventType type)
@ -679,7 +989,7 @@ clutter_event_new (ClutterEventType type)
*
* Copies @event.
*
* Return value: A newly allocated #ClutterEvent
* Return value: (transfer full): A newly allocated #ClutterEvent
*/
ClutterEvent *
clutter_event_copy (const ClutterEvent *event)
@ -853,8 +1163,6 @@ _clutter_event_push (const ClutterEvent *event,
ClutterEvent *copy;
copy = clutter_event_copy (event);
copy->any.flags |= CLUTTER_EVENT_FLAG_SYNTHETIC;
event = copy;
}
@ -979,58 +1287,26 @@ clutter_event_get_source_device (const ClutterEvent *event)
return clutter_event_get_device (event);
}
void
_clutter_event_set_device (ClutterEvent *event,
ClutterInputDevice *device)
{
switch (event->type)
{
case CLUTTER_NOTHING:
case CLUTTER_STAGE_STATE:
case CLUTTER_DESTROY_NOTIFY:
case CLUTTER_CLIENT_MESSAGE:
case CLUTTER_DELETE:
case CLUTTER_ENTER:
case CLUTTER_LEAVE:
break;
case CLUTTER_BUTTON_PRESS:
case CLUTTER_BUTTON_RELEASE:
event->button.device = device;
break;
case CLUTTER_MOTION:
event->motion.device = device;
break;
case CLUTTER_SCROLL:
event->scroll.device = device;
break;
case CLUTTER_KEY_PRESS:
case CLUTTER_KEY_RELEASE:
event->key.device = device;
break;
}
}
/*< private >
/**
* clutter_event_set_source_device:
* @event: a #ClutterEvent
* @device: a #ClutterInputDevice
* @device: (allow-none): a #ClutterInputDevice
*
* Sets the source #ClutterInputDevice for @event.
*
* The #ClutterEvent must have been created using clutter_event_new().
*
* Since: 1.6
* Since: 1.8
*/
void
_clutter_event_set_source_device (ClutterEvent *event,
clutter_event_set_source_device (ClutterEvent *event,
ClutterInputDevice *device)
{
ClutterEventPrivate *real_event;
g_return_if_fail (event != NULL);
g_return_if_fail (device == NULL || CLUTTER_IS_INPUT_DEVICE (device));
if (!is_event_allocated (event))
return;

View File

@ -63,7 +63,7 @@ G_BEGIN_DECLS
*
* Since: 0.6
*/
typedef enum {
typedef enum { /*< flags prefix=CLUTTER_EVENT >*/
CLUTTER_EVENT_NONE = 0,
CLUTTER_EVENT_FLAG_SYNTHETIC = 1 << 0
} ClutterEventFlags;
@ -88,8 +88,7 @@ typedef enum {
*
* Since: 0.4
*/
typedef enum
{
typedef enum { /*< prefix=CLUTTER >*/
CLUTTER_NOTHING = 0,
CLUTTER_KEY_PRESS,
CLUTTER_KEY_RELEASE,
@ -116,8 +115,7 @@ typedef enum
*
* Since: 0.4
*/
typedef enum
{
typedef enum { /*< prefix=CLUTTER_SCROLL >*/
CLUTTER_SCROLL_UP,
CLUTTER_SCROLL_DOWN,
CLUTTER_SCROLL_LEFT,
@ -134,8 +132,7 @@ typedef enum
*
* Since: 0.4
*/
typedef enum
{
typedef enum {
CLUTTER_STAGE_STATE_FULLSCREEN = (1<<1),
CLUTTER_STAGE_STATE_OFFSCREEN = (1<<2),
CLUTTER_STAGE_STATE_ACTIVATED = (1<<3)
@ -397,39 +394,67 @@ ClutterEvent * clutter_event_copy (const ClutterEvent
void clutter_event_free (ClutterEvent *event);
ClutterEventType clutter_event_type (const ClutterEvent *event);
void clutter_event_set_flags (ClutterEvent *event,
ClutterEventFlags flags);
ClutterEventFlags clutter_event_get_flags (const ClutterEvent *event);
void clutter_event_set_time (ClutterEvent *event,
guint32 time_);
guint32 clutter_event_get_time (const ClutterEvent *event);
void clutter_event_set_state (ClutterEvent *event,
ClutterModifierType state);
ClutterModifierType clutter_event_get_state (const ClutterEvent *event);
gint clutter_event_get_device_id (const ClutterEvent *event);
ClutterInputDeviceType clutter_event_get_device_type (const ClutterEvent *event);
void clutter_event_set_device (ClutterEvent *event,
ClutterInputDevice *device);
ClutterInputDevice * clutter_event_get_device (const ClutterEvent *event);
void clutter_event_set_source_device (ClutterEvent *event,
ClutterInputDevice *device);
ClutterInputDevice * clutter_event_get_source_device (const ClutterEvent *event);
ClutterActor * clutter_event_get_source (const ClutterEvent *event);
void clutter_event_set_stage (ClutterEvent *event,
ClutterStage *stage);
ClutterStage * clutter_event_get_stage (const ClutterEvent *event);
gint clutter_event_get_device_id (const ClutterEvent *event);
ClutterInputDeviceType clutter_event_get_device_type (const ClutterEvent *event);
void clutter_event_set_coords (ClutterEvent *event,
gfloat x,
gfloat y);
void clutter_event_get_coords (const ClutterEvent *event,
gfloat *x,
gfloat *y);
gdouble * clutter_event_get_axes (const ClutterEvent *event,
guint *n_axes);
void clutter_event_set_key_symbol (ClutterEvent *event,
guint key_sym);
guint clutter_event_get_key_symbol (const ClutterEvent *event);
void clutter_event_set_key_code (ClutterEvent *event,
guint16 key_code);
guint16 clutter_event_get_key_code (const ClutterEvent *event);
void clutter_event_set_key_unicode (ClutterEvent *event,
guint32 key_unicode);
guint32 clutter_event_get_key_unicode (const ClutterEvent *event);
void clutter_event_set_button (ClutterEvent *event,
guint32 button);
guint32 clutter_event_get_button (const ClutterEvent *event);
guint clutter_event_get_click_count (const ClutterEvent *event);
void clutter_event_set_related (ClutterEvent *event,
ClutterActor *actor);
ClutterActor * clutter_event_get_related (const ClutterEvent *event);
void clutter_event_set_scroll_direction (ClutterEvent *event,
ClutterScrollDirection direction);
ClutterScrollDirection clutter_event_get_scroll_direction (const ClutterEvent *event);
void clutter_event_set_device (ClutterEvent *event,
ClutterInputDevice *device);
guint32 clutter_keysym_to_unicode (guint keyval);
guint32 clutter_get_current_event_time (void);
G_CONST_RETURN ClutterEvent *clutter_get_current_event (void);
G_END_DECLS

View File

@ -657,11 +657,11 @@ clutter_device_manager_xi2_translate_event (ClutterEventTranslator *translator,
source_device = g_hash_table_lookup (manager_xi2->devices_by_id,
GINT_TO_POINTER (xev->sourceid));
_clutter_event_set_source_device (event, source_device);
clutter_event_set_source_device (event, source_device);
device = g_hash_table_lookup (manager_xi2->devices_by_id,
GINT_TO_POINTER (xev->deviceid));
_clutter_event_set_device (event, device);
clutter_event_set_device (event, device);
/* XXX keep this in sync with the evdev device manager */
n = print_keysym (event->key.keyval, buffer, sizeof (buffer));
@ -729,11 +729,11 @@ clutter_device_manager_xi2_translate_event (ClutterEventTranslator *translator,
source_device = g_hash_table_lookup (manager_xi2->devices_by_id,
GINT_TO_POINTER (xev->sourceid));
_clutter_event_set_source_device (event, source_device);
clutter_event_set_source_device (event, source_device);
device = g_hash_table_lookup (manager_xi2->devices_by_id,
GINT_TO_POINTER (xev->deviceid));
_clutter_event_set_device (event, device);
clutter_event_set_device (event, device);
event->scroll.axes = translate_axes (event->scroll.device,
event->scroll.x,
@ -760,11 +760,11 @@ clutter_device_manager_xi2_translate_event (ClutterEventTranslator *translator,
source_device = g_hash_table_lookup (manager_xi2->devices_by_id,
GINT_TO_POINTER (xev->sourceid));
_clutter_event_set_source_device (event, source_device);
clutter_event_set_source_device (event, source_device);
device = g_hash_table_lookup (manager_xi2->devices_by_id,
GINT_TO_POINTER (xev->deviceid));
_clutter_event_set_device (event, device);
clutter_event_set_device (event, device);
event->button.axes = translate_axes (event->button.device,
event->button.x,
@ -813,11 +813,11 @@ clutter_device_manager_xi2_translate_event (ClutterEventTranslator *translator,
source_device = g_hash_table_lookup (manager_xi2->devices_by_id,
GINT_TO_POINTER (xev->sourceid));
_clutter_event_set_source_device (event, source_device);
clutter_event_set_source_device (event, source_device);
device = g_hash_table_lookup (manager_xi2->devices_by_id,
GINT_TO_POINTER (xev->deviceid));
_clutter_event_set_device (event, device);
clutter_event_set_device (event, device);
event->motion.axes = translate_axes (event->motion.device,
event->motion.x,
@ -890,7 +890,7 @@ clutter_device_manager_xi2_translate_event (ClutterEventTranslator *translator,
}
clutter_event_set_device (event, device);
_clutter_event_set_source_device (event, source_device);
clutter_event_set_source_device (event, source_device);
retval = CLUTTER_TRANSLATE_QUEUE;
}

View File

@ -1023,11 +1023,17 @@ clutter_event_free
clutter_event_type
<SUBSECTION>
clutter_event_set_coords
clutter_event_get_coords
clutter_event_set_state
clutter_event_get_state
clutter_event_set_time
clutter_event_get_time
clutter_event_set_source
clutter_event_get_source
clutter_event_set_stage
clutter_event_get_stage
clutter_event_set_flags
clutter_event_get_flags
clutter_event_get_axes
@ -1038,27 +1044,34 @@ clutter_event_put
clutter_events_pending
<SUBSECTION>
clutter_event_set_button
clutter_event_get_button
clutter_event_get_click_count
<SUBSECTION>
clutter_event_set_key_symbol
clutter_event_get_key_symbol
clutter_event_set_key_code
clutter_event_get_key_code
clutter_event_set_key_unicode
clutter_event_get_key_unicode
clutter_keysym_to_unicode
<SUBSECTION>
clutter_event_set_related
clutter_event_get_related
<SUBSECTION>
clutter_event_set_scroll_direction
clutter_event_get_scroll_direction
<SUBSECTION>
clutter_event_set_device
clutter_event_get_device
clutter_event_set_source_device
clutter_event_get_source_device
clutter_event_get_device_id
clutter_event_get_device_type
clutter_event_get_source_device
<SUBSECTION>
clutter_get_current_event_time

View File

@ -300,40 +300,43 @@ text_password_char (void)
clutter_actor_destroy (CLUTTER_ACTOR (text));
}
static void
init_event (ClutterKeyEvent *event)
static ClutterEvent *
init_event (void)
{
event->type = CLUTTER_KEY_PRESS;
event->time = 0; /* not needed */
event->flags = CLUTTER_EVENT_FLAG_SYNTHETIC;
event->stage = NULL; /* not needed */
event->source = NULL; /* not needed */
event->modifier_state = 0;
event->hardware_keycode = 0; /* not needed */
ClutterEvent *retval = clutter_event_new (CLUTTER_KEY_PRESS);
clutter_event_set_time (retval, CLUTTER_CURRENT_TIME);
clutter_event_set_flags (retval, CLUTTER_EVENT_FLAG_SYNTHETIC);
return retval;
}
static void
send_keyval (ClutterText *text, int keyval)
{
ClutterKeyEvent event;
ClutterEvent *event = init_event ();
init_event (&event);
event.keyval = keyval;
event.unicode_value = 0; /* should be ignored for cursor keys etc. */
/* Unicode should be ignored for cursor keys etc. */
clutter_event_set_key_unicode (event, 0);
clutter_event_set_key_symbol (event, keyval);
clutter_actor_event (CLUTTER_ACTOR (text), (ClutterEvent *) &event, FALSE);
clutter_actor_event (CLUTTER_ACTOR (text), event, FALSE);
clutter_event_free (event);
}
static void
send_unichar (ClutterText *text, gunichar unichar)
{
ClutterKeyEvent event;
ClutterEvent *event = init_event ();
init_event (&event);
event.keyval = 0; /* should be ignored for printable characters */
event.unicode_value = unichar;
/* Key symbol should be ignored for printable characters */
clutter_event_set_key_symbol (event, 0);
clutter_event_set_key_unicode (event, unichar);
clutter_actor_event (CLUTTER_ACTOR (text), (ClutterEvent *) &event, FALSE);
clutter_actor_event (CLUTTER_ACTOR (text), event, FALSE);
clutter_event_free (event);
}
void