summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Garnacho <carlosg@gnome.org>2015-01-09 17:37:28 +0100
committerCarlos Garnacho <carlosg@gnome.org>2016-04-05 18:56:35 +0200
commit08aaea3d9c9c9e2239023feae9cd6d25c268a26d (patch)
treee2efe56bac78b77d4617f0955421b4b28ddbdfea
parentcbe1f5b810e7f7c5c79d7b3fffa103f30078f849 (diff)
downloadclutter-08aaea3d9c9c9e2239023feae9cd6d25c268a26d.tar.gz
input-device: Add ClutterInputDeviceTool
This is an unique opaque struct that identifies a given tool of a given device.
-rw-r--r--clutter/Makefile.am2
-rw-r--r--clutter/clutter-device-manager-private.h8
-rw-r--r--clutter/clutter-enums.h26
-rw-r--r--clutter/clutter-input-device-tool.c172
-rw-r--r--clutter/clutter-input-device-tool.h66
-rw-r--r--clutter/clutter-input-device.c41
-rw-r--r--clutter/clutter-types.h1
-rw-r--r--clutter/clutter.h1
-rw-r--r--doc/reference/clutter-sections.txt6
9 files changed, 323 insertions, 0 deletions
diff --git a/clutter/Makefile.am b/clutter/Makefile.am
index c285f433c..652f42b98 100644
--- a/clutter/Makefile.am
+++ b/clutter/Makefile.am
@@ -89,6 +89,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 \
@@ -169,6 +170,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-device-manager-private.h b/clutter/clutter-device-manager-private.h
index 4aa169371..3b33135af 100644
--- a/clutter/clutter-device-manager-private.h
+++ b/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-enums.h b/clutter/clutter-enums.h
index e44744d56..6794c2bd9 100644
--- a/clutter/clutter-enums.h
+++ b/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-input-device-tool.c b/clutter/clutter-input-device-tool.c
new file mode 100644
index 000000000..547801ead
--- /dev/null
+++ b/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 <http://www.gnu.org/licenses/>.
+ *
+ * Author: Carlos Garnacho <carlosg@gnome.org>
+ */
+
+#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-input-device-tool.h b/clutter/clutter-input-device-tool.h
new file mode 100644
index 000000000..ace8d1d19
--- /dev/null
+++ b/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 <http://www.gnu.org/licenses/>.
+ *
+ * Author: Carlos Garnacho <carlosg@gnome.org>
+ */
+
+#ifndef __CLUTTER_INPUT_DEVICE_TOOL_H__
+#define __CLUTTER_INPUT_DEVICE_TOOL_H__
+
+#if !defined(__CLUTTER_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
+#error "Only <clutter/clutter.h> can be included directly."
+#endif
+
+#include <clutter/clutter-types.h>
+#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_1_28
+GType clutter_input_device_tool_get_type (void) G_GNUC_CONST;
+
+CLUTTER_AVAILABLE_IN_1_28
+guint clutter_input_device_tool_get_serial (ClutterInputDeviceTool *tool);
+
+CLUTTER_AVAILABLE_IN_1_28
+ClutterInputDeviceToolType clutter_input_device_tool_get_tool_type (ClutterInputDeviceTool *tool);
+
+G_END_DECLS
+
+#endif /* __CLUTTER_INPUT_DEVICE_TOOL_H__ */
diff --git a/clutter/clutter-input-device.c b/clutter/clutter-input-device.c
index d9fd4f5d1..add413d47 100644
--- a/clutter/clutter-input-device.c
+++ b/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 <math.h>
@@ -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-types.h b/clutter/clutter-types.h
index a8a08a3d1..fd4c7669a 100644
--- a/clutter/clutter-types.h
+++ b/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.h b/clutter/clutter.h
index 7d5c7506f..6f6a37d7a 100644
--- a/clutter/clutter.h
+++ b/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"
diff --git a/doc/reference/clutter-sections.txt b/doc/reference/clutter-sections.txt
index bb40d33e5..b6596b2f0 100644
--- a/doc/reference/clutter-sections.txt
+++ b/doc/reference/clutter-sections.txt
@@ -1251,6 +1251,12 @@ clutter_input_device_sequence_get_grabbed_actor
<SUBSECTION>
clutter_input_device_update_from_event
+<SUBSECTION>
+ClutterInputDeviceTool
+ClutterInputDeviceToolType
+clutter_input_device_tool_get_serial
+clutter_input_device_tool_get_tool_type
+
<SUBSECTION Standard>
CLUTTER_TYPE_INPUT_DEVICE
CLUTTER_INPUT_DEVICE