| 1 |
/* |
| 2 |
* Clutter. |
| 3 |
* |
| 4 |
* An OpenGL based 'interactive canvas' library. |
| 5 |
* |
| 6 |
* Copyright © 2011 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 |
#include "config.h" |
| 25 |
|
| 26 |
#include <stdint.h> |
| 27 |
|
| 28 |
#include "clutter-device-manager-xi2.h" |
| 29 |
|
| 30 |
#include "clutter-backend-x11.h" |
| 31 |
#include "clutter-input-device-xi2.h" |
| 32 |
#include "clutter-stage-x11.h" |
| 33 |
|
| 34 |
#include "clutter-backend.h" |
| 35 |
#include "clutter-debug.h" |
| 36 |
#include "clutter-device-manager-private.h" |
| 37 |
#include "clutter-event-private.h" |
| 38 |
#include "clutter-event-translator.h" |
| 39 |
#include "clutter-stage-private.h" |
| 40 |
#include "clutter-private.h" |
| 41 |
|
| 42 |
#include <X11/extensions/XInput2.h> |
| 43 |
|
| 44 |
enum |
| 45 |
{ |
| 46 |
PROP_0, |
| 47 |
|
| 48 |
PROP_OPCODE, |
| 49 |
|
| 50 |
PROP_LAST |
| 51 |
}; |
| 52 |
|
| 53 |
static GParamSpec *obj_props[PROP_LAST] = { NULL, }; |
| 54 |
|
| 55 |
static const char *clutter_input_axis_atom_names[] = { |
| 56 |
"Abs X", /* CLUTTER_INPUT_AXIS_X */ |
| 57 |
"Abs Y", /* CLUTTER_INPUT_AXIS_Y */ |
| 58 |
"Abs Pressure", /* CLUTTER_INPUT_AXIS_PRESSURE */ |
| 59 |
"Abs Tilt X", /* CLUTTER_INPUT_AXIS_XTILT */ |
| 60 |
"Abs Tilt Y", /* CLUTTER_INPUT_AXIS_YTILT */ |
| 61 |
"Abs Wheel", /* CLUTTER_INPUT_AXIS_WHEEL */ |
| 62 |
"Abs Distance", /* CLUTTER_INPUT_AXIS_DISTANCE */ |
| 63 |
}; |
| 64 |
|
| 65 |
#define N_AXIS_ATOMS G_N_ELEMENTS (clutter_input_axis_atom_names) |
| 66 |
|
| 67 |
static Atom clutter_input_axis_atoms[N_AXIS_ATOMS] = { 0, }; |
| 68 |
|
| 69 |
static void clutter_event_translator_iface_init (ClutterEventTranslatorIface *iface); |
| 70 |
static void clutter_event_extender_iface_init (ClutterEventExtenderInterface *iface); |
| 71 |
|
| 72 |
#define clutter_device_manager_xi2_get_type _clutter_device_manager_xi2_get_type |
| 73 |
|
| 74 |
G_DEFINE_TYPE_WITH_CODE (ClutterDeviceManagerXI2, |
| 75 |
clutter_device_manager_xi2, |
| 76 |
CLUTTER_TYPE_DEVICE_MANAGER, |
| 77 |
G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_EVENT_TRANSLATOR, |
| 78 |
clutter_event_translator_iface_init) |
| 79 |
G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_EVENT_EXTENDER, |
| 80 |
clutter_event_extender_iface_init)) |
| 81 |
|
| 82 |
static void |
| 83 |
clutter_device_manager_x11_copy_event_data (ClutterEventExtender *event_extender, |
| 84 |
const ClutterEvent *src, |
| 85 |
ClutterEvent *dest) |
| 86 |
{ |
| 87 |
gpointer event_x11; |
| 88 |
|
| 89 |
event_x11 = _clutter_event_get_platform_data (src); |
| 90 |
if (event_x11 != NULL) |
| 91 |
_clutter_event_set_platform_data (dest, _clutter_event_x11_copy (event_x11)); |
| 92 |
} |
| 93 |
|
| 94 |
static void |
| 95 |
clutter_device_manager_x11_free_event_data (ClutterEventExtender *event_extender, |
| 96 |
ClutterEvent *event) |
| 97 |
{ |
| 98 |
gpointer event_x11; |
| 99 |
|
| 100 |
event_x11 = _clutter_event_get_platform_data (event); |
| 101 |
if (event_x11 != NULL) |
| 102 |
_clutter_event_x11_free (event_x11); |
| 103 |
} |
| 104 |
|
| 105 |
static void |
| 106 |
clutter_event_extender_iface_init (ClutterEventExtenderInterface *iface) |
| 107 |
{ |
| 108 |
iface->copy_event_data = clutter_device_manager_x11_copy_event_data; |
| 109 |
iface->free_event_data = clutter_device_manager_x11_free_event_data; |
| 110 |
} |
| 111 |
|
| 112 |
static void |
| 113 |
translate_valuator_class (Display *xdisplay, |
| 114 |
ClutterInputDevice *device, |
| 115 |
XIValuatorClassInfo *class) |
| 116 |
{ |
| 117 |
static gboolean atoms_initialized = FALSE; |
| 118 |
ClutterInputAxis i, axis = CLUTTER_INPUT_AXIS_IGNORE; |
| 119 |
|
| 120 |
if (G_UNLIKELY (!atoms_initialized)) |
| 121 |
{ |
| 122 |
XInternAtoms (xdisplay, |
| 123 |
(char **) clutter_input_axis_atom_names, N_AXIS_ATOMS, |
| 124 |
False, |
| 125 |
clutter_input_axis_atoms); |
| 126 |
|
| 127 |
atoms_initialized = TRUE; |
| 128 |
} |
| 129 |
|
| 130 |
for (i = 0; |
| 131 |
i < N_AXIS_ATOMS; |
| 132 |
i += 1) |
| 133 |
{ |
| 134 |
if (clutter_input_axis_atoms[i] == class->label) |
| 135 |
{ |
| 136 |
axis = i + 1; |
| 137 |
break; |
| 138 |
} |
| 139 |
} |
| 140 |
|
| 141 |
_clutter_input_device_add_axis (device, axis, |
| 142 |
class->min, |
| 143 |
class->max, |
| 144 |
class->resolution); |
| 145 |
|
| 146 |
CLUTTER_NOTE (BACKEND, |
| 147 |
"Added axis '%s' (min:%.2f, max:%.2fd, res:%d) of device %d", |
| 148 |
clutter_input_axis_atom_names[axis], |
| 149 |
class->min, |
| 150 |
class->max, |
| 151 |
class->resolution, |
| 152 |
device->id); |
| 153 |
} |
| 154 |
|
| 155 |
static void |
| 156 |
translate_device_classes (Display *xdisplay, |
| 157 |
ClutterInputDevice *device, |
| 158 |
XIAnyClassInfo **classes, |
| 159 |
guint n_classes) |
| 160 |
{ |
| 161 |
gint i; |
| 162 |
|
| 163 |
for (i = 0; i < n_classes; i++) |
| 164 |
{ |
| 165 |
XIAnyClassInfo *class_info = classes[i]; |
| 166 |
|
| 167 |
switch (class_info->type) |
| 168 |
{ |
| 169 |
case XIKeyClass: |
| 170 |
{ |
| 171 |
XIKeyClassInfo *key_info = (XIKeyClassInfo *) class_info; |
| 172 |
gint j; |
| 173 |
|
| 174 |
_clutter_input_device_set_n_keys (device, |
| 175 |
key_info->num_keycodes); |
| 176 |
|
| 177 |
for (j = 0; j < key_info->num_keycodes; j++) |
| 178 |
{ |
| 179 |
clutter_input_device_set_key (device, j, |
| 180 |
key_info->keycodes[i], |
| 181 |
0); |
| 182 |
} |
| 183 |
} |
| 184 |
break; |
| 185 |
|
| 186 |
case XIValuatorClass: |
| 187 |
translate_valuator_class (xdisplay, device, |
| 188 |
(XIValuatorClassInfo *) class_info); |
| 189 |
break; |
| 190 |
|
| 191 |
#ifdef HAVE_XINPUT_2_2 |
| 192 |
case XIScrollClass: |
| 193 |
{ |
| 194 |
XIScrollClassInfo *scroll_info = (XIScrollClassInfo *) class_info; |
| 195 |
ClutterScrollDirection direction; |
| 196 |
|
| 197 |
if (scroll_info->scroll_type == XIScrollTypeVertical) |
| 198 |
direction = CLUTTER_SCROLL_DOWN; |
| 199 |
else |
| 200 |
direction = CLUTTER_SCROLL_RIGHT; |
| 201 |
|
| 202 |
CLUTTER_NOTE (BACKEND, "Scroll valuator %d: %s, increment: %f", |
| 203 |
scroll_info->number, |
| 204 |
scroll_info->scroll_type == XIScrollTypeVertical |
| 205 |
? "vertical" |
| 206 |
: "horizontal", |
| 207 |
scroll_info->increment); |
| 208 |
|
| 209 |
_clutter_input_device_add_scroll_info (device, |
| 210 |
scroll_info->number, |
| 211 |
direction, |
| 212 |
scroll_info->increment); |
| 213 |
} |
| 214 |
break; |
| 215 |
#endif /* HAVE_XINPUT_2_2 */ |
| 216 |
|
| 217 |
default: |
| 218 |
break; |
| 219 |
} |
| 220 |
} |
| 221 |
} |
| 222 |
|
| 223 |
static gboolean |
| 224 |
is_touch_device (XIAnyClassInfo **classes, |
| 225 |
guint n_classes, |
| 226 |
ClutterInputDeviceType *device_type, |
| 227 |
guint *n_touch_points) |
| 228 |
{ |
| 229 |
#ifdef HAVE_XINPUT_2_2 |
| 230 |
guint i; |
| 231 |
|
| 232 |
for (i = 0; i < n_classes; i++) |
| 233 |
{ |
| 234 |
XITouchClassInfo *class = (XITouchClassInfo *) classes[i]; |
| 235 |
|
| 236 |
if (class->type != XITouchClass) |
| 237 |
continue; |
| 238 |
|
| 239 |
if (class->num_touches > 0) |
| 240 |
{ |
| 241 |
if (class->mode == XIDirectTouch) |
| 242 |
*device_type = CLUTTER_TOUCHSCREEN_DEVICE; |
| 243 |
else if (class->mode == XIDependentTouch) |
| 244 |
*device_type = CLUTTER_TOUCHPAD_DEVICE; |
| 245 |
else |
| 246 |
continue; |
| 247 |
|
| 248 |
*n_touch_points = class->num_touches; |
| 249 |
|
| 250 |
return TRUE; |
| 251 |
} |
| 252 |
} |
| 253 |
#endif |
| 254 |
|
| 255 |
return FALSE; |
| 256 |
} |
| 257 |
|
| 258 |
static gboolean |
| 259 |
is_touchpad_device (ClutterBackendX11 *backend_x11, |
| 260 |
XIDeviceInfo *info) |
| 261 |
{ |
| 262 |
gulong nitems, bytes_after; |
| 263 |
guint32 *data = NULL; |
| 264 |
int rc, format; |
| 265 |
Atom type; |
| 266 |
Atom prop; |
| 267 |
|
| 268 |
prop = XInternAtom (backend_x11->xdpy, "libinput Tapping Enabled", True); |
| 269 |
if (prop == None) |
| 270 |
return FALSE; |
| 271 |
|
| 272 |
clutter_x11_trap_x_errors (); |
| 273 |
rc = XIGetProperty (backend_x11->xdpy, |
| 274 |
info->deviceid, |
| 275 |
prop, |
| 276 |
0, 1, False, XA_INTEGER, &type, &format, &nitems, &bytes_after, |
| 277 |
(guchar **) &data); |
| 278 |
clutter_x11_untrap_x_errors (); |
| 279 |
|
| 280 |
/* We don't care about the data */ |
| 281 |
XFree (data); |
| 282 |
|
| 283 |
if (rc != Success || type != XA_INTEGER || format != 8 || nitems != 1) |
| 284 |
return FALSE; |
| 285 |
|
| 286 |
return TRUE; |
| 287 |
} |
| 288 |
|
| 289 |
static gboolean |
| 290 |
get_device_ids (ClutterBackendX11 *backend_x11, |
| 291 |
XIDeviceInfo *info, |
| 292 |
gchar **vendor_id, |
| 293 |
gchar **product_id) |
| 294 |
{ |
| 295 |
gulong nitems, bytes_after; |
| 296 |
guint32 *data = NULL; |
| 297 |
int rc, format; |
| 298 |
Atom type; |
| 299 |
|
| 300 |
clutter_x11_trap_x_errors (); |
| 301 |
rc = XIGetProperty (backend_x11->xdpy, |
| 302 |
info->deviceid, |
| 303 |
XInternAtom (backend_x11->xdpy, "Device Product ID", False), |
| 304 |
0, 2, False, XA_INTEGER, &type, &format, &nitems, &bytes_after, |
| 305 |
(guchar **) &data); |
| 306 |
clutter_x11_untrap_x_errors (); |
| 307 |
|
| 308 |
if (rc != Success || type != XA_INTEGER || format != 32 || nitems != 2) |
| 309 |
{ |
| 310 |
XFree (data); |
| 311 |
return FALSE; |
| 312 |
} |
| 313 |
|
| 314 |
if (vendor_id) |
| 315 |
*vendor_id = g_strdup_printf ("%.4x", data[0]); |
| 316 |
if (product_id) |
| 317 |
*product_id = g_strdup_printf ("%.4x", data[1]); |
| 318 |
|
| 319 |
XFree (data); |
| 320 |
|
| 321 |
return TRUE; |
| 322 |
} |
| 323 |
|
| 324 |
static ClutterInputDevice * |
| 325 |
create_device (ClutterDeviceManagerXI2 *manager_xi2, |
| 326 |
ClutterBackendX11 *backend_x11, |
| 327 |
XIDeviceInfo *info) |
| 328 |
{ |
| 329 |
ClutterInputDeviceType source, touch_source; |
| 330 |
ClutterInputDevice *retval; |
| 331 |
ClutterInputMode mode; |
| 332 |
gboolean is_enabled; |
| 333 |
guint num_touches = 0; |
| 334 |
gchar *vendor_id = NULL, *product_id = NULL; |
| 335 |
|
| 336 |
if (info->use == XIMasterKeyboard || info->use == XISlaveKeyboard) |
| 337 |
{ |
| 338 |
source = CLUTTER_KEYBOARD_DEVICE; |
| 339 |
} |
| 340 |
else if (is_touchpad_device (backend_x11, info)) |
| 341 |
{ |
| 342 |
source = CLUTTER_TOUCHPAD_DEVICE; |
| 343 |
} |
| 344 |
else if (info->use == XISlavePointer && |
| 345 |
is_touch_device (info->classes, info->num_classes, |
| 346 |
&touch_source, |
| 347 |
&num_touches)) |
| 348 |
{ |
| 349 |
source = touch_source; |
| 350 |
} |
| 351 |
else |
| 352 |
{ |
| 353 |
gchar *name; |
| 354 |
|
| 355 |
name = g_ascii_strdown (info->name, -1); |
| 356 |
|
| 357 |
if (strstr (name, "eraser") != NULL) |
| 358 |
source = CLUTTER_ERASER_DEVICE; |
| 359 |
else if (strstr (name, "cursor") != NULL) |
| 360 |
source = CLUTTER_CURSOR_DEVICE; |
| 361 |
else if (strstr (name, "wacom") != NULL || strstr (name, "pen") != NULL) |
| 362 |
source = CLUTTER_PEN_DEVICE; |
| 363 |
else if (strstr (name, "touchpad") != NULL) |
| 364 |
source = CLUTTER_TOUCHPAD_DEVICE; |
| 365 |
else |
| 366 |
source = CLUTTER_POINTER_DEVICE; |
| 367 |
|
| 368 |
g_free (name); |
| 369 |
} |
| 370 |
|
| 371 |
switch (info->use) |
| 372 |
{ |
| 373 |
case XIMasterKeyboard: |
| 374 |
case XIMasterPointer: |
| 375 |
mode = CLUTTER_INPUT_MODE_MASTER; |
| 376 |
is_enabled = TRUE; |
| 377 |
break; |
| 378 |
|
| 379 |
case XISlaveKeyboard: |
| 380 |
case XISlavePointer: |
| 381 |
mode = CLUTTER_INPUT_MODE_SLAVE; |
| 382 |
is_enabled = FALSE; |
| 383 |
break; |
| 384 |
|
| 385 |
case XIFloatingSlave: |
| 386 |
default: |
| 387 |
mode = CLUTTER_INPUT_MODE_FLOATING; |
| 388 |
is_enabled = FALSE; |
| 389 |
break; |
| 390 |
} |
| 391 |
|
| 392 |
if (info->use != XIMasterKeyboard && |
| 393 |
info->use != XIMasterPointer) |
| 394 |
get_device_ids (backend_x11, info, &vendor_id, &product_id); |
| 395 |
|
| 396 |
retval = g_object_new (CLUTTER_TYPE_INPUT_DEVICE_XI2, |
| 397 |
"name", info->name, |
| 398 |
"id", info->deviceid, |
| 399 |
"has-cursor", (info->use == XIMasterPointer), |
| 400 |
"device-manager", manager_xi2, |
| 401 |
"device-type", source, |
| 402 |
"device-mode", mode, |
| 403 |
"backend", backend_x11, |
| 404 |
"enabled", is_enabled, |
| 405 |
"vendor-id", vendor_id, |
| 406 |
"product-id", product_id, |
| 407 |
NULL); |
| 408 |
|
| 409 |
translate_device_classes (backend_x11->xdpy, retval, |
| 410 |
info->classes, |
| 411 |
info->num_classes); |
| 412 |
g_free (vendor_id); |
| 413 |
g_free (product_id); |
| 414 |
|
| 415 |
CLUTTER_NOTE (BACKEND, "Created device '%s' (id: %d, has-cursor: %s)", |
| 416 |
info->name, |
| 417 |
info->deviceid, |
| 418 |
info->use == XIMasterPointer ? "yes" : "no"); |
| 419 |
|
| 420 |
return retval; |
| 421 |
} |
| 422 |
|
| 423 |
static ClutterInputDevice * |
| 424 |
add_device (ClutterDeviceManagerXI2 *manager_xi2, |
| 425 |
ClutterBackendX11 *backend_x11, |
| 426 |
XIDeviceInfo *info, |
| 427 |
gboolean in_construction) |
| 428 |
{ |
| 429 |
ClutterInputDevice *device; |
| 430 |
|
| 431 |
device = create_device (manager_xi2, backend_x11, info); |
| 432 |
|
| 433 |
/* we don't go through the DeviceManager::add_device() vfunc because |
| 434 |
* that emits the signal, and we only do it conditionally |
| 435 |
*/ |
| 436 |
g_hash_table_replace (manager_xi2->devices_by_id, |
| 437 |
GINT_TO_POINTER (info->deviceid), |
| 438 |
device); |
| 439 |
|
| 440 |
if (info->use == XIMasterPointer || |
| 441 |
info->use == XIMasterKeyboard) |
| 442 |
{ |
| 443 |
manager_xi2->master_devices = |
| 444 |
g_list_prepend (manager_xi2->master_devices, device); |
| 445 |
} |
| 446 |
else if (info->use == XISlavePointer || |
| 447 |
info->use == XISlaveKeyboard || |
| 448 |
info->use == XIFloatingSlave) |
| 449 |
{ |
| 450 |
manager_xi2->slave_devices = |
| 451 |
g_list_prepend (manager_xi2->slave_devices, device); |
| 452 |
} |
| 453 |
else |
| 454 |
g_warning ("Unhandled device: %s", |
| 455 |
clutter_input_device_get_device_name (device)); |
| 456 |
|
| 457 |
/* relationships between devices and signal emissions are not |
| 458 |
* necessary while we're constructing the device manager instance |
| 459 |
*/ |
| 460 |
if (!in_construction) |
| 461 |
{ |
| 462 |
if (info->use == XISlavePointer || info->use == XISlaveKeyboard) |
| 463 |
{ |
| 464 |
ClutterInputDevice *master; |
| 465 |
|
| 466 |
master = g_hash_table_lookup (manager_xi2->devices_by_id, |
| 467 |
GINT_TO_POINTER (info->attachment)); |
| 468 |
_clutter_input_device_set_associated_device (device, master); |
| 469 |
_clutter_input_device_add_slave (master, device); |
| 470 |
} |
| 471 |
|
| 472 |
/* blow the cache */ |
| 473 |
g_slist_free (manager_xi2->all_devices); |
| 474 |
manager_xi2->all_devices = NULL; |
| 475 |
|
| 476 |
g_signal_emit_by_name (manager_xi2, "device-added", device); |
| 477 |
} |
| 478 |
|
| 479 |
return device; |
| 480 |
} |
| 481 |
|
| 482 |
static void |
| 483 |
remove_device (ClutterDeviceManagerXI2 *manager_xi2, |
| 484 |
gint device_id) |
| 485 |
{ |
| 486 |
ClutterInputDevice *device; |
| 487 |
|
| 488 |
device = g_hash_table_lookup (manager_xi2->devices_by_id, |
| 489 |
GINT_TO_POINTER (device_id)); |
| 490 |
|
| 491 |
if (device != NULL) |
| 492 |
{ |
| 493 |
manager_xi2->master_devices = |
| 494 |
g_list_remove (manager_xi2->master_devices, device); |
| 495 |
manager_xi2->slave_devices = |
| 496 |
g_list_remove (manager_xi2->slave_devices, device); |
| 497 |
|
| 498 |
/* blow the cache */ |
| 499 |
g_slist_free (manager_xi2->all_devices); |
| 500 |
manager_xi2->all_devices = NULL; |
| 501 |
|
| 502 |
g_signal_emit_by_name (manager_xi2, "device-removed", device); |
| 503 |
|
| 504 |
g_object_run_dispose (G_OBJECT (device)); |
| 505 |
|
| 506 |
g_hash_table_remove (manager_xi2->devices_by_id, |
| 507 |
GINT_TO_POINTER (device_id)); |
| 508 |
} |
| 509 |
} |
| 510 |
|
| 511 |
static void |
| 512 |
translate_hierarchy_event (ClutterBackendX11 *backend_x11, |
| 513 |
ClutterDeviceManagerXI2 *manager_xi2, |
| 514 |
XIHierarchyEvent *ev) |
| 515 |
{ |
| 516 |
int i; |
| 517 |
|
| 518 |
for (i = 0; i < ev->num_info; i++) |
| 519 |
{ |
| 520 |
if (ev->info[i].flags & XIDeviceEnabled && |
| 521 |
!g_hash_table_lookup (manager_xi2->devices_by_id, |
| 522 |
GINT_TO_POINTER (ev->info[i].deviceid))) |
| 523 |
{ |
| 524 |
XIDeviceInfo *info; |
| 525 |
int n_devices; |
| 526 |
|
| 527 |
CLUTTER_NOTE (EVENT, "Hierarchy event: device enabled"); |
| 528 |
|
| 529 |
clutter_x11_trap_x_errors (); |
| 530 |
info = XIQueryDevice (backend_x11->xdpy, |
| 531 |
ev->info[i].deviceid, |
| 532 |
&n_devices); |
| 533 |
clutter_x11_untrap_x_errors (); |
| 534 |
if (info != NULL) |
| 535 |
{ |
| 536 |
add_device (manager_xi2, backend_x11, &info[0], FALSE); |
| 537 |
XIFreeDeviceInfo (info); |
| 538 |
} |
| 539 |
} |
| 540 |
else if (ev->info[i].flags & XIDeviceDisabled) |
| 541 |
{ |
| 542 |
CLUTTER_NOTE (EVENT, "Hierarchy event: device disabled"); |
| 543 |
|
| 544 |
remove_device (manager_xi2, ev->info[i].deviceid); |
| 545 |
} |
| 546 |
else if ((ev->info[i].flags & XISlaveAttached) || |
| 547 |
(ev->info[i].flags & XISlaveDetached)) |
| 548 |
{ |
| 549 |
ClutterInputDevice *master, *slave; |
| 550 |
XIDeviceInfo *info; |
| 551 |
int n_devices; |
| 552 |
gboolean send_changed = FALSE; |
| 553 |
|
| 554 |
CLUTTER_NOTE (EVENT, "Hierarchy event: slave %s", |
| 555 |
(ev->info[i].flags & XISlaveAttached) |
| 556 |
? "attached" |
| 557 |
: "detached"); |
| 558 |
|
| 559 |
slave = g_hash_table_lookup (manager_xi2->devices_by_id, |
| 560 |
GINT_TO_POINTER (ev->info[i].deviceid)); |
| 561 |
master = clutter_input_device_get_associated_device (slave); |
| 562 |
|
| 563 |
/* detach the slave in both cases */ |
| 564 |
if (master != NULL) |
| 565 |
{ |
| 566 |
_clutter_input_device_remove_slave (master, slave); |
| 567 |
_clutter_input_device_set_associated_device (slave, NULL); |
| 568 |
|
| 569 |
send_changed = TRUE; |
| 570 |
} |
| 571 |
|
| 572 |
/* and attach the slave to the new master if needed */ |
| 573 |
if (ev->info[i].flags & XISlaveAttached) |
| 574 |
{ |
| 575 |
clutter_x11_trap_x_errors (); |
| 576 |
info = XIQueryDevice (backend_x11->xdpy, |
| 577 |
ev->info[i].deviceid, |
| 578 |
&n_devices); |
| 579 |
clutter_x11_untrap_x_errors (); |
| 580 |
if (info != NULL) |
| 581 |
{ |
| 582 |
master = g_hash_table_lookup (manager_xi2->devices_by_id, |
| 583 |
GINT_TO_POINTER (info->attachment)); |
| 584 |
if (master != NULL) |
| 585 |
{ |
| 586 |
_clutter_input_device_set_associated_device (slave, master); |
| 587 |
_clutter_input_device_add_slave (master, slave); |
| 588 |
|
| 589 |
send_changed = TRUE; |
| 590 |
} |
| 591 |
XIFreeDeviceInfo (info); |
| 592 |
} |
| 593 |
} |
| 594 |
|
| 595 |
if (send_changed) |
| 596 |
{ |
| 597 |
ClutterStage *stage = _clutter_input_device_get_stage (master); |
| 598 |
if (stage != NULL) |
| 599 |
_clutter_stage_x11_events_device_changed (CLUTTER_STAGE_X11 (_clutter_stage_get_window (stage)), |
| 600 |
master, |
| 601 |
CLUTTER_DEVICE_MANAGER (manager_xi2)); |
| 602 |
} |
| 603 |
} |
| 604 |
} |
| 605 |
} |
| 606 |
|
| 607 |
static void |
| 608 |
clutter_device_manager_xi2_select_events (ClutterDeviceManager *manager, |
| 609 |
Window xwindow, |
| 610 |
XIEventMask *event_mask) |
| 611 |
{ |
| 612 |
Display *xdisplay; |
| 613 |
|
| 614 |
xdisplay = clutter_x11_get_default_display (); |
| 615 |
|
| 616 |
XISelectEvents (xdisplay, xwindow, event_mask, 1); |
| 617 |
} |
| 618 |
|
| 619 |
static ClutterStage * |
| 620 |
get_event_stage (ClutterEventTranslator *translator, |
| 621 |
XIEvent *xi_event) |
| 622 |
{ |
| 623 |
Window xwindow = None; |
| 624 |
|
| 625 |
switch (xi_event->evtype) |
| 626 |
{ |
| 627 |
case XI_KeyPress: |
| 628 |
case XI_KeyRelease: |
| 629 |
case XI_ButtonPress: |
| 630 |
case XI_ButtonRelease: |
| 631 |
case XI_Motion: |
| 632 |
#ifdef HAVE_XINPUT_2_2 |
| 633 |
case XI_TouchBegin: |
| 634 |
case XI_TouchUpdate: |
| 635 |
case XI_TouchEnd: |
| 636 |
#endif /* HAVE_XINPUT_2_2 */ |
| 637 |
{ |
| 638 |
XIDeviceEvent *xev = (XIDeviceEvent *) xi_event; |
| 639 |
|
| 640 |
xwindow = xev->event; |
| 641 |
} |
| 642 |
break; |
| 643 |
|
| 644 |
case XI_Enter: |
| 645 |
case XI_Leave: |
| 646 |
case XI_FocusIn: |
| 647 |
case XI_FocusOut: |
| 648 |
{ |
| 649 |
XIEnterEvent *xev = (XIEnterEvent *) xi_event; |
| 650 |
|
| 651 |
xwindow = xev->event; |
| 652 |
} |
| 653 |
break; |
| 654 |
|
| 655 |
default: |
| 656 |
break; |
| 657 |
} |
| 658 |
|
| 659 |
if (xwindow == None) |
| 660 |
return NULL; |
| 661 |
|
| 662 |
return clutter_x11_get_stage_from_window (xwindow); |
| 663 |
} |
| 664 |
|
| 665 |
/* |
| 666 |
* print_key_sym: Translate a symbol to its printable form if any |
| 667 |
* @symbol: the symbol to translate |
| 668 |
* @buffer: the buffer where to put the translated string |
| 669 |
* @len: size of the buffer |
| 670 |
* |
| 671 |
* Translates @symbol into a printable representation in @buffer, if possible. |
| 672 |
* |
| 673 |
* Return value: The number of bytes of the translated string, 0 if the |
| 674 |
* symbol can't be printed |
| 675 |
* |
| 676 |
* Note: The code is derived from libX11's src/KeyBind.c |
| 677 |
* Copyright 1985, 1987, 1998 The Open Group |
| 678 |
* |
| 679 |
* Note: This code works for Latin-1 symbols. clutter_keysym_to_unicode() |
| 680 |
* does the work for the other keysyms. |
| 681 |
*/ |
| 682 |
static int |
| 683 |
print_keysym (uint32_t symbol, |
| 684 |
char *buffer, |
| 685 |
int len) |
| 686 |
{ |
| 687 |
unsigned long high_bytes; |
| 688 |
unsigned char c; |
| 689 |
|
| 690 |
high_bytes = symbol >> 8; |
| 691 |
if (!(len && |
| 692 |
((high_bytes == 0) || |
| 693 |
((high_bytes == 0xFF) && |
| 694 |
(((symbol >= CLUTTER_KEY_BackSpace) && |
| 695 |
(symbol <= CLUTTER_KEY_Clear)) || |
| 696 |
(symbol == CLUTTER_KEY_Return) || |
| 697 |
(symbol == CLUTTER_KEY_Escape) || |
| 698 |
(symbol == CLUTTER_KEY_KP_Space) || |
| 699 |
(symbol == CLUTTER_KEY_KP_Tab) || |
| 700 |
(symbol == CLUTTER_KEY_KP_Enter) || |
| 701 |
((symbol >= CLUTTER_KEY_KP_Multiply) && |
| 702 |
(symbol <= CLUTTER_KEY_KP_9)) || |
| 703 |
(symbol == CLUTTER_KEY_KP_Equal) || |
| 704 |
(symbol == CLUTTER_KEY_Delete)))))) |
| 705 |
return 0; |
| 706 |
|
| 707 |
/* if X keysym, convert to ascii by grabbing low 7 bits */ |
| 708 |
if (symbol == CLUTTER_KEY_KP_Space) |
| 709 |
c = CLUTTER_KEY_space & 0x7F; /* patch encoding botch */ |
| 710 |
else if (high_bytes == 0xFF) |
| 711 |
c = symbol & 0x7F; |
| 712 |
else |
| 713 |
c = symbol & 0xFF; |
| 714 |
|
| 715 |
buffer[0] = c; |
| 716 |
return 1; |
| 717 |
} |
| 718 |
|
| 719 |
static gdouble * |
| 720 |
translate_axes (ClutterInputDevice *device, |
| 721 |
gdouble x, |
| 722 |
gdouble y, |
| 723 |
XIValuatorState *valuators) |
| 724 |
{ |
| 725 |
guint n_axes = clutter_input_device_get_n_axes (device); |
| 726 |
guint i; |
| 727 |
gdouble *retval; |
| 728 |
double *values; |
| 729 |
|
| 730 |
retval = g_new0 (gdouble, n_axes); |
| 731 |
values = valuators->values; |
| 732 |
|
| 733 |
for (i = 0; i < valuators->mask_len * 8; i++) |
| 734 |
{ |
| 735 |
ClutterInputAxis axis; |
| 736 |
gdouble val; |
| 737 |
|
| 738 |
if (!XIMaskIsSet (valuators->mask, i)) |
| 739 |
continue; |
| 740 |
|
| 741 |
axis = clutter_input_device_get_axis (device, i); |
| 742 |
val = *values++; |
| 743 |
|
| 744 |
switch (axis) |
| 745 |
{ |
| 746 |
case CLUTTER_INPUT_AXIS_X: |
| 747 |
retval[i] = x; |
| 748 |
break; |
| 749 |
|
| 750 |
case CLUTTER_INPUT_AXIS_Y: |
| 751 |
retval[i] = y; |
| 752 |
break; |
| 753 |
|
| 754 |
default: |
| 755 |
_clutter_input_device_translate_axis (device, i, val, &retval[i]); |
| 756 |
break; |
| 757 |
} |
| 758 |
} |
| 759 |
|
| 760 |
return retval; |
| 761 |
} |
| 762 |
|
| 763 |
static void |
| 764 |
translate_coords (ClutterStageX11 *stage_x11, |
| 765 |
gdouble event_x, |
| 766 |
gdouble event_y, |
| 767 |
gfloat *x_out, |
| 768 |
gfloat *y_out) |
| 769 |
{ |
| 770 |
ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_x11); |
| 771 |
ClutterActor *stage = CLUTTER_ACTOR (stage_cogl->wrapper); |
| 772 |
gfloat stage_width; |
| 773 |
gfloat stage_height; |
| 774 |
|
| 775 |
clutter_actor_get_size (stage, &stage_width, &stage_height); |
| 776 |
|
| 777 |
*x_out = CLAMP (event_x / stage_x11->scale_factor, 0, stage_width); |
| 778 |
*y_out = CLAMP (event_y / stage_x11->scale_factor, 0, stage_height); |
| 779 |
} |
| 780 |
|
| 781 |
static gdouble |
| 782 |
scroll_valuators_changed (ClutterInputDevice *device, |
| 783 |
XIValuatorState *valuators, |
| 784 |
gdouble *dx_p, |
| 785 |
gdouble *dy_p) |
| 786 |
{ |
| 787 |
gboolean retval = FALSE; |
| 788 |
guint n_axes, n_val, i; |
| 789 |
double *values; |
| 790 |
|
| 791 |
n_axes = clutter_input_device_get_n_axes (device); |
| 792 |
values = valuators->values; |
| 793 |
|
| 794 |
*dx_p = *dy_p = 0.0; |
| 795 |
|
| 796 |
n_val = 0; |
| 797 |
|
| 798 |
for (i = 0; i < MIN (valuators->mask_len * 8, n_axes); i++) |
| 799 |
{ |
| 800 |
ClutterScrollDirection direction; |
| 801 |
gdouble delta; |
| 802 |
|
| 803 |
if (!XIMaskIsSet (valuators->mask, i)) |
| 804 |
continue; |
| 805 |
|
| 806 |
if (_clutter_input_device_get_scroll_delta (device, i, |
| 807 |
values[n_val], |
| 808 |
&direction, |
| 809 |
&delta)) |
| 810 |
{ |
| 811 |
retval = TRUE; |
| 812 |
|
| 813 |
if (direction == CLUTTER_SCROLL_UP || |
| 814 |
direction == CLUTTER_SCROLL_DOWN) |
| 815 |
*dy_p = delta; |
| 816 |
else |
| 817 |
*dx_p = delta; |
| 818 |
} |
| 819 |
|
| 820 |
n_val += 1; |
| 821 |
} |
| 822 |
|
| 823 |
return retval; |
| 824 |
} |
| 825 |
|
| 826 |
static void |
| 827 |
clutter_device_manager_xi2_select_stage_events (ClutterDeviceManager *manager, |
| 828 |
ClutterStage *stage) |
| 829 |
{ |
| 830 |
ClutterBackendX11 *backend_x11; |
| 831 |
ClutterStageX11 *stage_x11; |
| 832 |
XIEventMask xi_event_mask; |
| 833 |
unsigned char *mask; |
| 834 |
int len; |
| 835 |
|
| 836 |
backend_x11 = CLUTTER_BACKEND_X11 (clutter_get_default_backend ()); |
| 837 |
stage_x11 = CLUTTER_STAGE_X11 (_clutter_stage_get_window (stage)); |
| 838 |
|
| 839 |
len = XIMaskLen (XI_LASTEVENT); |
| 840 |
mask = g_new0 (unsigned char, len); |
| 841 |
|
| 842 |
XISetMask (mask, XI_Motion); |
| 843 |
XISetMask (mask, XI_ButtonPress); |
| 844 |
XISetMask (mask, XI_ButtonRelease); |
| 845 |
XISetMask (mask, XI_KeyPress); |
| 846 |
XISetMask (mask, XI_KeyRelease); |
| 847 |
XISetMask (mask, XI_Enter); |
| 848 |
XISetMask (mask, XI_Leave); |
| 849 |
|
| 850 |
#ifdef HAVE_XINPUT_2_2 |
| 851 |
/* enable touch event support if we're running on XInput 2.2 */ |
| 852 |
if (backend_x11->xi_minor >= 2) |
| 853 |
{ |
| 854 |
XISetMask (mask, XI_TouchBegin); |
| 855 |
XISetMask (mask, XI_TouchUpdate); |
| 856 |
XISetMask (mask, XI_TouchEnd); |
| 857 |
} |
| 858 |
#endif /* HAVE_XINPUT_2_2 */ |
| 859 |
|
| 860 |
xi_event_mask.deviceid = XIAllMasterDevices; |
| 861 |
xi_event_mask.mask = mask; |
| 862 |
xi_event_mask.mask_len = len; |
| 863 |
|
| 864 |
XISelectEvents (backend_x11->xdpy, stage_x11->xwin, &xi_event_mask, 1); |
| 865 |
|
| 866 |
g_free (mask); |
| 867 |
} |
| 868 |
|
| 869 |
static ClutterTranslateReturn |
| 870 |
clutter_device_manager_xi2_translate_event (ClutterEventTranslator *translator, |
| 871 |
gpointer native, |
| 872 |
ClutterEvent *event) |
| 873 |
{ |
| 874 |
ClutterDeviceManagerXI2 *manager_xi2 = CLUTTER_DEVICE_MANAGER_XI2 (translator); |
| 875 |
ClutterTranslateReturn retval = CLUTTER_TRANSLATE_CONTINUE; |
| 876 |
ClutterBackendX11 *backend_x11; |
| 877 |
ClutterStageX11 *stage_x11 = NULL; |
| 878 |
ClutterStage *stage = NULL; |
| 879 |
ClutterInputDevice *device, *source_device; |
| 880 |
XGenericEventCookie *cookie; |
| 881 |
XIEvent *xi_event; |
| 882 |
XEvent *xevent; |
| 883 |
|
| 884 |
backend_x11 = CLUTTER_BACKEND_X11 (clutter_get_default_backend ()); |
| 885 |
|
| 886 |
xevent = native; |
| 887 |
|
| 888 |
cookie = &xevent->xcookie; |
| 889 |
|
| 890 |
if (cookie->type != GenericEvent || |
| 891 |
cookie->extension != manager_xi2->opcode) |
| 892 |
return CLUTTER_TRANSLATE_CONTINUE; |
| 893 |
|
| 894 |
xi_event = (XIEvent *) cookie->data; |
| 895 |
|
| 896 |
if (!xi_event) |
| 897 |
return CLUTTER_TRANSLATE_REMOVE; |
| 898 |
|
| 899 |
if (!(xi_event->evtype == XI_HierarchyChanged || |
| 900 |
xi_event->evtype == XI_DeviceChanged)) |
| 901 |
{ |
| 902 |
stage = get_event_stage (translator, xi_event); |
| 903 |
if (stage == NULL || CLUTTER_ACTOR_IN_DESTRUCTION (stage)) |
| 904 |
return CLUTTER_TRANSLATE_CONTINUE; |
| 905 |
else |
| 906 |
stage_x11 = CLUTTER_STAGE_X11 (_clutter_stage_get_window (stage)); |
| 907 |
} |
| 908 |
|
| 909 |
event->any.stage = stage; |
| 910 |
|
| 911 |
switch (xi_event->evtype) |
| 912 |
{ |
| 913 |
case XI_HierarchyChanged: |
| 914 |
{ |
| 915 |
XIHierarchyEvent *xev = (XIHierarchyEvent *) xi_event; |
| 916 |
|
| 917 |
translate_hierarchy_event (backend_x11, manager_xi2, xev); |
| 918 |
} |
| 919 |
retval = CLUTTER_TRANSLATE_REMOVE; |
| 920 |
break; |
| 921 |
|
| 922 |
case XI_DeviceChanged: |
| 923 |
{ |
| 924 |
XIDeviceChangedEvent *xev = (XIDeviceChangedEvent *) xi_event; |
| 925 |
|
| 926 |
device = g_hash_table_lookup (manager_xi2->devices_by_id, |
| 927 |
GINT_TO_POINTER (xev->deviceid)); |
| 928 |
source_device = g_hash_table_lookup (manager_xi2->devices_by_id, |
| 929 |
GINT_TO_POINTER (xev->sourceid)); |
| 930 |
if (device) |
| 931 |
{ |
| 932 |
_clutter_input_device_reset_axes (device); |
| 933 |
translate_device_classes (backend_x11->xdpy, |
| 934 |
device, |
| 935 |
xev->classes, |
| 936 |
xev->num_classes); |
| 937 |
} |
| 938 |
|
| 939 |
if (source_device) |
| 940 |
_clutter_input_device_reset_scroll_info (source_device); |
| 941 |
} |
| 942 |
retval = CLUTTER_TRANSLATE_REMOVE; |
| 943 |
break; |
| 944 |
|
| 945 |
case XI_KeyPress: |
| 946 |
case XI_KeyRelease: |
| 947 |
{ |
| 948 |
XIDeviceEvent *xev = (XIDeviceEvent *) xi_event; |
| 949 |
ClutterEventX11 *event_x11; |
| 950 |
char buffer[7] = { 0, }; |
| 951 |
gunichar n; |
| 952 |
|
| 953 |
event->key.type = event->type = (xev->evtype == XI_KeyPress) |
| 954 |
? CLUTTER_KEY_PRESS |
| 955 |
: CLUTTER_KEY_RELEASE; |
| 956 |
|
| 957 |
event->key.time = xev->time; |
| 958 |
event->key.stage = stage; |
| 959 |
_clutter_input_device_xi2_translate_state (event, &xev->mods, &xev->buttons, &xev->group); |
| 960 |
event->key.hardware_keycode = xev->detail; |
| 961 |
|
| 962 |
/* keyval is the key ignoring all modifiers ('1' vs. '!') */ |
| 963 |
event->key.keyval = |
| 964 |
_clutter_keymap_x11_translate_key_state (backend_x11->keymap, |
| 965 |
event->key.hardware_keycode, |
| 966 |
&event->key.modifier_state, |
| 967 |
NULL); |
| 968 |
|
| 969 |
/* KeyEvents have platform specific data associated to them */ |
| 970 |
event_x11 = _clutter_event_x11_new (); |
| 971 |
_clutter_event_set_platform_data (event, event_x11); |
| 972 |
|
| 973 |
event_x11->key_group = |
| 974 |
_clutter_keymap_x11_get_key_group (backend_x11->keymap, |
| 975 |
event->key.modifier_state); |
| 976 |
event_x11->key_is_modifier = |
| 977 |
_clutter_keymap_x11_get_is_modifier (backend_x11->keymap, |
| 978 |
event->key.hardware_keycode); |
| 979 |
event_x11->num_lock_set = |
| 980 |
_clutter_keymap_x11_get_num_lock_state (backend_x11->keymap); |
| 981 |
event_x11->caps_lock_set = |
| 982 |
_clutter_keymap_x11_get_caps_lock_state (backend_x11->keymap); |
| 983 |
|
| 984 |
source_device = g_hash_table_lookup (manager_xi2->devices_by_id, |
| 985 |
GINT_TO_POINTER (xev->sourceid)); |
| 986 |
clutter_event_set_source_device (event, source_device); |
| 987 |
|
| 988 |
device = g_hash_table_lookup (manager_xi2->devices_by_id, |
| 989 |
GINT_TO_POINTER (xev->deviceid)); |
| 990 |
clutter_event_set_device (event, device); |
| 991 |
|
| 992 |
/* XXX keep this in sync with the evdev device manager */ |
| 993 |
n = print_keysym (event->key.keyval, buffer, sizeof (buffer)); |
| 994 |
if (n == 0) |
| 995 |
{ |
| 996 |
/* not printable */ |
| 997 |
event->key.unicode_value = (gunichar) '\0'; |
| 998 |
} |
| 999 |
else |
| 1000 |
{ |
| 1001 |
event->key.unicode_value = g_utf8_get_char_validated (buffer, n); |
| 1002 |
if (event->key.unicode_value == -1 || |
| 1003 |
event->key.unicode_value == -2) |
| 1004 |
event->key.unicode_value = (gunichar) '\0'; |
| 1005 |
} |
| 1006 |
|
| 1007 |
CLUTTER_NOTE (EVENT, |
| 1008 |
"%s: win:0x%x device:%d source:%d, key: %12s (%d)", |
| 1009 |
event->any.type == CLUTTER_KEY_PRESS |
| 1010 |
? "key press " |
| 1011 |
: "key release", |
| 1012 |
(unsigned int) stage_x11->xwin, |
| 1013 |
xev->deviceid, |
| 1014 |
xev->sourceid, |
| 1015 |
event->key.keyval ? buffer : "(none)", |
| 1016 |
event->key.keyval); |
| 1017 |
|
| 1018 |
if (xi_event->evtype == XI_KeyPress) |
| 1019 |
_clutter_stage_x11_set_user_time (stage_x11, event->key.time); |
| 1020 |
|
| 1021 |
retval = CLUTTER_TRANSLATE_QUEUE; |
| 1022 |
} |
| 1023 |
break; |
| 1024 |
|
| 1025 |
case XI_ButtonPress: |
| 1026 |
case XI_ButtonRelease: |
| 1027 |
{ |
| 1028 |
XIDeviceEvent *xev = (XIDeviceEvent *) xi_event; |
| 1029 |
|
| 1030 |
source_device = g_hash_table_lookup (manager_xi2->devices_by_id, |
| 1031 |
GINT_TO_POINTER (xev->sourceid)); |
| 1032 |
device = g_hash_table_lookup (manager_xi2->devices_by_id, |
| 1033 |
GINT_TO_POINTER (xev->deviceid)); |
| 1034 |
|
| 1035 |
/* Set the stage for core events coming out of nowhere (see bug #684509) */ |
| 1036 |
if (clutter_input_device_get_device_mode (device) == CLUTTER_INPUT_MODE_MASTER && |
| 1037 |
clutter_input_device_get_pointer_stage (device) == NULL && |
| 1038 |
stage != NULL) |
| 1039 |
_clutter_input_device_set_stage (device, stage); |
| 1040 |
|
| 1041 |
switch (xev->detail) |
| 1042 |
{ |
| 1043 |
case 4: |
| 1044 |
case 5: |
| 1045 |
case 6: |
| 1046 |
case 7: |
| 1047 |
/* we only generate Scroll events on ButtonPress */ |
| 1048 |
if (xi_event->evtype == XI_ButtonRelease) |
| 1049 |
return CLUTTER_TRANSLATE_REMOVE; |
| 1050 |
|
| 1051 |
event->scroll.type = event->type = CLUTTER_SCROLL; |
| 1052 |
|
| 1053 |
if (xev->detail == 4) |
| 1054 |
event->scroll.direction = CLUTTER_SCROLL_UP; |
| 1055 |
else if (xev->detail == 5) |
| 1056 |
event->scroll.direction = CLUTTER_SCROLL_DOWN; |
| 1057 |
else if (xev->detail == 6) |
| 1058 |
event->scroll.direction = CLUTTER_SCROLL_LEFT; |
| 1059 |
else |
| 1060 |
event->scroll.direction = CLUTTER_SCROLL_RIGHT; |
| 1061 |
|
| 1062 |
event->scroll.stage = stage; |
| 1063 |
|
| 1064 |
event->scroll.time = xev->time; |
| 1065 |
translate_coords (stage_x11, xev->event_x, xev->event_y, &event->scroll.x, &event->scroll.y); |
| 1066 |
_clutter_input_device_xi2_translate_state (event, |
| 1067 |
&xev->mods, |
| 1068 |
&xev->buttons, |
| 1069 |
&xev->group); |
| 1070 |
|
| 1071 |
clutter_event_set_source_device (event, source_device); |
| 1072 |
clutter_event_set_device (event, device); |
| 1073 |
|
| 1074 |
event->scroll.axes = translate_axes (event->scroll.device, |
| 1075 |
event->scroll.x, |
| 1076 |
event->scroll.y, |
| 1077 |
&xev->valuators); |
| 1078 |
|
| 1079 |
CLUTTER_NOTE (EVENT, |
| 1080 |
"scroll: win:0x%x, device:%d '%s', time:%d " |
| 1081 |
"(direction:%s, " |
| 1082 |
"x:%.2f, y:%.2f, " |
| 1083 |
"emulated:%s)", |
| 1084 |
(unsigned int) stage_x11->xwin, |
| 1085 |
device->id, |
| 1086 |
device->device_name, |
| 1087 |
event->any.time, |
| 1088 |
event->scroll.direction == CLUTTER_SCROLL_UP ? "up" : |
| 1089 |
event->scroll.direction == CLUTTER_SCROLL_DOWN ? "down" : |
| 1090 |
event->scroll.direction == CLUTTER_SCROLL_LEFT ? "left" : |
| 1091 |
event->scroll.direction == CLUTTER_SCROLL_RIGHT ? "right" : |
| 1092 |
"invalid", |
| 1093 |
event->scroll.x, |
| 1094 |
event->scroll.y, |
| 1095 |
#ifdef HAVE_XINPUT_2_2 |
| 1096 |
(xev->flags & XIPointerEmulated) ? "yes" : "no" |
| 1097 |
#else |
| 1098 |
"no" |
| 1099 |
#endif |
| 1100 |
); |
| 1101 |
break; |
| 1102 |
|
| 1103 |
default: |
| 1104 |
event->button.type = event->type = |
| 1105 |
(xi_event->evtype == XI_ButtonPress) ? CLUTTER_BUTTON_PRESS |
| 1106 |
: CLUTTER_BUTTON_RELEASE; |
| 1107 |
|
| 1108 |
event->button.stage = stage; |
| 1109 |
|
| 1110 |
event->button.time = xev->time; |
| 1111 |
translate_coords (stage_x11, xev->event_x, xev->event_y, &event->button.x, &event->button.y); |
| 1112 |
event->button.button = xev->detail; |
| 1113 |
_clutter_input_device_xi2_translate_state (event, |
| 1114 |
&xev->mods, |
| 1115 |
&xev->buttons, |
| 1116 |
&xev->group); |
| 1117 |
|
| 1118 |
clutter_event_set_source_device (event, source_device); |
| 1119 |
clutter_event_set_device (event, device); |
| 1120 |
|
| 1121 |
event->button.axes = translate_axes (event->button.device, |
| 1122 |
event->button.x, |
| 1123 |
event->button.y, |
| 1124 |
&xev->valuators); |
| 1125 |
|
| 1126 |
CLUTTER_NOTE (EVENT, |
| 1127 |
"%s: win:0x%x, device:%d '%s', time:%d " |
| 1128 |
"(button:%d, " |
| 1129 |
"x:%.2f, y:%.2f, " |
| 1130 |
"axes:%s, " |
| 1131 |
"emulated:%s)", |
| 1132 |
event->any.type == CLUTTER_BUTTON_PRESS |
| 1133 |
? "button press " |
| 1134 |
: "button release", |
| 1135 |
(unsigned int) stage_x11->xwin, |
| 1136 |
device->id, |
| 1137 |
device->device_name, |
| 1138 |
event->any.time, |
| 1139 |
event->button.button, |
| 1140 |
event->button.x, |
| 1141 |
event->button.y, |
| 1142 |
event->button.axes != NULL ? "yes" : "no", |
| 1143 |
#ifdef HAVE_XINPUT_2_2 |
| 1144 |
(xev->flags & XIPointerEmulated) ? "yes" : "no" |
| 1145 |
#else |
| 1146 |
"no" |
| 1147 |
#endif |
| 1148 |
); |
| 1149 |
break; |
| 1150 |
} |
| 1151 |
|
| 1152 |
if (source_device != NULL && device->stage != NULL) |
| 1153 |
_clutter_input_device_set_stage (source_device, device->stage); |
| 1154 |
|
| 1155 |
#ifdef HAVE_XINPUT_2_2 |
| 1156 |
if (xev->flags & XIPointerEmulated) |
| 1157 |
_clutter_event_set_pointer_emulated (event, TRUE); |
| 1158 |
#endif /* HAVE_XINPUT_2_2 */ |
| 1159 |
|
| 1160 |
if (xi_event->evtype == XI_ButtonPress) |
| 1161 |
_clutter_stage_x11_set_user_time (stage_x11, event->button.time); |
| 1162 |
|
| 1163 |
retval = CLUTTER_TRANSLATE_QUEUE; |
| 1164 |
} |
| 1165 |
break; |
| 1166 |
|
| 1167 |
case XI_Motion: |
| 1168 |
{ |
| 1169 |
XIDeviceEvent *xev = (XIDeviceEvent *) xi_event; |
| 1170 |
gdouble delta_x, delta_y; |
| 1171 |
|
| 1172 |
source_device = g_hash_table_lookup (manager_xi2->devices_by_id, |
| 1173 |
GINT_TO_POINTER (xev->sourceid)); |
| 1174 |
device = g_hash_table_lookup (manager_xi2->devices_by_id, |
| 1175 |
GINT_TO_POINTER (xev->deviceid)); |
| 1176 |
|
| 1177 |
/* Set the stage for core events coming out of nowhere (see bug #684509) */ |
| 1178 |
if (clutter_input_device_get_device_mode (device) == CLUTTER_INPUT_MODE_MASTER && |
| 1179 |
clutter_input_device_get_pointer_stage (device) == NULL && |
| 1180 |
stage != NULL) |
| 1181 |
_clutter_input_device_set_stage (device, stage); |
| 1182 |
|
| 1183 |
if (scroll_valuators_changed (source_device, |
| 1184 |
&xev->valuators, |
| 1185 |
&delta_x, &delta_y)) |
| 1186 |
{ |
| 1187 |
event->scroll.type = event->type = CLUTTER_SCROLL; |
| 1188 |
event->scroll.direction = CLUTTER_SCROLL_SMOOTH; |
| 1189 |
|
| 1190 |
event->scroll.stage = stage; |
| 1191 |
event->scroll.time = xev->time; |
| 1192 |
translate_coords (stage_x11, xev->event_x, xev->event_y, &event->scroll.x, &event->scroll.y); |
| 1193 |
_clutter_input_device_xi2_translate_state (event, |
| 1194 |
&xev->mods, |
| 1195 |
&xev->buttons, |
| 1196 |
&xev->group); |
| 1197 |
|
| 1198 |
clutter_event_set_scroll_delta (event, delta_x, delta_y); |
| 1199 |
clutter_event_set_source_device (event, source_device); |
| 1200 |
clutter_event_set_device (event, device); |
| 1201 |
|
| 1202 |
CLUTTER_NOTE (EVENT, |
| 1203 |
"smooth scroll: win:0x%x device:%d '%s' (x:%.2f, y:%.2f, delta:%f, %f)", |
| 1204 |
(unsigned int) stage_x11->xwin, |
| 1205 |
event->scroll.device->id, |
| 1206 |
event->scroll.device->device_name, |
| 1207 |
event->scroll.x, |
| 1208 |
event->scroll.y, |
| 1209 |
delta_x, delta_y); |
| 1210 |
|
| 1211 |
retval = CLUTTER_TRANSLATE_QUEUE; |
| 1212 |
break; |
| 1213 |
} |
| 1214 |
|
| 1215 |
event->motion.type = event->type = CLUTTER_MOTION; |
| 1216 |
|
| 1217 |
event->motion.stage = stage; |
| 1218 |
|
| 1219 |
event->motion.time = xev->time; |
| 1220 |
translate_coords (stage_x11, xev->event_x, xev->event_y, &event->motion.x, &event->motion.y); |
| 1221 |
_clutter_input_device_xi2_translate_state (event, |
| 1222 |
&xev->mods, |
| 1223 |
&xev->buttons, |
| 1224 |
&xev->group); |
| 1225 |
|
| 1226 |
clutter_event_set_source_device (event, source_device); |
| 1227 |
clutter_event_set_device (event, device); |
| 1228 |
|
| 1229 |
event->motion.axes = translate_axes (event->motion.device, |
| 1230 |
event->motion.x, |
| 1231 |
event->motion.y, |
| 1232 |
&xev->valuators); |
| 1233 |
|
| 1234 |
if (source_device != NULL && device->stage != NULL) |
| 1235 |
_clutter_input_device_set_stage (source_device, device->stage); |
| 1236 |
|
| 1237 |
#ifdef HAVE_XINPUT_2_2 |
| 1238 |
if (xev->flags & XIPointerEmulated) |
| 1239 |
_clutter_event_set_pointer_emulated (event, TRUE); |
| 1240 |
#endif /* HAVE_XINPUT_2_2 */ |
| 1241 |
|
| 1242 |
CLUTTER_NOTE (EVENT, "motion: win:0x%x device:%d '%s' (x:%.2f, y:%.2f, axes:%s)", |
| 1243 |
(unsigned int) stage_x11->xwin, |
| 1244 |
event->motion.device->id, |
| 1245 |
event->motion.device->device_name, |
| 1246 |
event->motion.x, |
| 1247 |
event->motion.y, |
| 1248 |
event->motion.axes != NULL ? "yes" : "no"); |
| 1249 |
|
| 1250 |
retval = CLUTTER_TRANSLATE_QUEUE; |
| 1251 |
} |
| 1252 |
break; |
| 1253 |
|
| 1254 |
#ifdef HAVE_XINPUT_2_2 |
| 1255 |
case XI_TouchBegin: |
| 1256 |
{ |
| 1257 |
XIDeviceEvent *xev = (XIDeviceEvent *) xi_event; |
| 1258 |
device = g_hash_table_lookup (manager_xi2->devices_by_id, |
| 1259 |
GINT_TO_POINTER (xev->deviceid)); |
| 1260 |
if (!_clutter_input_device_get_stage (device)) |
| 1261 |
_clutter_input_device_set_stage (device, stage); |
| 1262 |
} |
| 1263 |
/* Fall through */ |
| 1264 |
case XI_TouchEnd: |
| 1265 |
{ |
| 1266 |
XIDeviceEvent *xev = (XIDeviceEvent *) xi_event; |
| 1267 |
|
| 1268 |
source_device = g_hash_table_lookup (manager_xi2->devices_by_id, |
| 1269 |
GINT_TO_POINTER (xev->sourceid)); |
| 1270 |
|
| 1271 |
if (xi_event->evtype == XI_TouchBegin) |
| 1272 |
event->touch.type = event->type = CLUTTER_TOUCH_BEGIN; |
| 1273 |
else |
| 1274 |
event->touch.type = event->type = CLUTTER_TOUCH_END; |
| 1275 |
|
| 1276 |
event->touch.stage = stage; |
| 1277 |
event->touch.time = xev->time; |
| 1278 |
translate_coords (stage_x11, xev->event_x, xev->event_y, &event->touch.x, &event->touch.y); |
| 1279 |
_clutter_input_device_xi2_translate_state (event, |
| 1280 |
&xev->mods, |
| 1281 |
&xev->buttons, |
| 1282 |
&xev->group); |
| 1283 |
|
| 1284 |
clutter_event_set_source_device (event, source_device); |
| 1285 |
|
| 1286 |
device = g_hash_table_lookup (manager_xi2->devices_by_id, |
| 1287 |
GINT_TO_POINTER (xev->deviceid)); |
| 1288 |
clutter_event_set_device (event, device); |
| 1289 |
|
| 1290 |
event->touch.axes = translate_axes (event->touch.device, |
| 1291 |
event->motion.x, |
| 1292 |
event->motion.y, |
| 1293 |
&xev->valuators); |
| 1294 |
|
| 1295 |
if (xi_event->evtype == XI_TouchBegin) |
| 1296 |
{ |
| 1297 |
event->touch.modifier_state |= CLUTTER_BUTTON1_MASK; |
| 1298 |
|
| 1299 |
_clutter_stage_x11_set_user_time (stage_x11, event->touch.time); |
| 1300 |
} |
| 1301 |
|
| 1302 |
event->touch.sequence = GUINT_TO_POINTER (xev->detail); |
| 1303 |
|
| 1304 |
if (xev->flags & XITouchEmulatingPointer) |
| 1305 |
_clutter_event_set_pointer_emulated (event, TRUE); |
| 1306 |
|
| 1307 |
CLUTTER_NOTE (EVENT, "touch %s: win:0x%x device:%d '%s' (seq:%d, x:%.2f, y:%.2f, axes:%s)", |
| 1308 |
event->type == CLUTTER_TOUCH_BEGIN ? "begin" : "end", |
| 1309 |
(unsigned int) stage_x11->xwin, |
| 1310 |
event->touch.device->id, |
| 1311 |
event->touch.device->device_name, |
| 1312 |
GPOINTER_TO_UINT (event->touch.sequence), |
| 1313 |
event->touch.x, |
| 1314 |
event->touch.y, |
| 1315 |
event->touch.axes != NULL ? "yes" : "no"); |
| 1316 |
|
| 1317 |
retval = CLUTTER_TRANSLATE_QUEUE; |
| 1318 |
} |
| 1319 |
break; |
| 1320 |
|
| 1321 |
case XI_TouchUpdate: |
| 1322 |
{ |
| 1323 |
XIDeviceEvent *xev = (XIDeviceEvent *) xi_event; |
| 1324 |
|
| 1325 |
source_device = g_hash_table_lookup (manager_xi2->devices_by_id, |
| 1326 |
GINT_TO_POINTER (xev->sourceid)); |
| 1327 |
|
| 1328 |
event->touch.type = event->type = CLUTTER_TOUCH_UPDATE; |
| 1329 |
event->touch.stage = stage; |
| 1330 |
event->touch.time = xev->time; |
| 1331 |
event->touch.sequence = GUINT_TO_POINTER (xev->detail); |
| 1332 |
translate_coords (stage_x11, xev->event_x, xev->event_y, &event->touch.x, &event->touch.y); |
| 1333 |
|
| 1334 |
clutter_event_set_source_device (event, source_device); |
| 1335 |
|
| 1336 |
device = g_hash_table_lookup (manager_xi2->devices_by_id, |
| 1337 |
GINT_TO_POINTER (xev->deviceid)); |
| 1338 |
clutter_event_set_device (event, device); |
| 1339 |
|
| 1340 |
event->touch.axes = translate_axes (event->touch.device, |
| 1341 |
event->motion.x, |
| 1342 |
event->motion.y, |
| 1343 |
&xev->valuators); |
| 1344 |
|
| 1345 |
_clutter_input_device_xi2_translate_state (event, |
| 1346 |
&xev->mods, |
| 1347 |
&xev->buttons, |
| 1348 |
&xev->group); |
| 1349 |
event->touch.modifier_state |= CLUTTER_BUTTON1_MASK; |
| 1350 |
|
| 1351 |
if (xev->flags & XITouchEmulatingPointer) |
| 1352 |
_clutter_event_set_pointer_emulated (event, TRUE); |
| 1353 |
|
| 1354 |
CLUTTER_NOTE (EVENT, "touch update: win:0x%x device:%d '%s' (seq:%d, x:%.2f, y:%.2f, axes:%s)", |
| 1355 |
(unsigned int) stage_x11->xwin, |
| 1356 |
event->touch.device->id, |
| 1357 |
event->touch.device->device_name, |
| 1358 |
GPOINTER_TO_UINT (event->touch.sequence), |
| 1359 |
event->touch.x, |
| 1360 |
event->touch.y, |
| 1361 |
event->touch.axes != NULL ? "yes" : "no"); |
| 1362 |
|
| 1363 |
retval = CLUTTER_TRANSLATE_QUEUE; |
| 1364 |
} |
| 1365 |
break; |
| 1366 |
#endif /* HAVE_XINPUT_2_2 */ |
| 1367 |
|
| 1368 |
case XI_Enter: |
| 1369 |
case XI_Leave: |
| 1370 |
{ |
| 1371 |
XIEnterEvent *xev = (XIEnterEvent *) xi_event; |
| 1372 |
|
| 1373 |
device = g_hash_table_lookup (manager_xi2->devices_by_id, |
| 1374 |
GINT_TO_POINTER (xev->deviceid)); |
| 1375 |
|
| 1376 |
source_device = g_hash_table_lookup (manager_xi2->devices_by_id, |
| 1377 |
GINT_TO_POINTER (xev->sourceid)); |
| 1378 |
|
| 1379 |
if (xi_event->evtype == XI_Enter) |
| 1380 |
{ |
| 1381 |
event->crossing.type = event->type = CLUTTER_ENTER; |
| 1382 |
|
| 1383 |
event->crossing.stage = stage; |
| 1384 |
event->crossing.source = CLUTTER_ACTOR (stage); |
| 1385 |
event->crossing.related = NULL; |
| 1386 |
|
| 1387 |
event->crossing.time = xev->time; |
| 1388 |
translate_coords (stage_x11, xev->event_x, xev->event_y, &event->crossing.x, &event->crossing.y); |
| 1389 |
|
| 1390 |
_clutter_input_device_set_stage (device, stage); |
| 1391 |
} |
| 1392 |
else |
| 1393 |
{ |
| 1394 |
if (device->stage == NULL) |
| 1395 |
{ |
| 1396 |
CLUTTER_NOTE (EVENT, |
| 1397 |
"Discarding Leave for ButtonRelease " |
| 1398 |
"event off-stage"); |
| 1399 |
|
| 1400 |
retval = CLUTTER_TRANSLATE_REMOVE; |
| 1401 |
break; |
| 1402 |
} |
| 1403 |
|
| 1404 |
event->crossing.type = event->type = CLUTTER_LEAVE; |
| 1405 |
|
| 1406 |
event->crossing.stage = stage; |
| 1407 |
event->crossing.source = CLUTTER_ACTOR (stage); |
| 1408 |
event->crossing.related = NULL; |
| 1409 |
|
| 1410 |
event->crossing.time = xev->time; |
| 1411 |
translate_coords (stage_x11, xev->event_x, xev->event_y, &event->crossing.x, &event->crossing.y); |
| 1412 |
|
| 1413 |
_clutter_input_device_set_stage (device, NULL); |
| 1414 |
} |
| 1415 |
|
| 1416 |
_clutter_input_device_reset_scroll_info (source_device); |
| 1417 |
|
| 1418 |
clutter_event_set_device (event, device); |
| 1419 |
clutter_event_set_source_device (event, source_device); |
| 1420 |
|
| 1421 |
retval = CLUTTER_TRANSLATE_QUEUE; |
| 1422 |
} |
| 1423 |
break; |
| 1424 |
|
| 1425 |
case XI_FocusIn: |
| 1426 |
case XI_FocusOut: |
| 1427 |
retval = CLUTTER_TRANSLATE_CONTINUE; |
| 1428 |
break; |
| 1429 |
} |
| 1430 |
|
| 1431 |
return retval; |
| 1432 |
} |
| 1433 |
|
| 1434 |
static void |
| 1435 |
clutter_event_translator_iface_init (ClutterEventTranslatorIface *iface) |
| 1436 |
{ |
| 1437 |
iface->translate_event = clutter_device_manager_xi2_translate_event; |
| 1438 |
} |
| 1439 |
|
| 1440 |
static void |
| 1441 |
clutter_device_manager_xi2_add_device (ClutterDeviceManager *manager, |
| 1442 |
ClutterInputDevice *device) |
| 1443 |
{ |
| 1444 |
/* XXX implement */ |
| 1445 |
} |
| 1446 |
|
| 1447 |
static void |
| 1448 |
clutter_device_manager_xi2_remove_device (ClutterDeviceManager *manager, |
| 1449 |
ClutterInputDevice *device) |
| 1450 |
{ |
| 1451 |
/* XXX implement */ |
| 1452 |
} |
| 1453 |
|
| 1454 |
static const GSList * |
| 1455 |
clutter_device_manager_xi2_get_devices (ClutterDeviceManager *manager) |
| 1456 |
{ |
| 1457 |
ClutterDeviceManagerXI2 *manager_xi2 = CLUTTER_DEVICE_MANAGER_XI2 (manager); |
| 1458 |
GSList *all_devices = NULL; |
| 1459 |
GList *l; |
| 1460 |
|
| 1461 |
if (manager_xi2->all_devices != NULL) |
| 1462 |
return manager_xi2->all_devices; |
| 1463 |
|
| 1464 |
for (l = manager_xi2->master_devices; l != NULL; l = l->next) |
| 1465 |
all_devices = g_slist_prepend (all_devices, l->data); |
| 1466 |
|
| 1467 |
for (l = manager_xi2->slave_devices; l != NULL; l = l->next) |
| 1468 |
all_devices = g_slist_prepend (all_devices, l->data); |
| 1469 |
|
| 1470 |
manager_xi2->all_devices = g_slist_reverse (all_devices); |
| 1471 |
|
| 1472 |
return manager_xi2->all_devices; |
| 1473 |
} |
| 1474 |
|
| 1475 |
static ClutterInputDevice * |
| 1476 |
clutter_device_manager_xi2_get_device (ClutterDeviceManager *manager, |
| 1477 |
gint id) |
| 1478 |
{ |
| 1479 |
ClutterDeviceManagerXI2 *manager_xi2 = CLUTTER_DEVICE_MANAGER_XI2 (manager); |
| 1480 |
|
| 1481 |
return g_hash_table_lookup (manager_xi2->devices_by_id, |
| 1482 |
GINT_TO_POINTER (id)); |
| 1483 |
} |
| 1484 |
|
| 1485 |
static ClutterInputDevice * |
| 1486 |
clutter_device_manager_xi2_get_core_device (ClutterDeviceManager *manager, |
| 1487 |
ClutterInputDeviceType device_type) |
| 1488 |
{ |
| 1489 |
ClutterDeviceManagerXI2 *manager_xi2 = CLUTTER_DEVICE_MANAGER_XI2 (manager); |
| 1490 |
ClutterInputDevice *pointer = NULL; |
| 1491 |
GList *l; |
| 1492 |
|
| 1493 |
for (l = manager_xi2->master_devices; l != NULL ; l = l->next) |
| 1494 |
{ |
| 1495 |
ClutterInputDevice *device = l->data; |
| 1496 |
if (clutter_input_device_get_device_type (device) == CLUTTER_POINTER_DEVICE) |
| 1497 |
{ |
| 1498 |
pointer = device; |
| 1499 |
break; |
| 1500 |
} |
| 1501 |
} |
| 1502 |
|
| 1503 |
if (pointer == NULL) |
| 1504 |
return NULL; |
| 1505 |
|
| 1506 |
switch (device_type) |
| 1507 |
{ |
| 1508 |
case CLUTTER_POINTER_DEVICE: |
| 1509 |
return pointer; |
| 1510 |
|
| 1511 |
case CLUTTER_KEYBOARD_DEVICE: |
| 1512 |
return clutter_input_device_get_associated_device (pointer); |
| 1513 |
|
| 1514 |
default: |
| 1515 |
break; |
| 1516 |
} |
| 1517 |
|
| 1518 |
return NULL; |
| 1519 |
} |
| 1520 |
|
| 1521 |
static void |
| 1522 |
relate_masters (gpointer key, |
| 1523 |
gpointer value, |
| 1524 |
gpointer data) |
| 1525 |
{ |
| 1526 |
ClutterDeviceManagerXI2 *manager_xi2 = data; |
| 1527 |
ClutterInputDevice *device, *relative; |
| 1528 |
|
| 1529 |
device = g_hash_table_lookup (manager_xi2->devices_by_id, key); |
| 1530 |
relative = g_hash_table_lookup (manager_xi2->devices_by_id, value); |
| 1531 |
|
| 1532 |
_clutter_input_device_set_associated_device (device, relative); |
| 1533 |
_clutter_input_device_set_associated_device (relative, device); |
| 1534 |
} |
| 1535 |
|
| 1536 |
static void |
| 1537 |
relate_slaves (gpointer key, |
| 1538 |
gpointer value, |
| 1539 |
gpointer data) |
| 1540 |
{ |
| 1541 |
ClutterDeviceManagerXI2 *manager_xi2 = data; |
| 1542 |
ClutterInputDevice *master, *slave; |
| 1543 |
|
| 1544 |
slave = g_hash_table_lookup (manager_xi2->devices_by_id, key); |
| 1545 |
master = g_hash_table_lookup (manager_xi2->devices_by_id, value); |
| 1546 |
|
| 1547 |
_clutter_input_device_set_associated_device (slave, master); |
| 1548 |
_clutter_input_device_add_slave (master, slave); |
| 1549 |
} |
| 1550 |
|
| 1551 |
static void |
| 1552 |
clutter_device_manager_xi2_constructed (GObject *gobject) |
| 1553 |
{ |
| 1554 |
ClutterDeviceManagerXI2 *manager_xi2 = CLUTTER_DEVICE_MANAGER_XI2 (gobject); |
| 1555 |
ClutterDeviceManager *manager = CLUTTER_DEVICE_MANAGER (gobject); |
| 1556 |
ClutterBackendX11 *backend_x11; |
| 1557 |
GHashTable *masters, *slaves; |
| 1558 |
XIDeviceInfo *info; |
| 1559 |
XIEventMask event_mask; |
| 1560 |
unsigned char mask[2] = { 0, }; |
| 1561 |
int n_devices, i; |
| 1562 |
|
| 1563 |
backend_x11 = |
| 1564 |
CLUTTER_BACKEND_X11 (_clutter_device_manager_get_backend (manager)); |
| 1565 |
|
| 1566 |
masters = g_hash_table_new (NULL, NULL); |
| 1567 |
slaves = g_hash_table_new (NULL, NULL); |
| 1568 |
|
| 1569 |
info = XIQueryDevice (backend_x11->xdpy, XIAllDevices, &n_devices); |
| 1570 |
|
| 1571 |
for (i = 0; i < n_devices; i++) |
| 1572 |
{ |
| 1573 |
XIDeviceInfo *xi_device = &info[i]; |
| 1574 |
|
| 1575 |
if (!xi_device->enabled) |
| 1576 |
continue; |
| 1577 |
|
| 1578 |
add_device (manager_xi2, backend_x11, xi_device, TRUE); |
| 1579 |
|
| 1580 |
if (xi_device->use == XIMasterPointer || |
| 1581 |
xi_device->use == XIMasterKeyboard) |
| 1582 |
{ |
| 1583 |
g_hash_table_insert (masters, |
| 1584 |
GINT_TO_POINTER (xi_device->deviceid), |
| 1585 |
GINT_TO_POINTER (xi_device->attachment)); |
| 1586 |
} |
| 1587 |
else if (xi_device->use == XISlavePointer || |
| 1588 |
xi_device->use == XISlaveKeyboard) |
| 1589 |
{ |
| 1590 |
g_hash_table_insert (slaves, |
| 1591 |
GINT_TO_POINTER (xi_device->deviceid), |
| 1592 |
GINT_TO_POINTER (xi_device->attachment)); |
| 1593 |
} |
| 1594 |
} |
| 1595 |
|
| 1596 |
XIFreeDeviceInfo (info); |
| 1597 |
|
| 1598 |
g_hash_table_foreach (masters, relate_masters, manager_xi2); |
| 1599 |
g_hash_table_destroy (masters); |
| 1600 |
|
| 1601 |
g_hash_table_foreach (slaves, relate_slaves, manager_xi2); |
| 1602 |
g_hash_table_destroy (slaves); |
| 1603 |
|
| 1604 |
XISetMask (mask, XI_HierarchyChanged); |
| 1605 |
XISetMask (mask, XI_DeviceChanged); |
| 1606 |
|
| 1607 |
event_mask.deviceid = XIAllDevices; |
| 1608 |
event_mask.mask_len = sizeof (mask); |
| 1609 |
event_mask.mask = mask; |
| 1610 |
|
| 1611 |
clutter_device_manager_xi2_select_events (manager, |
| 1612 |
clutter_x11_get_root_window (), |
| 1613 |
&event_mask); |
| 1614 |
|
| 1615 |
XSync (backend_x11->xdpy, False); |
| 1616 |
|
| 1617 |
if (G_OBJECT_CLASS (clutter_device_manager_xi2_parent_class)->constructed) |
| 1618 |
G_OBJECT_CLASS (clutter_device_manager_xi2_parent_class)->constructed (gobject); |
| 1619 |
} |
| 1620 |
|
| 1621 |
static void |
| 1622 |
clutter_device_manager_xi2_set_property (GObject *gobject, |
| 1623 |
guint prop_id, |
| 1624 |
const GValue *value, |
| 1625 |
GParamSpec *pspec) |
| 1626 |
{ |
| 1627 |
ClutterDeviceManagerXI2 *manager_xi2 = CLUTTER_DEVICE_MANAGER_XI2 (gobject); |
| 1628 |
|
| 1629 |
switch (prop_id) |
| 1630 |
{ |
| 1631 |
case PROP_OPCODE: |
| 1632 |
manager_xi2->opcode = g_value_get_int (value); |
| 1633 |
break; |
| 1634 |
|
| 1635 |
default: |
| 1636 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); |
| 1637 |
break; |
| 1638 |
} |
| 1639 |
} |
| 1640 |
|
| 1641 |
static void |
| 1642 |
clutter_device_manager_xi2_class_init (ClutterDeviceManagerXI2Class *klass) |
| 1643 |
{ |
| 1644 |
ClutterDeviceManagerClass *manager_class; |
| 1645 |
GObjectClass *gobject_class; |
| 1646 |
|
| 1647 |
obj_props[PROP_OPCODE] = |
| 1648 |
g_param_spec_int ("opcode", |
| 1649 |
"Opcode", |
| 1650 |
"The XI2 opcode", |
| 1651 |
-1, G_MAXINT, |
| 1652 |
-1, |
| 1653 |
CLUTTER_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY); |
| 1654 |
|
| 1655 |
gobject_class = G_OBJECT_CLASS (klass); |
| 1656 |
gobject_class->constructed = clutter_device_manager_xi2_constructed; |
| 1657 |
gobject_class->set_property = clutter_device_manager_xi2_set_property; |
| 1658 |
|
| 1659 |
g_object_class_install_properties (gobject_class, PROP_LAST, obj_props); |
| 1660 |
|
| 1661 |
manager_class = CLUTTER_DEVICE_MANAGER_CLASS (klass); |
| 1662 |
manager_class->add_device = clutter_device_manager_xi2_add_device; |
| 1663 |
manager_class->remove_device = clutter_device_manager_xi2_remove_device; |
| 1664 |
manager_class->get_devices = clutter_device_manager_xi2_get_devices; |
| 1665 |
manager_class->get_core_device = clutter_device_manager_xi2_get_core_device; |
| 1666 |
manager_class->get_device = clutter_device_manager_xi2_get_device; |
| 1667 |
manager_class->select_stage_events = clutter_device_manager_xi2_select_stage_events; |
| 1668 |
} |
| 1669 |
|
| 1670 |
static void |
| 1671 |
clutter_device_manager_xi2_init (ClutterDeviceManagerXI2 *self) |
| 1672 |
{ |
| 1673 |
self->devices_by_id = g_hash_table_new_full (NULL, NULL, |
| 1674 |
NULL, |
| 1675 |
(GDestroyNotify) g_object_unref); |
| 1676 |
} |