The extension keyboard support in XInput 1.x is hopelessly broken.
Nevertheless, it's possible to use some bits of it, as we prefer the
core keyboard events to the XInput events, thus at least having proper
handling for X11 key events on the Stage window.
device_type = CLUTTER_POINTER_DEVICE;
break;
-#if 0
/* XInput1 is broken for keyboards */
case IsXExtensionKeyboard:
device_type = CLUTTER_KEYBOARD_DEVICE;
break;
-#endif
case IsXExtensionDevice:
device_type = CLUTTER_EXTENSION_DEVICE;
}
}
-#if 0 /* See XInput keyboard comment below HAVE_XINPUT */
+#ifdef HAVE_XINPUT
static void
-convert_xdevicekey_to_xkey (XDeviceKeyEvent *xkev, XEvent *xevent)
+convert_xdevicekey_to_xkey (XDeviceKeyEvent *xkev,
+ XEvent *xevent)
{
xevent->xany.type = xevent->xkey.type = xkev->type;
xevent->xkey.serial = xkev->serial;
#ifdef HAVE_XINPUT
int *ev_types = backend_x11->event_types;
int button_press, button_release;
+ int key_press, key_release;
int motion_notify;
button_press = ev_types[CLUTTER_X11_XINPUT_BUTTON_PRESS_EVENT];
button_release = ev_types[CLUTTER_X11_XINPUT_BUTTON_RELEASE_EVENT];
motion_notify = ev_types[CLUTTER_X11_XINPUT_MOTION_NOTIFY_EVENT];
+ key_press = ev_types[CLUTTER_X11_XINPUT_KEY_PRESS_EVENT];
+ key_release = ev_types[CLUTTER_X11_XINPUT_KEY_RELEASE_EVENT];
CLUTTER_NOTE (EVENT, "XInput event type: %d", xevent->type);
res = TRUE;
}
+ else if (xevent->type == key_press || xevent->type == key_release)
+ {
+ /* the XInput 1.x handling of key presses/releases is broken:
+ * it makes key repeat, key presses and releases outside the
+ * window not generate events even when the window has focus
+ */
+ XDeviceKeyEvent *xkev = (XDeviceKeyEvent *) xevent;
+ XEvent xevent_converted;
+
+ convert_xdevicekey_to_xkey (xkev, &xevent_converted);
+
+ event->key.type = event->type = (xevent->type == key_press)
+ ? CLUTTER_KEY_PRESS
+ : CLUTTER_KEY_RELEASE;
+
+ translate_key_event (backend, event, &xevent_converted);
+
+ if (xevent->type == key_press)
+ set_user_time (backend_x11, &xwindow, xkev->time);
+ }
else
#endif /* HAVE_XINPUT */
{
{
XInputClassInfo *xclass_info = x_device->classes + i;
int *button_press, *button_release, *motion_notify;
+ int *key_press, *key_release;
button_press =
&backend->event_types[CLUTTER_X11_XINPUT_BUTTON_PRESS_EVENT];
motion_notify =
&backend->event_types[CLUTTER_X11_XINPUT_MOTION_NOTIFY_EVENT];
+ key_press =
+ &backend->event_types[CLUTTER_X11_XINPUT_KEY_PRESS_EVENT];
+ key_release =
+ &backend->event_types[CLUTTER_X11_XINPUT_KEY_RELEASE_EVENT];
+
switch (xclass_info->input_class)
{
-#if 0
- /* XInput 1.x is broken for keyboards: */
+ /* event though XInput 1.x is broken for keyboard-like devices
+ * it might still be useful to track them down; the core keyboard
+ * will handle the right events anyway
+ */
case KeyClass:
- DeviceKeyPress (xdevice,
- backend->event_types[CLUTTER_X11_XINPUT_KEY_PRESS_EVENT],
+ DeviceKeyPress (x_device,
+ *key_press,
device_x11->xevent_list[n_events]);
n_events++;
- DeviceKeyRelease (xdevice,
- backend->event_types[CLUTTER_X11_XINPUT_KEY_RELEASE_EVENT],
+ DeviceKeyRelease (x_device,
+ *key_release,
device_x11->xevent_list[n_events]);
n_events++;
break;
-#endif
case ButtonClass:
DeviceButtonPress (x_device,
ClutterInputDeviceType device_type;
ClutterActor *hand = NULL;
+ g_print ("got a %s device '%s' with id %d...\n",
+ device_type_name (device),
+ clutter_input_device_get_device_name (device),
+ clutter_input_device_get_device_id (device));
+
device_type = clutter_input_device_get_device_type (device);
- if (device_type == CLUTTER_POINTER_DEVICE)
+ if (device_type == CLUTTER_POINTER_DEVICE ||
+ device_type == CLUTTER_EXTENSION_DEVICE)
{
- g_print ("got a pointer device '%s' with id %d...\n",
- clutter_input_device_get_device_name (device),
- clutter_input_device_get_device_id (device));
-
hand = clutter_texture_new_from_file (TESTS_DATADIR
G_DIR_SEPARATOR_S
"redhand.png",