summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stone <daniel@fooishbar.org>2012-08-30 15:08:43 -0700
committerEmmanuele Bassi <ebassi@gnome.org>2012-10-13 18:12:18 +0100
commit437679c0533583f006616ae811b7340183bacec3 (patch)
tree2859d3f0a1100b0cd54a7b96f1e4d6ba26b088a6
parent75934dadbe5765644e28f10e9520b79b93662f03 (diff)
downloadclutter-437679c0533583f006616ae811b7340183bacec3.tar.gz
Wayland: Add key repeat
Add support for repeating keys to the Wayland input backend. Unfortunately the repeat delay/interval is hardcoded into the Clutter backend, as Wayland doesn't yet tell clients what the global values should be. Signed-off-by: Daniel Stone <daniel@fooishbar.org> (cherry picked from commit 1c7a740385abf4abed9dce162797653331f93615) Signed-off-by: Emmanuele Bassi <ebassi@gnome.org>
-rw-r--r--clutter/wayland/clutter-input-device-wayland.c58
-rw-r--r--clutter/wayland/clutter-input-device-wayland.h5
2 files changed, 63 insertions, 0 deletions
diff --git a/clutter/wayland/clutter-input-device-wayland.c b/clutter/wayland/clutter-input-device-wayland.c
index 756a156fc..89c8fc569 100644
--- a/clutter/wayland/clutter-input-device-wayland.c
+++ b/clutter/wayland/clutter-input-device-wayland.c
@@ -216,6 +216,38 @@ clutter_wayland_handle_keymap (void *data,
}
}
+/* XXX: Need a wl_keyboard event to harmonise these across clients. */
+#define KEY_REPEAT_DELAY 660
+#define KEY_REPEAT_INTERVAL 40
+
+static gboolean
+clutter_wayland_repeat_key (void *data)
+{
+ ClutterInputDeviceWayland *device = data;
+ ClutterStageCogl *stage_cogl = device->keyboard_focus;
+ ClutterEvent *event;
+
+ event = _clutter_key_event_new_from_evdev ((ClutterInputDevice *) device,
+ stage_cogl->wrapper,
+ device->xkb,
+ device->repeat_time,
+ device->repeat_key,
+ 1);
+ device->repeat_time += KEY_REPEAT_INTERVAL;
+ _clutter_event_push (event, FALSE);
+
+ if (!device->is_initial_repeat)
+ return TRUE;
+
+ g_source_remove (device->repeat_source);
+ device->repeat_source = g_timeout_add (KEY_REPEAT_INTERVAL,
+ clutter_wayland_repeat_key,
+ device);
+ device->is_initial_repeat = FALSE;
+
+ return FALSE;
+}
+
static void
clutter_wayland_handle_key (void *data,
struct wl_keyboard *keyboard,
@@ -235,6 +267,26 @@ clutter_wayland_handle_key (void *data,
_time, key, state);
_clutter_event_push (event, FALSE);
+
+ if (!xkb_key_repeats (xkb_state_get_map (device->xkb), key))
+ return;
+
+ if (state)
+ {
+ if (device->repeat_key != XKB_KEYCODE_INVALID)
+ g_source_remove (device->repeat_source);
+ device->repeat_key = key;
+ device->repeat_time = _time + KEY_REPEAT_DELAY;
+ device->repeat_source = g_timeout_add (KEY_REPEAT_DELAY,
+ clutter_wayland_repeat_key,
+ device);
+ device->is_initial_repeat = TRUE;
+ }
+ else if (device->repeat_key == key)
+ {
+ g_source_remove (device->repeat_source);
+ device->repeat_key = XKB_KEYCODE_INVALID;
+ }
}
static void
@@ -374,6 +426,12 @@ clutter_wayland_handle_keyboard_leave (void *data,
CLUTTER_STAGE_STATE_ACTIVATED,
0);
+ if (device->repeat_key != XKB_KEYCODE_INVALID)
+ {
+ g_source_remove (device->repeat_source);
+ device->repeat_key = XKB_KEYCODE_INVALID;
+ }
+
device->keyboard_focus = NULL;
}
diff --git a/clutter/wayland/clutter-input-device-wayland.h b/clutter/wayland/clutter-input-device-wayland.h
index 723bde0fe..fc79ffbbc 100644
--- a/clutter/wayland/clutter-input-device-wayland.h
+++ b/clutter/wayland/clutter-input-device-wayland.h
@@ -26,6 +26,7 @@
#ifndef __CLUTTER_INPUT_DEVICE_WAYLAND_H__
#define __CLUTTER_INPUT_DEVICE_WAYLAND_H__
+#include <xkbcommon/xkbcommon.h>
#include <glib-object.h>
#include <clutter/clutter-event.h>
@@ -48,6 +49,10 @@ struct _ClutterInputDeviceWayland
struct xkb_state *xkb;
gint has_pointer;
gint has_keyboard;
+ xkb_keycode_t repeat_key;
+ guint repeat_time;
+ guint repeat_source;
+ gboolean is_initial_repeat;
};
GType clutter_input_device_wayland_get_type (void) G_GNUC_CONST;