Debian Codegraph @

clutter/osx/clutter-device-manager-osx.c

raw
1 /*
2 * Clutter.
3 *
4 * An OpenGL based 'interactive canvas' library.
5 *
6 * Copyright (C) 2009 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: Emmanuele Bassi <[email protected]>
22 */
23
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #include "clutter-backend-osx.h"
29 #include "clutter-device-manager-osx.h"
30 #include "clutter-device-manager-osx.h"
31 #include "clutter-stage-osx.h"
32
33 #include "clutter-backend.h"
34 #include "clutter-debug.h"
35 #include "clutter-device-manager-private.h"
36 #include "clutter-private.h"
37
38 enum
39 {
40 PROP_0
41 };
42
43 G_DEFINE_TYPE (ClutterDeviceManagerOSX,
44 clutter_device_manager_osx,
45 CLUTTER_TYPE_DEVICE_MANAGER);
46
47 static void
48 clutter_device_manager_osx_constructed (GObject *gobject)
49 {
50 ClutterDeviceManager *manager = CLUTTER_DEVICE_MANAGER (gobject);
51 ClutterDeviceManagerOSX *manager_osx;
52 ClutterInputDevice *device;
53
54 device = g_object_new (CLUTTER_TYPE_INPUT_DEVICE,
55 "id", 0,
56 "name", "Core Pointer",
57 "device-type", CLUTTER_POINTER_DEVICE,
58 "device-mode", CLUTTER_INPUT_MODE_MASTER,
59 "has-cursor", TRUE,
60 "enabled", TRUE,
61 NULL);
62 CLUTTER_NOTE (BACKEND, "Added core pointer device");
63 _clutter_device_manager_add_device (manager, device);
64
65 device = g_object_new (CLUTTER_TYPE_INPUT_DEVICE,
66 "id", 1,
67 "name", "Core Keyboard",
68 "device-type", CLUTTER_KEYBOARD_DEVICE,
69 "device-mode", CLUTTER_INPUT_MODE_MASTER,
70 "enabled", TRUE,
71 NULL);
72 CLUTTER_NOTE (BACKEND, "Added core keyboard device");
73 _clutter_device_manager_add_device (manager, device);
74
75 manager_osx = CLUTTER_DEVICE_MANAGER_OSX (manager);
76
77 _clutter_input_device_set_associated_device (manager_osx->core_pointer,
78 manager_osx->core_keyboard);
79 _clutter_input_device_set_associated_device (manager_osx->core_keyboard,
80 manager_osx->core_pointer);
81 }
82
83 static void
84 clutter_device_manager_osx_add_device (ClutterDeviceManager *manager,
85 ClutterInputDevice *device)
86 {
87 ClutterDeviceManagerOSX *manager_osx = CLUTTER_DEVICE_MANAGER_OSX (manager);
88 ClutterInputDeviceType device_type;
89 gboolean is_pointer, is_keyboard;
90
91 device_type = clutter_input_device_get_device_type (device);
92 is_pointer = (device_type == CLUTTER_POINTER_DEVICE) ? TRUE : FALSE;
93 is_keyboard = (device_type == CLUTTER_KEYBOARD_DEVICE) ? TRUE : FALSE;
94
95 manager_osx->devices = g_slist_prepend (manager_osx->devices, device);
96
97 if (is_pointer && manager_osx->core_pointer == NULL)
98 manager_osx->core_pointer = device;
99
100 if (is_keyboard && manager_osx->core_keyboard == NULL)
101 manager_osx->core_keyboard = device;
102 }
103
104 static void
105 clutter_device_manager_osx_remove_device (ClutterDeviceManager *manager,
106 ClutterInputDevice *device)
107 {
108 ClutterDeviceManagerOSX *manager_osx = CLUTTER_DEVICE_MANAGER_OSX (manager);
109
110 manager_osx->devices = g_slist_remove (manager_osx->devices, device);
111 }
112
113 static const GSList *
114 clutter_device_manager_osx_get_devices (ClutterDeviceManager *manager)
115 {
116 return CLUTTER_DEVICE_MANAGER_OSX (manager)->devices;
117 }
118
119 static ClutterInputDevice *
120 clutter_device_manager_osx_get_core_device (ClutterDeviceManager *manager,
121 ClutterInputDeviceType type)
122 {
123 ClutterDeviceManagerOSX *manager_osx;
124
125 manager_osx = CLUTTER_DEVICE_MANAGER_OSX (manager);
126
127 switch (type)
128 {
129 case CLUTTER_POINTER_DEVICE:
130 return manager_osx->core_pointer;
131
132 case CLUTTER_KEYBOARD_DEVICE:
133 return manager_osx->core_keyboard;
134
135 case CLUTTER_EXTENSION_DEVICE:
136 default:
137 return NULL;
138 }
139
140 return NULL;
141 }
142
143 static ClutterInputDevice *
144 clutter_device_manager_osx_get_device (ClutterDeviceManager *manager,
145 gint id_)
146 {
147 ClutterDeviceManagerOSX *manager_osx = CLUTTER_DEVICE_MANAGER_OSX (manager);
148 GSList *l;
149
150 for (l = manager_osx->devices; l != NULL; l = l->next)
151 {
152 ClutterInputDevice *device = l->data;
153
154 if (clutter_input_device_get_device_id (device) == id_)
155 return device;
156 }
157
158 return NULL;
159 }
160
161 static void
162 clutter_device_manager_osx_class_init (ClutterDeviceManagerOSXClass *klass)
163 {
164 ClutterDeviceManagerClass *manager_class;
165 GObjectClass *gobject_class = (GObjectClass *) klass;
166
167 gobject_class->constructed = clutter_device_manager_osx_constructed;
168
169 manager_class = CLUTTER_DEVICE_MANAGER_CLASS (klass);
170 manager_class->add_device = clutter_device_manager_osx_add_device;
171 manager_class->remove_device = clutter_device_manager_osx_remove_device;
172 manager_class->get_devices = clutter_device_manager_osx_get_devices;
173 manager_class->get_core_device = clutter_device_manager_osx_get_core_device;
174 manager_class->get_device = clutter_device_manager_osx_get_device;
175 }
176
177 static void
178 clutter_device_manager_osx_init (ClutterDeviceManagerOSX *self)
179 {
180 }