From 63b1a5528338a46fcf6375894d2ddc5df5506feb Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Fri, 9 Jan 2015 17:37:28 +0100 Subject: [PATCH] input-device: Add ClutterInputDeviceTool This is an unique opaque struct that identifies a given tool of a given device. --- clutter/clutter/Makefile.am | 2 + .../clutter/clutter-device-manager-private.h | 8 + clutter/clutter/clutter-enums.h | 26 +++ clutter/clutter/clutter-input-device-tool.c | 172 ++++++++++++++++++ clutter/clutter/clutter-input-device-tool.h | 66 +++++++ clutter/clutter/clutter-input-device.c | 41 +++++ clutter/clutter/clutter-types.h | 1 + clutter/clutter/clutter.h | 1 + 8 files changed, 317 insertions(+) create mode 100644 clutter/clutter/clutter-input-device-tool.c create mode 100644 clutter/clutter/clutter-input-device-tool.h diff --git a/clutter/clutter/Makefile.am b/clutter/clutter/Makefile.am index d8edb12ef..f77fe6c20 100644 --- a/clutter/clutter/Makefile.am +++ b/clutter/clutter/Makefile.am @@ -87,6 +87,7 @@ source_h = \ clutter-group.h \ clutter-image.h \ clutter-input-device.h \ + clutter-input-device-tool.h \ clutter-interval.h \ clutter-keyframe-transition.h \ clutter-keysyms.h \ @@ -167,6 +168,7 @@ source_c = \ clutter-grid-layout.c \ clutter-image.c \ clutter-input-device.c \ + clutter-input-device-tool.c \ clutter-interval.c \ clutter-keyframe-transition.c \ clutter-keysyms-table.c \ diff --git a/clutter/clutter/clutter-device-manager-private.h b/clutter/clutter/clutter-device-manager-private.h index 4aa169371..3b33135af 100644 --- a/clutter/clutter/clutter-device-manager-private.h +++ b/clutter/clutter/clutter-device-manager-private.h @@ -132,6 +132,8 @@ struct _ClutterInputDevice gchar *vendor_id; gchar *product_id; + GPtrArray *tools; + guint has_cursor : 1; guint is_enabled : 1; }; @@ -235,6 +237,12 @@ gboolean _clutter_input_device_get_scroll_delta (ClutterInputDev ClutterScrollDirection *direction_p, gdouble *delta_p); +ClutterInputDeviceTool * clutter_input_device_lookup_tool (ClutterInputDevice *device, + guint64 serial, + ClutterInputDeviceToolType type); +void clutter_input_device_add_tool (ClutterInputDevice *device, + ClutterInputDeviceTool *tool); + G_END_DECLS #endif /* __CLUTTER_DEVICE_MANAGER_PRIVATE_H__ */ diff --git a/clutter/clutter/clutter-enums.h b/clutter/clutter/clutter-enums.h index e44744d56..6794c2bd9 100644 --- a/clutter/clutter/clutter-enums.h +++ b/clutter/clutter/clutter-enums.h @@ -1488,6 +1488,32 @@ typedef enum { CLUTTER_SCROLL_FINISHED_VERTICAL = 1 << 1 } ClutterScrollFinishFlags; +/** + * ClutterInputDeviceToolType: + * @CLUTTER_INPUT_DEVICE_TOOL_NONE: No tool + * @CLUTTER_INPUT_DEVICE_TOOL_PEN: The tool is a pen + * @CLUTTER_INPUT_DEVICE_TOOL_ERASER: The tool is an eraser + * @CLUTTER_INPUT_DEVICE_TOOL_BRUSH: The tool is a brush + * @CLUTTER_INPUT_DEVICE_TOOL_PENCIL: The tool is a pencil + * @CLUTTER_INPUT_DEVICE_TOOL_AIRBRUSH: The tool is an airbrush + * @CLUTTER_INPUT_DEVICE_TOOL_MOUSE: The tool is a mouse + * @CLUTTER_INPUT_DEVICE_TOOL_LENS: The tool is a lens + * + * Defines the type of tool that a #ClutterInputDeviceTool represents. + * + * Since: 1.28 + */ +typedef enum { + CLUTTER_INPUT_DEVICE_TOOL_NONE, + CLUTTER_INPUT_DEVICE_TOOL_PEN, + CLUTTER_INPUT_DEVICE_TOOL_ERASER, + CLUTTER_INPUT_DEVICE_TOOL_BRUSH, + CLUTTER_INPUT_DEVICE_TOOL_PENCIL, + CLUTTER_INPUT_DEVICE_TOOL_AIRBRUSH, + CLUTTER_INPUT_DEVICE_TOOL_MOUSE, + CLUTTER_INPUT_DEVICE_TOOL_LENS +} ClutterInputDeviceToolType; + G_END_DECLS #endif /* __CLUTTER_ENUMS_H__ */ diff --git a/clutter/clutter/clutter-input-device-tool.c b/clutter/clutter/clutter-input-device-tool.c new file mode 100644 index 000000000..547801ead --- /dev/null +++ b/clutter/clutter/clutter-input-device-tool.c @@ -0,0 +1,172 @@ +/* + * Clutter. + * + * An OpenGL based 'interactive canvas' library. + * + * Copyright © 2009, 2010, 2011 Intel Corp. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + * + * Author: Carlos Garnacho + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "clutter-input-device-tool.h" +#include "clutter-private.h" + +typedef struct _ClutterInputDeviceToolPrivate ClutterInputDeviceToolPrivate; + +struct _ClutterInputDeviceToolPrivate +{ + ClutterInputDeviceToolType type; + guint64 serial; +}; + +enum { + PROP_0, + PROP_TYPE, + PROP_SERIAL, + PROP_LAST +}; + +static GParamSpec *props[PROP_LAST] = { NULL, }; + +G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (ClutterInputDeviceTool, clutter_input_device_tool, G_TYPE_OBJECT) + +static void +clutter_input_device_tool_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + ClutterInputDeviceTool *tool = CLUTTER_INPUT_DEVICE_TOOL (object); + ClutterInputDeviceToolPrivate *priv; + + priv = clutter_input_device_tool_get_instance_private (tool); + + switch (prop_id) + { + case PROP_TYPE: + priv->type = g_value_get_enum (value); + break; + case PROP_SERIAL: + priv->serial = g_value_get_uint64 (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +clutter_input_device_tool_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + ClutterInputDeviceTool *tool = CLUTTER_INPUT_DEVICE_TOOL (object); + ClutterInputDeviceToolPrivate *priv; + + priv = clutter_input_device_tool_get_instance_private (tool); + + switch (prop_id) + { + case PROP_TYPE: + g_value_set_enum (value, priv->type); + break; + case PROP_SERIAL: + g_value_set_uint64 (value, priv->serial); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +clutter_input_device_tool_class_init (ClutterInputDeviceToolClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + + gobject_class->set_property = clutter_input_device_tool_set_property; + gobject_class->get_property = clutter_input_device_tool_get_property; + + props[PROP_TYPE] = + g_param_spec_enum ("type", + P_("Tool type"), + P_("Tool type"), + CLUTTER_TYPE_INPUT_DEVICE_TOOL_TYPE, + CLUTTER_INPUT_DEVICE_TOOL_NONE, + CLUTTER_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); + props[PROP_SERIAL] = + g_param_spec_uint64 ("serial", + P_("Tool serial"), + P_("Tool serial"), + 0, G_MAXUINT64, 0, + CLUTTER_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); + + g_object_class_install_properties (gobject_class, PROP_LAST, props); +} + +static void +clutter_input_device_tool_init (ClutterInputDeviceTool *tool) +{ +} + +/** + * clutter_input_device_tool_get_serial: + * @tool: a #ClutterInputDeviceTool + * + * Gets the serial of this tool, this value can be used to identify a + * physical tool (eg. a tablet pen) across program executions. + * + * Returns: The serial ID for this tool + * + * Since: 1.28 + **/ +guint +clutter_input_device_tool_get_serial (ClutterInputDeviceTool *tool) +{ + ClutterInputDeviceToolPrivate *priv; + + g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE_TOOL (tool), 0); + + priv = clutter_input_device_tool_get_instance_private (tool); + + return priv->serial; +} + + +/** + * clutter_input_device_tool_get_tool_type: + * @tool: a #ClutterInputDeviceTool + * + * Gets the tool type of this tool. + * + * Returns: The tool type of this tool + * + * Since: 1.28 + **/ +ClutterInputDeviceToolType +clutter_input_device_tool_get_tool_type (ClutterInputDeviceTool *tool) +{ + ClutterInputDeviceToolPrivate *priv; + + g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE_TOOL (tool), 0); + + priv = clutter_input_device_tool_get_instance_private (tool); + + return priv->type; +} diff --git a/clutter/clutter/clutter-input-device-tool.h b/clutter/clutter/clutter-input-device-tool.h new file mode 100644 index 000000000..8795d058d --- /dev/null +++ b/clutter/clutter/clutter-input-device-tool.h @@ -0,0 +1,66 @@ +/* + * Clutter. + * + * An OpenGL based 'interactive canvas' library. + * + * Copyright © 2009, 2010, 2011 Intel Corp. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + * + * Author: Carlos Garnacho + */ + +#ifndef __CLUTTER_INPUT_DEVICE_TOOL_H__ +#define __CLUTTER_INPUT_DEVICE_TOOL_H__ + +#if !defined(__CLUTTER_H_INSIDE__) && !defined(CLUTTER_COMPILATION) +#error "Only can be included directly." +#endif + +#include +#include "clutter-enum-types.h" + +G_BEGIN_DECLS + +#define CLUTTER_TYPE_INPUT_DEVICE_TOOL (clutter_input_device_tool_get_type ()) +#define CLUTTER_INPUT_DEVICE_TOOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_INPUT_DEVICE_TOOL, ClutterInputDeviceTool)) +#define CLUTTER_IS_INPUT_DEVICE_TOOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_INPUT_DEVICE_TOOL)) +#define CLUTTER_INPUT_DEVICE_TOOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLUTTER_TYPE_INPUT_DEVICE_TOOL, ClutterInputDeviceToolClass)) +#define CLUTTER_IS_INPUT_DEVICE_TOOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CLUTTER_TYPE_INPUT_DEVICE_TOOL)) +#define CLUTTER_INPUT_DEVICE_TOOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CLUTTER_TYPE_INPUT_DEVICE_TOOL, ClutterInputDeviceToolClass)) + +typedef struct _ClutterInputDeviceToolClass ClutterInputDeviceToolClass; + +struct _ClutterInputDeviceTool +{ + GObject parent_instance; +}; + +struct _ClutterInputDeviceToolClass +{ + GObjectClass parent_class; +}; + +CLUTTER_AVAILABLE_IN_ALL +GType clutter_input_device_tool_get_type (void) G_GNUC_CONST; + +CLUTTER_AVAILABLE_IN_ALL +guint clutter_input_device_tool_get_serial (ClutterInputDeviceTool *tool); + +CLUTTER_AVAILABLE_IN_ALL +ClutterInputDeviceToolType clutter_input_device_tool_get_tool_type (ClutterInputDeviceTool *tool); + +G_END_DECLS + +#endif /* __CLUTTER_INPUT_DEVICE_TOOL_H__ */ diff --git a/clutter/clutter/clutter-input-device.c b/clutter/clutter/clutter-input-device.c index d9fd4f5d1..add413d47 100644 --- a/clutter/clutter/clutter-input-device.c +++ b/clutter/clutter/clutter-input-device.c @@ -45,6 +45,7 @@ #include "clutter-marshal.h" #include "clutter-private.h" #include "clutter-stage-private.h" +#include "clutter-input-device-tool.h" #include @@ -2011,3 +2012,43 @@ clutter_input_device_get_product_id (ClutterInputDevice *device) return device->product_id; } + +void +clutter_input_device_add_tool (ClutterInputDevice *device, + ClutterInputDeviceTool *tool) +{ + g_return_if_fail (CLUTTER_IS_INPUT_DEVICE (device)); + g_return_if_fail (clutter_input_device_get_device_mode (device) != CLUTTER_INPUT_MODE_MASTER); + g_return_if_fail (CLUTTER_IS_INPUT_DEVICE_TOOL (tool)); + + if (!device->tools) + device->tools = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); + + g_ptr_array_add (device->tools, tool); +} + +ClutterInputDeviceTool * +clutter_input_device_lookup_tool (ClutterInputDevice *device, + guint64 serial, + ClutterInputDeviceToolType type) +{ + ClutterInputDeviceTool *tool; + guint i; + + g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), NULL); + g_return_val_if_fail (clutter_input_device_get_device_mode (device) != CLUTTER_INPUT_MODE_MASTER, NULL); + + if (!device->tools) + return NULL; + + for (i = 0; i < device->tools->len; i++) + { + tool = g_ptr_array_index (device->tools, i); + + if (serial == clutter_input_device_tool_get_serial (tool) && + type == clutter_input_device_tool_get_tool_type (tool)) + return tool; + } + + return NULL; +} diff --git a/clutter/clutter/clutter-types.h b/clutter/clutter/clutter-types.h index a8a08a3d1..fd4c7669a 100644 --- a/clutter/clutter/clutter-types.h +++ b/clutter/clutter/clutter-types.h @@ -92,6 +92,7 @@ typedef struct _ClutterAnimation ClutterAnimation; typedef struct _ClutterAnimator ClutterAnimator; typedef struct _ClutterState ClutterState; +typedef struct _ClutterInputDeviceTool ClutterInputDeviceTool; typedef struct _ClutterInputDevice ClutterInputDevice; typedef CoglMatrix ClutterMatrix; diff --git a/clutter/clutter/clutter.h b/clutter/clutter/clutter.h index 7d5c7506f..6f6a37d7a 100644 --- a/clutter/clutter/clutter.h +++ b/clutter/clutter/clutter.h @@ -71,6 +71,7 @@ #include "clutter-group.h" #include "clutter-image.h" #include "clutter-input-device.h" +#include "clutter-input-device-tool.h" #include "clutter-interval.h" #include "clutter-keyframe-transition.h" #include "clutter-keysyms.h"