Blame clutter/clutter-input-device.c

Packit Service bf98b9
/*
Packit Service bf98b9
 * Clutter.
Packit Service bf98b9
 *
Packit Service bf98b9
 * An OpenGL based 'interactive canvas' library.
Packit Service bf98b9
 *
Packit Service bf98b9
 * Copyright © 2009, 2010, 2011  Intel Corp.
Packit Service bf98b9
 *
Packit Service bf98b9
 * This library is free software; you can redistribute it and/or
Packit Service bf98b9
 * modify it under the terms of the GNU Lesser General Public
Packit Service bf98b9
 * License as published by the Free Software Foundation; either
Packit Service bf98b9
 * version 2 of the License, or (at your option) any later version.
Packit Service bf98b9
 *
Packit Service bf98b9
 * This library is distributed in the hope that it will be useful,
Packit Service bf98b9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service bf98b9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service bf98b9
 * Lesser General Public License for more details.
Packit Service bf98b9
 *
Packit Service bf98b9
 * You should have received a copy of the GNU Lesser General Public
Packit Service bf98b9
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
Packit Service bf98b9
 *
Packit Service bf98b9
 * Author: Emmanuele Bassi <ebassi@linux.intel.com>
Packit Service bf98b9
 */
Packit Service bf98b9
Packit Service bf98b9
/**
Packit Service bf98b9
 * SECTION:clutter-input-device
Packit Service bf98b9
 * @short_description: An input device managed by Clutter
Packit Service bf98b9
 *
Packit Service bf98b9
 * #ClutterInputDevice represents an input device known to Clutter.
Packit Service bf98b9
 *
Packit Service bf98b9
 * The #ClutterInputDevice class holds the state of the device, but
Packit Service bf98b9
 * its contents are usually defined by the Clutter backend in use.
Packit Service bf98b9
 */
