Use enum wl_pointer_button_state instead of integer
authorDaniel Stone <daniel@fooishbar.org>
Wed, 30 May 2012 15:31:51 +0000 (16:31 +0100)
committerKristian Høgsberg <krh@bitplanet.net>
Thu, 31 May 2012 19:42:47 +0000 (15:42 -0400)
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>
20 files changed:
clients/clickdot.c
clients/desktop-shell.c
clients/dnd.c
clients/eventdemo.c
clients/flower.c
clients/gears.c
clients/resizor.c
clients/tablet-shell.c
clients/terminal.c
clients/view.c
clients/window.c
clients/window.h
src/compositor-wayland.c
src/compositor-x11.c
src/compositor.c
src/compositor.h
src/evdev-touchpad.c
src/evdev.c
src/shell.c
tests/test-client.c

index d935ae5..be4ee18 100644 (file)
@@ -197,11 +197,12 @@ key_handler(struct window *window, struct input *input, uint32_t time,
 static void
 button_handler(struct widget *widget,
               struct input *input, uint32_t time,
-              uint32_t button, uint32_t state, void *data)
+              uint32_t button,
+              enum wl_pointer_button_state state, void *data)
 {
        struct clickdot *clickdot = data;
 
-       if (state && button == BTN_LEFT)
+       if (state == WL_POINTER_BUTTON_STATE_PRESSED && button == BTN_LEFT)
                input_get_position(input, &clickdot->dot.x, &clickdot->dot.y);
 
        widget_schedule_redraw(widget);
index 23a7f90..cceeadf 100644 (file)
@@ -269,24 +269,26 @@ panel_launcher_leave_handler(struct widget *widget,
 static void
 panel_launcher_button_handler(struct widget *widget,
                              struct input *input, uint32_t time,
-                             uint32_t button, uint32_t state, void *data)
+                             uint32_t button,
+                             enum wl_pointer_button_state state, void *data)
 {
        struct panel_launcher *launcher;
 
        launcher = widget_get_user_data(widget);
        widget_schedule_redraw(widget);
-       if (state == 0)
+       if (state == WL_POINTER_BUTTON_STATE_RELEASED)
                panel_launcher_activate(launcher);
 }
 
 static void
 panel_button_handler(struct widget *widget,
                     struct input *input, uint32_t time,
-                    uint32_t button, uint32_t state, void *data)
+                    uint32_t button,
+                    enum wl_pointer_button_state state, void *data)
 {
        struct panel *panel = data;
 
-       if (button == BTN_RIGHT && state)
+       if (button == BTN_RIGHT && state == WL_POINTER_BUTTON_STATE_PRESSED)
                show_menu(panel, input, time);
 }
 
