| 1 |
/* |
| 2 |
* Clutter. |
| 3 |
* |
| 4 |
* An OpenGL based 'interactive canvas' library. |
| 5 |
* |
| 6 |
* Copyright © 2011 Intel Corp. |
| 7 |
* 2011 Giovanni Campagna <[email protected]> |
| 8 |
* |
| 9 |
* This library is free software; you can redistribute it and/or |
| 10 |
* modify it under the terms of the GNU Lesser General Public |
| 11 |
* License as published by the Free Software Foundation; either |
| 12 |
* version 2 of the License, or (at your option) any later version. |
| 13 |
* |
| 14 |
* This library is distributed in the hope that it will be useful, |
| 15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 |
* Lesser General Public License for more details. |
| 18 |
* |
| 19 |
* You should have received a copy of the GNU Lesser General Public |
| 20 |
* License along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 21 |
* |
| 22 |
* Author: Emmanuele Bassi <[email protected]> |
| 23 |
*/ |
| 24 |
|
| 25 |
#include "config.h" |
| 26 |
|
| 27 |
#include "clutter-input-device-gdk.h" |
| 28 |
|
| 29 |
#ifdef GDK_WINDOWING_X11 |
| 30 |
#include <gdk/gdkx.h> |
| 31 |
#endif |
| 32 |
|
| 33 |
#include "clutter-debug.h" |
| 34 |
#include "clutter-device-manager-private.h" |
| 35 |
#include "clutter-private.h" |
| 36 |
#include "clutter-stage-private.h" |
| 37 |
|
| 38 |
#include "clutter-backend-gdk.h" |
| 39 |
#include "clutter-stage-gdk.h" |
| 40 |
|
| 41 |
typedef struct _ClutterInputDeviceClass ClutterInputDeviceGdkClass; |
| 42 |
|
| 43 |
#define clutter_input_device_gdk_get_type _clutter_input_device_gdk_get_type |
| 44 |
|
| 45 |
G_DEFINE_TYPE (ClutterInputDeviceGdk, |
| 46 |
clutter_input_device_gdk, |
| 47 |
CLUTTER_TYPE_INPUT_DEVICE); |
| 48 |
|
| 49 |
static int device_int_counter; |
| 50 |
|
| 51 |
enum { |
| 52 |
PROP_0, |
| 53 |
PROP_GDK_DEVICE, |
| 54 |
PROP_LAST |
| 55 |
}; |
| 56 |
|
| 57 |
static void |
| 58 |
clutter_input_device_gdk_set_property (GObject *gobject, |
| 59 |
guint prop_id, |
| 60 |
const GValue *value, |
| 61 |
GParamSpec *pspec) |
| 62 |
{ |
| 63 |
ClutterInputDeviceGdk *self = CLUTTER_INPUT_DEVICE_GDK (gobject); |
| 64 |
|
| 65 |
switch (prop_id) |
| 66 |
{ |
| 67 |
case PROP_GDK_DEVICE: |
| 68 |
self->gdk_device = GDK_DEVICE (g_value_get_object (value)); |
| 69 |
break; |
| 70 |
|
| 71 |
default: |
| 72 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); |
| 73 |
break; |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
static void |
| 78 |
clutter_input_device_gdk_class_init (ClutterInputDeviceGdkClass *klass) |
| 79 |
{ |
| 80 |
GObjectClass *gobject_class = G_OBJECT_CLASS (klass); |
| 81 |
|
| 82 |
gobject_class->set_property = clutter_input_device_gdk_set_property; |
| 83 |
|
| 84 |
g_object_class_install_property (gobject_class, PROP_GDK_DEVICE, |
| 85 |
g_param_spec_object ("gdk-device", |
| 86 |
"GdkDevice", |
| 87 |
"The GDK device", |
| 88 |
GDK_TYPE_DEVICE, |
| 89 |
CLUTTER_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
| 90 |
} |
| 91 |
|
| 92 |
static void |
| 93 |
clutter_input_device_gdk_init (ClutterInputDeviceGdk *self) |
| 94 |
{ |
| 95 |
} |
| 96 |
|
| 97 |
ClutterInputDevice* |
| 98 |
_clutter_input_device_gdk_new (ClutterDeviceManager *manager, |
| 99 |
GdkDevice *device) |
| 100 |
{ |
| 101 |
ClutterBackend *backend; |
| 102 |
ClutterInputDevice *clutter_device; |
| 103 |
ClutterInputMode input_mode = CLUTTER_INPUT_MODE_FLOATING; |
| 104 |
ClutterInputDeviceType device_type = CLUTTER_EXTENSION_DEVICE; |
| 105 |
gboolean has_cursor = FALSE; |
| 106 |
const gchar *name; |
| 107 |
gboolean is_enabled = FALSE; |
| 108 |
gint device_id; |
| 109 |
const char *vendor_id = NULL; |
| 110 |
const char *product_id = NULL; |
| 111 |
|
| 112 |
g_object_get (manager, "backend", &backend, NULL); |
| 113 |
|
| 114 |
/* yay for name consistency */ |
| 115 |
switch (gdk_device_get_device_type (device)) |
| 116 |
{ |
| 117 |
case GDK_DEVICE_TYPE_MASTER: |
| 118 |
input_mode = CLUTTER_INPUT_MODE_MASTER; |
| 119 |
is_enabled = TRUE; |
| 120 |
break; |
| 121 |
case GDK_DEVICE_TYPE_SLAVE: |
| 122 |
input_mode = CLUTTER_INPUT_MODE_SLAVE; |
| 123 |
is_enabled = FALSE; |
| 124 |
break; |
| 125 |
case GDK_DEVICE_TYPE_FLOATING: |
| 126 |
input_mode = CLUTTER_INPUT_MODE_FLOATING; |
| 127 |
is_enabled = FALSE; |
| 128 |
break; |
| 129 |
} |
| 130 |
|
| 131 |
switch (gdk_device_get_source (device)) |
| 132 |
{ |
| 133 |
case GDK_SOURCE_MOUSE: |
| 134 |
device_type = CLUTTER_POINTER_DEVICE; |
| 135 |
break; |
| 136 |
case GDK_SOURCE_PEN: |
| 137 |
device_type = CLUTTER_PEN_DEVICE; |
| 138 |
break; |
| 139 |
case GDK_SOURCE_ERASER: |
| 140 |
device_type = CLUTTER_ERASER_DEVICE; |
| 141 |
break; |
| 142 |
case GDK_SOURCE_CURSOR: |
| 143 |
device_type = CLUTTER_CURSOR_DEVICE; |
| 144 |
break; |
| 145 |
case GDK_SOURCE_KEYBOARD: |
| 146 |
device_type = CLUTTER_KEYBOARD_DEVICE; |
| 147 |
break; |
| 148 |
case GDK_SOURCE_TOUCHSCREEN: |
| 149 |
device_type = CLUTTER_TOUCHSCREEN_DEVICE; |
| 150 |
break; |
| 151 |
case GDK_SOURCE_TOUCHPAD: |
| 152 |
device_type = CLUTTER_TOUCHPAD_DEVICE; |
| 153 |
break; |
| 154 |
case GDK_SOURCE_TRACKPOINT: |
| 155 |
device_type = CLUTTER_POINTER_DEVICE; |
| 156 |
break; |
| 157 |
case GDK_SOURCE_TABLET_PAD: |
| 158 |
device_type = CLUTTER_CURSOR_DEVICE; |
| 159 |
break; |
| 160 |
} |
| 161 |
|
| 162 |
if (device_type != CLUTTER_KEYBOARD_DEVICE) |
| 163 |
has_cursor = gdk_device_get_has_cursor (device); |
| 164 |
|
| 165 |
name = gdk_device_get_name (device); |
| 166 |
|
| 167 |
#if defined(GDK_WINDOWING_X11) |
| 168 |
/* If we're on X11, keep the device id in sync */ |
| 169 |
if (GDK_IS_X11_DISPLAY (gdk_device_get_display (device))) |
| 170 |
device_id = gdk_x11_device_get_id (device); |
| 171 |
else |
| 172 |
#endif |
| 173 |
device_id = device_int_counter++; |
| 174 |
|
| 175 |
if (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER) |
| 176 |
{ |
| 177 |
product_id = gdk_device_get_product_id (device); |
| 178 |
vendor_id = gdk_device_get_vendor_id (device); |
| 179 |
} |
| 180 |
|
| 181 |
clutter_device = g_object_new (CLUTTER_TYPE_INPUT_DEVICE_GDK, |
| 182 |
"backend", backend, |
| 183 |
"device-manager", manager, |
| 184 |
"device-mode", input_mode, |
| 185 |
"device-type", device_type, |
| 186 |
"has-cursor", has_cursor, |
| 187 |
"gdk-device", device, |
| 188 |
"id", device_id, |
| 189 |
"name", name, |
| 190 |
"enabled", is_enabled, |
| 191 |
"product-id", product_id, |
| 192 |
"vendor-id", vendor_id, |
| 193 |
NULL); |
| 194 |
return clutter_device; |
| 195 |
} |