Rather than attempting to have the one handler prototype everywhere.
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
}
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";
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);
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);
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;
}
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)
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;
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);
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;
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);
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);
}
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";
}
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;
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);
}
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;
}
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;
}
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;
}
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;
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;
}
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
};
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 =
}
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)
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);
}
};
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;
}
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;
}
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;
}
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
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
}
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;
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);
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;
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;
}
}
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)
{