From 325fc2d53a6885119c505c928c41b2744edada36 Mon Sep 17 00:00:00 2001 From: Daniel Stone Date: Wed, 30 May 2012 16:31:58 +0100 Subject: [PATCH] Split bindings into separate key/button/axis bindings Rather than attempting to have the one handler prototype everywhere. Signed-off-by: Daniel Stone --- src/compositor-drm.c | 12 ++-- src/compositor.c | 21 +++--- src/compositor.h | 60 ++++++++++++----- src/screenshooter.c | 17 ++--- src/shell.c | 151 +++++++++++++++++++++---------------------- src/tablet-shell.c | 34 +++++----- src/util.c | 121 +++++++++++++++++++++++++++++----- 7 files changed, 265 insertions(+), 151 deletions(-) diff --git a/src/compositor-drm.c b/src/compositor-drm.c index ce024dd8..98e8b07d 100644 --- a/src/compositor-drm.c +++ b/src/compositor-drm.c @@ -1727,13 +1727,11 @@ vt_func(struct weston_compositor *compositor, int event) } static void -switch_vt_binding(struct wl_seat *seat, uint32_t time, - uint32_t key, uint32_t button, uint32_t axis, int32_t state, void *data) +switch_vt_binding(struct wl_seat *seat, uint32_t time, uint32_t key, void *data) { struct drm_compositor *ec = data; - if (state) - tty_activate_vt(ec->tty, key - KEY_F1 + 1); + tty_activate_vt(ec->tty, key - KEY_F1 + 1); } static const char default_seat[] = "seat0"; @@ -1810,9 +1808,9 @@ drm_compositor_create(struct wl_display *display, return NULL; for (key = KEY_F1; key < KEY_F9; key++) - weston_compositor_add_binding(&ec->base, key, 0, 0, - MODIFIER_CTRL | MODIFIER_ALT, - switch_vt_binding, ec); + weston_compositor_add_key_binding(&ec->base, key, + MODIFIER_CTRL | MODIFIER_ALT, + switch_vt_binding, ec); wl_list_init(&ec->sprite_list); create_sprites(ec); diff --git a/src/compositor.c b/src/compositor.c index e9a11ec6..faa06191 100644 --- a/src/compositor.c +++ b/src/compositor.c @@ -1694,8 +1694,8 @@ notify_button(struct wl_seat *seat, uint32_t time, int32_t button, seat->pointer->button_count--; } - weston_compositor_run_binding(compositor, ws, time, 0, button, 0, - state); + weston_compositor_run_button_binding(compositor, ws, time, button, + state); seat->pointer->grab->interface->button(seat->pointer->grab, time, button, state); @@ -1721,9 +1721,8 @@ notify_axis(struct wl_seat *seat, uint32_t time, uint32_t axis, weston_compositor_activity(compositor); if (value) - weston_compositor_run_binding(compositor, ws, - time, 0, 0, axis, - wl_fixed_to_int(value)); + weston_compositor_run_axis_binding(compositor, ws, time, axis, + wl_fixed_to_int(value)); else return; @@ -1830,8 +1829,8 @@ notify_key(struct wl_seat *seat, uint32_t time, uint32_t key, } if (grab == &seat->keyboard->default_grab) - weston_compositor_run_binding(compositor, ws, - time, key, 0, 0, state); + weston_compositor_run_key_binding(compositor, ws, time, key, + state); grab->interface->key(grab, time, key, state); if (mods) @@ -2835,7 +2834,9 @@ weston_compositor_init(struct weston_compositor *ec, struct wl_display *display) wl_list_init(&ec->layer_list); wl_list_init(&ec->seat_list); wl_list_init(&ec->output_list); - wl_list_init(&ec->binding_list); + wl_list_init(&ec->key_binding_list); + wl_list_init(&ec->button_binding_list); + wl_list_init(&ec->axis_binding_list); wl_list_init(&ec->animation_list); weston_spring_init(&ec->fade.spring, 30.0, 1.0, 1.0); ec->fade.animation.frame = fade_frame; @@ -2884,7 +2885,9 @@ weston_compositor_shutdown(struct weston_compositor *ec) wl_list_for_each_safe(output, next, &ec->output_list, link) output->destroy(output); - weston_binding_list_destroy_all(&ec->binding_list); + weston_binding_list_destroy_all(&ec->key_binding_list); + weston_binding_list_destroy_all(&ec->button_binding_list); + weston_binding_list_destroy_all(&ec->axis_binding_list); wl_array_release(&ec->vertices); wl_array_release(&ec->indices); diff --git a/src/compositor.h b/src/compositor.h index 256ffd98..b0cca43b 100644 --- a/src/compositor.h +++ b/src/compositor.h @@ -268,7 +268,9 @@ struct weston_compositor { struct wl_list seat_list; struct wl_list layer_list; struct wl_list surface_list; - struct wl_list binding_list; + struct wl_list key_binding_list; + struct wl_list button_binding_list; + struct wl_list axis_binding_list; struct wl_list animation_list; struct { struct weston_spring spring; @@ -525,16 +527,35 @@ weston_compositor_update_drag_surfaces(struct weston_compositor *compositor); struct weston_binding; -typedef void (*weston_binding_handler_t)(struct wl_seat *seat, - uint32_t time, uint32_t key, - uint32_t button, - uint32_t axis, - int32_t value, void *data); +typedef void (*weston_key_binding_handler_t)(struct wl_seat *seat, + uint32_t time, uint32_t key, + void *data); struct weston_binding * -weston_compositor_add_binding(struct weston_compositor *compositor, - uint32_t key, uint32_t button, uint32_t axis, - enum weston_keyboard_modifier modifier, - weston_binding_handler_t binding, void *data); +weston_compositor_add_key_binding(struct weston_compositor *compositor, + uint32_t key, + enum weston_keyboard_modifier modifier, + weston_key_binding_handler_t binding, + void *data); + +typedef void (*weston_button_binding_handler_t)(struct wl_seat *seat, + uint32_t time, uint32_t button, + void *data); +struct weston_binding * +weston_compositor_add_button_binding(struct weston_compositor *compositor, + uint32_t button, + enum weston_keyboard_modifier modifier, + weston_button_binding_handler_t binding, + void *data); + +typedef void (*weston_axis_binding_handler_t)(struct wl_seat *seat, + uint32_t time, uint32_t axis, + int32_t value, void *data); +struct weston_binding * +weston_compositor_add_axis_binding(struct weston_compositor *compositor, + uint32_t axis, + enum weston_keyboard_modifier modifier, + weston_axis_binding_handler_t binding, + void *data); void weston_binding_destroy(struct weston_binding *binding); @@ -542,11 +563,20 @@ void weston_binding_list_destroy_all(struct wl_list *list); void -weston_compositor_run_binding(struct weston_compositor *compositor, - struct weston_seat *seat, - uint32_t time, - uint32_t key, uint32_t button, uint32_t axis, - int32_t value); +weston_compositor_run_key_binding(struct weston_compositor *compositor, + struct weston_seat *seat, uint32_t time, + uint32_t key, + enum wl_keyboard_key_state state); +void +weston_compositor_run_button_binding(struct weston_compositor *compositor, + struct weston_seat *seat, uint32_t time, + uint32_t button, + enum wl_pointer_button_state value); +void +weston_compositor_run_axis_binding(struct weston_compositor *compositor, + struct weston_seat *seat, uint32_t time, + uint32_t axis, int32_t value); + int weston_environment_get_fd(const char *env); diff --git a/src/screenshooter.c b/src/screenshooter.c index 246796eb..284111a8 100644 --- a/src/screenshooter.c +++ b/src/screenshooter.c @@ -199,9 +199,8 @@ screenshooter_sigchld(struct weston_process *process, int status) } static void -screenshooter_binding(struct wl_seat *seat, uint32_t time, - uint32_t key, uint32_t button, uint32_t axis, - int32_t state, void *data) +screenshooter_binding(struct wl_seat *seat, uint32_t time, uint32_t key, + void *data) { struct screenshooter *shooter = data; const char *screenshooter_exe = LIBEXECDIR "/weston-screenshooter"; @@ -390,9 +389,7 @@ weston_recorder_destroy(struct weston_recorder *recorder) } static void -recorder_binding(struct wl_seat *seat, uint32_t time, - uint32_t key, uint32_t button, uint32_t axis, - int32_t state, void *data) +recorder_binding(struct wl_seat *seat, uint32_t time, uint32_t key, void *data) { struct weston_seat *ws = (struct weston_seat *) seat; struct weston_compositor *ec = ws->compositor; @@ -448,10 +445,10 @@ screenshooter_create(struct weston_compositor *ec) shooter->global = wl_display_add_global(ec->wl_display, &screenshooter_interface, shooter, bind_shooter); - weston_compositor_add_binding(ec, KEY_S, 0, 0, MODIFIER_SUPER, - screenshooter_binding, shooter); - weston_compositor_add_binding(ec, KEY_R, 0, 0, MODIFIER_SUPER, - recorder_binding, shooter); + weston_compositor_add_key_binding(ec, KEY_S, MODIFIER_SUPER, + screenshooter_binding, shooter); + weston_compositor_add_key_binding(ec, KEY_R, MODIFIER_SUPER, + recorder_binding, shooter); shooter->destroy_listener.notify = screenshooter_destroy; wl_signal_add(&ec->destroy_signal, &shooter->destroy_listener); diff --git a/src/shell.c b/src/shell.c index fe7b982c..fc7f48f6 100644 --- a/src/shell.c +++ b/src/shell.c @@ -1541,9 +1541,7 @@ get_shell_surface_type(struct weston_surface *surface) } static void -move_binding(struct wl_seat *seat, uint32_t time, - uint32_t key, uint32_t button, uint32_t axis, int32_t value, - void *data) +move_binding(struct wl_seat *seat, uint32_t time, uint32_t button, void *data) { struct weston_surface *surface = (struct weston_surface *) seat->pointer->focus; @@ -1570,9 +1568,7 @@ move_binding(struct wl_seat *seat, uint32_t time, } static void -resize_binding(struct wl_seat *seat, uint32_t time, - uint32_t key, uint32_t button, uint32_t axis, int32_t value, - void *data) +resize_binding(struct wl_seat *seat, uint32_t time, uint32_t button, void *data) { struct weston_surface *surface = (struct weston_surface *) seat->pointer->focus; @@ -1620,8 +1616,7 @@ resize_binding(struct wl_seat *seat, uint32_t time, } static void -surface_opacity_binding(struct wl_seat *seat, uint32_t time, - uint32_t key, uint32_t button, uint32_t axis, +surface_opacity_binding(struct wl_seat *seat, uint32_t time, uint32_t axis, int32_t value, void *data) { float step = 0.05; @@ -1656,9 +1651,8 @@ surface_opacity_binding(struct wl_seat *seat, uint32_t time, } static void -zoom_binding(struct wl_seat *seat, uint32_t time, - uint32_t key, uint32_t button, uint32_t axis, int32_t value, - void *data) +do_zoom(struct wl_seat *seat, uint32_t time, uint32_t key, uint32_t axis, + int32_t value) { struct weston_seat *ws = (struct weston_seat *) seat; struct weston_compositor *compositor = ws->compositor; @@ -1670,9 +1664,9 @@ zoom_binding(struct wl_seat *seat, uint32_t time, wl_fixed_to_double(seat->pointer->x), wl_fixed_to_double(seat->pointer->y), NULL)) { - if (key == KEY_PAGEUP && value) + if (key == KEY_PAGEUP) increment = output->zoom.increment; - else if (key == KEY_PAGEDOWN && value) + else if (key == KEY_PAGEDOWN) increment = -output->zoom.increment; else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) increment = output->zoom.increment * value; @@ -1701,13 +1695,26 @@ zoom_binding(struct wl_seat *seat, uint32_t time, } static void -terminate_binding(struct wl_seat *seat, uint32_t time, - uint32_t key, uint32_t button, uint32_t axis, int32_t state, void *data) +zoom_axis_binding(struct wl_seat *seat, uint32_t time, uint32_t axis, + int32_t value, void *data) +{ + do_zoom(seat, time, 0, axis, value); +} + +static void +zoom_key_binding(struct wl_seat *seat, uint32_t time, uint32_t key, + void *data) +{ + do_zoom(seat, time, key, 0, 0); +} + +static void +terminate_binding(struct wl_seat *seat, uint32_t time, uint32_t key, + void *data) { struct weston_compositor *compositor = data; - if (state) - wl_display_terminate(compositor->wl_display); + wl_display_terminate(compositor->wl_display); } static void @@ -1807,8 +1814,7 @@ static const struct wl_pointer_grab_interface rotate_grab_interface = { }; static void -rotate_binding(struct wl_seat *seat, uint32_t time, - uint32_t key, uint32_t button, uint32_t axis, int32_t value, +rotate_binding(struct wl_seat *seat, uint32_t time, uint32_t button, void *data) { struct weston_surface *base_surface = @@ -1936,16 +1942,13 @@ 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_w, +click_to_activate_binding(struct wl_seat *seat, uint32_t time, uint32_t button, 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) @@ -1954,8 +1957,7 @@ click_to_activate_binding(struct wl_seat *seat, if (is_black_surface(focus, &upper)) focus = upper; - if (state == WL_POINTER_BUTTON_STATE_PRESSED && - seat->pointer->grab == &seat->pointer->default_grab) + if (seat->pointer->grab == &seat->pointer->default_grab) activate(shell, focus, ws); } @@ -2511,9 +2513,8 @@ static const struct wl_keyboard_grab_interface switcher_grab = { }; static void -switcher_binding(struct wl_seat *seat, uint32_t time, - uint32_t key, uint32_t button, uint32_t axis, - int32_t value, void *data) +switcher_binding(struct wl_seat *seat, uint32_t time, uint32_t key, + void *data) { struct desktop_shell *shell = data; struct switcher *switcher; @@ -2531,8 +2532,8 @@ switcher_binding(struct wl_seat *seat, uint32_t time, } static void -backlight_binding(struct wl_seat *seat, uint32_t time, - uint32_t key, uint32_t button, uint32_t axis, int32_t state, void *data) +backlight_binding(struct wl_seat *seat, uint32_t time, uint32_t key, + void *data) { struct weston_compositor *compositor = data; struct weston_output *output; @@ -2564,9 +2565,8 @@ backlight_binding(struct wl_seat *seat, uint32_t time, } static void -debug_repaint_binding(struct wl_seat *seat, uint32_t time, - uint32_t key, uint32_t button, uint32_t axis, - int32_t value, void *data) +debug_repaint_binding(struct wl_seat *seat, uint32_t time, uint32_t key, + void *data) { struct desktop_shell *shell = data; struct weston_compositor *compositor = shell->compositor; @@ -2599,21 +2599,18 @@ debug_repaint_binding(struct wl_seat *seat, uint32_t time, } static void -force_kill_binding(struct wl_seat *seat, uint32_t time, - uint32_t key, uint32_t button, uint32_t axis, - int32_t value, void *data) +force_kill_binding(struct wl_seat *seat, uint32_t time, uint32_t key, + void *data) { struct wl_client *client; pid_t pid; uid_t uid; gid_t gid; - if (value == 1) { - client = seat->keyboard->focus->resource.client; - wl_client_get_credentials(client, &pid, &uid, &gid); + client = seat->keyboard->focus->resource.client; + wl_client_get_credentials(client, &pid, &uid, &gid); - kill(pid, SIGKILL); - } + kill(pid, SIGKILL); } static void @@ -2638,45 +2635,45 @@ shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) uint32_t mod; /* fixed bindings */ - weston_compositor_add_binding(ec, KEY_BACKSPACE, 0, 0, - MODIFIER_CTRL | MODIFIER_ALT, - terminate_binding, ec); - weston_compositor_add_binding(ec, 0, BTN_LEFT, 0, 0, - click_to_activate_binding, shell); - weston_compositor_add_binding(ec, 0, 0, - WL_POINTER_AXIS_VERTICAL_SCROLL, - MODIFIER_SUPER | MODIFIER_ALT, - surface_opacity_binding, NULL); - weston_compositor_add_binding(ec, 0, 0, - WL_POINTER_AXIS_VERTICAL_SCROLL, - MODIFIER_SUPER, zoom_binding, NULL); + weston_compositor_add_key_binding(ec, KEY_BACKSPACE, + MODIFIER_CTRL | MODIFIER_ALT, + terminate_binding, ec); + weston_compositor_add_button_binding(ec, BTN_LEFT, 0, + click_to_activate_binding, + shell); + weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, + MODIFIER_SUPER | MODIFIER_ALT, + surface_opacity_binding, NULL); + weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, + MODIFIER_SUPER, zoom_axis_binding, + NULL); /* configurable bindings */ mod = shell->binding_modifier; - weston_compositor_add_binding(ec, KEY_PAGEUP, 0, 0, mod, - zoom_binding, NULL); - weston_compositor_add_binding(ec, KEY_PAGEDOWN, 0, 0, mod, - zoom_binding, NULL); - weston_compositor_add_binding(ec, 0, BTN_LEFT, 0, mod, - move_binding, shell); - weston_compositor_add_binding(ec, 0, BTN_MIDDLE, 0, mod, - resize_binding, shell); - weston_compositor_add_binding(ec, 0, BTN_RIGHT, 0, mod, - rotate_binding, NULL); - weston_compositor_add_binding(ec, KEY_TAB, 0, 0, mod, - switcher_binding, shell); - weston_compositor_add_binding(ec, KEY_F9, 0, 0, mod, - backlight_binding, ec); - weston_compositor_add_binding(ec, KEY_BRIGHTNESSDOWN, 0, 0, 0, - backlight_binding, ec); - weston_compositor_add_binding(ec, KEY_F10, 0, 0, mod, - backlight_binding, ec); - weston_compositor_add_binding(ec, KEY_BRIGHTNESSUP, 0, 0, 0, - backlight_binding, ec); - weston_compositor_add_binding(ec, KEY_SPACE, 0, 0, mod, - debug_repaint_binding, shell); - weston_compositor_add_binding(ec, KEY_K, 0, 0, mod, - force_kill_binding, shell); + weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, + zoom_key_binding, NULL); + weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, + zoom_key_binding, NULL); + weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, + shell); + weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, + resize_binding, shell); + weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, + rotate_binding, NULL); + weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, + shell); + weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, + ec); + weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, + backlight_binding, ec); + weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, + ec); + weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, + backlight_binding, ec); + weston_compositor_add_key_binding(ec, KEY_SPACE, mod, + debug_repaint_binding, shell); + weston_compositor_add_key_binding(ec, KEY_K, mod, + force_kill_binding, shell); } int diff --git a/src/tablet-shell.c b/src/tablet-shell.c index 90642bae..925817c8 100644 --- a/src/tablet-shell.c +++ b/src/tablet-shell.c @@ -447,31 +447,29 @@ long_press_handler(void *data) } static void -menu_key_binding(struct wl_seat *seat, uint32_t time, - uint32_t key, uint32_t button, uint32_t axis, int32_t state, void *data) +menu_key_binding(struct wl_seat *seat, uint32_t time, uint32_t key, void *data) { struct tablet_shell *shell = data; if (shell->state == STATE_LOCKED) return; - if (state) - toggle_switcher(shell); + toggle_switcher(shell); } static void -home_key_binding(struct wl_seat *seat, uint32_t time, - uint32_t key, uint32_t button, uint32_t axis, int32_t state, void *data) +home_key_binding(struct wl_seat *seat, uint32_t time, uint32_t key, void *data) { struct tablet_shell *shell = data; if (shell->state == STATE_LOCKED) return; - if (state) { + if (1) { wl_event_source_timer_update(shell->long_press_source, 500); shell->long_press_active = 1; } else if (shell->long_press_active) { + /* This code has never been run ... */ wl_event_source_timer_update(shell->long_press_source, 0); shell->long_press_active = 0; @@ -561,16 +559,18 @@ shell_init(struct weston_compositor *compositor) shell->long_press_source = wl_event_loop_add_timer(loop, long_press_handler, shell); - weston_compositor_add_binding(compositor, KEY_LEFTMETA, 0, 0, 0, - home_key_binding, shell); - weston_compositor_add_binding(compositor, KEY_RIGHTMETA, 0, 0, 0, - home_key_binding, shell); - weston_compositor_add_binding(compositor, KEY_LEFTMETA, 0, 0, - MODIFIER_SUPER, home_key_binding, shell); - weston_compositor_add_binding(compositor, KEY_RIGHTMETA, 0, 0, - MODIFIER_SUPER, home_key_binding, shell); - weston_compositor_add_binding(compositor, KEY_COMPOSE, 0, 0, 0, - menu_key_binding, shell); + weston_compositor_add_key_binding(compositor, KEY_LEFTMETA, 0, + home_key_binding, shell); + weston_compositor_add_key_binding(compositor, KEY_RIGHTMETA, 0, + home_key_binding, shell); + weston_compositor_add_key_binding(compositor, KEY_LEFTMETA, + MODIFIER_SUPER, home_key_binding, + shell); + weston_compositor_add_key_binding(compositor, KEY_RIGHTMETA, + MODIFIER_SUPER, home_key_binding, + shell); + weston_compositor_add_key_binding(compositor, KEY_COMPOSE, 0, + menu_key_binding, shell); weston_layer_init(&shell->homescreen_layer, &compositor->cursor_layer.link); diff --git a/src/util.c b/src/util.c index 0b44b56d..bde49874 100644 --- a/src/util.c +++ b/src/util.c @@ -199,15 +199,15 @@ struct weston_binding { uint32_t button; uint32_t axis; uint32_t modifier; - weston_binding_handler_t handler; + void *handler; void *data; struct wl_list link; }; -WL_EXPORT struct weston_binding * +static struct weston_binding * weston_compositor_add_binding(struct weston_compositor *compositor, - uint32_t key, uint32_t button, uint32_t axis, uint32_t modifier, - weston_binding_handler_t handler, void *data) + uint32_t key, uint32_t button, uint32_t axis, + uint32_t modifier, void *handler, void *data) { struct weston_binding *binding; @@ -221,7 +221,60 @@ weston_compositor_add_binding(struct weston_compositor *compositor, binding->modifier = modifier; binding->handler = handler; binding->data = data; - wl_list_insert(compositor->binding_list.prev, &binding->link); + + return binding; +} + +WL_EXPORT struct weston_binding * +weston_compositor_add_key_binding(struct weston_compositor *compositor, + uint32_t key, uint32_t modifier, + weston_key_binding_handler_t handler, + void *data) +{ + struct weston_binding *binding; + + binding = weston_compositor_add_binding(compositor, key, 0, 0, + modifier, handler, data); + if (binding == NULL) + return NULL; + + wl_list_insert(compositor->key_binding_list.prev, &binding->link); + + return binding; +} + +WL_EXPORT struct weston_binding * +weston_compositor_add_button_binding(struct weston_compositor *compositor, + uint32_t button, uint32_t modifier, + weston_button_binding_handler_t handler, + void *data) +{ + struct weston_binding *binding; + + binding = weston_compositor_add_binding(compositor, 0, button, 0, + modifier, handler, data); + if (binding == NULL) + return NULL; + + wl_list_insert(compositor->button_binding_list.prev, &binding->link); + + return binding; +} + +WL_EXPORT struct weston_binding * +weston_compositor_add_axis_binding(struct weston_compositor *compositor, + uint32_t axis, uint32_t modifier, + weston_axis_binding_handler_t handler, + void *data) +{ + struct weston_binding *binding; + + binding = weston_compositor_add_binding(compositor, 0, 0, axis, + modifier, handler, data); + if (binding == NULL) + return NULL; + + wl_list_insert(compositor->axis_binding_list.prev, &binding->link); return binding; } @@ -304,30 +357,66 @@ install_binding_grab(struct wl_seat *seat, } WL_EXPORT void -weston_compositor_run_binding(struct weston_compositor *compositor, - struct weston_seat *seat, - uint32_t time, uint32_t key, - uint32_t button, uint32_t axis, int32_t value) +weston_compositor_run_key_binding(struct weston_compositor *compositor, + struct weston_seat *seat, + uint32_t time, uint32_t key, + enum wl_keyboard_key_state state) { struct weston_binding *b; - wl_list_for_each(b, &compositor->binding_list, link) { - if (b->key == key && b->button == button && b->axis == axis && - b->modifier == seat->modifier_state && value) { - b->handler(&seat->seat, - time, key, button, axis, value, b->data); + if (state == WL_KEYBOARD_KEY_STATE_RELEASED) + return; + + wl_list_for_each(b, &compositor->key_binding_list, link) { + if (b->key == key && b->modifier == seat->modifier_state) { + weston_key_binding_handler_t handler = b->handler; + handler(&seat->seat, time, key, b->data); /* If this was a key binding and it didn't * install a keyboard grab, install one now to * swallow the key release. */ - if (b->key && - seat->seat.keyboard->grab == + if (seat->seat.keyboard->grab == &seat->seat.keyboard->default_grab) install_binding_grab(&seat->seat, time, key); } } } +WL_EXPORT void +weston_compositor_run_button_binding(struct weston_compositor *compositor, + struct weston_seat *seat, + uint32_t time, uint32_t button, + enum wl_pointer_button_state state) +{ + struct weston_binding *b; + + if (state == WL_POINTER_BUTTON_STATE_RELEASED) + return; + + wl_list_for_each(b, &compositor->button_binding_list, link) { + if (b->button == button && b->modifier == seat->modifier_state) { + weston_button_binding_handler_t handler = b->handler; + handler(&seat->seat, time, button, b->data); + } + } +} + +WL_EXPORT void +weston_compositor_run_axis_binding(struct weston_compositor *compositor, + struct weston_seat *seat, + uint32_t time, uint32_t axis, + int32_t value) +{ + struct weston_binding *b; + + wl_list_for_each(b, &compositor->axis_binding_list, link) { + if (b->axis == axis && b->modifier == seat->modifier_state) { + weston_axis_binding_handler_t handler = b->handler; + handler(&seat->seat, time, axis, value, b->data); + } + } +} + WL_EXPORT int weston_environment_get_fd(const char *env) {