[gtk+/matthiasc/wayland/slowkeys: 4/9] wayland: Refactor key event processing
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/matthiasc/wayland/slowkeys: 4/9] wayland: Refactor key event processing
- Date: Thu, 3 Mar 2016 06:41:45 +0000 (UTC)
commit 38cd533159420dd7d24dceaaf9ae9c29b53409cb
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Mar 2 15:55:36 2016 -0500
wayland: Refactor key event processing
Split out the event translation and the key repeat handling
in subroutines.
gdk/wayland/gdkdevice-wayland.c | 86 +++++++++++++++++++++++---------------
1 files changed, 52 insertions(+), 34 deletions(-)
---
diff --git a/gdk/wayland/gdkdevice-wayland.c b/gdk/wayland/gdkdevice-wayland.c
index dae132b..d71bab7 100644
--- a/gdk/wayland/gdkdevice-wayland.c
+++ b/gdk/wayland/gdkdevice-wayland.c
@@ -1691,6 +1691,34 @@ get_key_repeat (GdkWaylandDeviceData *device,
}
static void
+start_key_repeat (GdkWaylandDeviceData *device,
+ uint32_t key)
+{
+ struct xkb_keymap *xkb_keymap;
+ guint delay, interval, timeout;
+
+ xkb_keymap = _gdk_wayland_keymap_get_xkb_keymap (device->keymap);
+
+ if (!xkb_keymap_key_repeats (xkb_keymap, key))
+ return;
+
+ if (!get_key_repeat (device, &delay, &interval))
+ return;
+
+ device->repeat_count++;
+ device->repeat_key = key;
+
+ if (device->repeat_count == 1)
+ timeout = delay;
+ else
+ timeout = interval;
+
+ device->repeat_timer =
+ gdk_threads_add_timeout (timeout, keyboard_repeat, device);
+ g_source_set_name_by_id (device->repeat_timer, "[gtk+] keyboard_repeat");
+}
+
+static void
stop_key_repeat (GdkWaylandDeviceData *device)
{
if (device->repeat_timer)
@@ -1702,30 +1730,19 @@ stop_key_repeat (GdkWaylandDeviceData *device)
g_clear_pointer (&device->repeat_callback, wl_callback_destroy);
}
-static void
-deliver_key_event (GdkWaylandDeviceData *device,
- uint32_t time_,
- uint32_t key,
- uint32_t state)
+static Gdkevent *
+translate_key_event (GdkWaylandDeviceData *device,
+ uint32_t time_,
+ uint32_t key,
+ uint32_t state)
{
GdkEvent *event;
struct xkb_state *xkb_state;
- struct xkb_keymap *xkb_keymap;
- GdkKeymap *keymap;
xkb_keysym_t sym;
- guint delay, interval, timeout;
-
- stop_key_repeat (device);
-
- keymap = device->keymap;
- xkb_state = _gdk_wayland_keymap_get_xkb_state (keymap);
- xkb_keymap = _gdk_wayland_keymap_get_xkb_keymap (keymap);
+ xkb_state = _gdk_wayland_keymap_get_xkb_state (device->keymap);
sym = xkb_state_key_get_one_sym (xkb_state, key);
- device->time = time_;
- device->key_modifiers = gdk_keymap_get_modifier_state (keymap);
-
event = gdk_event_new (state ? GDK_KEY_PRESS : GDK_KEY_RELEASE);
event->key.window = device->keyboard_focus ? g_object_ref (device->keyboard_focus) : NULL;
gdk_event_set_device (event, device->master_keyboard);
@@ -1740,6 +1757,21 @@ deliver_key_event (GdkWaylandDeviceData *device,
translate_keyboard_string (&event->key);
+ return event;
+}
+
+static void
+deliver_key_event (GdkWaylandDeviceData *device,
+ uint32_t time_,
+ uint32_t key,
+ uint32_t state)
+{
+ GdkEvent *event;
+
+ device->time = time_;
+ device->key_modifiers = gdk_keymap_get_modifier_state (device->keymap);
+
+ event = translate_key_event (device, time_, key, state);
_gdk_wayland_display_deliver_event (device->display, event);
GDK_NOTE (EVENTS,
@@ -1748,26 +1780,12 @@ deliver_key_event (GdkWaylandDeviceData *device,
event->key.hardware_keycode, event->key.keyval,
event->key.string, event->key.state));
- if (state == 0)
- return;
-
- if (!xkb_keymap_key_repeats (xkb_keymap, key))
- return;
+ stop_key_repeat (device);
- if (!get_key_repeat (device, &delay, &interval))
+ if (state == 0)
return;
- device->repeat_count++;
- device->repeat_key = key;
-
- if (device->repeat_count == 1)
- timeout = delay;
- else
- timeout = interval;
-
- device->repeat_timer =
- gdk_threads_add_timeout (timeout, keyboard_repeat, device);
- g_source_set_name_by_id (device->repeat_timer, "[gtk+] keyboard_repeat");
+ start_key_repeat (device, key);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]