Release Clutter 1.11.4 (snapshot)
[profile/ivi/clutter.git] / clutter / evdev / clutter-input-device-evdev.c
1 /*
2  * Clutter.
3  *
4  * An OpenGL based 'interactive canvas' library.
5  *
6  * Copyright (C) 2010 Intel Corp.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
20  *
21  * Author: Damien Lespiau <damien.lespiau@intel.com>
22  */
23
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #include "clutter/clutter-device-manager-private.h"
29 #include "clutter-private.h"
30
31 #include "clutter-input-device-evdev.h"
32
33 typedef struct _ClutterInputDeviceClass        ClutterInputDeviceEvdevClass;
34 typedef struct _ClutterInputDeviceEvdevPrivate ClutterInputDeviceEvdevPrivate;
35
36 #define INPUT_DEVICE_EVDEV_PRIVATE(o)                             \
37   (G_TYPE_INSTANCE_GET_PRIVATE ((o),                              \
38                                 CLUTTER_TYPE_INPUT_DEVICE_EVDEV,  \
39                                 ClutterInputDeviceEvdevPrivate))
40
41 enum
42 {
43   PROP_0,
44
45   PROP_SYSFS_PATH,
46   PROP_DEVICE_PATH,
47
48   PROP_LAST
49 };
50
51 struct _ClutterInputDeviceEvdevPrivate
52 {
53   gchar *sysfs_path;
54   gchar *device_path;
55 };
56
57 struct _ClutterInputDeviceEvdev
58 {
59   ClutterInputDevice parent;
60
61   ClutterInputDeviceEvdevPrivate *priv;
62 };
63
64 G_DEFINE_TYPE (ClutterInputDeviceEvdev,
65                clutter_input_device_evdev,
66                CLUTTER_TYPE_INPUT_DEVICE)
67
68 static GParamSpec *obj_props[PROP_LAST];
69
70 static void
71 clutter_input_device_evdev_get_property (GObject    *object,
72                                          guint       property_id,
73                                          GValue     *value,
74                                          GParamSpec *pspec)
75 {
76   ClutterInputDeviceEvdev  *input = CLUTTER_INPUT_DEVICE_EVDEV (object);
77   ClutterInputDeviceEvdevPrivate *priv = input->priv;
78
79   switch (property_id)
80     {
81     case PROP_SYSFS_PATH:
82       g_value_set_string (value, priv->sysfs_path);
83       break;
84     case PROP_DEVICE_PATH:
85       g_value_set_string (value, priv->device_path);
86       break;
87     default:
88       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
89     }
90 }
91
92 static void
93 clutter_input_device_evdev_set_property (GObject      *object,
94                                          guint         property_id,
95                                          const GValue *value,
96                                          GParamSpec   *pspec)
97 {
98   ClutterInputDeviceEvdev  *input = CLUTTER_INPUT_DEVICE_EVDEV (object);
99   ClutterInputDeviceEvdevPrivate *priv = input->priv;
100
101   switch (property_id)
102     {
103     case PROP_SYSFS_PATH:
104       priv->sysfs_path = g_value_dup_string (value);
105       break;
106     case PROP_DEVICE_PATH:
107       priv->device_path = g_value_dup_string (value);
108       break;
109     default:
110       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
111     }
112 }
113
114 static void
115 clutter_input_device_evdev_finalize (GObject *object)
116 {
117   ClutterInputDeviceEvdev  *input = CLUTTER_INPUT_DEVICE_EVDEV (object);
118   ClutterInputDeviceEvdevPrivate *priv = input->priv;
119
120   g_free (priv->sysfs_path);
121   g_free (priv->device_path);
122
123   G_OBJECT_CLASS (clutter_input_device_evdev_parent_class)->finalize (object);
124 }
125
126 static gboolean
127 clutter_input_device_evdev_keycode_to_evdev (ClutterInputDevice *device,
128                                              guint hardware_keycode,
129                                              guint *evdev_keycode)
130 {
131   /* The hardware keycodes from the evdev backend are already evdev
132      keycodes */
133   *evdev_keycode = hardware_keycode;
134   return TRUE;
135 }
136
137 static void
138 clutter_input_device_evdev_class_init (ClutterInputDeviceEvdevClass *klass)
139 {
140   GObjectClass *object_class = G_OBJECT_CLASS (klass);
141   GParamSpec *pspec;
142
143   g_type_class_add_private (klass, sizeof (ClutterInputDeviceEvdevPrivate));
144
145   object_class->get_property = clutter_input_device_evdev_get_property;
146   object_class->set_property = clutter_input_device_evdev_set_property;
147   object_class->finalize = clutter_input_device_evdev_finalize;
148   klass->keycode_to_evdev = clutter_input_device_evdev_keycode_to_evdev;
149
150   /*
151    * ClutterInputDeviceEvdev:udev-device:
152    *
153    * The Sysfs path of the device
154    *
155    * Since: 1.6
156    */
157   pspec =
158     g_param_spec_string ("sysfs-path",
159                          P_("sysfs Path"),
160                          P_("Path of the device in sysfs"),
161                          NULL,
162                          G_PARAM_CONSTRUCT_ONLY | CLUTTER_PARAM_READWRITE);
163   obj_props[PROP_SYSFS_PATH] = pspec;
164   g_object_class_install_property (object_class, PROP_SYSFS_PATH, pspec);
165
166   /*
167    * ClutterInputDeviceEvdev:device-path
168    *
169    * The path of the device file.
170    *
171    * Since: 1.6
172    */
173   pspec =
174     g_param_spec_string ("device-path",
175                          P_("Device Path"),
176                          P_("Path of the device node"),
177                          NULL,
178                          G_PARAM_CONSTRUCT_ONLY | CLUTTER_PARAM_READWRITE);
179   obj_props[PROP_DEVICE_PATH] = pspec;
180   g_object_class_install_property (object_class, PROP_DEVICE_PATH, pspec);
181 }
182
183 static void
184 clutter_input_device_evdev_init (ClutterInputDeviceEvdev *self)
185 {
186   self->priv = INPUT_DEVICE_EVDEV_PRIVATE (self);
187 }
188
189 ClutterInputDeviceEvdev *
190 _clutter_input_device_evdev_new (void)
191 {
192   return g_object_new (CLUTTER_TYPE_INPUT_DEVICE_EVDEV, NULL);
193 }
194
195 const gchar *
196 _clutter_input_device_evdev_get_sysfs_path (ClutterInputDeviceEvdev *device)
197 {
198   g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE_EVDEV (device), NULL);
199
200   return device->priv->sysfs_path;
201 }
202
203 const gchar *
204 _clutter_input_device_evdev_get_device_path (ClutterInputDeviceEvdev *device)
205 {
206   g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE_EVDEV (device), NULL);
207
208   return device->priv->device_path;
209 }