Use enum wl_pointer_button_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_pointer_button_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 332e1c2..02ebc6c 100644
--- a/src/compositor-wayland.c
+++ b/src/compositor-wayland.c
@@ -547,10 +547,12 @@
static void
input_handle_button(void *data, struct wl_pointer *pointer,
- uint32_t serial, uint32_t time, uint32_t button, uint32_t state)
+ uint32_t serial, uint32_t time, uint32_t button,
+ uint32_t state_w)
{
struct wayland_input *input = data;
struct wayland_compositor *c = input->compositor;
+ enum wl_pointer_button_state state = state_w;
notify_button(&c->base.seat->seat, time, button, state);
}
diff --git a/src/compositor-x11.c b/src/compositor-x11.c
index 98baa8a..5a5c8db 100644
--- a/src/compositor-x11.c
+++ b/src/compositor-x11.c
@@ -525,7 +525,9 @@
}
notify_button(&c->base.seat->seat,
- weston_compositor_get_time(), button, state);
+ weston_compositor_get_time(), button,
+ state ? WL_POINTER_BUTTON_STATE_PRESSED :
+ WL_POINTER_BUTTON_STATE_RELEASED);
}
static int
diff --git a/src/compositor.c b/src/compositor.c
index eb3d474..14d1494 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -1668,7 +1668,7 @@
WL_EXPORT void
notify_button(struct wl_seat *seat, uint32_t time, int32_t button,
- uint32_t state)
+ enum wl_pointer_button_state state)
{
struct weston_seat *ws = (struct weston_seat *) seat;
struct weston_compositor *compositor = ws->compositor;
@@ -1676,7 +1676,7 @@
(struct weston_surface *) seat->pointer->focus;
uint32_t serial = wl_display_next_serial(compositor->wl_display);
- if (state) {
+ if (state == WL_POINTER_BUTTON_STATE_PRESSED) {
if (compositor->ping_handler && focus)
compositor->ping_handler(focus, serial);
weston_compositor_idle_inhibit(compositor);
diff --git a/src/compositor.h b/src/compositor.h
index 08dcd77..1ea2de5 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -478,7 +478,7 @@
wl_fixed_t x, wl_fixed_t y);
void
notify_button(struct wl_seat *seat, uint32_t time, int32_t button,
- uint32_t state);
+ enum wl_pointer_button_state state);
void
notify_axis(struct wl_seat *seat, uint32_t time, uint32_t axis,
int32_t value);
diff --git a/src/evdev-touchpad.c b/src/evdev-touchpad.c
index f658081..d371a65 100644
--- a/src/evdev-touchpad.c
+++ b/src/evdev-touchpad.c
@@ -444,7 +444,9 @@
case BTN_BACK:
case BTN_TASK:
notify_button(&device->master->base.seat,
- time, e->code, e->value);
+ time, e->code,
+ e->value ? WL_POINTER_BUTTON_STATE_PRESSED :
+ WL_POINTER_BUTTON_STATE_RELEASED);
break;
case BTN_TOOL_PEN:
case BTN_TOOL_RUBBER:
diff --git a/src/evdev.c b/src/evdev.c
index e73f343..a7162fc 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -79,7 +79,9 @@
case BTN_BACK:
case BTN_TASK:
notify_button(&device->master->base.seat,
- time, e->code, e->value);
+ time, e->code,
+ e->value ? WL_POINTER_BUTTON_STATE_PRESSED :
+ WL_POINTER_BUTTON_STATE_RELEASED);
break;
default:
diff --git a/src/shell.c b/src/shell.c
index fcac599..8f4822f 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -335,13 +335,15 @@
static void
move_grab_button(struct wl_pointer_grab *grab,
- uint32_t time, uint32_t button, uint32_t state)
+ uint32_t time, uint32_t button, uint32_t state_w)
{
struct shell_grab *shell_grab = container_of(grab, struct shell_grab,
grab);
struct wl_pointer *pointer = grab->pointer;
+ enum wl_pointer_button_state state = state_w;
- if (pointer->button_count == 0 && state == 0) {
+ if (pointer->button_count == 0 &&
+ state == WL_POINTER_BUTTON_STATE_RELEASED) {
shell_grab_finish(shell_grab);
wl_pointer_end_grab(pointer);
free(grab);
@@ -608,12 +610,14 @@
static void
resize_grab_button(struct wl_pointer_grab *grab,
- uint32_t time, uint32_t button, uint32_t state)
+ uint32_t time, uint32_t button, uint32_t state_w)
{
struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
struct wl_pointer *pointer = grab->pointer;
+ enum wl_pointer_button_state state = state_w;
- if (pointer->button_count == 0 && state == 0) {
+ if (pointer->button_count == 0 &&
+ state == WL_POINTER_BUTTON_STATE_RELEASED) {
shell_grab_finish(&resize->base);
wl_pointer_end_grab(pointer);
free(grab);
@@ -1097,12 +1101,13 @@
static void
popup_grab_button(struct wl_pointer_grab *grab,
- uint32_t time, uint32_t button, uint32_t state)
+ uint32_t time, uint32_t button, uint32_t state_w)
{
struct wl_resource *resource;
struct shell_surface *shsurf =
container_of(grab, struct shell_surface, popup.grab);
struct wl_display *display;
+ enum wl_pointer_button_state state = state_w;
uint32_t serial;
resource = grab->pointer->focus_resource;
@@ -1110,7 +1115,7 @@
display = wl_client_get_display(resource->client);
serial = wl_display_get_serial(display);
wl_pointer_send_button(resource, serial, time, button, state);
- } else if (state == 0 &&
+ } else if (state == WL_POINTER_BUTTON_STATE_RELEASED &&
(shsurf->popup.initial_up ||
time - shsurf->popup.seat->pointer->grab_time > 500)) {
wl_shell_surface_send_popup_done(&shsurf->resource);
@@ -1118,7 +1123,7 @@
shsurf->popup.grab.pointer = NULL;
}
- if (state == 0)
+ if (state == WL_POINTER_BUTTON_STATE_RELEASED)
shsurf->popup.initial_up = 1;
}
@@ -1776,14 +1781,16 @@
static void
rotate_grab_button(struct wl_pointer_grab *grab,
- uint32_t time, uint32_t button, uint32_t state)
+ uint32_t time, uint32_t button, uint32_t state_w)
{
struct rotate_grab *rotate =
container_of(grab, struct rotate_grab, base.grab);
struct wl_pointer *pointer = grab->pointer;
struct shell_surface *shsurf = rotate->base.shsurf;
+ enum wl_pointer_button_state state = state_w;
- if (pointer->button_count == 0 && state == 0) {
+ if (pointer->button_count == 0 &&
+ state == WL_POINTER_BUTTON_STATE_RELEASED) {
if (shsurf)
weston_matrix_multiply(&shsurf->rotation.rotation,
&rotate->rotation);
@@ -1931,12 +1938,14 @@
static void
click_to_activate_binding(struct wl_seat *seat,
uint32_t time, uint32_t key,
- uint32_t button, uint32_t axis, int32_t state, void *data)
+ uint32_t button, uint32_t axis, int32_t state_w,
+ void *data)
{
struct weston_seat *ws = (struct weston_seat *) seat;
struct desktop_shell *shell = data;
struct weston_surface *focus;
struct weston_surface *upper;
+ enum wl_pointer_button_state state = state_w;
focus = (struct weston_surface *) seat->pointer->focus;
if (!focus)
@@ -1945,7 +1954,8 @@
if (is_black_surface(focus, &upper))
focus = upper;
- if (state && seat->pointer->grab == &seat->pointer->default_grab)
+ if (state == WL_POINTER_BUTTON_STATE_PRESSED &&
+ seat->pointer->grab == &seat->pointer->default_grab)
activate(shell, focus, ws);
}