Packit Service bf98b9
Packit Service bf98b9
#ifdef HAVE_CONFIG_H
Packit Service bf98b9
#include "config.h"
Packit Service bf98b9
#endif
Packit Service bf98b9
Packit Service bf98b9
#include "clutter-input-device.h"
Packit Service bf98b9
Packit Service bf98b9
#include "clutter-actor-private.h"
Packit Service bf98b9
#include "clutter-debug.h"
Packit Service bf98b9
#include "clutter-device-manager-private.h"
Packit Service bf98b9
#include "clutter-enum-types.h"
Packit Service bf98b9
#include "clutter-event-private.h"
Packit Service bf98b9
#include "clutter-marshal.h"
Packit Service bf98b9
#include "clutter-private.h"
Packit Service bf98b9
#include "clutter-stage-private.h"
Packit Service bf98b9
Packit Service bf98b9
#include <math.h>
Packit Service bf98b9
Packit Service bf98b9
enum
Packit Service bf98b9
{
Packit Service bf98b9
  PROP_0,
Packit Service bf98b9
Packit Service bf98b9
  PROP_BACKEND,
Packit Service bf98b9
Packit Service bf98b9
  PROP_ID,
Packit Service bf98b9
  PROP_NAME,
Packit Service bf98b9
Packit Service bf98b9
  PROP_DEVICE_TYPE,
Packit Service bf98b9
  PROP_DEVICE_MANAGER,
Packit Service bf98b9
  PROP_DEVICE_MODE,
Packit Service bf98b9
Packit Service bf98b9
  PROP_HAS_CURSOR,
Packit Service bf98b9
  PROP_ENABLED,
Packit Service bf98b9
Packit Service bf98b9
  PROP_N_AXES,
Packit Service bf98b9
Packit Service bf98b9
  PROP_VENDOR_ID,
Packit Service bf98b9
  PROP_PRODUCT_ID,
Packit Service bf98b9
Packit Service bf98b9
  PROP_LAST
Packit Service bf98b9
};
Packit Service bf98b9
Packit Service bf98b9
static void _clutter_input_device_free_touch_info (gpointer data);
Packit Service bf98b9
Packit Service bf98b9
Packit Service bf98b9
static GParamSpec *obj_props[PROP_LAST] = { NULL, };
Packit Service bf98b9
Packit Service bf98b9
G_DEFINE_TYPE (ClutterInputDevice, clutter_input_device, G_TYPE_OBJECT);
Packit Service bf98b9
Packit Service bf98b9
static void
Packit Service bf98b9
clutter_input_device_dispose (GObject *gobject)
Packit Service bf98b9
{
Packit Service bf98b9
  ClutterInputDevice *device = CLUTTER_INPUT_DEVICE (gobject);
Packit Service bf98b9
Packit Service bf98b9
  g_clear_pointer (&device->device_name, g_free);
Packit Service bf98b9
  g_clear_pointer (&device->vendor_id, g_free);
Packit Service bf98b9
  g_clear_pointer (&device->product_id, g_free);
Packit Service bf98b9
Packit Service bf98b9
  if (device->associated != NULL)
Packit Service bf98b9
    {
Packit Service bf98b9
      if (device->device_mode == CLUTTER_INPUT_MODE_SLAVE)
Packit Service bf98b9
        _clutter_input_device_remove_slave (device->associated, device);
Packit Service bf98b9
Packit Service bf98b9
      _clutter_input_device_set_associated_device (device->associated, NULL);
Packit Service bf98b9
      g_object_unref (device->associated);
Packit Service bf98b9
      device->associated = NULL;
Packit Service bf98b9
    }
Packit Service bf98b9
Packit Service bf98b9
  g_clear_pointer (&device->axes, g_array_unref);
Packit Service bf98b9
  g_clear_pointer (&device->keys, g_array_unref);
Packit Service bf98b9
  g_clear_pointer (&device->scroll_info, g_array_unref);
Packit Service bf98b9
  g_clear_pointer (&device->touch_sequences_info, g_hash_table_unref);
Packit Service bf98b9
Packit Service bf98b9
  if (device->inv_touch_sequence_actors)
Packit Service bf98b9
    {
Packit Service bf98b9
      GHashTableIter iter;
Packit Service bf98b9
      gpointer key, value;
Packit Service bf98b9
Packit Service bf98b9
      g_hash_table_iter_init (&iter, device->inv_touch_sequence_actors);
Packit Service bf98b9
      while (g_hash_table_iter_next (&iter, &key, &value))
Packit Service bf98b9
        g_list_free (value);
Packit Service bf98b9
Packit Service bf98b9
      g_hash_table_unref (device->inv_touch_sequence_actors);
Packit Service bf98b9
      device->inv_touch_sequence_actors = NULL;
Packit Service bf98b9
    }
Packit Service bf98b9
Packit Service bf98b9
  G_OBJECT_CLASS (clutter_input_device_parent_class)->dispose (gobject);
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
static void
Packit Service bf98b9
clutter_input_device_set_property (GObject      *gobject,
Packit Service bf98b9
                                   guint         prop_id,
Packit Service bf98b9
                                   const GValue *value,
Packit Service bf98b9
                                   GParamSpec   *pspec)
Packit Service bf98b9
{
Packit Service bf98b9
  ClutterInputDevice *self = CLUTTER_INPUT_DEVICE (gobject);
Packit Service bf98b9
Packit Service bf98b9
  switch (prop_id)
Packit Service bf98b9
    {
Packit Service bf98b9
    case PROP_ID:
Packit Service bf98b9
      self->id = g_value_get_int (value);
Packit Service bf98b9
      break;
Packit Service bf98b9
Packit Service bf98b9
    case PROP_DEVICE_TYPE:
Packit Service bf98b9
      self->device_type = g_value_get_enum (value);
Packit Service bf98b9
      break;
Packit Service bf98b9
Packit Service bf98b9
    case PROP_DEVICE_MANAGER:
Packit Service bf98b9
      self->device_manager = g_value_get_object (value);
Packit Service bf98b9
      break;
Packit Service bf98b9
Packit Service bf98b9
    case PROP_DEVICE_MODE:
Packit Service bf98b9
      self->device_mode = g_value_get_enum (value);
Packit Service bf98b9
      break;
Packit Service bf98b9
Packit Service bf98b9
    case PROP_BACKEND:
Packit Service bf98b9
      self->backend = g_value_get_object (value);
Packit Service bf98b9
      break;
Packit Service bf98b9
Packit Service bf98b9
    case PROP_NAME:
Packit Service bf98b9
      self->device_name = g_value_dup_string (value);
Packit Service bf98b9
      break;
Packit Service bf98b9
Packit Service bf98b9
    case PROP_HAS_CURSOR:
Packit Service bf98b9
      self->has_cursor = g_value_get_boolean (value);
Packit Service bf98b9
      break;
Packit Service bf98b9
Packit Service bf98b9
    case PROP_ENABLED:
Packit Service bf98b9
      clutter_input_device_set_enabled (self, g_value_get_boolean (value));
Packit Service bf98b9
      break;
Packit Service bf98b9
Packit Service bf98b9
    case PROP_VENDOR_ID:
Packit Service bf98b9
      self->vendor_id = g_value_dup_string (value);
Packit Service bf98b9
      break;
Packit Service bf98b9
Packit Service bf98b9
    case PROP_PRODUCT_ID:
Packit Service bf98b9
      self->product_id = g_value_dup_string (value);
Packit Service bf98b9
      break;
Packit Service bf98b9
Packit Service bf98b9
    default:
Packit Service bf98b9
      G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
Packit Service bf98b9
      break;
Packit Service bf98b9
    }
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
static void
Packit Service bf98b9
clutter_input_device_get_property (GObject    *gobject,
Packit Service bf98b9
                                   guint       prop_id,
Packit Service bf98b9
                                   GValue     *value,
Packit Service bf98b9
                                   GParamSpec *pspec)
Packit Service bf98b9
{
Packit Service bf98b9
  ClutterInputDevice *self = CLUTTER_INPUT_DEVICE (gobject);
Packit Service bf98b9
Packit Service bf98b9
  switch (prop_id)
Packit Service bf98b9
    {
Packit Service bf98b9
    case PROP_ID:
Packit Service bf98b9
      g_value_set_int (value, self->id);
Packit Service bf98b9
      break;
Packit Service bf98b9
Packit Service bf98b9
    case PROP_DEVICE_TYPE:
Packit Service bf98b9
      g_value_set_enum (value, self->device_type);
Packit Service bf98b9
      break;
Packit Service bf98b9
Packit Service bf98b9
    case PROP_DEVICE_MANAGER:
Packit Service bf98b9
      g_value_set_object (value, self->device_manager);
Packit Service bf98b9
      break;
Packit Service bf98b9
Packit Service bf98b9
    case PROP_DEVICE_MODE:
Packit Service bf98b9
      g_value_set_enum (value, self->device_mode);
Packit Service bf98b9
      break;
Packit Service bf98b9
Packit Service bf98b9
    case PROP_BACKEND:
Packit Service bf98b9
      g_value_set_object (value, self->backend);
Packit Service bf98b9
      break;
Packit Service bf98b9
Packit Service bf98b9
    case PROP_NAME:
Packit Service bf98b9
      g_value_set_string (value, self->device_name);
Packit Service bf98b9
      break;
Packit Service bf98b9
Packit Service bf98b9
    case PROP_HAS_CURSOR:
Packit Service bf98b9
      g_value_set_boolean (value, self->has_cursor);
Packit Service bf98b9
      break;
Packit Service bf98b9
Packit Service bf98b9
    case PROP_N_AXES:
Packit Service bf98b9
      g_value_set_uint (value, clutter_input_device_get_n_axes (self));
Packit Service bf98b9
      break;
Packit Service bf98b9
Packit Service bf98b9
    case PROP_ENABLED:
Packit Service bf98b9
      g_value_set_boolean (value, self->is_enabled);
Packit Service bf98b9
      break;
Packit Service bf98b9
Packit Service bf98b9
    case PROP_VENDOR_ID:
Packit Service bf98b9
      g_value_set_string (value, self->vendor_id);
Packit Service bf98b9
      break;
Packit Service bf98b9
Packit Service bf98b9
    case PROP_PRODUCT_ID:
Packit Service bf98b9
      g_value_set_string (value, self->product_id);
Packit Service bf98b9
      break;
Packit Service bf98b9
Packit Service bf98b9
    default:
Packit Service bf98b9
      G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
Packit Service bf98b9
      break;
Packit Service bf98b9
    }
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
static void
Packit Service bf98b9
clutter_input_device_class_init (ClutterInputDeviceClass *klass)
Packit Service bf98b9
{
Packit Service bf98b9
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
Packit Service bf98b9
Packit Service bf98b9
  /**
Packit Service bf98b9
   * ClutterInputDevice:id:
Packit Service bf98b9
   *
Packit Service bf98b9
   * The unique identifier of the device
Packit Service bf98b9
   *
Packit Service bf98b9
   * Since: 1.2
Packit Service bf98b9
   */
Packit Service bf98b9
  obj_props[PROP_ID] =
Packit Service bf98b9
    g_param_spec_int ("id",
Packit Service bf98b9
                      P_("Id"),
Packit Service bf98b9
                      P_("Unique identifier of the device"),
Packit Service bf98b9
                      -1, G_MAXINT,
Packit Service bf98b9
                      0,
Packit Service bf98b9
                      CLUTTER_PARAM_READWRITE |
Packit Service bf98b9
                      G_PARAM_CONSTRUCT_ONLY);
Packit Service bf98b9
Packit Service bf98b9
  /**
Packit Service bf98b9
   * ClutterInputDevice:name:
Packit Service bf98b9
   *
Packit Service bf98b9
   * The name of the device
Packit Service bf98b9
   *
Packit Service bf98b9
   * Since: 1.2
Packit Service bf98b9
   */
Packit Service bf98b9
  obj_props[PROP_NAME] =
Packit Service bf98b9
    g_param_spec_string ("name",
Packit Service bf98b9
                         P_("Name"),
Packit Service bf98b9
                         P_("The name of the device"),
Packit Service bf98b9
                         NULL,
Packit Service bf98b9
                         CLUTTER_PARAM_READWRITE |
Packit Service bf98b9
                         G_PARAM_CONSTRUCT_ONLY);
Packit Service bf98b9
Packit Service bf98b9
  /**
Packit Service bf98b9
   * ClutterInputDevice:device-type:
Packit Service bf98b9
   *
Packit Service bf98b9
   * The type of the device
Packit Service bf98b9
   *
Packit Service bf98b9
   * Since: 1.2
Packit Service bf98b9
   */
Packit Service bf98b9
  obj_props[PROP_DEVICE_TYPE] =
Packit Service bf98b9
    g_param_spec_enum ("device-type",
Packit Service bf98b9
                       P_("Device Type"),
Packit Service bf98b9
                       P_("The type of the device"),
Packit Service bf98b9
                       CLUTTER_TYPE_INPUT_DEVICE_TYPE,
Packit Service bf98b9
                       CLUTTER_POINTER_DEVICE,
Packit Service bf98b9
                       CLUTTER_PARAM_READWRITE |
Packit Service bf98b9
                       G_PARAM_CONSTRUCT_ONLY);
Packit Service bf98b9
Packit Service bf98b9
  /**
Packit Service bf98b9
   * ClutterInputDevice:device-manager:
Packit Service bf98b9
   *
Packit Service bf98b9
   * The #ClutterDeviceManager instance which owns the device
Packit Service bf98b9
   *
Packit Service bf98b9
   * Since: 1.6
Packit Service bf98b9
   */
Packit Service bf98b9
  obj_props[PROP_DEVICE_MANAGER] =
Packit Service bf98b9
    g_param_spec_object ("device-manager",
Packit Service bf98b9
                         P_("Device Manager"),
Packit Service bf98b9
                         P_("The device manager instance"),
Packit Service bf98b9
                         CLUTTER_TYPE_DEVICE_MANAGER,
Packit Service bf98b9
                         CLUTTER_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
Packit Service bf98b9
Packit Service bf98b9
  /**
Packit Service bf98b9
   * ClutterInputDevice:mode:
Packit Service bf98b9
   *
Packit Service bf98b9
   * The mode of the device.
Packit Service bf98b9
   *
Packit Service bf98b9
   * Since: 1.6
Packit Service bf98b9
   */
Packit Service bf98b9
  obj_props[PROP_DEVICE_MODE] =
Packit Service bf98b9
    g_param_spec_enum ("device-mode",
Packit Service bf98b9
                       P_("Device Mode"),
Packit Service bf98b9
                       P_("The mode of the device"),
Packit Service bf98b9
                       CLUTTER_TYPE_INPUT_MODE,
Packit Service bf98b9
                       CLUTTER_INPUT_MODE_FLOATING,
Packit Service bf98b9
                       CLUTTER_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
Packit Service bf98b9
Packit Service bf98b9
  /**
Packit Service bf98b9
   * ClutterInputDevice:has-cursor:
Packit Service bf98b9
   *
Packit Service bf98b9
   * Whether the device has an on screen cursor following its movement.
Packit Service bf98b9
   *
Packit Service bf98b9
   * Since: 1.6
Packit Service bf98b9
   */
Packit Service bf98b9
  obj_props[PROP_HAS_CURSOR] =
Packit Service bf98b9
    g_param_spec_boolean ("has-cursor",
Packit Service bf98b9
                          P_("Has Cursor"),
Packit Service bf98b9
                          P_("Whether the device has a cursor"),
Packit Service bf98b9
                          FALSE,
Packit Service bf98b9
                          CLUTTER_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
Packit Service bf98b9
Packit Service bf98b9
  /**
Packit Service bf98b9
   * ClutterInputDevice:enabled:
Packit Service bf98b9
   *
Packit Service bf98b9
   * Whether the device is enabled.
Packit Service bf98b9
   *
Packit Service bf98b9
   * A device with the #ClutterInputDevice:device-mode property set
Packit Service bf98b9
   * to %CLUTTER_INPUT_MODE_MASTER cannot be disabled.
Packit Service bf98b9
   *
Packit Service bf98b9
   * A device must be enabled in order to receive events from it.
Packit Service bf98b9
   *
Packit Service bf98b9
   * Since: 1.6
Packit Service bf98b9
   */
Packit Service bf98b9
  obj_props[PROP_ENABLED] =
Packit Service bf98b9
    g_param_spec_boolean ("enabled",
Packit Service bf98b9
                          P_("Enabled"),
Packit Service bf98b9
                          P_("Whether the device is enabled"),
Packit Service bf98b9
                          FALSE,
Packit Service bf98b9
                          CLUTTER_PARAM_READWRITE);
Packit Service bf98b9
Packit Service bf98b9
  /**
Packit Service bf98b9
   * ClutterInputDevice:n-axes:
Packit Service bf98b9
   *
Packit Service bf98b9
   * The number of axes of the device.
Packit Service bf98b9
   *
Packit Service bf98b9
   * Since: 1.6
Packit Service bf98b9
   */
Packit Service bf98b9
  obj_props[PROP_N_AXES] =
Packit Service bf98b9
    g_param_spec_uint ("n-axes",
Packit Service bf98b9
                       P_("Number of Axes"),
Packit Service bf98b9
                       P_("The number of axes on the device"),
Packit Service bf98b9
                       0, G_MAXUINT,
Packit Service bf98b9
                       0,
Packit Service bf98b9
                       CLUTTER_PARAM_READABLE);
Packit Service bf98b9
Packit Service bf98b9
  /**
Packit Service bf98b9
   * ClutterInputDevice:backend:
Packit Service bf98b9
   *
Packit Service bf98b9
   * The #ClutterBackend that created the device.
Packit Service bf98b9
   *
Packit Service bf98b9
   * Since: 1.6
Packit Service bf98b9
   */
Packit Service bf98b9
  obj_props[PROP_BACKEND] =
Packit Service bf98b9
    g_param_spec_object ("backend",
Packit Service bf98b9
                         P_("Backend"),
Packit Service bf98b9
                         P_("The backend instance"),
Packit Service bf98b9
                         CLUTTER_TYPE_BACKEND,
Packit Service bf98b9
                         CLUTTER_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
Packit Service bf98b9
Packit Service bf98b9
  /**
Packit Service bf98b9
   * ClutterInputDevice:vendor-id:
Packit Service bf98b9
   *
Packit Service bf98b9
   * Vendor ID of this device.
Packit Service bf98b9
   *
Packit Service bf98b9
   * Since: 1.22
Packit Service bf98b9
   */
Packit Service bf98b9
  obj_props[PROP_VENDOR_ID] =
Packit Service bf98b9
    g_param_spec_string ("vendor-id",
Packit Service bf98b9
                         P_("Vendor ID"),
Packit Service bf98b9
                         P_("Vendor ID"),
Packit Service bf98b9
                         NULL,
Packit Service bf98b9
                         CLUTTER_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
Packit Service bf98b9
Packit Service bf98b9
  /**
Packit Service bf98b9
   * ClutterInputDevice:product-id:
Packit Service bf98b9
   *
Packit Service bf98b9
   * Product ID of this device.
Packit Service bf98b9
   *
Packit Service bf98b9
   * Since: 1.22
Packit Service bf98b9
   */
Packit Service bf98b9
  obj_props[PROP_PRODUCT_ID] =
Packit Service bf98b9
    g_param_spec_string ("product-id",
Packit Service bf98b9
                         P_("Product ID"),
Packit Service bf98b9
                         P_("Product ID"),
Packit Service bf98b9
                         NULL,
Packit Service bf98b9
                         CLUTTER_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
Packit Service bf98b9
Packit Service bf98b9
  gobject_class->dispose = clutter_input_device_dispose;
Packit Service bf98b9
  gobject_class->set_property = clutter_input_device_set_property;
Packit Service bf98b9
  gobject_class->get_property = clutter_input_device_get_property;
Packit Service bf98b9
  g_object_class_install_properties (gobject_class, PROP_LAST, obj_props);
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
static void
Packit Service bf98b9
clutter_input_device_init (ClutterInputDevice *self)
Packit Service bf98b9
{
Packit Service bf98b9
  self->id = -1;
Packit Service bf98b9
  self->device_type = CLUTTER_POINTER_DEVICE;
Packit Service bf98b9
Packit Service bf98b9
  self->click_count = 0;
Packit Service bf98b9
Packit Service bf98b9
  self->current_time = self->previous_time = CLUTTER_CURRENT_TIME;
Packit Service bf98b9
  self->current_x = self->previous_x = -1;
Packit Service bf98b9
  self->current_y = self->previous_y = -1;
Packit Service bf98b9
  self->current_button_number = self->previous_button_number = -1;
Packit Service bf98b9
  self->current_state = self->previous_state = 0;
Packit Service bf98b9
Packit Service bf98b9
  self->touch_sequences_info =
Packit Service bf98b9
    g_hash_table_new_full (NULL, NULL,
Packit Service bf98b9
                           NULL, _clutter_input_device_free_touch_info);
Packit Service bf98b9
  self->inv_touch_sequence_actors = g_hash_table_new (NULL, NULL);
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
static ClutterTouchInfo *
Packit Service bf98b9
_clutter_input_device_ensure_touch_info (ClutterInputDevice *device,
Packit Service bf98b9
                                         ClutterEventSequence *sequence,
Packit Service bf98b9
                                         ClutterStage *stage)
Packit Service bf98b9
{
Packit Service bf98b9
  ClutterTouchInfo *info;
Packit Service bf98b9
Packit Service bf98b9
  info = g_hash_table_lookup (device->touch_sequences_info, sequence);
Packit Service bf98b9
Packit Service bf98b9
  if (info == NULL)
Packit Service bf98b9
    {
Packit Service bf98b9
      info = g_slice_new0 (ClutterTouchInfo);
Packit Service bf98b9
      info->sequence = sequence;
Packit Service bf98b9
      g_hash_table_insert (device->touch_sequences_info, sequence, info);
Packit Service bf98b9
Packit Service bf98b9
      if (g_hash_table_size (device->touch_sequences_info) == 1)
Packit Service bf98b9
        _clutter_input_device_set_stage (device, stage);
Packit Service bf98b9
    }
Packit Service bf98b9
Packit Service bf98b9
  return info;
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/*< private >
Packit Service bf98b9
 * clutter_input_device_set_coords:
Packit Service bf98b9
 * @device: a #ClutterInputDevice
Packit Service bf98b9
 * @sequence: a #ClutterEventSequence or NULL
Packit Service bf98b9
 * @x: X coordinate of the device
Packit Service bf98b9
 * @y: Y coordinate of the device
Packit Service bf98b9
 *
Packit Service bf98b9
 * Stores the last known coordinates of the device
Packit Service bf98b9
 */
Packit Service bf98b9
void
Packit Service bf98b9
_clutter_input_device_set_coords (ClutterInputDevice   *device,
Packit Service bf98b9
                                  ClutterEventSequence *sequence,
Packit Service bf98b9
                                  gfloat                x,
Packit Service bf98b9
                                  gfloat                y,
Packit Service bf98b9
                                  ClutterStage         *stage)
Packit Service bf98b9
{
Packit Service bf98b9
  g_return_if_fail (CLUTTER_IS_INPUT_DEVICE (device));
Packit Service bf98b9
Packit Service bf98b9
  if (sequence == NULL)
Packit Service bf98b9
    {
Packit Service bf98b9
      if (device->current_x != x)
Packit Service bf98b9
        device->current_x = x;
Packit Service bf98b9
Packit Service bf98b9
      if (device->current_y != y)
Packit Service bf98b9
        device->current_y = y;
Packit Service bf98b9
    }
Packit Service bf98b9
  else
Packit Service bf98b9
    {
Packit Service bf98b9
      ClutterTouchInfo *info;
Packit Service bf98b9
      info = _clutter_input_device_ensure_touch_info (device, sequence, stage);
Packit Service bf98b9
      info->current_x = x;
Packit Service bf98b9
      info->current_y = y;
Packit Service bf98b9
    }
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/*< private >
Packit Service bf98b9
 * clutter_input_device_set_state:
Packit Service bf98b9
 * @device: a #ClutterInputDevice
Packit Service bf98b9
 * @state: a bitmask of modifiers
Packit Service bf98b9
 *
Packit Service bf98b9
 * Stores the last known modifiers state of the device
Packit Service bf98b9
 */
Packit Service bf98b9
void
Packit Service bf98b9
_clutter_input_device_set_state (ClutterInputDevice  *device,
Packit Service bf98b9
                                 ClutterModifierType  state)
Packit Service bf98b9
{
Packit Service bf98b9
  g_return_if_fail (CLUTTER_IS_INPUT_DEVICE (device));
Packit Service bf98b9
Packit Service bf98b9
  device->current_state = state;
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/**
Packit Service bf98b9
 * clutter_input_device_get_modifier_state:
Packit Service bf98b9
 * @device: a #ClutterInputDevice
Packit Service bf98b9
 *
Packit Service bf98b9
 * Retrieves the current modifiers state of the device, as seen
Packit Service bf98b9
 * by the last event Clutter processed.
Packit Service bf98b9
 *
Packit Service bf98b9
 * Return value: the last known modifier state
Packit Service bf98b9
 *
Packit Service bf98b9
 * Since: 1.16
Packit Service bf98b9
 */
Packit Service bf98b9
ClutterModifierType
Packit Service bf98b9
clutter_input_device_get_modifier_state (ClutterInputDevice *device)
Packit Service bf98b9
{
Packit Service bf98b9
  g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), 0);
Packit Service bf98b9
Packit Service bf98b9
  return device->current_state;
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/*< private >
Packit Service bf98b9
 * clutter_input_device_set_time:
Packit Service bf98b9
 * @device: a #ClutterInputDevice
Packit Service bf98b9
 * @time_: the time
Packit Service bf98b9
 *
Packit Service bf98b9
 * Stores the last known event time of the device
Packit Service bf98b9
 */
Packit Service bf98b9
void
Packit Service bf98b9
_clutter_input_device_set_time (ClutterInputDevice *device,
Packit Service bf98b9
                                guint32             time_)
Packit Service bf98b9
{
Packit Service bf98b9
  g_return_if_fail (CLUTTER_IS_INPUT_DEVICE (device));
Packit Service bf98b9
Packit Service bf98b9
  if (device->current_time != time_)
Packit Service bf98b9
    device->current_time = time_;
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/*< private >
Packit Service bf98b9
 * clutter_input_device_set_stage:
Packit Service bf98b9
 * @device: a #ClutterInputDevice
Packit Service bf98b9
 * @stage: a #ClutterStage or %NULL
Packit Service bf98b9
 *
Packit Service bf98b9
 * Stores the stage under the device
Packit Service bf98b9
 */
Packit Service bf98b9
void
Packit Service bf98b9
_clutter_input_device_set_stage (ClutterInputDevice *device,
Packit Service bf98b9
                                 ClutterStage       *stage)
Packit Service bf98b9
{
Packit Service bf98b9
  if (device->stage == stage)
Packit Service bf98b9
    return;
Packit Service bf98b9
Packit Service bf98b9
  device->stage = stage;
Packit Service bf98b9
Packit Service bf98b9
  /* we leave the ->cursor_actor in place in order to check
Packit Service bf98b9
   * if we left the stage without crossing it again; this way
Packit Service bf98b9
   * we can emit a leave event on the cursor actor right before
Packit Service bf98b9
   * we emit the leave event on the stage.
Packit Service bf98b9
   */
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/*< private >
Packit Service bf98b9
 * clutter_input_device_get_stage:
Packit Service bf98b9
 * @device: a #ClutterInputDevice
Packit Service bf98b9
 *
Packit Service bf98b9
 * Retrieves the stage currently associated with @device.
Packit Service bf98b9
 *
Packit Service bf98b9
 * Return value: The stage currently associated with @device.
Packit Service bf98b9
 */
Packit Service bf98b9
ClutterStage *
Packit Service bf98b9
_clutter_input_device_get_stage (ClutterInputDevice *device)
Packit Service bf98b9
{
Packit Service bf98b9
  return device->stage;
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
static void
Packit Service bf98b9
_clutter_input_device_free_touch_info (gpointer data)
Packit Service bf98b9
{
Packit Service bf98b9
  g_slice_free (ClutterTouchInfo, data);
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
static ClutterActor *
Packit Service bf98b9
_clutter_input_device_get_actor (ClutterInputDevice   *device,
Packit Service bf98b9
                                 ClutterEventSequence *sequence)
Packit Service bf98b9
{
Packit Service bf98b9
  ClutterTouchInfo *info;
Packit Service bf98b9
Packit Service bf98b9
  if (sequence == NULL)
Packit Service bf98b9
    return device->cursor_actor;
Packit Service bf98b9
Packit Service bf98b9
  info = g_hash_table_lookup (device->touch_sequences_info, sequence);
Packit Service bf98b9
Packit Service bf98b9
  return info->actor;
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
static void on_cursor_actor_destroy (ClutterActor       *actor,
Packit Service bf98b9
                                     ClutterInputDevice *device);
Packit Service bf98b9
static void on_cursor_actor_reactive_changed (ClutterActor       *actor,
Packit Service bf98b9
                                              GParamSpec         *pspec,
Packit Service bf98b9
                                              ClutterInputDevice *device);
Packit Service bf98b9
Packit Service bf98b9
static void
Packit Service bf98b9
_clutter_input_device_associate_actor (ClutterInputDevice   *device,
Packit Service bf98b9
                                       ClutterEventSequence *sequence,
Packit Service bf98b9
                                       ClutterActor         *actor)
Packit Service bf98b9
{
Packit Service bf98b9
  if (sequence == NULL)
Packit Service bf98b9
    device->cursor_actor = actor;
Packit Service bf98b9
  else
Packit Service bf98b9
    {
Packit Service bf98b9
      GList *sequences =
Packit Service bf98b9
        g_hash_table_lookup (device->inv_touch_sequence_actors, actor);
Packit Service bf98b9
      ClutterTouchInfo *info;
Packit Service bf98b9
      ClutterStage *stage = CLUTTER_STAGE (clutter_actor_get_stage (actor));
Packit Service bf98b9
Packit Service bf98b9
      info = _clutter_input_device_ensure_touch_info (device, sequence, stage);
Packit Service bf98b9
      info->actor = actor;
Packit Service bf98b9
Packit Service bf98b9
      g_hash_table_insert (device->inv_touch_sequence_actors,
Packit Service bf98b9
                           actor, g_list_prepend (sequences, sequence));
Packit Service bf98b9
    }
Packit Service bf98b9
Packit Service bf98b9
  g_signal_connect (actor,
Packit Service bf98b9
                    "destroy", G_CALLBACK (on_cursor_actor_destroy),
Packit Service bf98b9
                    device);
Packit Service bf98b9
  g_signal_connect (actor,
Packit Service bf98b9
                    "notify::reactive", G_CALLBACK (on_cursor_actor_reactive_changed),
Packit Service bf98b9
                    device);
Packit Service bf98b9
  _clutter_actor_set_has_pointer (actor, TRUE);
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
static void
Packit Service bf98b9
_clutter_input_device_unassociate_actor (ClutterInputDevice   *device,
Packit Service bf98b9
                                         ClutterActor         *actor,
Packit Service bf98b9
                                         gboolean              destroyed)
Packit Service bf98b9
{
Packit Service bf98b9
  if (device->cursor_actor == actor)
Packit Service bf98b9
    device->cursor_actor = NULL;
Packit Service bf98b9
  else
Packit Service bf98b9
    {
Packit Service bf98b9
      GList *l, *sequences =
Packit Service bf98b9
        g_hash_table_lookup (device->inv_touch_sequence_actors,
Packit Service bf98b9
                             actor);
Packit Service bf98b9
Packit Service bf98b9
      for (l = sequences; l != NULL; l = l->next)
Packit Service bf98b9
        {
Packit Service bf98b9
          ClutterTouchInfo *info =
Packit Service bf98b9
            g_hash_table_lookup (device->touch_sequences_info, l->data);
Packit Service bf98b9
Packit Service bf98b9
          if (info)
Packit Service bf98b9
            info->actor = NULL;
Packit Service bf98b9
        }
Packit Service bf98b9
Packit Service bf98b9
      g_list_free (sequences);
Packit Service bf98b9
      g_hash_table_remove (device->inv_touch_sequence_actors, actor);
Packit Service bf98b9
    }
Packit Service bf98b9
Packit Service bf98b9
  if (destroyed == FALSE)
Packit Service bf98b9
    {
Packit Service bf98b9
      g_signal_handlers_disconnect_by_func (actor,
Packit Service bf98b9
                                            G_CALLBACK (on_cursor_actor_destroy),
Packit Service bf98b9
                                            device);
Packit Service bf98b9
      g_signal_handlers_disconnect_by_func (actor,
Packit Service bf98b9
                                            G_CALLBACK (on_cursor_actor_reactive_changed),
Packit Service bf98b9
                                            device);
Packit Service bf98b9
      _clutter_actor_set_has_pointer (actor, FALSE);
Packit Service bf98b9
    }
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
static void
Packit Service bf98b9
on_cursor_actor_destroy (ClutterActor       *actor,
Packit Service bf98b9
                         ClutterInputDevice *device)
Packit Service bf98b9
{
Packit Service bf98b9
  _clutter_input_device_unassociate_actor (device, actor, TRUE);
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
static void
Packit Service bf98b9
on_cursor_actor_reactive_changed (ClutterActor       *actor,
Packit Service bf98b9
                                  GParamSpec         *pspec,
Packit Service bf98b9
                                  ClutterInputDevice *device)
Packit Service bf98b9
{
Packit Service bf98b9
  if (!clutter_actor_get_reactive (actor))
Packit Service bf98b9
    _clutter_input_device_unassociate_actor (device, actor, FALSE);
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/*< private >
Packit Service bf98b9
 * clutter_input_device_set_actor:
Packit Service bf98b9
 * @device: a #ClutterInputDevice
Packit Service bf98b9
 * @actor: a #ClutterActor
Packit Service bf98b9
 * @emit_crossing: %TRUE to emit crossing events
Packit Service bf98b9
 *
Packit Service bf98b9
 * Sets the actor under the pointer coordinates of @device
Packit Service bf98b9
 *
Packit Service bf98b9
 * This function is called by _clutter_input_device_update()
Packit Service bf98b9
 * and it will:
Packit Service bf98b9
 *
Packit Service bf98b9
 *   - queue a %CLUTTER_LEAVE event on the previous pointer actor
Packit Service bf98b9
 *     of @device, if any
Packit Service bf98b9
 *   - set to %FALSE the :has-pointer property of the previous
Packit Service bf98b9
 *     pointer actor of @device, if any
Packit Service bf98b9
 *   - queue a %CLUTTER_ENTER event on the new pointer actor
Packit Service bf98b9
 *   - set to %TRUE the :has-pointer property of the new pointer
Packit Service bf98b9
 *     actor
Packit Service bf98b9
 */
Packit Service bf98b9
void
Packit Service bf98b9
_clutter_input_device_set_actor (ClutterInputDevice   *device,
Packit Service bf98b9
                                 ClutterEventSequence *sequence,
Packit Service bf98b9
                                 ClutterActor         *actor,
Packit Service bf98b9
                                 gboolean              emit_crossing)
Packit Service bf98b9
{
Packit Service bf98b9
  ClutterActor *old_actor = _clutter_input_device_get_actor (device, sequence);
Packit Service bf98b9
Packit Service bf98b9
  if (old_actor == actor)
Packit Service bf98b9
    return;
Packit Service bf98b9
Packit Service bf98b9
  if (old_actor != NULL)
Packit Service bf98b9
    {
Packit Service bf98b9
      ClutterActor *tmp_old_actor;
Packit Service bf98b9
Packit Service bf98b9
      if (emit_crossing)
Packit Service bf98b9
        {
Packit Service bf98b9
          ClutterEvent *event;
Packit Service bf98b9
Packit Service bf98b9
          event = clutter_event_new (CLUTTER_LEAVE);
Packit Service bf98b9
          event->crossing.time = device->current_time;
Packit Service bf98b9
          event->crossing.flags = 0;
Packit Service bf98b9
          event->crossing.stage = device->stage;
Packit Service bf98b9
          event->crossing.source = old_actor;
Packit Service bf98b9
          event->crossing.x = device->current_x;
Packit Service bf98b9
          event->crossing.y = device->current_y;
Packit Service bf98b9
          event->crossing.related = actor;
Packit Service bf98b9
          clutter_event_set_device (event, device);
Packit Service bf98b9
Packit Service bf98b9
          /* we need to make sure that this event is processed
Packit Service bf98b9
           * before any other event we might have queued up until
Packit Service bf98b9
           * now, so we go on, and synthesize the event emission
Packit Service bf98b9
           * ourselves
Packit Service bf98b9
           */
Packit Service bf98b9
          _clutter_process_event (event);
Packit Service bf98b9
Packit Service bf98b9
          clutter_event_free (event);
Packit Service bf98b9
        }
Packit Service bf98b9
Packit Service bf98b9
      /* processing the event might have destroyed the actor */
Packit Service bf98b9
      tmp_old_actor = _clutter_input_device_get_actor (device, sequence);
Packit Service bf98b9
      _clutter_input_device_unassociate_actor (device,
Packit Service bf98b9
                                               old_actor,
Packit Service bf98b9
                                               tmp_old_actor == NULL);
Packit Service bf98b9
      old_actor = tmp_old_actor;
Packit Service bf98b9
    }
Packit Service bf98b9
Packit Service bf98b9
  if (actor != NULL)
Packit Service bf98b9
    {
Packit Service bf98b9
      _clutter_input_device_associate_actor (device, sequence, actor);
Packit Service bf98b9
Packit Service bf98b9
      if (emit_crossing)
Packit Service bf98b9
        {
Packit Service bf98b9
          ClutterEvent *event;
Packit Service bf98b9
Packit Service bf98b9
          event = clutter_event_new (CLUTTER_ENTER);
Packit Service bf98b9
          event->crossing.time = device->current_time;
Packit Service bf98b9
          event->crossing.flags = 0;
Packit Service bf98b9
          event->crossing.stage = device->stage;
Packit Service bf98b9
          event->crossing.x = device->current_x;
Packit Service bf98b9
          event->crossing.y = device->current_y;
Packit Service bf98b9
          event->crossing.source = actor;
Packit Service bf98b9
          event->crossing.related = old_actor;
Packit Service bf98b9
          clutter_event_set_device (event, device);
Packit Service bf98b9
Packit Service bf98b9
          /* see above */
Packit Service bf98b9
          _clutter_process_event (event);
Packit Service bf98b9
Packit Service bf98b9
          clutter_event_free (event);
Packit Service bf98b9
        }
Packit Service bf98b9
    }
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/**
Packit Service bf98b9
 * clutter_input_device_get_device_type:
Packit Service bf98b9
 * @device: a #ClutterInputDevice
Packit Service bf98b9
 *
Packit Service bf98b9
 * Retrieves the type of @device
Packit Service bf98b9
 *
Packit Service bf98b9
 * Return value: the type of the device
Packit Service bf98b9
 *
Packit Service bf98b9
 * Since: 1.0
Packit Service bf98b9
 */
Packit Service bf98b9
ClutterInputDeviceType
Packit Service bf98b9
clutter_input_device_get_device_type (ClutterInputDevice *device)
Packit Service bf98b9
{
Packit Service bf98b9
  g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device),
Packit Service bf98b9
                        CLUTTER_POINTER_DEVICE);
Packit Service bf98b9
Packit Service bf98b9
  return device->device_type;
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/**
Packit Service bf98b9
 * clutter_input_device_get_device_id:
Packit Service bf98b9
 * @device: a #ClutterInputDevice
Packit Service bf98b9
 *
Packit Service bf98b9
 * Retrieves the unique identifier of @device
Packit Service bf98b9
 *
Packit Service bf98b9
 * Return value: the identifier of the device
Packit Service bf98b9
 *
Packit Service bf98b9
 * Since: 1.0
Packit Service bf98b9
 */
Packit Service bf98b9
gint
Packit Service bf98b9
clutter_input_device_get_device_id (ClutterInputDevice *device)
Packit Service bf98b9
{
Packit Service bf98b9
  g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), -1);
Packit Service bf98b9
Packit Service bf98b9
  return device->id;
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/**
Packit Service bf98b9
 * clutter_input_device_set_enabled:
Packit Service bf98b9
 * @device: a #ClutterInputDevice
Packit Service bf98b9
 * @enabled: %TRUE to enable the @device
Packit Service bf98b9
 *
Packit Service bf98b9
 * Enables or disables a #ClutterInputDevice.
Packit Service bf98b9
 *
Packit Service bf98b9
 * Only devices with a #ClutterInputDevice:device-mode property set
Packit Service bf98b9
 * to %CLUTTER_INPUT_MODE_SLAVE or %CLUTTER_INPUT_MODE_FLOATING can
Packit Service bf98b9
 * be disabled.
Packit Service bf98b9
 *
Packit Service bf98b9
 * Since: 1.6
Packit Service bf98b9
 */
Packit Service bf98b9
void
Packit Service bf98b9
clutter_input_device_set_enabled (ClutterInputDevice *device,
Packit Service bf98b9
                                  gboolean            enabled)
Packit Service bf98b9
{
Packit Service bf98b9
  g_return_if_fail (CLUTTER_IS_INPUT_DEVICE (device));
Packit Service bf98b9
Packit Service bf98b9
  enabled = !!enabled;
Packit Service bf98b9
Packit Service bf98b9
  if (!enabled && device->device_mode == CLUTTER_INPUT_MODE_MASTER)
Packit Service bf98b9
    return;
Packit Service bf98b9
Packit Service bf98b9
  if (device->is_enabled == enabled)
Packit Service bf98b9
    return;
Packit Service bf98b9
Packit Service bf98b9
  device->is_enabled = enabled;
Packit Service bf98b9
Packit Service bf98b9
  g_object_notify_by_pspec (G_OBJECT (device), obj_props[PROP_ENABLED]);
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/**
Packit Service bf98b9
 * clutter_input_device_get_enabled:
Packit Service bf98b9
 * @device: a #ClutterInputDevice
Packit Service bf98b9
 *
Packit Service bf98b9
 * Retrieves whether @device is enabled.
Packit Service bf98b9
 *
Packit Service bf98b9
 * Return value: %TRUE if the device is enabled
Packit Service bf98b9
 *
Packit Service bf98b9
 * Since: 1.6
Packit Service bf98b9
 */
Packit Service bf98b9
gboolean
Packit Service bf98b9
clutter_input_device_get_enabled (ClutterInputDevice *device)
Packit Service bf98b9
{
Packit Service bf98b9
  g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), FALSE);
Packit Service bf98b9
Packit Service bf98b9
  return device->is_enabled;
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/**
Packit Service bf98b9
 * clutter_input_device_get_coords:
Packit Service bf98b9
 * @device: a #ClutterInputDevice
Packit Service bf98b9
 * @sequence: (allow-none): a #ClutterEventSequence, or %NULL if
Packit Service bf98b9
 *   the device is not touch-based
Packit Service bf98b9
 * @point: (out caller-allocates): return location for the pointer
Packit Service bf98b9
 *   or touch point
Packit Service bf98b9
 *
Packit Service bf98b9
 * Retrieves the latest coordinates of a pointer or touch point of
Packit Service bf98b9
 * @device.
Packit Service bf98b9
 *
Packit Service bf98b9
 * Return value: %FALSE if the device's sequence hasn't been found,
Packit Service bf98b9
 *   and %TRUE otherwise.
Packit Service bf98b9
 *
Packit Service bf98b9
 * Since: 1.12
Packit Service bf98b9
 */
Packit Service bf98b9
gboolean
Packit Service bf98b9
clutter_input_device_get_coords (ClutterInputDevice   *device,
Packit Service bf98b9
                                 ClutterEventSequence *sequence,
Packit Service bf98b9
                                 ClutterPoint         *point)
Packit Service bf98b9
{
Packit Service bf98b9
  g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), FALSE);
Packit Service bf98b9
  g_return_val_if_fail (point != NULL, FALSE);
Packit Service bf98b9
Packit Service bf98b9
  if (sequence == NULL)
Packit Service bf98b9
    {
Packit Service bf98b9
      point->x = device->current_x;
Packit Service bf98b9
      point->y = device->current_y;
Packit Service bf98b9
    }
Packit Service bf98b9
  else
Packit Service bf98b9
    {
Packit Service bf98b9
      ClutterTouchInfo *info =
Packit Service bf98b9
        g_hash_table_lookup (device->touch_sequences_info, sequence);
Packit Service bf98b9
Packit Service bf98b9
      if (info == NULL)
Packit Service bf98b9
        return FALSE;
Packit Service bf98b9
Packit Service bf98b9
      point->x = info->current_x;
Packit Service bf98b9
      point->y = info->current_y;
Packit Service bf98b9
    }
Packit Service bf98b9
Packit Service bf98b9
  return TRUE;
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/*
Packit Service bf98b9
 * _clutter_input_device_update:
Packit Service bf98b9
 * @device: a #ClutterInputDevice
Packit Service bf98b9
 *
Packit Service bf98b9
 * Updates the input @device by determining the #ClutterActor underneath the
Packit Service bf98b9
 * pointer's cursor
Packit Service bf98b9
 *
Packit Service bf98b9
 * This function calls _clutter_input_device_set_actor() if needed.
Packit Service bf98b9
 *
Packit Service bf98b9
 * This function only works for #ClutterInputDevice of type
Packit Service bf98b9
 * %CLUTTER_POINTER_DEVICE.
Packit Service bf98b9
 *
Packit Service bf98b9
 * Since: 1.2
Packit Service bf98b9
 */
Packit Service bf98b9
ClutterActor *
Packit Service bf98b9
_clutter_input_device_update (ClutterInputDevice   *device,
Packit Service bf98b9
                              ClutterEventSequence *sequence,
Packit Service bf98b9
                              gboolean              emit_crossing)
Packit Service bf98b9
{
Packit Service bf98b9
  ClutterStage *stage;
Packit Service bf98b9
  ClutterActor *new_cursor_actor;
Packit Service bf98b9
  ClutterActor *old_cursor_actor;
Packit Service bf98b9
  ClutterPoint point = { -1, -1 };
Packit Service bf98b9
Packit Service bf98b9
  if (device->device_type == CLUTTER_KEYBOARD_DEVICE)
Packit Service bf98b9
    return NULL;
Packit Service bf98b9
Packit Service bf98b9
  stage = device->stage;
Packit Service bf98b9
  if (G_UNLIKELY (stage == NULL))
Packit Service bf98b9
    {
Packit Service bf98b9
      CLUTTER_NOTE (EVENT, "No stage defined for device %d '%s'",
Packit Service bf98b9
                    clutter_input_device_get_device_id (device),
Packit Service bf98b9
                    clutter_input_device_get_device_name (device));
Packit Service bf98b9
      return NULL;
Packit Service bf98b9
    }
Packit Service bf98b9
Packit Service bf98b9
  clutter_input_device_get_coords (device, sequence, &point);
Packit Service bf98b9
Packit Service bf98b9
  old_cursor_actor = _clutter_input_device_get_actor (device, sequence);
Packit Service bf98b9
  new_cursor_actor =
Packit Service bf98b9
    _clutter_stage_do_pick (stage, point.x, point.y, CLUTTER_PICK_REACTIVE);
Packit Service bf98b9
Packit Service bf98b9
  /* if the pick could not find an actor then we do not update the
Packit Service bf98b9
   * input device, to avoid ghost enter/leave events; the pick should
Packit Service bf98b9
   * never fail, except for bugs in the glReadPixels() implementation
Packit Service bf98b9
   * in which case this is the safest course of action anyway
Packit Service bf98b9
   */
Packit Service bf98b9
  if (new_cursor_actor == NULL)
Packit Service bf98b9
    return NULL;
Packit Service bf98b9
Packit Service bf98b9
  CLUTTER_NOTE (EVENT,
Packit Service bf98b9
                "Actor under cursor (device %d, at %.2f, %.2f): %s",
Packit Service bf98b9
                clutter_input_device_get_device_id (device),
Packit Service bf98b9
                point.x,
Packit Service bf98b9
                point.y,
Packit Service bf98b9
                _clutter_actor_get_debug_name (new_cursor_actor));
Packit Service bf98b9
Packit Service bf98b9
  /* short-circuit here */
Packit Service bf98b9
  if (new_cursor_actor == old_cursor_actor)
Packit Service bf98b9
    return old_cursor_actor;
Packit Service bf98b9
Packit Service bf98b9
  _clutter_input_device_set_actor (device, sequence,
Packit Service bf98b9
                                   new_cursor_actor,
Packit Service bf98b9
                                   emit_crossing);
Packit Service bf98b9
Packit Service bf98b9
  return new_cursor_actor;
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/**
Packit Service bf98b9
 * clutter_input_device_get_pointer_actor:
Packit Service bf98b9
 * @device: a #ClutterInputDevice of type %CLUTTER_POINTER_DEVICE
Packit Service bf98b9
 *
Packit Service bf98b9
 * Retrieves the #ClutterActor underneath the pointer of @device
Packit Service bf98b9
 *
Packit Service bf98b9
 * Return value: (transfer none): a pointer to the #ClutterActor or %NULL
Packit Service bf98b9
 *
Packit Service bf98b9
 * Since: 1.2
Packit Service bf98b9
 */
Packit Service bf98b9
ClutterActor *
Packit Service bf98b9
clutter_input_device_get_pointer_actor (ClutterInputDevice *device)
Packit Service bf98b9
{
Packit Service bf98b9
  g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), NULL);
Packit Service bf98b9
  g_return_val_if_fail (device->device_type == CLUTTER_POINTER_DEVICE, NULL);
Packit Service bf98b9
Packit Service bf98b9
  return device->cursor_actor;
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/**
Packit Service bf98b9
 * clutter_input_device_get_pointer_stage:
Packit Service bf98b9
 * @device: a #ClutterInputDevice of type %CLUTTER_POINTER_DEVICE
Packit Service bf98b9
 *
Packit Service bf98b9
 * Retrieves the #ClutterStage underneath the pointer of @device
Packit Service bf98b9
 *
Packit Service bf98b9
 * Return value: (transfer none): a pointer to the #ClutterStage or %NULL
Packit Service bf98b9
 *
Packit Service bf98b9
 * Since: 1.2
Packit Service bf98b9
 */
Packit Service bf98b9
ClutterStage *
Packit Service bf98b9
clutter_input_device_get_pointer_stage (ClutterInputDevice *device)
Packit Service bf98b9
{
Packit Service bf98b9
  g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), NULL);
Packit Service bf98b9
  g_return_val_if_fail (device->device_type == CLUTTER_POINTER_DEVICE, NULL);
Packit Service bf98b9
Packit Service bf98b9
  return device->stage;
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/**
Packit Service bf98b9
 * clutter_input_device_get_device_name:
Packit Service bf98b9
 * @device: a #ClutterInputDevice
Packit Service bf98b9
 *
Packit Service bf98b9
 * Retrieves the name of the @device
Packit Service bf98b9
 *
Packit Service bf98b9
 * Return value: the name of the device, or %NULL. The returned string
Packit Service bf98b9
 *   is owned by the #ClutterInputDevice and should never be modified
Packit Service bf98b9
 *   or freed
Packit Service bf98b9
 *
Packit Service bf98b9
 * Since: 1.2
Packit Service bf98b9
 */
Packit Service bf98b9
const gchar *
Packit Service bf98b9
clutter_input_device_get_device_name (ClutterInputDevice *device)
Packit Service bf98b9
{
Packit Service bf98b9
  g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), NULL);
Packit Service bf98b9
Packit Service bf98b9
  return device->device_name;
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/**
Packit Service bf98b9
 * clutter_input_device_get_has_cursor:
Packit Service bf98b9
 * @device: a #ClutterInputDevice
Packit Service bf98b9
 *
Packit Service bf98b9
 * Retrieves whether @device has a pointer that follows the
Packit Service bf98b9
 * device motion.
Packit Service bf98b9
 *
Packit Service bf98b9
 * Return value: %TRUE if the device has a cursor
Packit Service bf98b9
 *
Packit Service bf98b9
 * Since: 1.6
Packit Service bf98b9
 */
Packit Service bf98b9
gboolean
Packit Service bf98b9
clutter_input_device_get_has_cursor (ClutterInputDevice *device)
Packit Service bf98b9
{
Packit Service bf98b9
  g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), FALSE);
Packit Service bf98b9
Packit Service bf98b9
  return device->has_cursor;
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/**
Packit Service bf98b9
 * clutter_input_device_get_device_mode:
Packit Service bf98b9
 * @device: a #ClutterInputDevice
Packit Service bf98b9
 *
Packit Service bf98b9
 * Retrieves the #ClutterInputMode of @device.
Packit Service bf98b9
 *
Packit Service bf98b9
 * Return value: the device mode
Packit Service bf98b9
 *
Packit Service bf98b9
 * Since: 1.6
Packit Service bf98b9
 */
Packit Service bf98b9
ClutterInputMode
Packit Service bf98b9
clutter_input_device_get_device_mode (ClutterInputDevice *device)
Packit Service bf98b9
{
Packit Service bf98b9
  g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device),
Packit Service bf98b9
                        CLUTTER_INPUT_MODE_FLOATING);
Packit Service bf98b9
Packit Service bf98b9
  return device->device_mode;
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/**
Packit Service bf98b9
 * clutter_input_device_update_from_event:
Packit Service bf98b9
 * @device: a #ClutterInputDevice
Packit Service bf98b9
 * @event: a #ClutterEvent
Packit Service bf98b9
 * @update_stage: whether to update the #ClutterStage of the @device
Packit Service bf98b9
 *   using the stage of the event
Packit Service bf98b9
 *
Packit Service bf98b9
 * Forcibly updates the state of the @device using a #ClutterEvent
Packit Service bf98b9
 *
Packit Service bf98b9
 * This function should never be used by applications: it is meant
Packit Service bf98b9
 * for integration with embedding toolkits, like clutter-gtk
Packit Service bf98b9
 *
Packit Service bf98b9
 * Embedding toolkits that disable the event collection inside Clutter
Packit Service bf98b9
 * need to use this function to update the state of input devices depending
Packit Service bf98b9
 * on a #ClutterEvent that they are going to submit to the event handling code
Packit Service bf98b9
 * in Clutter though clutter_do_event(). Since the input devices hold the state
Packit Service bf98b9
 * that is going to be used to fill in fields like the #ClutterButtonEvent
Packit Service bf98b9
 * click count, or to emit synthesized events like %CLUTTER_ENTER and
Packit Service bf98b9
 * %CLUTTER_LEAVE, it is necessary for embedding toolkits to also be
Packit Service bf98b9
 * responsible of updating the input device state.
Packit Service bf98b9
 *
Packit Service bf98b9
 * For instance, this might be the code to translate an embedding toolkit
Packit Service bf98b9
 * native motion notification into a Clutter #ClutterMotionEvent and ask
Packit Service bf98b9
 * Clutter to process it:
Packit Service bf98b9
 *
Packit Service bf98b9
 * |[
Packit Service bf98b9
 *   ClutterEvent c_event;
Packit Service bf98b9
 *
Packit Service bf98b9
 *   translate_native_event_to_clutter (native_event, &c_event);
Packit Service bf98b9
 *
Packit Service bf98b9
 *   clutter_do_event (&c_event);
Packit Service bf98b9
 * ]|
Packit Service bf98b9
 *
Packit Service bf98b9
 * Before letting clutter_do_event() process the event, it is necessary to call
Packit Service bf98b9
 * clutter_input_device_update_from_event():
Packit Service bf98b9
 *
Packit Service bf98b9
 * |[
Packit Service bf98b9
 *   ClutterEvent c_event;
Packit Service bf98b9
 *   ClutterDeviceManager *manager;
Packit Service bf98b9
 *   ClutterInputDevice *device;
Packit Service bf98b9
 *
Packit Service bf98b9
 *   translate_native_event_to_clutter (native_event, &c_event);
Packit Service bf98b9
 *
Packit Service bf98b9
 *   // get the device manager
Packit Service bf98b9
 *   manager = clutter_device_manager_get_default ();
Packit Service bf98b9
 *
Packit Service bf98b9
 *   // use the default Core Pointer that Clutter backends register by default
Packit Service bf98b9
 *   device = clutter_device_manager_get_core_device (manager, %CLUTTER_POINTER_DEVICE);
Packit Service bf98b9
 *
Packit Service bf98b9
 *   // update the state of the input device
Packit Service bf98b9
 *   clutter_input_device_update_from_event (device, &c_event, FALSE);
Packit Service bf98b9
 *
Packit Service bf98b9
 *   clutter_do_event (&c_event);
Packit Service bf98b9
 * ]|
Packit Service bf98b9
 *
Packit Service bf98b9
 * The @update_stage boolean argument should be used when the input device
Packit Service bf98b9
 * enters and leaves a #ClutterStage; it will use the #ClutterStage field
Packit Service bf98b9
 * of the passed @event to update the stage associated to the input device.
Packit Service bf98b9
 *
Packit Service bf98b9
 * Since: 1.2
Packit Service bf98b9
 */
Packit Service bf98b9
void
Packit Service bf98b9
clutter_input_device_update_from_event (ClutterInputDevice *device,
Packit Service bf98b9
                                        ClutterEvent       *event,
Packit Service bf98b9
                                        gboolean            update_stage)
Packit Service bf98b9
{
Packit Service bf98b9
  ClutterModifierType event_state;
Packit Service bf98b9
  ClutterEventSequence *sequence;
Packit Service bf98b9
  ClutterStage *event_stage;
Packit Service bf98b9
  gfloat event_x, event_y;
Packit Service bf98b9
  guint32 event_time;
Packit Service bf98b9
Packit Service bf98b9
  g_return_if_fail (CLUTTER_IS_INPUT_DEVICE (device));
Packit Service bf98b9
  g_return_if_fail (event != NULL);
Packit Service bf98b9
Packit Service bf98b9
  event_state = clutter_event_get_state (event);
Packit Service bf98b9
  event_time = clutter_event_get_time (event);
Packit Service bf98b9
  event_stage = clutter_event_get_stage (event);
Packit Service bf98b9
  sequence = clutter_event_get_event_sequence (event);
Packit Service bf98b9
  clutter_event_get_coords (event, &event_x, &event_y);
Packit Service bf98b9
Packit Service bf98b9
  _clutter_input_device_set_coords (device, sequence, event_x, event_y, event_stage);
Packit Service bf98b9
  _clutter_input_device_set_state (device, event_state);
Packit Service bf98b9
  _clutter_input_device_set_time (device, event_time);
Packit Service bf98b9
Packit Service bf98b9
  if (update_stage)
Packit Service bf98b9
    _clutter_input_device_set_stage (device, event_stage);
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/*< private >
Packit Service bf98b9
 * clutter_input_device_reset_axes:
Packit Service bf98b9
 * @device: a #ClutterInputDevice
Packit Service bf98b9
 *
Packit Service bf98b9
 * Resets the axes on @device
Packit Service bf98b9
 */
Packit Service bf98b9
void
Packit Service bf98b9
_clutter_input_device_reset_axes (ClutterInputDevice *device)
Packit Service bf98b9
{
Packit Service bf98b9
  if (device->axes != NULL)
Packit Service bf98b9
    {
Packit Service bf98b9
      g_array_free (device->axes, TRUE);
Packit Service bf98b9
      device->axes = NULL;
Packit Service bf98b9
Packit Service bf98b9
      g_object_notify_by_pspec (G_OBJECT (device), obj_props[PROP_N_AXES]);
Packit Service bf98b9
    }
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/*< private >
Packit Service bf98b9
 * clutter_input_device_add_axis:
Packit Service bf98b9
 * @device: a #ClutterInputDevice
Packit Service bf98b9
 * @axis: the axis type
Packit Service bf98b9
 * @minimum: the minimum axis value
Packit Service bf98b9
 * @maximum: the maximum axis value
Packit Service bf98b9
 * @resolution: the axis resolution
Packit Service bf98b9
 *
Packit Service bf98b9
 * Adds an axis of type @axis on @device.
Packit Service bf98b9
 */
Packit Service bf98b9
guint
Packit Service bf98b9
_clutter_input_device_add_axis (ClutterInputDevice *device,
Packit Service bf98b9
                                ClutterInputAxis    axis,
Packit Service bf98b9
                                gdouble             minimum,
Packit Service bf98b9
                                gdouble             maximum,
Packit Service bf98b9
                                gdouble             resolution)
Packit Service bf98b9
{
Packit Service bf98b9
  ClutterAxisInfo info;
Packit Service bf98b9
  guint pos;
Packit Service bf98b9
Packit Service bf98b9
  if (device->axes == NULL)
Packit Service bf98b9
    device->axes = g_array_new (FALSE, TRUE, sizeof (ClutterAxisInfo));
Packit Service bf98b9
Packit Service bf98b9
  info.axis = axis;
Packit Service bf98b9
  info.min_value = minimum;
Packit Service bf98b9
  info.max_value = maximum;
Packit Service bf98b9
  info.resolution = resolution;
Packit Service bf98b9
Packit Service bf98b9
  switch (axis)
Packit Service bf98b9
    {
Packit Service bf98b9
    case CLUTTER_INPUT_AXIS_X:
Packit Service bf98b9
    case CLUTTER_INPUT_AXIS_Y:
Packit Service bf98b9
      info.min_axis = 0;
Packit Service bf98b9
      info.max_axis = 0;
Packit Service bf98b9
      break;
Packit Service bf98b9
Packit Service bf98b9
    case CLUTTER_INPUT_AXIS_XTILT:
Packit Service bf98b9
    case CLUTTER_INPUT_AXIS_YTILT:
Packit Service bf98b9
      info.min_axis = -1;
Packit Service bf98b9
      info.max_axis = 1;
Packit Service bf98b9
      break;
Packit Service bf98b9
Packit Service bf98b9
    default:
Packit Service bf98b9
      info.min_axis = 0;
Packit Service bf98b9
      info.max_axis = 1;
Packit Service bf98b9
      break;
Packit Service bf98b9
    }
Packit Service bf98b9
Packit Service bf98b9
  device->axes = g_array_append_val (device->axes, info);
Packit Service bf98b9
  pos = device->axes->len - 1;
Packit Service bf98b9
Packit Service bf98b9
  g_object_notify_by_pspec (G_OBJECT (device), obj_props[PROP_N_AXES]);
Packit Service bf98b9
Packit Service bf98b9
  return pos;
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/*< private >
Packit Service bf98b9
 * clutter_input_translate_axis:
Packit Service bf98b9
 * @device: a #ClutterInputDevice
Packit Service bf98b9
 * @index_: the index of the axis
Packit Service bf98b9
 * @gint: the absolute value of the axis
Packit Service bf98b9
 * @axis_value: (out): the translated value of the axis
Packit Service bf98b9
 *
Packit Service bf98b9
 * Performs a conversion from the absolute value of the axis
Packit Service bf98b9
 * to a relative value.
Packit Service bf98b9
 *
Packit Service bf98b9
 * The axis at @index_ must not be %CLUTTER_INPUT_AXIS_X or
Packit Service bf98b9
 * %CLUTTER_INPUT_AXIS_Y.
Packit Service bf98b9
 *
Packit Service bf98b9
 * Return value: %TRUE if the conversion was successful
Packit Service bf98b9
 */
Packit Service bf98b9
gboolean
Packit Service bf98b9
_clutter_input_device_translate_axis (ClutterInputDevice *device,
Packit Service bf98b9
                                      guint               index_,
Packit Service bf98b9
                                      gdouble             value,
Packit Service bf98b9
                                      gdouble            *axis_value)
Packit Service bf98b9
{
Packit Service bf98b9
  ClutterAxisInfo *info;
Packit Service bf98b9
  gdouble width;
Packit Service bf98b9
  gdouble real_value;
Packit Service bf98b9
Packit Service bf98b9
  if (device->axes == NULL || index_ >= device->axes->len)
Packit Service bf98b9
    return FALSE;
Packit Service bf98b9
Packit Service bf98b9
  info = &g_array_index (device->axes, ClutterAxisInfo, index_);
Packit Service bf98b9
Packit Service bf98b9
  if (info->axis == CLUTTER_INPUT_AXIS_X ||
Packit Service bf98b9
      info->axis == CLUTTER_INPUT_AXIS_Y)
Packit Service bf98b9
    return FALSE;
Packit Service bf98b9
Packit Service bf98b9
  if (fabs (info->max_value - info->min_value) < 0.0000001)
Packit Service bf98b9
    return FALSE;
Packit Service bf98b9
Packit Service bf98b9
  width = info->max_value - info->min_value;
Packit Service bf98b9
  real_value = (info->max_axis * (value - info->min_value)
Packit Service bf98b9
             + info->min_axis * (info->max_value - value))
Packit Service bf98b9
             / width;
Packit Service bf98b9
Packit Service bf98b9
  if (axis_value)
Packit Service bf98b9
    *axis_value = real_value;
Packit Service bf98b9
Packit Service bf98b9
  return TRUE;
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/**
Packit Service bf98b9
 * clutter_input_device_get_axis:
Packit Service bf98b9
 * @device: a #ClutterInputDevice
Packit Service bf98b9
 * @index_: the index of the axis
Packit Service bf98b9
 *
Packit Service bf98b9
 * Retrieves the type of axis on @device at the given index.
Packit Service bf98b9
 *
Packit Service bf98b9
 * Return value: the axis type
Packit Service bf98b9
 *
Packit Service bf98b9
 * Since: 1.6
Packit Service bf98b9
 */
Packit Service bf98b9
ClutterInputAxis
Packit Service bf98b9
clutter_input_device_get_axis (ClutterInputDevice *device,
Packit Service bf98b9
                               guint               index_)
Packit Service bf98b9
{
Packit Service bf98b9
  ClutterAxisInfo *info;
Packit Service bf98b9
Packit Service bf98b9
  g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device),
Packit Service bf98b9
                        CLUTTER_INPUT_AXIS_IGNORE);
Packit Service bf98b9
Packit Service bf98b9
  if (device->axes == NULL)
Packit Service bf98b9
    return CLUTTER_INPUT_AXIS_IGNORE;
Packit Service bf98b9
Packit Service bf98b9
  if (index_ >= device->axes->len)
Packit Service bf98b9
    return CLUTTER_INPUT_AXIS_IGNORE;
Packit Service bf98b9
Packit Service bf98b9
  info = &g_array_index (device->axes, ClutterAxisInfo, index_);
Packit Service bf98b9
Packit Service bf98b9
  return info->axis;
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/**
Packit Service bf98b9
 * clutter_input_device_get_axis_value:
Packit Service bf98b9
 * @device: a #ClutterInputDevice
Packit Service bf98b9
 * @axes: (array): an array of axes values, typically
Packit Service bf98b9
 *   coming from clutter_event_get_axes()
Packit Service bf98b9
 * @axis: the axis to extract
Packit Service bf98b9
 * @value: (out): return location for the axis value
Packit Service bf98b9
 *
Packit Service bf98b9
 * Extracts the value of the given @axis of a #ClutterInputDevice from
Packit Service bf98b9
 * an array of axis values.
Packit Service bf98b9
 *
Packit Service bf98b9
 * An example of typical usage for this function is:
Packit Service bf98b9
 *
Packit Service bf98b9
 * |[
Packit Service bf98b9
 *   ClutterInputDevice *device = clutter_event_get_device (event);
Packit Service bf98b9
 *   gdouble *axes = clutter_event_get_axes (event, NULL);
Packit Service bf98b9
 *   gdouble pressure_value = 0;
Packit Service bf98b9
 *
Packit Service bf98b9
 *   clutter_input_device_get_axis_value (device, axes,
Packit Service bf98b9
 *                                        CLUTTER_INPUT_AXIS_PRESSURE,
Packit Service bf98b9
 *                                        &pressure_value);
Packit Service bf98b9
 * ]|
Packit Service bf98b9
 *
Packit Service bf98b9
 * Return value: %TRUE if the value was set, and %FALSE otherwise
Packit Service bf98b9
 *
Packit Service bf98b9
 * Since: 1.6
Packit Service bf98b9
 */
Packit Service bf98b9
gboolean
Packit Service bf98b9
clutter_input_device_get_axis_value (ClutterInputDevice *device,
Packit Service bf98b9
                                     gdouble            *axes,
Packit Service bf98b9
                                     ClutterInputAxis    axis,
Packit Service bf98b9
                                     gdouble            *value)
Packit Service bf98b9
{
Packit Service bf98b9
  gint i;
Packit Service bf98b9
Packit Service bf98b9
  g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), FALSE);
Packit Service bf98b9
  g_return_val_if_fail (device->axes != NULL, FALSE);
Packit Service bf98b9
Packit Service bf98b9
  for (i = 0; i < device->axes->len; i++)
Packit Service bf98b9
    {
Packit Service bf98b9
      ClutterAxisInfo *info;
Packit Service bf98b9
Packit Service bf98b9
      info = &g_array_index (device->axes, ClutterAxisInfo, i);
Packit Service bf98b9
Packit Service bf98b9
      if (info->axis == axis)
Packit Service bf98b9
        {
Packit Service bf98b9
          if (value)
Packit Service bf98b9
            *value = axes[i];
Packit Service bf98b9
Packit Service bf98b9
          return TRUE;
Packit Service bf98b9
        }
Packit Service bf98b9
    }
Packit Service bf98b9
Packit Service bf98b9
  return FALSE;
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/**
Packit Service bf98b9
 * clutter_input_device_get_n_axes:
Packit Service bf98b9
 * @device: a #ClutterInputDevice
Packit Service bf98b9
 *
Packit Service bf98b9
 * Retrieves the number of axes available on @device.
Packit Service bf98b9
 *
Packit Service bf98b9
 * Return value: the number of axes on the device
Packit Service bf98b9
 *
Packit Service bf98b9
 * Since: 1.6
Packit Service bf98b9
 */
Packit Service bf98b9
guint
Packit Service bf98b9
clutter_input_device_get_n_axes (ClutterInputDevice *device)
Packit Service bf98b9
{
Packit Service bf98b9
  g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), 0);
Packit Service bf98b9
Packit Service bf98b9
  if (device->axes != NULL)
Packit Service bf98b9
    return device->axes->len;
Packit Service bf98b9
Packit Service bf98b9
  return 0;
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/*< private >
Packit Service bf98b9
 * clutter_input_device_set_n_keys:
Packit Service bf98b9
 * @device: a #ClutterInputDevice
Packit Service bf98b9
 * @n_keys: the number of keys of the device
Packit Service bf98b9
 *
Packit Service bf98b9
 * Initializes the keys of @device.
Packit Service bf98b9
 *
Packit Service bf98b9
 * Call clutter_input_device_set_key() on each key to set the keyval
Packit Service bf98b9
 * and modifiers.
Packit Service bf98b9
 */
Packit Service bf98b9
void
Packit Service bf98b9
_clutter_input_device_set_n_keys (ClutterInputDevice *device,
Packit Service bf98b9
                                  guint               n_keys)
Packit Service bf98b9
{
Packit Service bf98b9
  if (device->keys != NULL)
Packit Service bf98b9
    g_array_free (device->keys, TRUE);
Packit Service bf98b9
Packit Service bf98b9
  device->n_keys = n_keys;
Packit Service bf98b9
  device->keys = g_array_sized_new (FALSE, TRUE,
Packit Service bf98b9
                                    sizeof (ClutterKeyInfo),
Packit Service bf98b9
                                    n_keys);
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/**
Packit Service bf98b9
 * clutter_input_device_get_n_keys:
Packit Service bf98b9
 * @device: a #ClutterInputDevice
Packit Service bf98b9
 *
Packit Service bf98b9
 * Retrieves the number of keys registered for @device.
Packit Service bf98b9
 *
Packit Service bf98b9
 * Return value: the number of registered keys
Packit Service bf98b9
 *
Packit Service bf98b9
 * Since: 1.6
Packit Service bf98b9
 */
Packit Service bf98b9
guint
Packit Service bf98b9
clutter_input_device_get_n_keys (ClutterInputDevice *device)
Packit Service bf98b9
{
Packit Service bf98b9
  g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), 0);
Packit Service bf98b9
Packit Service bf98b9
  return device->n_keys;
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/**
Packit Service bf98b9
 * clutter_input_device_set_key:
Packit Service bf98b9
 * @device: a #ClutterInputDevice
Packit Service bf98b9
 * @index_: the index of the key
Packit Service bf98b9
 * @keyval: the keyval
Packit Service bf98b9
 * @modifiers: a bitmask of modifiers
Packit Service bf98b9
 *
Packit Service bf98b9
 * Sets the keyval and modifiers at the given @index_ for @device.
Packit Service bf98b9
 *
Packit Service bf98b9
 * Clutter will use the keyval and modifiers set when filling out
Packit Service bf98b9
 * an event coming from the same input device.
Packit Service bf98b9
 *
Packit Service bf98b9
 * Since: 1.6
Packit Service bf98b9
 */
Packit Service bf98b9
void
Packit Service bf98b9
clutter_input_device_set_key (ClutterInputDevice  *device,
Packit Service bf98b9
                              guint                index_,
Packit Service bf98b9
                              guint                keyval,
Packit Service bf98b9
                              ClutterModifierType  modifiers)
Packit Service bf98b9
{
Packit Service bf98b9
  ClutterKeyInfo *key_info;
Packit Service bf98b9
Packit Service bf98b9
  g_return_if_fail (CLUTTER_IS_INPUT_DEVICE (device));
Packit Service bf98b9
  g_return_if_fail (index_ < device->n_keys);
Packit Service bf98b9
Packit Service bf98b9
  key_info = &g_array_index (device->keys, ClutterKeyInfo, index_);
Packit Service bf98b9
  key_info->keyval = keyval;
Packit Service bf98b9
  key_info->modifiers = modifiers;
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/**
Packit Service bf98b9
 * clutter_input_device_get_key:
Packit Service bf98b9
 * @device: a #ClutterInputDevice
Packit Service bf98b9
 * @index_: the index of the key
Packit Service bf98b9
 * @keyval: (out): return location for the keyval at @index_
Packit Service bf98b9
 * @modifiers: (out): return location for the modifiers at @index_
Packit Service bf98b9
 *
Packit Service bf98b9
 * Retrieves the key set using clutter_input_device_set_key()
Packit Service bf98b9
 *
Packit Service bf98b9
 * Return value: %TRUE if a key was set at the given index
Packit Service bf98b9
 *
Packit Service bf98b9
 * Since: 1.6
Packit Service bf98b9
 */
Packit Service bf98b9
gboolean
Packit Service bf98b9
clutter_input_device_get_key (ClutterInputDevice  *device,
Packit Service bf98b9
                              guint                index_,
Packit Service bf98b9
                              guint               *keyval,
Packit Service bf98b9
                              ClutterModifierType *modifiers)
Packit Service bf98b9
{
Packit Service bf98b9
  ClutterKeyInfo *key_info;
Packit Service bf98b9
Packit Service bf98b9
  g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), FALSE);
Packit Service bf98b9
Packit Service bf98b9
  if (device->keys == NULL)
Packit Service bf98b9
    return FALSE;
Packit Service bf98b9
Packit Service bf98b9
  if (index_ > device->keys->len)
Packit Service bf98b9
    return FALSE;
Packit Service bf98b9
Packit Service bf98b9
  key_info = &g_array_index (device->keys, ClutterKeyInfo, index_);
Packit Service bf98b9
Packit Service bf98b9
  if (!key_info->keyval && !key_info->modifiers)
Packit Service bf98b9
    return FALSE;
Packit Service bf98b9
Packit Service bf98b9
  if (keyval)
Packit Service bf98b9
    *keyval = key_info->keyval;
Packit Service bf98b9
Packit Service bf98b9
  if (modifiers)
Packit Service bf98b9
    *modifiers = key_info->modifiers;
Packit Service bf98b9
Packit Service bf98b9
  return TRUE;
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/*< private >
Packit Service bf98b9
 * clutter_input_device_add_slave:
Packit Service bf98b9
 * @master: a #ClutterInputDevice
Packit Service bf98b9
 * @slave: a #ClutterInputDevice
Packit Service bf98b9
 *
Packit Service bf98b9
 * Adds @slave to the list of slave devices of @master
Packit Service bf98b9
 *
Packit Service bf98b9
 * This function does not increase the reference count of either @master
Packit Service bf98b9
 * or @slave.
Packit Service bf98b9
 */
Packit Service bf98b9
void
Packit Service bf98b9
_clutter_input_device_add_slave (ClutterInputDevice *master,
Packit Service bf98b9
                                 ClutterInputDevice *slave)
Packit Service bf98b9
{
Packit Service bf98b9
  if (g_list_find (master->slaves, slave) == NULL)
Packit Service bf98b9
    master->slaves = g_list_prepend (master->slaves, slave);
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/*< private >
Packit Service bf98b9
 * clutter_input_device_remove_slave:
Packit Service bf98b9
 * @master: a #ClutterInputDevice
Packit Service bf98b9
 * @slave: a #ClutterInputDevice
Packit Service bf98b9
 *
Packit Service bf98b9
 * Removes @slave from the list of slave devices of @master.
Packit Service bf98b9
 *
Packit Service bf98b9
 * This function does not decrease the reference count of either @master
Packit Service bf98b9
 * or @slave.
Packit Service bf98b9
 */
Packit Service bf98b9
void
Packit Service bf98b9
_clutter_input_device_remove_slave (ClutterInputDevice *master,
Packit Service bf98b9
                                    ClutterInputDevice *slave)
Packit Service bf98b9
{
Packit Service bf98b9
  if (g_list_find (master->slaves, slave) != NULL)
Packit Service bf98b9
    master->slaves = g_list_remove (master->slaves, slave);
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/*< private >
Packit Service bf98b9
 * clutter_input_device_add_sequence:
Packit Service bf98b9
 * @device: a #ClutterInputDevice
Packit Service bf98b9
 * @sequence: a #ClutterEventSequence
Packit Service bf98b9
 *
Packit Service bf98b9
 * Start tracking informations related to a touch point (position,
Packit Service bf98b9
 * actor underneath the touch point).
Packit Service bf98b9
 */
Packit Service bf98b9
void
Packit Service bf98b9
_clutter_input_device_add_event_sequence (ClutterInputDevice *device,
Packit Service bf98b9
                                          ClutterEvent       *event)
Packit Service bf98b9
{
Packit Service bf98b9
  ClutterEventSequence *sequence = clutter_event_get_event_sequence (event);
Packit Service bf98b9
  ClutterStage *stage;
Packit Service bf98b9
Packit Service bf98b9
  if (sequence == NULL)
Packit Service bf98b9
    return;
Packit Service bf98b9
Packit Service bf98b9
  stage = clutter_event_get_stage (event);
Packit Service bf98b9
  if (stage == NULL)
Packit Service bf98b9
    return;
Packit Service bf98b9
Packit Service bf98b9
  _clutter_input_device_ensure_touch_info (device, sequence, stage);
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/*< private >
Packit Service bf98b9
 * clutter_input_device_remove_sequence:
Packit Service bf98b9
 * @device: a #ClutterInputDevice
Packit Service bf98b9
 * @sequence: a #ClutterEventSequence
Packit Service bf98b9
 *
Packit Service bf98b9
 * Stop tracking informations related to a touch point.
Packit Service bf98b9
 */
Packit Service bf98b9
void
Packit Service bf98b9
_clutter_input_device_remove_event_sequence (ClutterInputDevice *device,
Packit Service bf98b9
                                             ClutterEvent       *event)
Packit Service bf98b9
{
Packit Service bf98b9
  ClutterEventSequence *sequence = clutter_event_get_event_sequence (event);
Packit Service bf98b9
  ClutterTouchInfo *info =
Packit Service bf98b9
    g_hash_table_lookup (device->touch_sequences_info, sequence);
Packit Service bf98b9
Packit Service bf98b9
  if (info == NULL)
Packit Service bf98b9
    return;
Packit Service bf98b9
Packit Service bf98b9
  if (info->actor != NULL)
Packit Service bf98b9
    {
Packit Service bf98b9
      GList *sequences =
Packit Service bf98b9
        g_hash_table_lookup (device->inv_touch_sequence_actors, info->actor);
Packit Service bf98b9
Packit Service bf98b9
      sequences = g_list_remove (sequences, sequence);
Packit Service bf98b9
Packit Service bf98b9
      g_hash_table_replace (device->inv_touch_sequence_actors,
Packit Service bf98b9
                            info->actor, sequences);
Packit Service bf98b9
      _clutter_input_device_set_actor (device, sequence, NULL, TRUE);
Packit Service bf98b9
    }
Packit Service bf98b9
Packit Service bf98b9
  g_hash_table_remove (device->touch_sequences_info, sequence);
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/**
Packit Service bf98b9
 * clutter_input_device_get_slave_devices:
Packit Service bf98b9
 * @device: a #ClutterInputDevice
Packit Service bf98b9
 *
Packit Service bf98b9
 * Retrieves the slave devices attached to @device.
Packit Service bf98b9
 *
Packit Service bf98b9
 * Return value: (transfer container) (element-type Clutter.InputDevice): a
Packit Service bf98b9
 *   list of #ClutterInputDevice, or %NULL. The contents of the list are
Packit Service bf98b9
 *   owned by the device. Use g_list_free() when done
Packit Service bf98b9
 *
Packit Service bf98b9
 * Since: 1.6
Packit Service bf98b9
 */
Packit Service bf98b9
GList *
Packit Service bf98b9
clutter_input_device_get_slave_devices (ClutterInputDevice *device)
Packit Service bf98b9
{
Packit Service bf98b9
  g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), NULL);
Packit Service bf98b9
Packit Service bf98b9
  return g_list_copy (device->slaves);
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/*< internal >
Packit Service bf98b9
 * clutter_input_device_set_associated_device:
Packit Service bf98b9
 * @device: a #ClutterInputDevice
Packit Service bf98b9
 * @associated: (allow-none): a #ClutterInputDevice, or %NULL
Packit Service bf98b9
 *
Packit Service bf98b9
 * Sets the associated device for @device.
Packit Service bf98b9
 *
Packit Service bf98b9
 * This function keeps a reference on the associated device.
Packit Service bf98b9
 */
Packit Service bf98b9
void
Packit Service bf98b9
_clutter_input_device_set_associated_device (ClutterInputDevice *device,
Packit Service bf98b9
                                             ClutterInputDevice *associated)
Packit Service bf98b9
{
Packit Service bf98b9
  if (device->associated == associated)
Packit Service bf98b9
    return;
Packit Service bf98b9
Packit Service bf98b9
  if (device->associated != NULL)
Packit Service bf98b9
    g_object_unref (device->associated);
Packit Service bf98b9
Packit Service bf98b9
  device->associated = associated;
Packit Service bf98b9
  if (device->associated != NULL)
Packit Service bf98b9
    g_object_ref (device->associated);
Packit Service bf98b9
Packit Service bf98b9
  CLUTTER_NOTE (MISC, "Associating device %d '%s' to device %d '%s'",
Packit Service bf98b9
                clutter_input_device_get_device_id (device),
Packit Service bf98b9
                clutter_input_device_get_device_name (device),
Packit Service bf98b9
                device->associated != NULL
Packit Service bf98b9
                  ? clutter_input_device_get_device_id (device->associated)
Packit Service bf98b9
                  : -1,
Packit Service bf98b9
                device->associated != NULL
Packit Service bf98b9
                  ? clutter_input_device_get_device_name (device->associated)
Packit Service bf98b9
                  : "(none)");
Packit Service bf98b9
Packit Service bf98b9
  if (device->device_mode != CLUTTER_INPUT_MODE_MASTER)
Packit Service bf98b9
    {
Packit Service bf98b9
      if (device->associated != NULL)
Packit Service bf98b9
        device->device_mode = CLUTTER_INPUT_MODE_SLAVE;
Packit Service bf98b9
      else
Packit Service bf98b9
        device->device_mode = CLUTTER_INPUT_MODE_FLOATING;
Packit Service bf98b9
Packit Service bf98b9
      g_object_notify_by_pspec (G_OBJECT (device), obj_props[PROP_DEVICE_MODE]);
Packit Service bf98b9
    }
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/**
Packit Service bf98b9
 * clutter_input_device_get_associated_device:
Packit Service bf98b9
 * @device: a #ClutterInputDevice
Packit Service bf98b9
 *
Packit Service bf98b9
 * Retrieves a pointer to the #ClutterInputDevice that has been
Packit Service bf98b9
 * associated to @device.
Packit Service bf98b9
 *
Packit Service bf98b9
 * If the #ClutterInputDevice:device-mode property of @device is
Packit Service bf98b9
 * set to %CLUTTER_INPUT_MODE_MASTER, this function will return
Packit Service bf98b9
 * %NULL.
Packit Service bf98b9
 *
Packit Service bf98b9
 * Return value: (transfer none): a #ClutterInputDevice, or %NULL
Packit Service bf98b9
 *
Packit Service bf98b9
 * Since: 1.6
Packit Service bf98b9
 */
Packit Service bf98b9
ClutterInputDevice *
Packit Service bf98b9
clutter_input_device_get_associated_device (ClutterInputDevice *device)
Packit Service bf98b9
{
Packit Service bf98b9
  g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), NULL);
Packit Service bf98b9
Packit Service bf98b9
  return device->associated;
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/**
Packit Service bf98b9
 * clutter_input_device_keycode_to_evdev:
Packit Service bf98b9
 * @device: A #ClutterInputDevice
Packit Service bf98b9
 * @hardware_keycode: The hardware keycode from a #ClutterKeyEvent
Packit Service bf98b9
 * @evdev_keycode: The return location for the evdev keycode
Packit Service bf98b9
 *
Packit Service bf98b9
 * Translates a hardware keycode from a #ClutterKeyEvent to the
Packit Service bf98b9
 * equivalent evdev keycode. Note that depending on the input backend
Packit Service bf98b9
 * used by Clutter this function can fail if there is no obvious
Packit Service bf98b9
 * mapping between the key codes. The hardware keycode can be taken
Packit Service bf98b9
 * from the #ClutterKeyEvent.hardware_keycode member of #ClutterKeyEvent.
Packit Service bf98b9
 *
Packit Service bf98b9
 * Return value: %TRUE if the conversion succeeded, %FALSE otherwise.
Packit Service bf98b9
 *
Packit Service bf98b9
 * Since: 1.10
Packit Service bf98b9
 */
Packit Service bf98b9
gboolean
Packit Service bf98b9
clutter_input_device_keycode_to_evdev (ClutterInputDevice *device,
Packit Service bf98b9
                                       guint               hardware_keycode,
Packit Service bf98b9
                                       guint              *evdev_keycode)
Packit Service bf98b9
{
Packit Service bf98b9
  ClutterInputDeviceClass *device_class;
Packit Service bf98b9
Packit Service bf98b9
  g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), FALSE);
Packit Service bf98b9
Packit Service bf98b9
  device_class = CLUTTER_INPUT_DEVICE_GET_CLASS (device);
Packit Service bf98b9
  if (device_class->keycode_to_evdev == NULL)
Packit Service bf98b9
    return FALSE;
Packit Service bf98b9
  else
Packit Service bf98b9
    return device_class->keycode_to_evdev (device,
Packit Service bf98b9
                                           hardware_keycode,
Packit Service bf98b9
                                           evdev_keycode);
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
void
Packit Service bf98b9
_clutter_input_device_add_scroll_info (ClutterInputDevice     *device,
Packit Service bf98b9
                                       guint                   index_,
Packit Service bf98b9
                                       ClutterScrollDirection  direction,
Packit Service bf98b9
                                       gdouble                 increment)
Packit Service bf98b9
{
Packit Service bf98b9
  ClutterScrollInfo info;
Packit Service bf98b9
Packit Service bf98b9
  g_return_if_fail (CLUTTER_IS_INPUT_DEVICE (device));
Packit Service bf98b9
  g_return_if_fail (index_ < clutter_input_device_get_n_axes (device));
Packit Service bf98b9
Packit Service bf98b9
  info.axis_id = index_;
Packit Service bf98b9
  info.direction = direction;
Packit Service bf98b9
  info.increment = increment;
Packit Service bf98b9
  info.last_value_valid = FALSE;
Packit Service bf98b9
Packit Service bf98b9
  if (device->scroll_info == NULL)
Packit Service bf98b9
    {
Packit Service bf98b9
      device->scroll_info = g_array_new (FALSE,
Packit Service bf98b9
                                         FALSE,
Packit Service bf98b9
                                         sizeof (ClutterScrollInfo));
Packit Service bf98b9
    }
Packit Service bf98b9
Packit Service bf98b9
  g_array_append_val (device->scroll_info, info);
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
gboolean
Packit Service bf98b9
_clutter_input_device_get_scroll_delta (ClutterInputDevice     *device,
Packit Service bf98b9
                                        guint                   index_,
Packit Service bf98b9
                                        gdouble                 value,
Packit Service bf98b9
                                        ClutterScrollDirection *direction_p,
Packit Service bf98b9
                                        gdouble                *delta_p)
Packit Service bf98b9
{
Packit Service bf98b9
  guint i;
Packit Service bf98b9
Packit Service bf98b9
  g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), FALSE);
Packit Service bf98b9
  g_return_val_if_fail (index_ < clutter_input_device_get_n_axes (device), FALSE);
Packit Service bf98b9
Packit Service bf98b9
  if (device->scroll_info == NULL)
Packit Service bf98b9
    return FALSE;
Packit Service bf98b9
Packit Service bf98b9
  for (i = 0; i < device->scroll_info->len; i++)
Packit Service bf98b9
    {
Packit Service bf98b9
      ClutterScrollInfo *info = &g_array_index (device->scroll_info,
Packit Service bf98b9
                                                ClutterScrollInfo,
Packit Service bf98b9
                                                i);
Packit Service bf98b9
Packit Service bf98b9
      if (info->axis_id == index_)
Packit Service bf98b9
        {
Packit Service bf98b9
          if (direction_p != NULL)
Packit Service bf98b9
            *direction_p = info->direction;
Packit Service bf98b9
Packit Service bf98b9
          if (delta_p != NULL)
Packit Service bf98b9
            *delta_p = 0.0;
Packit Service bf98b9
Packit Service bf98b9
          if (info->last_value_valid)
Packit Service bf98b9
            {
Packit Service bf98b9
              if (delta_p != NULL)
Packit Service bf98b9
                {
Packit Service bf98b9
                  *delta_p = (value - info->last_value)
Packit Service bf98b9
                           / info->increment;
Packit Service bf98b9
                }
Packit Service bf98b9
Packit Service bf98b9
              info->last_value = value;
Packit Service bf98b9
            }
Packit Service bf98b9
          else
Packit Service bf98b9
            {
Packit Service bf98b9
              info->last_value = value;
Packit Service bf98b9
              info->last_value_valid = TRUE;
Packit Service bf98b9
            }
Packit Service bf98b9
Packit Service bf98b9
          return TRUE;
Packit Service bf98b9
        }
Packit Service bf98b9
    }
Packit Service bf98b9
Packit Service bf98b9
  return FALSE;
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
void
Packit Service bf98b9
_clutter_input_device_reset_scroll_info (ClutterInputDevice *device)
Packit Service bf98b9
{
Packit Service bf98b9
  guint i;
Packit Service bf98b9
Packit Service bf98b9
  if (device->scroll_info == NULL)
Packit Service bf98b9
    return;
Packit Service bf98b9
Packit Service bf98b9
  for (i = 0; i < device->scroll_info->len; i++)
Packit Service bf98b9
    {
Packit Service bf98b9
      ClutterScrollInfo *info = &g_array_index (device->scroll_info,
Packit Service bf98b9
                                                ClutterScrollInfo,
Packit Service bf98b9
                                                i);
Packit Service bf98b9
Packit Service bf98b9
      info->last_value_valid = FALSE;
Packit Service bf98b9
    }
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
static void
Packit Service bf98b9
on_grab_sequence_actor_destroy (ClutterActor       *actor,
Packit Service bf98b9
                                ClutterInputDevice *device)
Packit Service bf98b9
{
Packit Service bf98b9
  ClutterEventSequence *sequence =
Packit Service bf98b9
    g_hash_table_lookup (device->inv_sequence_grab_actors, actor);
Packit Service bf98b9
Packit Service bf98b9
  if (sequence != NULL)
Packit Service bf98b9
    {
Packit Service bf98b9
      g_hash_table_remove (device->sequence_grab_actors, sequence);
Packit Service bf98b9
      g_hash_table_remove (device->inv_sequence_grab_actors, actor);
Packit Service bf98b9
    }
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/**
Packit Service bf98b9
 * clutter_input_device_sequence_grab:
Packit Service bf98b9
 * @device: a #ClutterInputDevice
Packit Service bf98b9
 * @sequence: a #ClutterEventSequence
Packit Service bf98b9
 * @actor: a #ClutterActor
Packit Service bf98b9
 *
Packit Service bf98b9
 * Acquires a grab on @actor for the given @device and the given touch
Packit Service bf98b9
 * @sequence.
Packit Service bf98b9
 *
Packit Service bf98b9
 * Any touch event coming from @device and from @sequence will be
Packit Service bf98b9
 * delivered to @actor, bypassing the usual event delivery mechanism,
Packit Service bf98b9
 * until the grab is released by calling
Packit Service bf98b9
 * clutter_input_device_sequence_ungrab().
Packit Service bf98b9
 *
Packit Service bf98b9
 * The grab is client-side: even if the windowing system used by the Clutter
Packit Service bf98b9
 * backend has the concept of "device grabs", Clutter will not use them.
Packit Service bf98b9
 *
Packit Service bf98b9
 * Since: 1.12
Packit Service bf98b9
 */
Packit Service bf98b9
void
Packit Service bf98b9
clutter_input_device_sequence_grab (ClutterInputDevice   *device,
Packit Service bf98b9
                                    ClutterEventSequence *sequence,
Packit Service bf98b9
                                    ClutterActor         *actor)
Packit Service bf98b9
{
Packit Service bf98b9
  ClutterActor *grab_actor;
Packit Service bf98b9
Packit Service bf98b9
  g_return_if_fail (CLUTTER_IS_INPUT_DEVICE (device));
Packit Service bf98b9
  g_return_if_fail (CLUTTER_IS_ACTOR (actor));
Packit Service bf98b9
Packit Service bf98b9
  if (device->sequence_grab_actors == NULL)
Packit Service bf98b9
    {
Packit Service bf98b9
      grab_actor = NULL;
Packit Service bf98b9
      device->sequence_grab_actors = g_hash_table_new (NULL, NULL);
Packit Service bf98b9
      device->inv_sequence_grab_actors = g_hash_table_new (NULL, NULL);
Packit Service bf98b9
    }
Packit Service bf98b9
  else
Packit Service bf98b9
    {
Packit Service bf98b9
      grab_actor = g_hash_table_lookup (device->sequence_grab_actors, sequence);
Packit Service bf98b9
    }
Packit Service bf98b9
Packit Service bf98b9
  if (grab_actor != NULL)
Packit Service bf98b9
    {
Packit Service bf98b9
      g_signal_handlers_disconnect_by_func (grab_actor,
Packit Service bf98b9
                                            G_CALLBACK (on_grab_sequence_actor_destroy),
Packit Service bf98b9
                                            device);
Packit Service bf98b9
      g_hash_table_remove (device->sequence_grab_actors, sequence);
Packit Service bf98b9
      g_hash_table_remove (device->inv_sequence_grab_actors, grab_actor);
Packit Service bf98b9
    }
Packit Service bf98b9
Packit Service bf98b9
  g_hash_table_insert (device->sequence_grab_actors, sequence, actor);
Packit Service bf98b9
  g_hash_table_insert (device->inv_sequence_grab_actors, actor, sequence);
Packit Service bf98b9
  g_signal_connect (actor,
Packit Service bf98b9
                    "destroy",
Packit Service bf98b9
                    G_CALLBACK (on_grab_sequence_actor_destroy),
Packit Service bf98b9
                    device);
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/**
Packit Service bf98b9
 * clutter_input_device_sequence_ungrab:
Packit Service bf98b9
 * @device: a #ClutterInputDevice
Packit Service bf98b9
 * @sequence: a #ClutterEventSequence
Packit Service bf98b9
 *
Packit Service bf98b9
 * Releases the grab on the @device for the given @sequence, if one is
Packit Service bf98b9
 * in place.
Packit Service bf98b9
 *
Packit Service bf98b9
 * Since: 1.12
Packit Service bf98b9
 */
Packit Service bf98b9
void
Packit Service bf98b9
clutter_input_device_sequence_ungrab (ClutterInputDevice   *device,
Packit Service bf98b9
                                      ClutterEventSequence *sequence)
Packit Service bf98b9
{
Packit Service bf98b9
  ClutterActor *grab_actor;
Packit Service bf98b9
Packit Service bf98b9
  g_return_if_fail (CLUTTER_IS_INPUT_DEVICE (device));
Packit Service bf98b9
Packit Service bf98b9
  if (device->sequence_grab_actors == NULL)
Packit Service bf98b9
    return;
Packit Service bf98b9
Packit Service bf98b9
  grab_actor = g_hash_table_lookup (device->sequence_grab_actors, sequence);
Packit Service bf98b9
Packit Service bf98b9
  if (grab_actor == NULL)
Packit Service bf98b9
    return;
Packit Service bf98b9
Packit Service bf98b9
  g_signal_handlers_disconnect_by_func (grab_actor,
Packit Service bf98b9
                                        G_CALLBACK (on_grab_sequence_actor_destroy),
Packit Service bf98b9
                                        device);
Packit Service bf98b9
  g_hash_table_remove (device->sequence_grab_actors, sequence);
Packit Service bf98b9
  g_hash_table_remove (device->inv_sequence_grab_actors, grab_actor);
Packit Service bf98b9
Packit Service bf98b9
  if (g_hash_table_size (device->sequence_grab_actors) == 0)
Packit Service bf98b9
    {
Packit Service bf98b9
      g_hash_table_destroy (device->sequence_grab_actors);
Packit Service bf98b9
      device->sequence_grab_actors = NULL;
Packit Service bf98b9
      g_hash_table_destroy (device->inv_sequence_grab_actors);
Packit Service bf98b9
      device->inv_sequence_grab_actors = NULL;
Packit Service bf98b9
    }
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/**
Packit Service bf98b9
 * clutter_input_device_sequence_get_grabbed_actor:
Packit Service bf98b9
 * @device: a #ClutterInputDevice
Packit Service bf98b9
 * @sequence: a #ClutterEventSequence
Packit Service bf98b9
 *
Packit Service bf98b9
 * Retrieves a pointer to the #ClutterActor currently grabbing the
Packit Service bf98b9
 * touch events coming from @device given the @sequence.
Packit Service bf98b9
 *
Packit Service bf98b9
 * Return value: (transfer none): a #ClutterActor, or %NULL
Packit Service bf98b9
 *
Packit Service bf98b9
 * Since: 1.12
Packit Service bf98b9
 */
Packit Service bf98b9
ClutterActor *
Packit Service bf98b9
clutter_input_device_sequence_get_grabbed_actor (ClutterInputDevice   *device,
Packit Service bf98b9
                                                 ClutterEventSequence *sequence)
Packit Service bf98b9
{
Packit Service bf98b9
  g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), NULL);
Packit Service bf98b9
Packit Service bf98b9
  if (device->sequence_grab_actors == NULL)
Packit Service bf98b9
    return NULL;
Packit Service bf98b9
Packit Service bf98b9
  return g_hash_table_lookup (device->sequence_grab_actors, sequence);
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/**
Packit Service bf98b9
 * clutter_input_device_get_vendor_id:
Packit Service bf98b9
 * @device: a slave #ClutterInputDevice
Packit Service bf98b9
 *
Packit Service bf98b9
 * Gets the vendor ID of this device.
Packit Service bf98b9
 *
Packit Service bf98b9
 * Returns: the vendor ID
Packit Service bf98b9
 *
Packit Service bf98b9
 * Since: 1.22
Packit Service bf98b9
 */
Packit Service bf98b9
const gchar *
Packit Service bf98b9
clutter_input_device_get_vendor_id (ClutterInputDevice *device)
Packit Service bf98b9
{
Packit Service bf98b9
  g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), NULL);
Packit Service bf98b9
  g_return_val_if_fail (clutter_input_device_get_device_mode (device) != CLUTTER_INPUT_MODE_MASTER, NULL);
Packit Service bf98b9
Packit Service bf98b9
  return device->vendor_id;
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/**
Packit Service bf98b9
 * clutter_input_device_get_product_id:
Packit Service bf98b9
 * @device: a slave #ClutterInputDevice
Packit Service bf98b9
 *
Packit Service bf98b9
 * Gets the product ID of this device.
Packit Service bf98b9
 *
Packit Service bf98b9
 * Returns: the product ID
Packit Service bf98b9
 *
Packit Service bf98b9
 * Since: 1.22
Packit Service bf98b9
 */
Packit Service bf98b9
const gchar *
Packit Service bf98b9
clutter_input_device_get_product_id (ClutterInputDevice *device)
Packit Service bf98b9
{
Packit Service bf98b9
  g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), NULL);
Packit Service bf98b9
  g_return_val_if_fail (clutter_input_device_get_device_mode (device) != CLUTTER_INPUT_MODE_MASTER, NULL);
Packit Service bf98b9
Packit Service bf98b9
  return device->product_id;
Packit Service bf98b9
}