mirror of
https://github.com/brl/mutter.git
synced 2024-12-23 19:42:05 +00:00
Add an input device function to convert keycodes to evdev codes
This adds a virtual function to ClutterInputDevice to translate a keycode from the hardware_keycode member of ClutterKeyEvent to an evdev keycode. The function can fail so that input backends that don't have a sensible way to translate to evdev keycodes can return FALSE. There are implementations for evdev, wayland and X. The X implementation assumes that the X server is using an evdev driver in which case the hardware keycodes are the evdev codes plus 8. Reviewed-by: Emmanuele Bassi <ebassi@linux.intel.com>
This commit is contained in:
parent
a3bbcff946
commit
13e3f9e5f1
@ -113,6 +113,9 @@ struct _ClutterInputDeviceClass
|
||||
void (* select_stage_events) (ClutterInputDevice *device,
|
||||
ClutterStage *stage,
|
||||
gint event_mask);
|
||||
gboolean (* keycode_to_evdev) (ClutterInputDevice *device,
|
||||
guint hardware_keycode,
|
||||
guint *evdev_keycode);
|
||||
};
|
||||
|
||||
/* device manager */
|
||||
|
@ -1410,3 +1410,34 @@ _clutter_input_device_select_stage_events (ClutterInputDevice *device,
|
||||
if (device_class->select_stage_events != NULL)
|
||||
device_class->select_stage_events (device, stage, event_mask);
|
||||
}
|
||||
|
||||
/**
|
||||
* clutter_input_device_keycode_to_evdev:
|
||||
* @device: A #ClutterInputDevice
|
||||
* @hardware_keycode: The hardware keycode from a #ClutterKeyEvent
|
||||
* @evdev_keycode: The return location for the evdev keycode
|
||||
*
|
||||
* Translates a hardware keycode from a #ClutterKeyEvent to the
|
||||
* equivalent evdev keycode. Note that depending on the input backend
|
||||
* used by Clutter this function can fail if there is no obvious
|
||||
* mapping between the key codes. The hardware keycode can be taken
|
||||
* from the hardware_keycode member of #ClutterKeyEvent.
|
||||
*
|
||||
* Return value: %TRUE if the conversion succeeded, %FALSE otherwise.
|
||||
* Since: 1.10
|
||||
*/
|
||||
gboolean
|
||||
clutter_input_device_keycode_to_evdev (ClutterInputDevice *device,
|
||||
guint hardware_keycode,
|
||||
guint *evdev_keycode)
|
||||
{
|
||||
ClutterInputDeviceClass *device_class;
|
||||
|
||||
device_class = CLUTTER_INPUT_DEVICE_GET_CLASS (device);
|
||||
if (device_class->keycode_to_evdev == NULL)
|
||||
return FALSE;
|
||||
else
|
||||
return device_class->keycode_to_evdev (device,
|
||||
hardware_keycode,
|
||||
evdev_keycode);
|
||||
}
|
||||
|
@ -97,6 +97,10 @@ void clutter_input_device_ungrab (ClutterInputDev
|
||||
CLUTTER_AVAILABLE_IN_1_10
|
||||
ClutterActor * clutter_input_device_get_grabbed_actor (ClutterInputDevice *device);
|
||||
|
||||
gboolean clutter_input_device_keycode_to_evdev (ClutterInputDevice *device,
|
||||
guint hardware_keycode,
|
||||
guint *evdev_keycode);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __CLUTTER_INPUT_DEVICE_H__ */
|
||||
|
@ -123,6 +123,17 @@ clutter_input_device_evdev_finalize (GObject *object)
|
||||
G_OBJECT_CLASS (clutter_input_device_evdev_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
clutter_input_device_evdev_keycode_to_evdev (ClutterInputDevice *device,
|
||||
guint hardware_keycode,
|
||||
guint *evdev_keycode)
|
||||
{
|
||||
/* The hardware keycodes from the evdev backend are already evdev
|
||||
keycodes */
|
||||
*evdev_keycode = hardware_keycode;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
clutter_input_device_evdev_class_init (ClutterInputDeviceEvdevClass *klass)
|
||||
{
|
||||
@ -134,6 +145,7 @@ clutter_input_device_evdev_class_init (ClutterInputDeviceEvdevClass *klass)
|
||||
object_class->get_property = clutter_input_device_evdev_get_property;
|
||||
object_class->set_property = clutter_input_device_evdev_set_property;
|
||||
object_class->finalize = clutter_input_device_evdev_finalize;
|
||||
klass->keycode_to_evdev = clutter_input_device_evdev_keycode_to_evdev;
|
||||
|
||||
/*
|
||||
* ClutterInputDeviceEvdev:udev-device:
|
||||
|
@ -247,9 +247,21 @@ const struct wl_input_device_listener _clutter_input_device_wayland_listener = {
|
||||
clutter_wayland_handle_keyboard_focus,
|
||||
};
|
||||
|
||||
static gboolean
|
||||
clutter_input_device_wayland_keycode_to_evdev (ClutterInputDevice *device,
|
||||
guint hardware_keycode,
|
||||
guint *evdev_keycode)
|
||||
{
|
||||
/* The hardware keycodes from the wayland backend are already evdev
|
||||
keycodes */
|
||||
*evdev_keycode = hardware_keycode;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
clutter_input_device_wayland_class_init (ClutterInputDeviceWaylandClass *klass)
|
||||
{
|
||||
klass->keycode_to_evdev = clutter_input_device_wayland_keycode_to_evdev;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -200,6 +200,20 @@ clutter_input_device_x11_constructed (GObject *gobject)
|
||||
G_OBJECT_CLASS (clutter_input_device_x11_parent_class)->constructed (gobject);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
clutter_input_device_x11_keycode_to_evdev (ClutterInputDevice *device,
|
||||
guint hardware_keycode,
|
||||
guint *evdev_keycode)
|
||||
{
|
||||
/* When using evdev under X11 the hardware keycodes are the evdev
|
||||
keycodes plus 8. I haven't been able to find any documentation to
|
||||
know what the +8 is for. FIXME: This should probably verify that
|
||||
X server is using evdev. */
|
||||
*evdev_keycode = hardware_keycode - 8;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
clutter_input_device_x11_class_init (ClutterInputDeviceX11Class *klass)
|
||||
{
|
||||
@ -210,6 +224,7 @@ clutter_input_device_x11_class_init (ClutterInputDeviceX11Class *klass)
|
||||
gobject_class->dispose = clutter_input_device_x11_dispose;
|
||||
|
||||
device_class->select_stage_events = clutter_input_device_x11_select_stage_events;
|
||||
device_class->keycode_to_evdev = clutter_input_device_x11_keycode_to_evdev;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -115,6 +115,20 @@ clutter_input_device_xi2_constructed (GObject *gobject)
|
||||
G_OBJECT_CLASS (clutter_input_device_xi2_parent_class)->constructed (gobject);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
clutter_input_device_xi2_keycode_to_evdev (ClutterInputDevice *device,
|
||||
guint hardware_keycode,
|
||||
guint *evdev_keycode)
|
||||
{
|
||||
/* When using evdev under X11 the hardware keycodes are the evdev
|
||||
keycodes plus 8. I haven't been able to find any documentation to
|
||||
know what the +8 is for. FIXME: This should probably verify that
|
||||
X server is using evdev. */
|
||||
*evdev_keycode = hardware_keycode - 8;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
clutter_input_device_xi2_class_init (ClutterInputDeviceXI2Class *klass)
|
||||
{
|
||||
@ -124,6 +138,7 @@ clutter_input_device_xi2_class_init (ClutterInputDeviceXI2Class *klass)
|
||||
gobject_class->constructed = clutter_input_device_xi2_constructed;
|
||||
|
||||
device_class->select_stage_events = clutter_input_device_xi2_select_stage_events;
|
||||
device_class->keycode_to_evdev = clutter_input_device_xi2_keycode_to_evdev;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -1184,6 +1184,7 @@ clutter_input_device_set_enabled
|
||||
clutter_input_device_get_enabled
|
||||
clutter_input_device_get_associated_device
|
||||
clutter_input_device_get_slave_devices
|
||||
clutter_input_device_keycode_to_evdev
|
||||
|
||||
<SUBSECTION>
|
||||
clutter_input_device_get_n_keys
|
||||
|
Loading…
Reference in New Issue
Block a user