[PATCH weston 18/19] bindings: Make run binding functions take apropriate device instead of a seat
Jonas Ådahl
jadahl at gmail.com
Wed Jul 1 01:56:18 PDT 2015
On Wed, Jun 03, 2015 at 03:53:37PM -0500, Derek Foreman wrote:
> Going from seat to input device requires that we test the device
> before relying on the pointer. In all of these binding functions
> we can trust exactly one input device type directly. If we pass
> that in instead of a seat it's more obvious that we can trust
> the one pointer we have.
>
> When a seat is required, we can access through the device we have
> and use that to get to other device types for the seat, provided
> we validate them appropriately.
>
> Signed-off-by: Derek Foreman <derekf at osg.samsung.com>
Reviewed-by: Jonas Ådahl <jadahl at gmail.com>
> ---
> src/bindings.c | 49 ++++++++++++++++++++++++++-----------------------
> src/compositor.h | 13 +++++++------
> src/input.c | 16 ++++++++--------
> 3 files changed, 41 insertions(+), 37 deletions(-)
>
> diff --git a/src/bindings.c b/src/bindings.c
> index 4f2f203..f94119e 100644
> --- a/src/bindings.c
> +++ b/src/bindings.c
> @@ -276,12 +276,13 @@ install_binding_grab(struct weston_keyboard *keyboard, uint32_t time,
>
> void
> weston_compositor_run_key_binding(struct weston_compositor *compositor,
> - struct weston_seat *seat,
> + struct weston_keyboard *keyboard,
> uint32_t time, uint32_t key,
> enum wl_keyboard_key_state state)
> {
> struct weston_binding *b, *tmp;
> struct weston_surface *focus;
> + struct weston_seat *seat = keyboard->seat;
>
> if (state == WL_KEYBOARD_KEY_STATE_RELEASED)
> return;
> @@ -293,15 +294,15 @@ weston_compositor_run_key_binding(struct weston_compositor *compositor,
> wl_list_for_each_safe(b, tmp, &compositor->key_binding_list, link) {
> if (b->key == key && b->modifier == seat->modifier_state) {
> weston_key_binding_handler_t handler = b->handler;
> - focus = seat->keyboard->focus;
> - handler(seat->keyboard, time, key, b->data);
> + focus = keyboard->focus;
> + handler(keyboard, 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 press. */
> - if (seat->keyboard->grab ==
> - &seat->keyboard->default_grab)
> - install_binding_grab(seat->keyboard,
> + if (keyboard->grab ==
> + &keyboard->default_grab)
> + install_binding_grab(keyboard,
> time,
> key,
> focus);
> @@ -311,13 +312,13 @@ weston_compositor_run_key_binding(struct weston_compositor *compositor,
>
> void
> weston_compositor_run_modifier_binding(struct weston_compositor *compositor,
> - struct weston_seat *seat,
> + struct weston_keyboard *keyboard,
> enum weston_keyboard_modifier modifier,
> enum wl_keyboard_key_state state)
> {
> struct weston_binding *b, *tmp;
>
> - if (seat->keyboard->grab != &seat->keyboard->default_grab)
> + if (keyboard->grab != &keyboard->default_grab)
> return;
>
> wl_list_for_each_safe(b, tmp, &compositor->modifier_binding_list, link) {
> @@ -336,13 +337,13 @@ weston_compositor_run_modifier_binding(struct weston_compositor *compositor,
> return;
> }
>
> - handler(seat->keyboard, modifier, b->data);
> + handler(keyboard, modifier, b->data);
> }
> }
>
> void
> weston_compositor_run_button_binding(struct weston_compositor *compositor,
> - struct weston_seat *seat,
> + struct weston_pointer *pointer,
> uint32_t time, uint32_t button,
> enum wl_pointer_button_state state)
> {
> @@ -356,34 +357,35 @@ weston_compositor_run_button_binding(struct weston_compositor *compositor,
> b->key = button;
>
> wl_list_for_each_safe(b, tmp, &compositor->button_binding_list, link) {
> - if (b->button == button && b->modifier == seat->modifier_state) {
> + if (b->button == button &&
> + b->modifier == pointer->seat->modifier_state) {
> weston_button_binding_handler_t handler = b->handler;
> - handler(seat->pointer, time, button, b->data);
> + handler(pointer, time, button, b->data);
> }
> }
> }
>
> void
> weston_compositor_run_touch_binding(struct weston_compositor *compositor,
> - struct weston_seat *seat, uint32_t time,
> + struct weston_touch *touch, uint32_t time,
> int touch_type)
> {
> struct weston_binding *b, *tmp;
>
> - if (seat->touch->num_tp != 1 || touch_type != WL_TOUCH_DOWN)
> + if (touch->num_tp != 1 || touch_type != WL_TOUCH_DOWN)
> return;
>
> wl_list_for_each_safe(b, tmp, &compositor->touch_binding_list, link) {
> - if (b->modifier == seat->modifier_state) {
> + if (b->modifier == touch->seat->modifier_state) {
> weston_touch_binding_handler_t handler = b->handler;
> - handler(seat->touch, time, b->data);
> + handler(touch, time, b->data);
> }
> }
> }
>
> int
> weston_compositor_run_axis_binding(struct weston_compositor *compositor,
> - struct weston_seat *seat,
> + struct weston_pointer *pointer,
> uint32_t time, uint32_t axis,
> wl_fixed_t value)
> {
> @@ -394,9 +396,10 @@ weston_compositor_run_axis_binding(struct weston_compositor *compositor,
> b->key = axis;
>
> wl_list_for_each_safe(b, tmp, &compositor->axis_binding_list, link) {
> - if (b->axis == axis && b->modifier == seat->modifier_state) {
> + if (b->axis == axis &&
> + b->modifier == pointer->seat->modifier_state) {
> weston_axis_binding_handler_t handler = b->handler;
> - handler(seat->pointer, time, axis, value, b->data);
> + handler(pointer, time, axis, value, b->data);
> return 1;
> }
> }
> @@ -406,7 +409,7 @@ weston_compositor_run_axis_binding(struct weston_compositor *compositor,
>
> int
> weston_compositor_run_debug_binding(struct weston_compositor *compositor,
> - struct weston_seat *seat,
> + struct weston_keyboard *keyboard,
> uint32_t time, uint32_t key,
> enum wl_keyboard_key_state state)
> {
> @@ -420,7 +423,7 @@ weston_compositor_run_debug_binding(struct weston_compositor *compositor,
>
> count++;
> handler = binding->handler;
> - handler(seat->keyboard, time, key, binding->data);
> + handler(keyboard, time, key, binding->data);
> }
>
> return count;
> @@ -476,8 +479,8 @@ debug_binding_key(struct weston_keyboard_grab *grab, uint32_t time,
> }
>
> if (check_binding) {
> - if (weston_compositor_run_debug_binding(ec, db->seat, time,
> - key, state)) {
> + if (weston_compositor_run_debug_binding(ec, grab->keyboard,
> + time, key, state)) {
> /* We ran a binding so swallow the press and keep the
> * grab to swallow the released too. */
> send = 0;
> diff --git a/src/compositor.h b/src/compositor.h
> index 4d9e1a0..36fe3c7 100644
> --- a/src/compositor.h
> +++ b/src/compositor.h
> @@ -1214,31 +1214,32 @@ weston_binding_list_destroy_all(struct wl_list *list);
>
> void
> weston_compositor_run_key_binding(struct weston_compositor *compositor,
> - struct weston_seat *seat, uint32_t time,
> + struct weston_keyboard *keyboard,
> + uint32_t time,
> uint32_t key,
> enum wl_keyboard_key_state state);
>
> void
> weston_compositor_run_modifier_binding(struct weston_compositor *compositor,
> - struct weston_seat *seat,
> + struct weston_keyboard *keyboard,
> enum weston_keyboard_modifier modifier,
> enum wl_keyboard_key_state state);
> void
> weston_compositor_run_button_binding(struct weston_compositor *compositor,
> - struct weston_seat *seat, uint32_t time,
> + struct weston_pointer *pointer, uint32_t time,
> uint32_t button,
> enum wl_pointer_button_state value);
> void
> weston_compositor_run_touch_binding(struct weston_compositor *compositor,
> - struct weston_seat *seat, uint32_t time,
> + struct weston_touch *touch, uint32_t time,
> int touch_type);
> int
> weston_compositor_run_axis_binding(struct weston_compositor *compositor,
> - struct weston_seat *seat, uint32_t time,
> + struct weston_pointer *pointer, uint32_t time,
> uint32_t axis, int32_t value);
> int
> weston_compositor_run_debug_binding(struct weston_compositor *compositor,
> - struct weston_seat *seat, uint32_t time,
> + struct weston_keyboard *keyboard, uint32_t time,
> uint32_t key,
> enum wl_keyboard_key_state state);
>
> diff --git a/src/input.c b/src/input.c
> index dee3ca9..b6944d7 100644
> --- a/src/input.c
> +++ b/src/input.c
> @@ -969,7 +969,7 @@ run_modifier_bindings(struct weston_seat *seat, uint32_t old, uint32_t new)
> for (i = 0; i < ARRAY_LENGTH(mods); i++) {
> if (diff & (1 << mods[i].xkb))
> weston_compositor_run_modifier_binding(compositor,
> - seat,
> + keyboard,
> mods[i].weston,
> WL_KEYBOARD_KEY_STATE_PRESSED);
> }
> @@ -978,7 +978,7 @@ run_modifier_bindings(struct weston_seat *seat, uint32_t old, uint32_t new)
> for (i = 0; i < ARRAY_LENGTH(mods); i++) {
> if (diff & (1 << mods[i].xkb))
> weston_compositor_run_modifier_binding(compositor,
> - seat,
> + keyboard,
> mods[i].weston,
> WL_KEYBOARD_KEY_STATE_RELEASED);
> }
> @@ -1030,7 +1030,7 @@ notify_button(struct weston_seat *seat, uint32_t time, int32_t button,
> pointer->button_count--;
> }
>
> - weston_compositor_run_button_binding(compositor, seat, time, button,
> + weston_compositor_run_button_binding(compositor, pointer, time, button,
> state);
>
> pointer->grab->interface->button(pointer->grab, time, button, state);
> @@ -1054,8 +1054,8 @@ notify_axis(struct weston_seat *seat, uint32_t time, uint32_t axis,
> if (!value)
> return;
>
> - if (weston_compositor_run_axis_binding(compositor, seat,
> - time, axis, value))
> + if (weston_compositor_run_axis_binding(compositor, pointer,
> + time, axis, value))
> return;
>
> resource_list = &pointer->focus_resource_list;
> @@ -1342,8 +1342,8 @@ notify_key(struct weston_seat *seat, uint32_t time, uint32_t key,
>
> if (grab == &keyboard->default_grab ||
> grab == &keyboard->input_method_grab) {
> - weston_compositor_run_key_binding(compositor, seat, time, key,
> - state);
> + weston_compositor_run_key_binding(compositor, keyboard, time,
> + key, state);
> grab = keyboard->grab;
> }
>
> @@ -1538,7 +1538,7 @@ notify_touch(struct weston_seat *seat, uint32_t time, int touch_id,
> return;
> }
>
> - weston_compositor_run_touch_binding(ec, seat,
> + weston_compositor_run_touch_binding(ec, touch,
> time, touch_type);
>
> grab->interface->down(grab, time, touch_id, sx, sy);
> --
> 2.1.4
>
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
More information about the wayland-devel
mailing list