mirror of
https://github.com/brl/mutter.git
synced 2024-12-01 12:20:47 -05:00
input-device: Add ClutterInputDeviceTool
This is an unique opaque struct that identifies a given tool of a given device.
This commit is contained in:
parent
aa0eea9814
commit
63b1a55283
@ -87,6 +87,7 @@ source_h = \
|
|||||||
clutter-group.h \
|
clutter-group.h \
|
||||||
clutter-image.h \
|
clutter-image.h \
|
||||||
clutter-input-device.h \
|
clutter-input-device.h \
|
||||||
|
clutter-input-device-tool.h \
|
||||||
clutter-interval.h \
|
clutter-interval.h \
|
||||||
clutter-keyframe-transition.h \
|
clutter-keyframe-transition.h \
|
||||||
clutter-keysyms.h \
|
clutter-keysyms.h \
|
||||||
@ -167,6 +168,7 @@ source_c = \
|
|||||||
clutter-grid-layout.c \
|
clutter-grid-layout.c \
|
||||||
clutter-image.c \
|
clutter-image.c \
|
||||||
clutter-input-device.c \
|
clutter-input-device.c \
|
||||||
|
clutter-input-device-tool.c \
|
||||||
clutter-interval.c \
|
clutter-interval.c \
|
||||||
clutter-keyframe-transition.c \
|
clutter-keyframe-transition.c \
|
||||||
clutter-keysyms-table.c \
|
clutter-keysyms-table.c \
|
||||||
|
@ -132,6 +132,8 @@ struct _ClutterInputDevice
|
|||||||
gchar *vendor_id;
|
gchar *vendor_id;
|
||||||
gchar *product_id;
|
gchar *product_id;
|
||||||
|
|
||||||
|
GPtrArray *tools;
|
||||||
|
|
||||||
guint has_cursor : 1;
|
guint has_cursor : 1;
|
||||||
guint is_enabled : 1;
|
guint is_enabled : 1;
|
||||||
};
|
};
|
||||||
@ -235,6 +237,12 @@ gboolean _clutter_input_device_get_scroll_delta (ClutterInputDev
|
|||||||
ClutterScrollDirection *direction_p,
|
ClutterScrollDirection *direction_p,
|
||||||
gdouble *delta_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
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __CLUTTER_DEVICE_MANAGER_PRIVATE_H__ */
|
#endif /* __CLUTTER_DEVICE_MANAGER_PRIVATE_H__ */
|
||||||
|
@ -1488,6 +1488,32 @@ typedef enum {
|
|||||||
CLUTTER_SCROLL_FINISHED_VERTICAL = 1 << 1
|
CLUTTER_SCROLL_FINISHED_VERTICAL = 1 << 1
|
||||||
} ClutterScrollFinishFlags;
|
} 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
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __CLUTTER_ENUMS_H__ */
|
#endif /* __CLUTTER_ENUMS_H__ */
|
||||||
|
172
clutter/clutter/clutter-input-device-tool.c
Normal file
172
clutter/clutter/clutter-input-device-tool.c
Normal file
@ -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;
|
||||||
|
}
|
66
clutter/clutter/clutter-input-device-tool.h
Normal file
66
clutter/clutter/clutter-input-device-tool.h
Normal file
@ -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_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__ */
|
@ -45,6 +45,7 @@
|
|||||||
#include "clutter-marshal.h"
|
#include "clutter-marshal.h"
|
||||||
#include "clutter-private.h"
|
#include "clutter-private.h"
|
||||||
#include "clutter-stage-private.h"
|
#include "clutter-stage-private.h"
|
||||||
|
#include "clutter-input-device-tool.h"
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
@ -2011,3 +2012,43 @@ clutter_input_device_get_product_id (ClutterInputDevice *device)
|
|||||||
|
|
||||||
return device->product_id;
|
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;
|
||||||
|
}
|
||||||
|
@ -92,6 +92,7 @@ typedef struct _ClutterAnimation ClutterAnimation;
|
|||||||
typedef struct _ClutterAnimator ClutterAnimator;
|
typedef struct _ClutterAnimator ClutterAnimator;
|
||||||
typedef struct _ClutterState ClutterState;
|
typedef struct _ClutterState ClutterState;
|
||||||
|
|
||||||
|
typedef struct _ClutterInputDeviceTool ClutterInputDeviceTool;
|
||||||
typedef struct _ClutterInputDevice ClutterInputDevice;
|
typedef struct _ClutterInputDevice ClutterInputDevice;
|
||||||
|
|
||||||
typedef CoglMatrix ClutterMatrix;
|
typedef CoglMatrix ClutterMatrix;
|
||||||
|
@ -71,6 +71,7 @@
|
|||||||
#include "clutter-group.h"
|
#include "clutter-group.h"
|
||||||
#include "clutter-image.h"
|
#include "clutter-image.h"
|
||||||
#include "clutter-input-device.h"
|
#include "clutter-input-device.h"
|
||||||
|
#include "clutter-input-device-tool.h"
|
||||||
#include "clutter-interval.h"
|
#include "clutter-interval.h"
|
||||||
#include "clutter-keyframe-transition.h"
|
#include "clutter-keyframe-transition.h"
|
||||||
#include "clutter-keysyms.h"
|
#include "clutter-keysyms.h"
|
||||||
|
Loading…
Reference in New Issue
Block a user