| 1 |
/* |
| 2 |
* Clutter. |
| 3 |
* |
| 4 |
* An OpenGL based 'interactive canvas' library. |
| 5 |
* |
| 6 |
* Copyright (C) 2014 Canonical Ltd. |
| 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 |
* Authors: |
| 22 |
* Marco Trevisan <[email protected]> |
| 23 |
*/ |
| 24 |
|
| 25 |
#ifdef HAVE_CONFIG_H |
| 26 |
#include "config.h" |
| 27 |
#endif |
| 28 |
|
| 29 |
#include "clutter-device-manager-private.h" |
| 30 |
#include "clutter-input-device-mir.h" |
| 31 |
#include "clutter-device-manager-mir.h" |
| 32 |
|
| 33 |
static guint device_counter; |
| 34 |
|
| 35 |
G_DEFINE_TYPE (ClutterDeviceManagerMir, _clutter_device_manager_mir, CLUTTER_TYPE_DEVICE_MANAGER); |
| 36 |
|
| 37 |
static void |
| 38 |
clutter_device_manager_mir_add_device (ClutterDeviceManager *manager, |
| 39 |
ClutterInputDevice *device) |
| 40 |
{ |
| 41 |
ClutterDeviceManagerMir *manager_mir = CLUTTER_DEVICE_MANAGER_MIR (manager); |
| 42 |
manager_mir->devices = g_slist_prepend (manager_mir->devices, device); |
| 43 |
} |
| 44 |
|
| 45 |
static void |
| 46 |
clutter_device_manager_mir_remove_device (ClutterDeviceManager *manager, |
| 47 |
ClutterInputDevice *device) |
| 48 |
{ |
| 49 |
ClutterDeviceManagerMir *manager_mir = CLUTTER_DEVICE_MANAGER_MIR (manager); |
| 50 |
manager_mir->devices = g_slist_remove (manager_mir->devices, device); |
| 51 |
} |
| 52 |
|
| 53 |
static const GSList * |
| 54 |
clutter_device_manager_mir_get_devices (ClutterDeviceManager *manager) |
| 55 |
{ |
| 56 |
return CLUTTER_DEVICE_MANAGER_MIR (manager)->devices; |
| 57 |
} |
| 58 |
|
| 59 |
static ClutterInputDevice * |
| 60 |
clutter_device_manager_mir_get_core_device (ClutterDeviceManager *manager, |
| 61 |
ClutterInputDeviceType type) |
| 62 |
{ |
| 63 |
ClutterDeviceManagerMir *manager_mir; |
| 64 |
|
| 65 |
manager_mir = CLUTTER_DEVICE_MANAGER_MIR (manager); |
| 66 |
|
| 67 |
switch (type) |
| 68 |
{ |
| 69 |
case CLUTTER_POINTER_DEVICE: |
| 70 |
return manager_mir->core_pointer; |
| 71 |
|
| 72 |
case CLUTTER_KEYBOARD_DEVICE: |
| 73 |
return manager_mir->core_keyboard; |
| 74 |
|
| 75 |
case CLUTTER_EXTENSION_DEVICE: |
| 76 |
default: |
| 77 |
return NULL; |
| 78 |
} |
| 79 |
|
| 80 |
return NULL; |
| 81 |
} |
| 82 |
|
| 83 |
static ClutterInputDevice * |
| 84 |
clutter_device_manager_mir_get_device (ClutterDeviceManager *manager, |
| 85 |
gint id) |
| 86 |
{ |
| 87 |
ClutterDeviceManagerMir *manager_mir = |
| 88 |
CLUTTER_DEVICE_MANAGER_MIR (manager); |
| 89 |
GSList *l; |
| 90 |
|
| 91 |
for (l = manager_mir->devices; l != NULL; l = l->next) |
| 92 |
{ |
| 93 |
ClutterInputDevice *device = l->data; |
| 94 |
|
| 95 |
if (clutter_input_device_get_device_id (device) == id) |
| 96 |
return device; |
| 97 |
} |
| 98 |
|
| 99 |
return NULL; |
| 100 |
} |
| 101 |
|
| 102 |
static void |
| 103 |
clutter_device_manager_mir_constructed (GObject *gobject) |
| 104 |
{ |
| 105 |
ClutterBackend *backend; |
| 106 |
ClutterDeviceManager *manager; |
| 107 |
ClutterDeviceManagerMir *manager_mir; |
| 108 |
ClutterInputDevice *device; |
| 109 |
|
| 110 |
manager = CLUTTER_DEVICE_MANAGER (gobject); |
| 111 |
manager_mir = CLUTTER_DEVICE_MANAGER_MIR (manager); |
| 112 |
|
| 113 |
g_object_get (manager, "backend", &backend, NULL); |
| 114 |
|
| 115 |
device = g_object_new (CLUTTER_TYPE_INPUT_DEVICE_MIR, |
| 116 |
"id", device_counter++, |
| 117 |
"backend", backend, |
| 118 |
"device-manager", manager, |
| 119 |
"device-type", CLUTTER_POINTER_DEVICE, |
| 120 |
"device-mode", CLUTTER_INPUT_MODE_MASTER, |
| 121 |
"name", "Mir pointer", |
| 122 |
"enabled", TRUE, |
| 123 |
"has-cursor", TRUE, |
| 124 |
NULL); |
| 125 |
|
| 126 |
manager_mir->core_pointer = device; |
| 127 |
_clutter_device_manager_add_device (manager, CLUTTER_INPUT_DEVICE (device)); |
| 128 |
|
| 129 |
device = g_object_new (CLUTTER_TYPE_INPUT_DEVICE_MIR, |
| 130 |
"id", device_counter++, |
| 131 |
"backend", backend, |
| 132 |
"device-manager", manager, |
| 133 |
"device-type", CLUTTER_KEYBOARD_DEVICE, |
| 134 |
"device-mode", CLUTTER_INPUT_MODE_MASTER, |
| 135 |
"name", "Mir keyboard", |
| 136 |
"enabled", TRUE, |
| 137 |
"has-cursor", FALSE, |
| 138 |
NULL); |
| 139 |
|
| 140 |
manager_mir->core_keyboard = device; |
| 141 |
_clutter_device_manager_add_device (manager, CLUTTER_INPUT_DEVICE (device)); |
| 142 |
|
| 143 |
_clutter_input_device_set_associated_device (manager_mir->core_pointer, |
| 144 |
manager_mir->core_keyboard); |
| 145 |
_clutter_input_device_set_associated_device (manager_mir->core_keyboard, |
| 146 |
manager_mir->core_pointer); |
| 147 |
|
| 148 |
if (G_OBJECT_CLASS (_clutter_device_manager_mir_parent_class)->constructed) |
| 149 |
G_OBJECT_CLASS (_clutter_device_manager_mir_parent_class)->constructed (gobject); |
| 150 |
} |
| 151 |
|
| 152 |
static void |
| 153 |
clutter_device_manager_mir_finalize (GObject *gobject) |
| 154 |
{ |
| 155 |
ClutterDeviceManagerMir *manager_mir; |
| 156 |
|
| 157 |
manager_mir = CLUTTER_DEVICE_MANAGER_MIR (gobject); |
| 158 |
g_slist_free_full (manager_mir->devices, g_object_unref); |
| 159 |
|
| 160 |
G_OBJECT_CLASS (_clutter_device_manager_mir_parent_class)->finalize (gobject); |
| 161 |
} |
| 162 |
|
| 163 |
static void |
| 164 |
_clutter_device_manager_mir_class_init (ClutterDeviceManagerMirClass *klass) |
| 165 |
{ |
| 166 |
ClutterDeviceManagerClass *manager_class; |
| 167 |
GObjectClass *gobject_class; |
| 168 |
|
| 169 |
gobject_class = G_OBJECT_CLASS (klass); |
| 170 |
gobject_class->constructed = clutter_device_manager_mir_constructed; |
| 171 |
gobject_class->finalize = clutter_device_manager_mir_finalize; |
| 172 |
|
| 173 |
manager_class = CLUTTER_DEVICE_MANAGER_CLASS (klass); |
| 174 |
manager_class->add_device = clutter_device_manager_mir_add_device; |
| 175 |
manager_class->remove_device = clutter_device_manager_mir_remove_device; |
| 176 |
manager_class->get_devices = clutter_device_manager_mir_get_devices; |
| 177 |
manager_class->get_core_device = clutter_device_manager_mir_get_core_device; |
| 178 |
manager_class->get_device = clutter_device_manager_mir_get_device; |
| 179 |
} |
| 180 |
|
| 181 |
static void |
| 182 |
_clutter_device_manager_mir_init (ClutterDeviceManagerMir *self) |
| 183 |
{ |
| 184 |
} |
| 185 |
|
| 186 |
ClutterDeviceManager * |
| 187 |
_clutter_device_manager_mir_new (ClutterBackend *backend) |
| 188 |
{ |
| 189 |
return g_object_new (CLUTTER_TYPE_DEVICE_MANAGER_MIR, |
| 190 |
"backend", backend, |
| 191 |
NULL); |
| 192 |
} |