[PATCH weston 14/31] Use enum wl_keyboard_key_state instead of integer
Daniel Stone
daniel at fooishbar.org
Wed May 30 08:31:52 PDT 2012
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 at fooishbar.org>
---
clients/clickdot.c | 5 +++--
clients/eventdemo.c | 10 +++++++---
clients/resizor.c | 5 +++--
clients/terminal.c | 10 ++++++----
clients/view.c | 5 +++--
clients/window.c | 6 ++++--
clients/window.h | 2 +-
src/compositor-wayland.c | 4 +++-
src/compositor-x11.c | 9 ++++++---
src/compositor.c | 7 ++++---
src/compositor.h | 2 +-
src/evdev.c | 4 +++-
src/shell.c | 5 +++--
src/util.c | 5 +++--
14 files changed, 50 insertions(+), 29 deletions(-)
diff --git a/clients/clickdot.c b/clients/clickdot.c
index be4ee18..c74bc91 100644
--- a/clients/clickdot.c
+++ b/clients/clickdot.c
@@ -180,11 +180,12 @@ keyboard_focus_handler(struct window *window,
static void
key_handler(struct window *window, struct input *input, uint32_t time,
- uint32_t key, uint32_t sym, uint32_t state, void *data)
+ uint32_t key, uint32_t sym,
+ enum wl_keyboard_key_state state, void *data)
{
struct clickdot *clickdot = data;
- if (state == 0)
+ if (state == WL_KEYBOARD_KEY_STATE_RELEASED)
return;
switch (sym) {
diff --git a/clients/eventdemo.c b/clients/eventdemo.c
index cb8cbbf..daf3283 100644
--- a/clients/eventdemo.c
+++ b/clients/eventdemo.c
@@ -188,15 +188,19 @@ keyboard_focus_handler(struct window *window,
*/
static void
key_handler(struct window *window, struct input *input, uint32_t time,
- uint32_t key, uint32_t unicode, uint32_t state, void *data)
+ uint32_t key, uint32_t unicode, enum wl_keyboard_key_state state,
+ void *data)
{
uint32_t modifiers = input_get_modifiers(input);
if(!log_key)
return;
- printf("key key: %d, unicode: %d, state: %d, modifiers: %d\n",
- key, unicode, state, modifiers);
+ printf("key key: %d, unicode: %d, state: %s, modifiers: 0x%x\n",
+ key, unicode,
+ (state == WL_KEYBOARD_KEY_STATE_PRESSED) ? "pressed" :
+ "released",
+ modifiers);
}
/**
diff --git a/clients/resizor.c b/clients/resizor.c
index 8186561..d02ab29 100644
--- a/clients/resizor.c
+++ b/clients/resizor.c
@@ -139,12 +139,13 @@ keyboard_focus_handler(struct window *window,
static void
key_handler(struct window *window, struct input *input, uint32_t time,
- uint32_t key, uint32_t sym, uint32_t state, void *data)
+ uint32_t key, uint32_t sym, enum wl_keyboard_key_state state,
+ void *data)
{
struct resizor *resizor = data;
struct rectangle allocation;
- if (state == 0)
+ if (state == WL_KEYBOARD_KEY_STATE_RELEASED)
return;
window_get_allocation(resizor->window, &allocation);
diff --git a/clients/terminal.c b/clients/terminal.c
index dab08f3..7841f29 100644
--- a/clients/terminal.c
+++ b/clients/terminal.c
@@ -2067,7 +2067,8 @@ handle_bound_key(struct terminal *terminal,
static void
key_handler(struct window *window, struct input *input, uint32_t time,
- uint32_t key, uint32_t sym, uint32_t state, void *data)
+ uint32_t key, uint32_t sym, enum wl_keyboard_key_state state,
+ void *data)
{
struct terminal *terminal = data;
char ch[MAX_RESPONSE];
@@ -2077,12 +2078,13 @@ key_handler(struct window *window, struct input *input, uint32_t time,
modifiers = input_get_modifiers(input);
if ((modifiers & MOD_CONTROL_MASK) &&
(modifiers & MOD_SHIFT_MASK) &&
- state && handle_bound_key(terminal, input, sym, time))
+ state == WL_KEYBOARD_KEY_STATE_PRESSED &&
+ handle_bound_key(terminal, input, sym, time))
return;
switch (sym) {
case XKB_KEY_F11:
- if (!state)
+ if (state == WL_KEYBOARD_KEY_STATE_RELEASED)
break;
terminal->fullscreen ^= 1;
window_set_fullscreen(window, terminal->fullscreen);
@@ -2193,7 +2195,7 @@ key_handler(struct window *window, struct input *input, uint32_t time,
break;
}
- if (state && len > 0)
+ if (state == WL_KEYBOARD_KEY_STATE_PRESSED && len > 0)
terminal_write(terminal, ch, len);
}
diff --git a/clients/view.c b/clients/view.c
index 6d32b3e..ee861e4 100644
--- a/clients/view.c
+++ b/clients/view.c
@@ -160,11 +160,12 @@ button_handler(struct widget *widget, struct input *input, uint32_t time,
static void
key_handler(struct window *window, struct input *input, uint32_t time,
- uint32_t key, uint32_t unicode, uint32_t state, void *data)
+ uint32_t key, uint32_t unicode,
+ enum wl_keyboard_key_state state, void *data)
{
struct view *view = data;
- if(!state)
+ if (state == WL_KEYBOARD_KEY_STATE_RELEASED)
return;
switch (key) {
diff --git a/clients/window.c b/clients/window.c
index 9abf1e3..1515226 100644
--- a/clients/window.c
+++ b/clients/window.c
@@ -1815,12 +1815,14 @@ pointer_handle_axis(void *data, struct wl_pointer *pointer,
static void
keyboard_handle_key(void *data, struct wl_keyboard *keyboard,
- uint32_t serial, uint32_t time, uint32_t key, uint32_t state)
+ uint32_t serial, uint32_t time, uint32_t key,
+ uint32_t state_w)
{
struct input *input = data;
struct window *window = input->keyboard_focus;
struct display *d = input->display;
uint32_t code, num_syms;
+ enum wl_keyboard_key_state state = state_w;
const xkb_keysym_t *syms;
xkb_keysym_t sym;
xkb_mod_mask_t mask;
@@ -1845,7 +1847,7 @@ keyboard_handle_key(void *data, struct wl_keyboard *keyboard,
if (num_syms == 1 && syms[0] == XKB_KEY_F5 &&
input->modifiers == MOD_ALT_MASK) {
- if (state)
+ if (state == WL_KEYBOARD_KEY_STATE_PRESSED)
window_set_maximized(window,
window->type != TYPE_MAXIMIZED);
} else if (window->key_handler) {
diff --git a/clients/window.h b/clients/window.h
index 10aa9a4..670a5fd 100644
--- a/clients/window.h
+++ b/clients/window.h
@@ -157,7 +157,7 @@ enum cursor_type {
typedef void (*window_key_handler_t)(struct window *window, struct input *input,
uint32_t time, uint32_t key, uint32_t unicode,
- uint32_t state, void *data);
+ enum wl_keyboard_key_state state, void *data);
typedef void (*window_keyboard_focus_handler_t)(struct window *window,
struct input *device, void *data);
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 @@ input_handle_key(void *data, struct wl_keyboard *keyboard,
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 @@ x11_compositor_handle_event(int fd, uint32_t mask, void *data)
* 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 @@ x11_compositor_handle_event(int fd, uint32_t mask, void *data)
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 @@ x11_compositor_handle_event(int fd, uint32_t mask, void *data)
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 67356e2..0e3e9ac 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -1792,7 +1792,8 @@ update_modifier_state(struct weston_seat *seat, uint32_t key, uint32_t state)
}
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;
@@ -1803,7 +1804,7 @@ notify_key(struct wl_seat *seat, uint32_t time, uint32_t key, uint32_t state)
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);
@@ -1821,7 +1822,7 @@ notify_key(struct wl_seat *seat, uint32_t time, uint32_t key, uint32_t state)
*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 2f7a9a6..16240ee 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -479,7 +479,7 @@ notify_axis(struct wl_seat *seat, uint32_t time, uint32_t axis,
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 @@ evdev_process_key(struct evdev_input_device *device,
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 b8a565b..887ce45 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -2481,11 +2481,12 @@ switcher_destroy(struct switcher *switcher)
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 @@ struct binding_keyboard_grab {
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);
}
--
1.7.10
More information about the wayland-devel
mailing list