diff options
author | Daniel Stone <daniel@fooishbar.org> | 2012-05-30 16:31:51 +0100 |
---|---|---|
committer | Kristian Høgsberg <krh@bitplanet.net> | 2012-05-31 15:42:47 -0400 |
commit | 4dbadb1556f296cf148ed91a1044004ec6c80707 (patch) | |
tree | 1bc7caaadce31fca754d003c379b5b026c31d6e0 | |
parent | 11d7139989860a1405124b889db2fbad087a5a09 (diff) |
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>
-rw-r--r-- | clients/clickdot.c | 5 | ||||
-rw-r--r-- | clients/desktop-shell.c | 16 | ||||
-rw-r--r-- | clients/dnd.c | 5 | ||||
-rw-r--r-- | clients/eventdemo.c | 9 | ||||
-rw-r--r-- | clients/flower.c | 8 | ||||
-rw-r--r-- | clients/gears.c | 5 | ||||
-rw-r--r-- | clients/resizor.c | 4 | ||||
-rw-r--r-- | clients/tablet-shell.c | 5 | ||||
-rw-r--r-- | clients/terminal.c | 5 | ||||
-rw-r--r-- | clients/view.c | 5 | ||||
-rw-r--r-- | clients/window.c | 31 | ||||
-rw-r--r-- | clients/window.h | 3 | ||||
-rw-r--r-- | src/compositor-wayland.c | 4 | ||||
-rw-r--r-- | src/compositor-x11.c | 4 | ||||
-rw-r--r-- | src/compositor.c | 4 | ||||
-rw-r--r-- | src/compositor.h | 2 | ||||
-rw-r--r-- | src/evdev-touchpad.c | 4 | ||||
-rw-r--r-- | src/evdev.c | 4 | ||||
-rw-r--r-- | src/shell.c | 32 | ||||
-rw-r--r-- | tests/test-client.c | 5 |
20 files changed, 101 insertions, 59 deletions
diff --git a/clients/clickdot.c b/clients/clickdot.c index d935ae5..be4ee18 100644 --- a/clients/clickdot.c +++ b/clients/clickdot.c @@ -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); diff --git a/clients/desktop-shell.c b/clients/desktop-shell.c index 23a7f90..cceeadf 100644 --- a/clients/desktop-shell.c +++ b/clients/desktop-shell.c @@ -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; } diff --git a/clients/dnd.c b/clients/dnd.c index c6f0f18..b6720f0 100644 --- a/clients/dnd.c +++ b/clients/dnd.c @@ -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; diff --git a/clients/eventdemo.c b/clients/eventdemo.c index 4781546..cb8cbbf 100644 --- a/clients/eventdemo.c +++ b/clients/eventdemo.c @@ -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); } /** diff --git a/clients/flower.c b/clients/flower.c index 9b22543..a403234 100644 --- a/clients/flower.c +++ b/clients/flower.c @@ -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; } diff --git a/clients/gears.c b/clients/gears.c index 5cfc298..166e6a4 100644 --- a/clients/gears.c +++ b/clients/gears.c @@ -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); diff --git a/clients/resizor.c b/clients/resizor.c index 58b4d5f..8186561 100644 --- a/clients/resizor.c +++ b/clients/resizor.c @@ -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; } diff --git a/clients/tablet-shell.c b/clients/tablet-shell.c index e2c49d3..87a60a9 100644 --- a/clients/tablet-shell.c +++ b/clients/tablet-shell.c @@ -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; } diff --git a/clients/terminal.c b/clients/terminal.c index 27ab300..a0c6942 100644 --- a/clients/terminal.c +++ b/clients/terminal.c @@ -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, diff --git a/clients/view.c b/clients/view.c index 1937fc1..6d32b3e 100644 --- a/clients/view.c +++ b/clients/view.c @@ -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) { diff --git a/clients/window.c b/clients/window.c index 012260d..6da1251 100644 --- a/clients/window.c +++ b/clients/window.c @@ -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, diff --git a/clients/window.h b/clients/window.h index a8537b3..9cef160 100644 --- a/clients/window.h +++ b/clients/window.h @@ -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 * 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 @@ 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); } 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 @@ 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 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 @@ 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); 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 @@ 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); 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 @@ 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: 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 @@ 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: 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 @@ 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); } diff --git a/tests/test-client.c b/tests/test-client.c index fc65ee6..7c8f3fe 100644 --- a/tests/test-client.c +++ b/tests/test-client.c @@ -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; |