summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeil Roberts <neil@linux.intel.com>2012-01-17 15:40:08 +0000
committerNeil Roberts <neil@linux.intel.com>2012-03-01 11:41:51 +0000
commit13e3f9e5f1f1f648280a154fe1900fce4a26500a (patch)
tree28ca8ba0607ea2b2abf1c7102909e54a26ab2345
parenta3bbcff946295f6e7232697fd167437baef6b785 (diff)
downloadclutter-13e3f9e5f1f1f648280a154fe1900fce4a26500a.tar.gz
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>
-rw-r--r--clutter/clutter-device-manager-private.h3
-rw-r--r--clutter/clutter-input-device.c31
-rw-r--r--clutter/clutter-input-device.h4
-rw-r--r--clutter/evdev/clutter-input-device-evdev.c12
-rw-r--r--clutter/wayland/clutter-input-device-wayland.c12
-rw-r--r--clutter/x11/clutter-input-device-core-x11.c15
-rw-r--r--clutter/x11/clutter-input-device-xi2.c15
-rw-r--r--doc/reference/clutter/clutter-sections.txt1
8 files changed, 93 insertions, 0 deletions
diff --git a/clutter/clutter-device-manager-private.h b/clutter/clutter-device-manager-private.h
index eb8fb1230..df9b8dfb5 100644
--- a/clutter/clutter-device-manager-private.h
+++ b/clutter/clutter-device-manager-private.h
@@ -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 */
diff --git a/clutter/clutter-input-device.c b/clutter/clutter-input-device.c
index 9743d057d..efec797bd 100644
--- a/clutter/clutter-input-device.c
+++ b/clutter/clutter-input-device.c
@@ -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);
+}
diff --git a/clutter/clutter-input-device.h b/clutter/clutter-input-device.h
index a2950f885..145874137 100644
--- a/clutter/clutter-input-device.h
+++ b/clutter/clutter-input-device.h
@@ -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__ */
diff --git a/clutter/evdev/clutter-input-device-evdev.c b/clutter/evdev/clutter-input-device-evdev.c
index fa769bde2..7eccbe58d 100644
--- a/clutter/evdev/clutter-input-device-evdev.c
+++ b/clutter/evdev/clutter-input-device-evdev.c
@@ -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:
diff --git a/clutter/wayland/clutter-input-device-wayland.c b/clutter/wayland/clutter-input-device-wayland.c
index 2210b5fa9..bc976e7a0 100644
--- a/clutter/wayland/clutter-input-device-wayland.c
+++ b/clutter/wayland/clutter-input-device-wayland.c
@@ -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
diff --git a/clutter/x11/clutter-input-device-core-x11.c b/clutter/x11/clutter-input-device-core-x11.c
index fe00fffbf..6c78a3024 100644
--- a/clutter/x11/clutter-input-device-core-x11.c
+++ b/clutter/x11/clutter-input-device-core-x11.c
@@ -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
diff --git a/clutter/x11/clutter-input-device-xi2.c b/clutter/x11/clutter-input-device-xi2.c
index a17d2bd46..620df9193 100644
--- a/clutter/x11/clutter-input-device-xi2.c
+++ b/clutter/x11/clutter-input-device-xi2.c
@@ -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
diff --git a/doc/reference/clutter/clutter-sections.txt b/doc/reference/clutter/clutter-sections.txt
index 913ffa93a..40ce97ae0 100644
--- a/doc/reference/clutter/clutter-sections.txt
+++ b/doc/reference/clutter/clutter-sections.txt
@@ -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