summaryrefslogtreecommitdiff
path: root/clutter/clutter/clutter-input-device-tool.c
blob: 982d94ce4067dca7b19179b5e8644837b1455498 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*
 * 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>
 */

#include "clutter-build-config.h"

#include "clutter-input-device-tool.h"
#include "clutter-private.h"

typedef struct _ClutterInputDeviceToolPrivate ClutterInputDeviceToolPrivate;

struct _ClutterInputDeviceToolPrivate
{
  ClutterInputDeviceToolType type;
  guint64 serial;
  guint64 id;
};

enum
{
  PROP_0,
  PROP_TYPE,
  PROP_SERIAL,
  PROP_ID,
  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;
    case PROP_ID:
      priv->id = 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;
    case PROP_ID:
      g_value_set_uint64 (value, priv->id);
      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);
  props[PROP_ID] =
    g_param_spec_uint64 ("id",
                         P_("Tool ID"),
                         P_("Tool ID"),
                         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
 **/
guint64
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;
}

/**
 * clutter_input_device_tool_get_id:
 * @tool: a #ClutterInputDeviceTool
 *
 * Gets the ID of this tool, this value can be used to identify a
 * physical tool (eg. a tablet pen) across program executions.
 *
 * Returns: The tool ID for this tool
 **/
guint64
clutter_input_device_tool_get_id (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->id;
}