[clutter/wip/wayland: 33/45] Add an input device function to convert keycodes to evdev codes



commit b6332926105204861408da2e697f8c961c4c6b98
Author: Neil Roberts <neil linux intel com>
Date:   Tue Jan 17 15:40:08 2012 +0000

    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.

 clutter/clutter-device-manager-private.h       |    3 ++
 clutter/clutter-input-device.c                 |   31 ++++++++++++++++++++++++
 clutter/clutter-input-device.h                 |    4 +++
 clutter/evdev/clutter-input-device-evdev.c     |   12 +++++++++
 clutter/wayland/clutter-input-device-wayland.c |   12 +++++++++
 clutter/x11/clutter-input-device-core-x11.c    |   15 +++++++++++
 clutter/x11/clutter-input-device-xi2.c         |   15 +++++++++++
 doc/reference/clutter/clutter-sections.txt     |    1 +
 8 files changed, 93 insertions(+), 0 deletions(-)
---
diff --git a/clutter/clutter-device-manager-private.h b/clutter/clutter-device-manager-private.h
index eb8fb12..df9b8df 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 9743d05..efec797 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 437a2cc..528707e 100644
--- a/clutter/clutter-input-device.h
+++ b/clutter/clutter-input-device.h
@@ -94,6 +94,10 @@ void                    clutter_input_device_grab               (ClutterInputDev
 void                    clutter_input_device_ungrab             (ClutterInputDevice  *device);
 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 fa769bd..7eccbe5 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 2210b5f..bc976e7 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 fe00fff..6c78a30 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 a17d2bd..620df91 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 59aa861..b9b017c 100644
--- a/doc/reference/clutter/clutter-sections.txt
+++ b/doc/reference/clutter/clutter-sections.txt
@@ -1178,6 +1178,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



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]