[mutter] wayland-keyboard: Make update_pressed_keys() more generic
- From: Rui Matos <rtcm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter] wayland-keyboard: Make update_pressed_keys() more generic
- Date: Tue, 5 Aug 2014 16:14:56 +0000 (UTC)
commit bf9fdf448d1d012571d400536641c7d760eef0bc
Author: Rui Matos <tiagomatos gmail com>
Date: Thu Mar 27 14:42:11 2014 +0100
wayland-keyboard: Make update_pressed_keys() more generic
It will allow us to re-use this function next. Also rename the keys
array to pressed_keys since we'll need to add a different one.
https://bugzilla.gnome.org/show_bug.cgi?id=727178
src/wayland/meta-wayland-keyboard.c | 33 ++++++++++++++-------------------
src/wayland/meta-wayland-keyboard.h | 2 +-
2 files changed, 15 insertions(+), 20 deletions(-)
---
diff --git a/src/wayland/meta-wayland-keyboard.c b/src/wayland/meta-wayland-keyboard.c
index d3a71d3..e1b1430 100644
--- a/src/wayland/meta-wayland-keyboard.c
+++ b/src/wayland/meta-wayland-keyboard.c
@@ -359,7 +359,7 @@ meta_wayland_keyboard_init (MetaWaylandKeyboard *keyboard,
keyboard->focus_surface_listener.notify = keyboard_handle_focus_surface_destroy;
- wl_array_init (&keyboard->keys);
+ wl_array_init (&keyboard->pressed_keys);
keyboard->xkb_context = xkb_context_new (0 /* flags */);
keyboard->xkb_info.keymap_fd = -1;
@@ -397,43 +397,38 @@ meta_wayland_keyboard_release (MetaWaylandKeyboard *keyboard)
xkb_context_unref (keyboard->xkb_context);
/* XXX: What about keyboard->resource_list? */
- wl_array_release (&keyboard->keys);
+ wl_array_release (&keyboard->pressed_keys);
g_object_unref (keyboard->settings);
}
static void
-update_pressed_keys (MetaWaylandKeyboard *keyboard,
- uint32_t evdev_code,
- gboolean is_press)
+update_pressed_keys (struct wl_array *keys,
+ uint32_t evdev_code,
+ gboolean is_press)
{
+ uint32_t *end = (void *) ((char *) keys->data + keys->size);
+ uint32_t *k;
+
if (is_press)
{
- uint32_t *end = (void *) ((char *) keyboard->keys.data +
- keyboard->keys.size);
- uint32_t *k;
-
/* Make sure we don't already have this key. */
- for (k = keyboard->keys.data; k < end; k++)
+ for (k = keys->data; k < end; k++)
if (*k == evdev_code)
return;
/* Otherwise add the key to the list of pressed keys */
- k = wl_array_add (&keyboard->keys, sizeof (*k));
+ k = wl_array_add (keys, sizeof (*k));
*k = evdev_code;
}
else
{
- uint32_t *end = (void *) ((char *) keyboard->keys.data +
- keyboard->keys.size);
- uint32_t *k;
-
/* Remove the key from the array */
- for (k = keyboard->keys.data; k < end; k++)
+ for (k = keys->data; k < end; k++)
if (*k == evdev_code)
{
*k = *(end - 1);
- keyboard->keys.size -= sizeof (*k);
+ keys->size -= sizeof (*k);
return;
}
@@ -457,7 +452,7 @@ meta_wayland_keyboard_update (MetaWaylandKeyboard *keyboard,
struct xkb_state *state = keyboard->xkb_info.state;
enum xkb_state_component changed_state;
- update_pressed_keys (keyboard, evdev_code (event), is_press);
+ update_pressed_keys (&keyboard->pressed_keys, evdev_code (event), is_press);
changed_state = xkb_state_update_key (state,
event->hardware_keycode,
@@ -581,7 +576,7 @@ meta_wayland_keyboard_set_focus (MetaWaylandKeyboard *keyboard,
xkb_state_serialize_mods (state, XKB_STATE_MODS_LOCKED),
xkb_state_serialize_layout (state, XKB_STATE_LAYOUT_EFFECTIVE));
wl_keyboard_send_enter (resource, serial, keyboard->focus_surface->resource,
- &keyboard->keys);
+ &keyboard->pressed_keys);
}
keyboard->focus_serial = serial;
diff --git a/src/wayland/meta-wayland-keyboard.h b/src/wayland/meta-wayland-keyboard.h
index 77bfff1..edad9f3 100644
--- a/src/wayland/meta-wayland-keyboard.h
+++ b/src/wayland/meta-wayland-keyboard.h
@@ -69,7 +69,7 @@ struct _MetaWaylandKeyboard
struct wl_listener focus_surface_listener;
uint32_t focus_serial;
- struct wl_array keys;
+ struct wl_array pressed_keys;
struct xkb_context *xkb_context;
MetaWaylandXkbInfo xkb_info;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]