@@ -496,13 +498,15 @@ unlock_dialog_redraw_handler(struct widget *widget, void *data)
 static void
 unlock_dialog_button_handler(struct widget *widget,
                             struct input *input, uint32_t time,
-                            uint32_t button, uint32_t state, void *data)
+                            uint32_t button,
+                            enum wl_pointer_button_state state, void *data)
 {
        struct unlock_dialog *dialog = data;
        struct desktop *desktop = dialog->desktop;
 
        if (button == BTN_LEFT) {
-               if (state == 0 && !dialog->closing) {
+               if (state == WL_POINTER_BUTTON_STATE_RELEASED &&
+                   !dialog->closing) {
                        display_defer(desktop->display, &desktop->unlock_task);
                        dialog->closing = 1;
                }
index c6f0f18..b6720f0 100644 (file)
@@ -358,7 +358,8 @@ create_drag_cursor(struct dnd_drag *dnd_drag,
 static void
 dnd_button_handler(struct widget *widget,
                   struct input *input, uint32_t time,
-                  uint32_t button, uint32_t state, void *data)
+                  uint32_t button, enum wl_pointer_button_state state,
+                  void *data)
 {
        struct dnd *dnd = data;
        int32_t x, y;
@@ -378,7 +379,7 @@ dnd_button_handler(struct widget *widget,
        x -= allocation.x;
        y -= allocation.y;
 
-       if (item && state == 1) {
+       if (item && state == WL_POINTER_BUTTON_STATE_PRESSED) {
                dnd_drag = malloc(sizeof *dnd_drag);
                dnd_drag->dnd = dnd;
                dnd_drag->input = input;
index 4781546..cb8cbbf 100644 (file)
@@ -210,7 +210,7 @@ key_handler(struct window *window, struct input *input, uint32_t time,
  */
 static void
 button_handler(struct widget *widget, struct input *input, uint32_t time,
-              uint32_t button, uint32_t state, void *data)
+              uint32_t button, enum wl_pointer_button_state state, void *data)
 {
        int32_t x, y;
 
@@ -218,8 +218,11 @@ button_handler(struct widget *widget, struct input *input, uint32_t time,
                return;
 
        input_get_position(input, &x, &y);
-       printf("button time: %d, button: %d, state: %d, x: %d, y: %d\n",
-              time, button, state, x, y);
+       printf("button time: %d, button: %d, state: %s, x: %d, y: %d\n",
+              time, button,
+              (state == WL_POINTER_BUTTON_STATE_PRESSED) ? "pressed" :
+                                                           "released",
+              x, y);
 }
 
 /**
index 9b22543..a403234 100644 (file)
@@ -139,22 +139,22 @@ motion_handler(struct widget *widget, struct input *input,
 static void
 button_handler(struct widget *widget,
               struct input *input, uint32_t time,
-              uint32_t button, uint32_t state, void *data)
+              uint32_t button, enum wl_pointer_button_state state, void *data)
 {
        struct flower *flower = data;
 
        switch (button) {
        case BTN_LEFT:
-               if (state)
+               if (state == WL_POINTER_BUTTON_STATE_PRESSED)
                        window_move(flower->window, input,
                                    display_get_serial(flower->display));
                break;
        case BTN_MIDDLE:
-               if (state)
+               if (state == WL_POINTER_BUTTON_STATE_PRESSED)
                        widget_schedule_redraw(widget);
                break;
        case BTN_RIGHT:
-               if (state)
+               if (state == WL_POINTER_BUTTON_STATE_PRESSED)
                        window_show_frame_menu(flower->window, input, time);
                break;
        }
index 5cfc298..166e6a4 100644 (file)
@@ -248,12 +248,13 @@ motion_handler(struct widget *widget, struct input *input,
 
 static void
 button_handler(struct widget *widget, struct input *input,
-               uint32_t time, uint32_t button, uint32_t state, void *data)
+               uint32_t time, uint32_t button,
+               enum wl_pointer_button_state state, void *data)
 {
        struct gears *gears = data;
 
        if (button == BTN_LEFT) {
-               if (state) {
+               if (state == WL_POINTER_BUTTON_STATE_PRESSED) {
                        gears->button_down = 1;
                        input_get_position(input,
                                        &gears->last_x, &gears->last_y);
index 58b4d5f..8186561 100644 (file)
@@ -215,13 +215,13 @@ show_menu(struct resizor *resizor, struct input *input, uint32_t time)
 static void
 button_handler(struct widget *widget,
               struct input *input, uint32_t time,
-              uint32_t button, uint32_t state, void *data)
+              uint32_t button, enum wl_pointer_button_state state, void *data)
 {
        struct resizor *resizor = data;
 
        switch (button) {
        case BTN_RIGHT:
-               if (state)
+               if (state == WL_POINTER_BUTTON_STATE_PRESSED)
                        show_menu(resizor, input, time);
                break;
        }
index e2c49d3..87a60a9 100644 (file)
@@ -217,11 +217,12 @@ lockscreen_draw(struct widget *widget, void *data)
 static void
 lockscreen_button_handler(struct widget *widget,
                          struct input *input, uint32_t time,
-                         uint32_t button, uint32_t state, void *data)
+                         uint32_t button,
+                         enum wl_pointer_button_state state, void *data)
 {
        struct lockscreen *lockscreen = data;
 
-       if (state && lockscreen->window) {
+       if (state == WL_POINTER_BUTTON_STATE_PRESSED && lockscreen->window) {
                window_destroy(lockscreen->window);
                lockscreen->window = NULL;
        }
index 27ab300..a0c6942 100644 (file)
@@ -2222,13 +2222,14 @@ keyboard_focus_handler(struct window *window,
 static void
 button_handler(struct widget *widget,
               struct input *input, uint32_t time,
-              uint32_t button, uint32_t state, void *data)
+              uint32_t button,
+              enum wl_pointer_button_state state, void *data)
 {
        struct terminal *terminal = data;
 
        switch (button) {
        case 272:
-               if (state) {
+               if (state == WL_POINTER_BUTTON_STATE_PRESSED) {
                        terminal->dragging = 1;
                        input_get_position(input,
                                           &terminal->selection_start_x,
index 1937fc1..6d32b3e 100644 (file)
@@ -138,11 +138,12 @@ view_page_down(struct view *view)
 
 static void
 button_handler(struct widget *widget, struct input *input, uint32_t time,
-               uint32_t button, uint32_t state, void *data)
+               uint32_t button, enum wl_pointer_button_state state,
+              void *data)
 {
         struct view *view = data;
 
-        if(!state)
+        if (state == WL_POINTER_BUTTON_STATE_RELEASED)
                 return;
 
         switch(button) {
index 012260d..6da1251 100644 (file)
@@ -1352,7 +1352,8 @@ frame_button_leave_handler(struct widget *widget, struct input *input, void *dat
 static void
 frame_button_button_handler(struct widget *widget,
                            struct input *input, uint32_t time,
-                           uint32_t button, uint32_t state, void *data)
+                           uint32_t button,
+                           enum wl_pointer_button_state state, void *data)
 {
        struct frame_button *frame_button = data;
        struct window *window = widget->window;
@@ -1361,14 +1362,14 @@ frame_button_button_handler(struct widget *widget,
                return;
 
        switch (state) {
-       case 1:
+       case WL_POINTER_BUTTON_STATE_PRESSED:
                frame_button->state = FRAME_BUTTON_ACTIVE;
                widget_schedule_redraw(frame_button->widget);
 
                if (frame_button->type == FRAME_BUTTON_ICON)
                        window_show_frame_menu(window, input, time);
                return;
-       case 0:
+       case WL_POINTER_BUTTON_STATE_RELEASED:
                frame_button->state = FRAME_BUTTON_DEFAULT;
                widget_schedule_redraw(frame_button->widget);
                break;
@@ -1593,7 +1594,8 @@ frame_motion_handler(struct widget *widget,
 static void
 frame_button_handler(struct widget *widget,
                     struct input *input, uint32_t time,
-                    uint32_t button, uint32_t state, void *data)
+                    uint32_t button, enum wl_pointer_button_state state,
+                    void *data)
 
 {
        struct frame *frame = data;
@@ -1605,7 +1607,8 @@ frame_button_handler(struct widget *widget,
                                      frame->widget->allocation.width,
                                      frame->widget->allocation.height);
 
-       if (window->display->shell && button == BTN_LEFT && state == 1) {
+       if (window->display->shell && button == BTN_LEFT &&
+           state == WL_POINTER_BUTTON_STATE_PRESSED) {
                switch (location) {
                case THEME_LOCATION_TITLEBAR:
                        if (!window->shell_surface)
@@ -1642,7 +1645,8 @@ frame_button_handler(struct widget *widget,
                                                display->serial, location);
                        break;
                }
-       } else if (button == BTN_RIGHT && state == 1) {
+       } else if (button == BTN_RIGHT &&
+                  state == WL_POINTER_BUTTON_STATE_PRESSED) {
                window_show_frame_menu(window, input, time);
        }
 }
@@ -1784,13 +1788,15 @@ input_ungrab(struct input *input)
 
 static void
 pointer_handle_button(void *data, struct wl_pointer *pointer, uint32_t serial,
-                     uint32_t time, uint32_t button, uint32_t state)
+                     uint32_t time, uint32_t button, uint32_t state_w)
 {
        struct input *input = data;
        struct widget *widget;
+       enum wl_pointer_button_state state = state_w;
 
        input->display->serial = serial;
-       if (input->focus_widget && input->grab == NULL && state)
+       if (input->focus_widget && input->grab == NULL &&
+           state == WL_POINTER_BUTTON_STATE_PRESSED)
                input_grab(input, input->focus_widget, button);
 
        widget = input->grab;
@@ -1800,7 +1806,8 @@ pointer_handle_button(void *data, struct wl_pointer *pointer, uint32_t serial,
                                          button, state,
                                          input->grab->user_data);
 
-       if (input->grab && input->grab_button == button && !state)
+       if (input->grab && input->grab_button == button &&
+           state == WL_POINTER_BUTTON_STATE_RELEASED)
                input_ungrab(input);
 }
 
@@ -2845,12 +2852,14 @@ menu_leave_handler(struct widget *widget, struct input *input, void *data)
 static void
 menu_button_handler(struct widget *widget,
                    struct input *input, uint32_t time,
-                   uint32_t button, uint32_t state, void *data)
+                   uint32_t button, enum wl_pointer_button_state state,
+                   void *data)
 
 {
        struct menu *menu = data;
 
-       if (state == 0 && time - menu->time > 500) {
+       if (state == WL_POINTER_BUTTON_STATE_PRESSED &&
+           time - menu->time > 500) {
                /* Either relase after press-drag-release or
                 * click-motion-click. */
                menu->func(menu->window->parent, 
index a8537b3..9cef160 100644 (file)
@@ -189,7 +189,8 @@ typedef int (*widget_motion_handler_t)(struct widget *widget,
                                       float x, float y, void *data);
 typedef void (*widget_button_handler_t)(struct widget *widget,
                                        struct input *input, uint32_t time,
-                                       uint32_t button, uint32_t state,
+                                       uint32_t button,
+                                       enum wl_pointer_button_state state,
                                        void *data);
 
 struct window *
index 332e1c2..02ebc6c 100644 (file)
@@ -547,10 +547,12 @@ input_handle_motion(void *data, struct wl_pointer *pointer,
 
 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);
 }
index 98baa8a..5a5c8db 100644 (file)
@@ -525,7 +525,9 @@ x11_compositor_deliver_button_event(struct x11_compositor *c,
        }
 
        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
index eb3d474..14d1494 100644 (file)
@@ -1668,7 +1668,7 @@ weston_surface_activate(struct weston_surface *surface,
 
 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 @@ notify_button(struct wl_seat *seat, uint32_t time, int32_t button,
                (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);
index 08dcd77..1ea2de5 100644 (file)
@@ -478,7 +478,7 @@ notify_motion(struct wl_seat *seat, uint32_t time,
              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);
index f658081..d371a65 100644 (file)
@@ -444,7 +444,9 @@ process_key(struct touchpad_dispatch *touchpad,
        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:
index e73f343..a7162fc 100644 (file)
@@ -79,7 +79,9 @@ evdev_process_key(struct evdev_input_device *device,
        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:
index fcac599..8f4822f 100644 (file)
@@ -335,13 +335,15 @@ move_grab_motion(struct wl_pointer_grab *grab,
 
 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 const struct weston_shell_client shell_client = {
 
 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 @@ popup_grab_motion(struct wl_pointer_grab *grab,
 
 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 @@ popup_grab_button(struct wl_pointer_grab *grab,
                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 @@ popup_grab_button(struct wl_pointer_grab *grab,
                shsurf->popup.grab.pointer = NULL;
        }
 
-       if (state == 0)
+       if (state == WL_POINTER_BUTTON_STATE_RELEASED)
                shsurf->popup.initial_up = 1;
 }
 
@@ -1776,14 +1781,16 @@ rotate_grab_motion(struct wl_pointer_grab *grab,
 
 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 @@ is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface)
 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 @@ click_to_activate_binding(struct wl_seat *seat,
        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);
 }
 
index fc65ee6..7c8f3fe 100644 (file)
@@ -92,13 +92,14 @@ pointer_handle_motion(void *data, struct wl_pointer *pointer,
 static void
 pointer_handle_button(void *data, struct wl_pointer *pointer,
                      uint32_t serial, uint32_t time, uint32_t button,
-                     uint32_t state)
+                     uint32_t state_w)
 {
        struct input *input = data;
        uint32_t bit;
+       enum wl_pointer_button_state state = state_w;
 
        bit = 1 << (button - BTN_LEFT);
-       if (state)
+       if (state == WL_POINTER_BUTTON_STATE_PRESSED)
                input->button_mask |= bit;
        else
                input->button_mask &= ~bit;