bindings: Make run binding functions take apropriate device instead of a seat

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.

Reviewed-by: Jonas Ådahl <jadahl@gmail.com>
Signed-off-by: Derek Foreman <derekf@osg.samsung.com>
dev
Derek Foreman 9 years ago committed by Bryce Harrington
parent b591a30ac2
commit 99a6a2db4c
  1. 49
      src/bindings.c
  2. 13
      src/compositor.h
  3. 14
      src/input.c

@ -280,12 +280,13 @@ install_binding_grab(struct weston_keyboard *keyboard, uint32_t time,
void void
weston_compositor_run_key_binding(struct weston_compositor *compositor, weston_compositor_run_key_binding(struct weston_compositor *compositor,
struct weston_seat *seat, struct weston_keyboard *keyboard,
uint32_t time, uint32_t key, uint32_t time, uint32_t key,
enum wl_keyboard_key_state state) enum wl_keyboard_key_state state)
{ {
struct weston_binding *b, *tmp; struct weston_binding *b, *tmp;
struct weston_surface *focus; struct weston_surface *focus;
struct weston_seat *seat = keyboard->seat;
if (state == WL_KEYBOARD_KEY_STATE_RELEASED) if (state == WL_KEYBOARD_KEY_STATE_RELEASED)
return; return;
@ -297,15 +298,15 @@ weston_compositor_run_key_binding(struct weston_compositor *compositor,
wl_list_for_each_safe(b, tmp, &compositor->key_binding_list, link) { wl_list_for_each_safe(b, tmp, &compositor->key_binding_list, link) {
if (b->key == key && b->modifier == seat->modifier_state) { if (b->key == key && b->modifier == seat->modifier_state) {
weston_key_binding_handler_t handler = b->handler; weston_key_binding_handler_t handler = b->handler;
focus = seat->keyboard->focus; focus = keyboard->focus;
handler(seat->keyboard, time, key, b->data); handler(keyboard, time, key, b->data);
/* If this was a key binding and it didn't /* If this was a key binding and it didn't
* install a keyboard grab, install one now to * install a keyboard grab, install one now to
* swallow the key press. */ * swallow the key press. */
if (seat->keyboard->grab == if (keyboard->grab ==
&seat->keyboard->default_grab) &keyboard->default_grab)
install_binding_grab(seat->keyboard, install_binding_grab(keyboard,
time, time,
key, key,
focus); focus);
@ -315,13 +316,13 @@ weston_compositor_run_key_binding(struct weston_compositor *compositor,
void void
weston_compositor_run_modifier_binding(struct weston_compositor *compositor, weston_compositor_run_modifier_binding(struct weston_compositor *compositor,
struct weston_seat *seat, struct weston_keyboard *keyboard,
enum weston_keyboard_modifier modifier, enum weston_keyboard_modifier modifier,
enum wl_keyboard_key_state state) enum wl_keyboard_key_state state)
{ {
struct weston_binding *b, *tmp; struct weston_binding *b, *tmp;
if (seat->keyboard->grab != &seat->keyboard->default_grab) if (keyboard->grab != &keyboard->default_grab)
return; return;
wl_list_for_each_safe(b, tmp, &compositor->modifier_binding_list, link) { wl_list_for_each_safe(b, tmp, &compositor->modifier_binding_list, link) {
@ -340,13 +341,13 @@ weston_compositor_run_modifier_binding(struct weston_compositor *compositor,
return; return;
} }
handler(seat->keyboard, modifier, b->data); handler(keyboard, modifier, b->data);
} }
} }
void void
weston_compositor_run_button_binding(struct weston_compositor *compositor, weston_compositor_run_button_binding(struct weston_compositor *compositor,
struct weston_seat *seat, struct weston_pointer *pointer,
uint32_t time, uint32_t button, uint32_t time, uint32_t button,
enum wl_pointer_button_state state) enum wl_pointer_button_state state)
{ {
@ -360,34 +361,35 @@ weston_compositor_run_button_binding(struct weston_compositor *compositor,
b->key = button; b->key = button;
wl_list_for_each_safe(b, tmp, &compositor->button_binding_list, link) { 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; weston_button_binding_handler_t handler = b->handler;
handler(seat->pointer, time, button, b->data); handler(pointer, time, button, b->data);
} }
} }
} }
void void
weston_compositor_run_touch_binding(struct weston_compositor *compositor, 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 touch_type)
{ {
struct weston_binding *b, *tmp; 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; return;
wl_list_for_each_safe(b, tmp, &compositor->touch_binding_list, link) { 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; weston_touch_binding_handler_t handler = b->handler;
handler(seat->touch, time, b->data); handler(touch, time, b->data);
} }
} }
} }
int int
weston_compositor_run_axis_binding(struct weston_compositor *compositor, weston_compositor_run_axis_binding(struct weston_compositor *compositor,
struct weston_seat *seat, struct weston_pointer *pointer,
uint32_t time, uint32_t axis, uint32_t time, uint32_t axis,
wl_fixed_t value) wl_fixed_t value)
{ {
@ -398,9 +400,10 @@ weston_compositor_run_axis_binding(struct weston_compositor *compositor,
b->key = axis; b->key = axis;
wl_list_for_each_safe(b, tmp, &compositor->axis_binding_list, link) { 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; 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; return 1;
} }
} }
@ -410,7 +413,7 @@ weston_compositor_run_axis_binding(struct weston_compositor *compositor,
int int
weston_compositor_run_debug_binding(struct weston_compositor *compositor, weston_compositor_run_debug_binding(struct weston_compositor *compositor,
struct weston_seat *seat, struct weston_keyboard *keyboard,
uint32_t time, uint32_t key, uint32_t time, uint32_t key,
enum wl_keyboard_key_state state) enum wl_keyboard_key_state state)
{ {
@ -424,7 +427,7 @@ weston_compositor_run_debug_binding(struct weston_compositor *compositor,
count++; count++;
handler = binding->handler; handler = binding->handler;
handler(seat->keyboard, time, key, binding->data); handler(keyboard, time, key, binding->data);
} }
return count; return count;
@ -480,8 +483,8 @@ debug_binding_key(struct weston_keyboard_grab *grab, uint32_t time,
} }
if (check_binding) { if (check_binding) {
if (weston_compositor_run_debug_binding(ec, db->seat, time, if (weston_compositor_run_debug_binding(ec, grab->keyboard,
key, state)) { time, key, state)) {
/* We ran a binding so swallow the press and keep the /* We ran a binding so swallow the press and keep the
* grab to swallow the released too. */ * grab to swallow the released too. */
send = 0; send = 0;

@ -1213,31 +1213,32 @@ weston_binding_list_destroy_all(struct wl_list *list);
void void
weston_compositor_run_key_binding(struct weston_compositor *compositor, 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, uint32_t key,
enum wl_keyboard_key_state state); enum wl_keyboard_key_state state);
void void
weston_compositor_run_modifier_binding(struct weston_compositor *compositor, weston_compositor_run_modifier_binding(struct weston_compositor *compositor,
struct weston_seat *seat, struct weston_keyboard *keyboard,
enum weston_keyboard_modifier modifier, enum weston_keyboard_modifier modifier,
enum wl_keyboard_key_state state); enum wl_keyboard_key_state state);
void void
weston_compositor_run_button_binding(struct weston_compositor *compositor, 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, uint32_t button,
enum wl_pointer_button_state value); enum wl_pointer_button_state value);
void void
weston_compositor_run_touch_binding(struct weston_compositor *compositor, 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 touch_type);
int int
weston_compositor_run_axis_binding(struct weston_compositor *compositor, 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); uint32_t axis, int32_t value);
int int
weston_compositor_run_debug_binding(struct weston_compositor *compositor, 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, uint32_t key,
enum wl_keyboard_key_state state); enum wl_keyboard_key_state state);

@ -973,7 +973,7 @@ run_modifier_bindings(struct weston_seat *seat, uint32_t old, uint32_t new)
for (i = 0; i < ARRAY_LENGTH(mods); i++) { for (i = 0; i < ARRAY_LENGTH(mods); i++) {
if (diff & (1 << mods[i].xkb)) if (diff & (1 << mods[i].xkb))
weston_compositor_run_modifier_binding(compositor, weston_compositor_run_modifier_binding(compositor,
seat, keyboard,
mods[i].weston, mods[i].weston,
WL_KEYBOARD_KEY_STATE_PRESSED); WL_KEYBOARD_KEY_STATE_PRESSED);
} }
@ -982,7 +982,7 @@ run_modifier_bindings(struct weston_seat *seat, uint32_t old, uint32_t new)
for (i = 0; i < ARRAY_LENGTH(mods); i++) { for (i = 0; i < ARRAY_LENGTH(mods); i++) {
if (diff & (1 << mods[i].xkb)) if (diff & (1 << mods[i].xkb))
weston_compositor_run_modifier_binding(compositor, weston_compositor_run_modifier_binding(compositor,
seat, keyboard,
mods[i].weston, mods[i].weston,
WL_KEYBOARD_KEY_STATE_RELEASED); WL_KEYBOARD_KEY_STATE_RELEASED);
} }
@ -1034,7 +1034,7 @@ notify_button(struct weston_seat *seat, uint32_t time, int32_t button,
pointer->button_count--; pointer->button_count--;
} }
weston_compositor_run_button_binding(compositor, seat, time, button, weston_compositor_run_button_binding(compositor, pointer, time, button,
state); state);
pointer->grab->interface->button(pointer->grab, time, button, state); pointer->grab->interface->button(pointer->grab, time, button, state);
@ -1058,7 +1058,7 @@ notify_axis(struct weston_seat *seat, uint32_t time, uint32_t axis,
if (!value) if (!value)
return; return;
if (weston_compositor_run_axis_binding(compositor, seat, if (weston_compositor_run_axis_binding(compositor, pointer,
time, axis, value)) time, axis, value))
return; return;
@ -1346,8 +1346,8 @@ notify_key(struct weston_seat *seat, uint32_t time, uint32_t key,
if (grab == &keyboard->default_grab || if (grab == &keyboard->default_grab ||
grab == &keyboard->input_method_grab) { grab == &keyboard->input_method_grab) {
weston_compositor_run_key_binding(compositor, seat, time, key, weston_compositor_run_key_binding(compositor, keyboard, time,
state); key, state);
grab = keyboard->grab; grab = keyboard->grab;
} }
@ -1542,7 +1542,7 @@ notify_touch(struct weston_seat *seat, uint32_t time, int touch_id,
return; return;
} }
weston_compositor_run_touch_binding(ec, seat, weston_compositor_run_touch_binding(ec, touch,
time, touch_type); time, touch_type);
grab->interface->down(grab, time, touch_id, sx, sy); grab->interface->down(grab, time, touch_id, sx, sy);

Loading…
Cancel
Save