Use enum wl_keyboard_key_state instead of integer
Instead of using a uint32_t for state everywhere (except on the wire,
where that's still the call signature), use the new
wl_keyboard_key_state enum, and explicit comparisons.
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
diff --git a/src/compositor-wayland.c b/src/compositor-wayland.c
index 02ebc6c..83bd683 100644
--- a/src/compositor-wayland.c
+++ b/src/compositor-wayland.c
@@ -607,7 +607,9 @@
struct wayland_input *input = data;
struct wayland_compositor *c = input->compositor;
- notify_key(&c->base.seat->seat, time, key, state);
+ notify_key(&c->base.seat->seat, time, key,
+ state ? WL_KEYBOARD_KEY_STATE_PRESSED :
+ WL_KEYBOARD_KEY_STATE_RELEASED);
}
static void
diff --git a/src/compositor-x11.c b/src/compositor-x11.c
index 5a5c8db..b64b26c 100644
--- a/src/compositor-x11.c
+++ b/src/compositor-x11.c
@@ -586,7 +586,8 @@
* event below. */
notify_key(&c->base.seat->seat,
weston_compositor_get_time(),
- key_release->detail - 8, 0);
+ key_release->detail - 8,
+ WL_KEYBOARD_KEY_STATE_RELEASED);
free(prev);
prev = NULL;
break;
@@ -623,7 +624,8 @@
key_press = (xcb_key_press_event_t *) event;
notify_key(&c->base.seat->seat,
weston_compositor_get_time(),
- key_press->detail - 8, 1);
+ key_press->detail - 8,
+ WL_KEYBOARD_KEY_STATE_PRESSED);
break;
case XCB_KEY_RELEASE:
prev = event;
@@ -707,7 +709,8 @@
key_release = (xcb_key_press_event_t *) prev;
notify_key(&c->base.seat->seat,
weston_compositor_get_time(),
- key_release->detail - 8, 0);
+ key_release->detail - 8,
+ WL_KEYBOARD_KEY_STATE_RELEASED);
free(prev);
prev = NULL;
break;
diff --git a/src/compositor.c b/src/compositor.c
index 14d1494..7d4069e 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -1790,7 +1790,8 @@
}
WL_EXPORT void
-notify_key(struct wl_seat *seat, uint32_t time, uint32_t key, uint32_t state)
+notify_key(struct wl_seat *seat, uint32_t time, uint32_t key,
+ enum wl_keyboard_key_state state)
{
struct weston_seat *ws = (struct weston_seat *) seat;
struct weston_compositor *compositor = ws->compositor;
@@ -1801,7 +1802,7 @@
uint32_t *k, *end;
int mods;
- if (state) {
+ if (state == WL_KEYBOARD_KEY_STATE_PRESSED) {
if (compositor->ping_handler && focus)
compositor->ping_handler(focus, serial);
@@ -1819,7 +1820,7 @@
*k = *--end;
}
seat->keyboard->keys.size = (void *) end - seat->keyboard->keys.data;
- if (state) {
+ if (state == WL_KEYBOARD_KEY_STATE_PRESSED) {
k = wl_array_add(&seat->keyboard->keys, sizeof *k);
*k = key;
}
diff --git a/src/compositor.h b/src/compositor.h
index 1ea2de5..af4f94d 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -484,7 +484,7 @@
int32_t value);
void
notify_key(struct wl_seat *seat, uint32_t time, uint32_t key,
- uint32_t state);
+ enum wl_keyboard_key_state state);
void
notify_pointer_focus(struct wl_seat *seat, struct weston_output *output,
diff --git a/src/evdev.c b/src/evdev.c
index a7162fc..0a5ec91 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -86,7 +86,9 @@
default:
notify_key(&device->master->base.seat,
- time, e->code, e->value);
+ time, e->code,
+ e->value ? WL_KEYBOARD_KEY_STATE_PRESSED :
+ WL_KEYBOARD_KEY_STATE_RELEASED);
break;
}
}
diff --git a/src/shell.c b/src/shell.c
index 8f4822f..bca7afc 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -2482,11 +2482,12 @@
static void
switcher_key(struct wl_keyboard_grab *grab,
- uint32_t time, uint32_t key, uint32_t state)
+ uint32_t time, uint32_t key, uint32_t state_w)
{
struct switcher *switcher = container_of(grab, struct switcher, grab);
+ enum wl_keyboard_key_state state = state_w;
- if (key == KEY_TAB && state)
+ if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED)
switcher_next(switcher);
}
diff --git a/src/util.c b/src/util.c
index 01e5991..0b44b56 100644
--- a/src/util.c
+++ b/src/util.c
@@ -249,17 +249,18 @@
static void
binding_key(struct wl_keyboard_grab *grab,
- uint32_t time, uint32_t key, uint32_t state)
+ uint32_t time, uint32_t key, uint32_t state_w)
{
struct binding_keyboard_grab *b =
container_of(grab, struct binding_keyboard_grab, grab);
struct wl_resource *resource;
struct wl_display *display;
+ enum wl_keyboard_key_state state = state_w;
uint32_t serial;
resource = grab->keyboard->focus_resource;
if (key == b->key) {
- if (!state) {
+ if (state == WL_KEYBOARD_KEY_STATE_RELEASED) {
wl_keyboard_end_grab(grab->keyboard);
free(b);
}