/** * clutter_input_device_get_has_cursor: * @device: a #ClutterInputDevice * * Retrieves whether @device has a pointer that follows the * device motion. * * Return value: %TRUE if the device has a cursor * * Since: 1.6 */ gboolean clutter_input_device_get_has_cursor (ClutterInputDevice *device) { g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), FALSE); return device->has_cursor; }
/** * 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 * * Embedding toolkits that disable the event collection inside Clutter * need to use this function to update the state of input devices depending * on a #ClutterEvent that they are going to submit to the event handling code * in Clutter though clutter_do_event(). Since the input devices hold the state * that is going to be used to fill in fields like the #ClutterButtonEvent * click count, or to emit synthesized events like %CLUTTER_ENTER and * %CLUTTER_LEAVE, it is necessary for embedding toolkits to also be * responsible of updating the input device state. * * For instance, this might be the code to translate an embedding toolkit * native motion notification into a Clutter #ClutterMotionEvent and ask * Clutter to process it: * * |[ * ClutterEvent c_event; * * translate_native_event_to_clutter (native_event, &c_event); * * clutter_do_event (&c_event); * ]| * * Before letting clutter_do_event() process the event, it is necessary to call * clutter_input_device_update_from_event(): * * |[ * ClutterEvent c_event; * ClutterDeviceManager *manager; * ClutterInputDevice *device; * * translate_native_event_to_clutter (native_event, &c_event); * * /* get the device manager */ * manager = clutter_device_manager_get_default (); * * /* use the default Core Pointer that Clutter * * backends register by default * */ * device = clutter_device_manager_get_core_device (manager, %CLUTTER_POINTER_DEVICE); * * /* update the state of the input device */ * clutter_input_device_update_from_event (device, &c_event, FALSE); * * clutter_do_event (&c_event); * ]| * * The @update_stage boolean argument should be used when the input device * enters and leaves a #ClutterStage; it will use the #ClutterStage field * of the passed @event to update the stage associated to the input device. * * 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); }
/** * clutter_input_device_get_associated_device: * @device: a #ClutterInputDevice * * Retrieves a pointer to the #ClutterInputDevice that has been * associated to @device. * * If the #ClutterInputDevice:device-mode property of @device is * set to %CLUTTER_INPUT_MODE_MASTER, this function will return * %NULL. * * Return value: (transfer none): a #ClutterInputDevice, or %NULL * * Since: 1.6 */ ClutterInputDevice * clutter_input_device_get_associated_device (ClutterInputDevice *device) { g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), NULL); return device->associated; }
/** * clutter_input_device_get_key: * @device: a #ClutterInputDevice * @index_: the index of the key * @keyval: (out): return location for the keyval at @index_ * @modifiers: (out): return location for the modifiers at @index_ * * Retrieves the key set using clutter_input_device_set_key() * * Return value: %TRUE if a key was set at the given index * * Since: 1.6 */ gboolean clutter_input_device_get_key (ClutterInputDevice *device, guint index_, guint *keyval, ClutterModifierType *modifiers) { ClutterKeyInfo *key_info; g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), FALSE); if (device->keys == NULL) return FALSE; if (index_ > device->keys->len) return FALSE; key_info = &g_array_index (device->keys, ClutterKeyInfo, index_); if (!key_info->keyval && !key_info->modifiers) return FALSE; if (keyval) *keyval = key_info->keyval; if (modifiers) *modifiers = key_info->modifiers; return TRUE; }
/** * clutter_input_device_get_slave_devices: * @device: a #ClutterInputDevice * * Retrieves the slave devices attached to @device. * * Return value: (transfer container) (element-type Clutter.InputDevice): a * list of #ClutterInputDevice, or %NULL. The contents of the list are * owned by the device. Use g_list_free() when done * * Since: 1.6 */ GList * clutter_input_device_get_slave_devices (ClutterInputDevice *device) { g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), NULL); return g_list_copy (device->slaves); }
/** * clutter_input_device_get_device_id: * @device: a #ClutterInputDevice * * Retrieves the unique identifier of @device * * Return value: the identifier of the device * * Since: 1.0 */ gint clutter_input_device_get_device_id (ClutterInputDevice *device) { g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), -1); return device->id; }
/** * clutter_input_device_get_n_keys: * @device: a #ClutterInputDevice * * Retrieves the number of keys registered for @device. * * Return value: the number of registered keys * * Since: 1.6 */ guint clutter_input_device_get_n_keys (ClutterInputDevice *device) { g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), 0); return device->n_keys; }
/** * clutter_input_device_get_axis_value: * @device: a #ClutterInputDevice * @axes: (array): an array of axes values, typically * coming from clutter_event_get_axes() * @axis: the axis to extract * @value: (out): return location for the axis value * * Extracts the value of the given @axis of a #ClutterInputDevice from * an array of axis values. * * An example of typical usage for this function is: * * |[ * ClutterInputDevice *device = clutter_event_get_device (event); * gdouble *axes = clutter_event_get_axes (event, NULL); * gdouble pressure_value = 0; * * clutter_input_device_get_axis_value (device, axes, * CLUTTER_INPUT_AXIS_PRESSURE, * &pressure_value); * ]| * * Return value: %TRUE if the value was set, and %FALSE otherwise * * Since: 1.6 */ gboolean clutter_input_device_get_axis_value (ClutterInputDevice *device, gdouble *axes, ClutterInputAxis axis, gdouble *value) { gint i; g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), FALSE); g_return_val_if_fail (device->axes != NULL, FALSE); for (i = 0; i < device->axes->len; i++) { ClutterAxisInfo *info; info = &g_array_index (device->axes, ClutterAxisInfo, i); if (info->axis == axis) { if (value) *value = axes[i]; return TRUE; } } return FALSE; }
/** * clutter_input_device_get_device_name: * @device: a #ClutterInputDevice * * Retrieves the name of the @device * * Return value: the name of the device, or %NULL. The returned string * is owned by the #ClutterInputDevice and should never be modified * or freed * * Since: 1.2 */ const gchar * clutter_input_device_get_device_name (ClutterInputDevice *device) { g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), NULL); return device->device_name; }
/** * clutter_input_device_get_enabled: * @device: a #ClutterInputDevice * * Retrieves whether @device is enabled. * * Return value: %TRUE if the device is enabled * * Since: 1.6 */ gboolean clutter_input_device_get_enabled (ClutterInputDevice *device) { g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), FALSE); return device->is_enabled; }
/** * clutter_input_device_get_device_type: * @device: a #ClutterInputDevice * * Retrieves the type of @device * * Return value: the type of the device * * Since: 1.0 */ ClutterInputDeviceType clutter_input_device_get_device_type (ClutterInputDevice *device) { g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), CLUTTER_POINTER_DEVICE); return device->device_type; }
/** * clutter_input_device_get_device_mode: * @device: a #ClutterInputDevice * * Retrieves the #ClutterInputMode of @device. * * Return value: the device mode * * Since: 1.6 */ ClutterInputMode clutter_input_device_get_device_mode (ClutterInputDevice *device) { g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), CLUTTER_INPUT_MODE_FLOATING); return device->device_mode; }
/** * 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_pointer_actor: * @device: a #ClutterInputDevice of type %CLUTTER_POINTER_DEVICE * * Retrieves the #ClutterActor underneath the pointer of @device * * Return value: (transfer none): a pointer to the #ClutterActor or %NULL * * Since: 1.2 */ ClutterActor * clutter_input_device_get_pointer_actor (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->cursor_actor; }
/* * _clutter_input_device_set_state: * @device: a #ClutterInputDevice * @state: a bitmask of modifiers * * Stores the last known modifiers state of the device */ void _clutter_input_device_set_state (ClutterInputDevice *device, ClutterModifierType state) { g_return_if_fail (CLUTTER_IS_INPUT_DEVICE (device)); device->current_state = state; }
/* * _clutter_input_device_set_time: * @device: a #ClutterInputDevice * @time_: the time * * Stores the last known event time of the device */ void _clutter_input_device_set_time (ClutterInputDevice *device, guint32 time_) { g_return_if_fail (CLUTTER_IS_INPUT_DEVICE (device)); if (device->current_time != time_) device->current_time = time_; }
/** * clutter_input_device_get_n_axes: * @device: a #ClutterInputDevice * * Retrieves the number of axes available on @device. * * Return value: the number of axes on the device * * Since: 1.6 */ guint clutter_input_device_get_n_axes (ClutterInputDevice *device) { g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), 0); if (device->axes != NULL) return device->axes->len; return 0; }
/** * clutter_event_set_device: * @event: a #ClutterEvent * @device: (allow-none): a #ClutterInputDevice, or %NULL * * Sets the device for @event. * * Since: 1.6 */ void clutter_event_set_device (ClutterEvent *event, ClutterInputDevice *device) { g_return_if_fail (event != NULL); g_return_if_fail (device == NULL || CLUTTER_IS_INPUT_DEVICE (device)); if (is_event_allocated (event)) { ClutterEventPrivate *real_event = (ClutterEventPrivate *) event; real_event->device = device; } switch (event->type) { case CLUTTER_NOTHING: case CLUTTER_STAGE_STATE: case CLUTTER_DESTROY_NOTIFY: case CLUTTER_CLIENT_MESSAGE: case CLUTTER_DELETE: case CLUTTER_EVENT_LAST: break; case CLUTTER_ENTER: case CLUTTER_LEAVE: event->crossing.device = device; 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_TOUCH_BEGIN: case CLUTTER_TOUCH_UPDATE: case CLUTTER_TOUCH_END: case CLUTTER_TOUCH_CANCEL: event->touch.device = device; break; case CLUTTER_KEY_PRESS: case CLUTTER_KEY_RELEASE: event->key.device = device; break; } }
/* * _clutter_input_device_set_coords: * @device: a #ClutterInputDevice * @x: X coordinate of the device * @y: Y coordinate of the device * * Stores the last known coordinates of the device */ void _clutter_input_device_set_coords (ClutterInputDevice *device, gint x, gint y) { g_return_if_fail (CLUTTER_IS_INPUT_DEVICE (device)); if (device->current_x != x) device->current_x = x; if (device->current_y != y) device->current_y = y; }
/** * clutter_input_device_get_device_coords: * @device: a #ClutterInputDevice of type %CLUTTER_POINTER_DEVICE * @x: (out): return location for the X coordinate * @y: (out): return location for the Y coordinate * * Retrieves the latest coordinates of the pointer of @device * * Since: 1.2 */ void clutter_input_device_get_device_coords (ClutterInputDevice *device, gint *x, gint *y) { g_return_if_fail (CLUTTER_IS_INPUT_DEVICE (device)); if (x) *x = device->current_x; if (y) *y = device->current_y; }
/** * clutter_input_device_set_key: * @device: a #ClutterInputDevice * @index_: the index of the key * @keyval: the keyval * @modifiers: a bitmask of modifiers * * Sets the keyval and modifiers at the given @index_ for @device. * * Clutter will use the keyval and modifiers set when filling out * an event coming from the same input device. * * Since: 1.6 */ void clutter_input_device_set_key (ClutterInputDevice *device, guint index_, guint keyval, ClutterModifierType modifiers) { ClutterKeyInfo *key_info; g_return_if_fail (CLUTTER_IS_INPUT_DEVICE (device)); g_return_if_fail (index_ < device->n_keys); key_info = &g_array_index (device->keys, ClutterKeyInfo, index_); key_info->keyval = keyval; key_info->modifiers = modifiers; }
/** * clutter_event_set_source_device: * @event: a #ClutterEvent * @device: (allow-none): a #ClutterInputDevice * * Sets the source #ClutterInputDevice for @event. * * The #ClutterEvent must have been created using clutter_event_new(). * * Since: 1.8 */ void 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; real_event = (ClutterEventPrivate *) event; real_event->source_device = device; }
/** * clutter_input_device_set_enabled: * @device: a #ClutterInputDevice * @enabled: %TRUE to enable the @device * * Enables or disables a #ClutterInputDevice. * * Only devices with a #ClutterInputDevice:device-mode property set * to %CLUTTER_INPUT_MODE_SLAVE or %CLUTTER_INPUT_MODE_FLOATING can * be disabled. * * Since: 1.6 */ void clutter_input_device_set_enabled (ClutterInputDevice *device, gboolean enabled) { g_return_if_fail (CLUTTER_IS_INPUT_DEVICE (device)); enabled = !!enabled; if (!enabled && device->device_mode == CLUTTER_INPUT_MODE_MASTER) return; if (device->is_enabled == enabled) return; device->is_enabled = enabled; g_object_notify_by_pspec (G_OBJECT (device), obj_props[PROP_ENABLED]); }
/** * clutter_input_device_get_axis: * @device: a #ClutterInputDevice * @index_: the index of the axis * * Retrieves the type of axis on @device at the given index. * * Return value: the axis type * * Since: 1.6 */ ClutterInputAxis clutter_input_device_get_axis (ClutterInputDevice *device, guint index_) { ClutterAxisInfo *info; g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), CLUTTER_INPUT_AXIS_IGNORE); if (device->axes == NULL) return CLUTTER_INPUT_AXIS_IGNORE; if (index_ >= device->axes->len) return CLUTTER_INPUT_AXIS_IGNORE; info = &g_array_index (device->axes, ClutterAxisInfo, index_); return info->axis; }
/* * _clutter_input_device_set_stage: * @device: a #ClutterInputDevice * @stage: a #ClutterStage or %NULL * * Stores the stage under the device */ void _clutter_input_device_set_stage (ClutterInputDevice *device, ClutterStage *stage) { ClutterStage *old_stage; g_return_if_fail (CLUTTER_IS_INPUT_DEVICE (device)); old_stage = device->stage; device->stage = stage; /* if we left the stage then we also need to unset the * cursor actor (and update its :has-pointer property) */ if (device->stage == NULL && device->cursor_actor != NULL && device->cursor_actor != CLUTTER_ACTOR (old_stage)) { ClutterEvent cev; cev.crossing.type = CLUTTER_LEAVE; cev.crossing.time = device->current_time; cev.crossing.flags = 0; cev.crossing.stage = old_stage; cev.crossing.source = device->cursor_actor; cev.crossing.x = device->current_x; cev.crossing.y = device->current_y; cev.crossing.device = device; cev.crossing.related = device->stage != NULL ? CLUTTER_ACTOR (device->stage) : CLUTTER_ACTOR (old_stage); _clutter_stage_queue_event (old_stage, &cev); _clutter_actor_set_has_pointer (device->cursor_actor, FALSE); g_object_weak_unref (G_OBJECT (device->cursor_actor), cursor_weak_unref, device); } device->cursor_actor = NULL; }
/* * _clutter_input_device_set_actor: * @device: a #ClutterInputDevice * @actor: a #ClutterActor * * Sets the actor under the pointer coordinates of @device * * This function is called by _clutter_input_device_update() * and it will: * * - queue a %CLUTTER_LEAVE event on the previous pointer actor * of @device, if any * - set to %FALSE the :has-pointer property of the previous * pointer actor of @device, if any * - queue a %CLUTTER_ENTER event on the new pointer actor * - set to %TRUE the :has-pointer property of the new pointer * actor */ void _clutter_input_device_set_actor (ClutterInputDevice *device, ClutterActor *actor) { ClutterActor *old_actor; ClutterEvent cev; g_return_if_fail (CLUTTER_IS_INPUT_DEVICE (device)); if (actor == device->cursor_actor) return; old_actor = device->cursor_actor; if (old_actor != NULL) { cev.crossing.type = CLUTTER_LEAVE; cev.crossing.time = device->current_time; cev.crossing.flags = 0; cev.crossing.stage = device->stage; cev.crossing.source = device->cursor_actor; cev.crossing.x = device->current_x; cev.crossing.y = device->current_y; cev.crossing.device = device; cev.crossing.related = actor; /* we need to make sure that this event is processed before * any other event we might have queued up until now, so we * go on and synthesize the event emission */ _clutter_process_event (&cev); _clutter_actor_set_has_pointer (device->cursor_actor, FALSE); g_object_weak_unref (G_OBJECT (device->cursor_actor), cursor_weak_unref, device); device->cursor_actor = NULL; } if (actor != NULL) { cev.crossing.type = CLUTTER_ENTER; cev.crossing.time = device->current_time; cev.crossing.flags = 0; cev.crossing.stage = device->stage; cev.crossing.x = device->current_x; cev.crossing.y = device->current_y; cev.crossing.device = device; CLUTTER_NOTE (EVENT, "Device '%s' entering '%s' at %d, %d", device->device_name, clutter_actor_get_name (actor) != NULL ? clutter_actor_get_name (actor) : G_OBJECT_TYPE_NAME (actor), device->current_x, device->current_y); /* if there is an actor overlapping the Stage boundary and we * don't do this check then we'll emit an ENTER event only on * the actor instead of emitting it on the Stage *and* the * actor */ if (old_actor == NULL && actor != CLUTTER_ACTOR (device->stage)) { cev.crossing.source = CLUTTER_ACTOR (device->stage); cev.crossing.related = NULL; CLUTTER_NOTE (EVENT, "Adding Crossing[Enter] event for Stage"); _clutter_process_event (&cev); cev.crossing.source = actor; cev.crossing.related = CLUTTER_ACTOR (device->stage); } else { cev.crossing.source = actor; cev.crossing.related = old_actor; } /* as above: we need to make sure that this event is processed * before any other event we might have queued up until now, so * we go on and synthesize the event emission */ _clutter_process_event (&cev); } device->cursor_actor = actor; if (device->cursor_actor != NULL) { g_object_weak_ref (G_OBJECT (device->cursor_actor), cursor_weak_unref, device); _clutter_actor_set_has_pointer (device->cursor_actor, TRUE); } }