diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c index 8b6499656..16223c051 100644 --- a/desktop-shell/shell.c +++ b/desktop-shell/shell.c @@ -757,21 +757,18 @@ surface_keyboard_focus_lost(struct weston_surface *surface) } static void -touch_move_grab_down(struct weston_touch_grab *grab, - const struct timespec *time, - int touch_id, struct weston_coord_global c) +touch_move_grab_down(struct weston_touch_grab *grab, const struct weston_touch_event *event) { } static void -touch_move_grab_up(struct weston_touch_grab *grab, const struct timespec *time, - int touch_id) +touch_move_grab_up(struct weston_touch_grab *grab, const struct weston_touch_event *event) { struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) container_of( grab, struct shell_touch_grab, grab); - if (touch_id == 0) + if (event->touch_id == 0) move->active = 0; if (grab->touch->num_tp == 0) { @@ -781,9 +778,7 @@ touch_move_grab_up(struct weston_touch_grab *grab, const struct timespec *time, } static void -touch_move_grab_motion(struct weston_touch_grab *grab, - const struct timespec *time, int touch_id, - struct weston_coord_global unused) +touch_move_grab_motion(struct weston_touch_grab *grab, const struct weston_touch_event *event) { struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; struct shell_surface *shsurf = move->base.shsurf; diff --git a/include/libweston/libweston.h b/include/libweston/libweston.h index 89fd622b3..22156d338 100644 --- a/include/libweston/libweston.h +++ b/include/libweston/libweston.h @@ -640,6 +640,14 @@ struct weston_key_event { enum weston_key_state_update key_update_state; }; +struct weston_touch_event { + struct weston_input_event base; + const struct weston_touch_device *device; + int32_t touch_type; + int32_t touch_id; + struct weston_coord_global pos; +}; + struct weston_pointer_grab; struct weston_pointer_grab_interface { @@ -677,17 +685,9 @@ struct weston_keyboard_grab { struct weston_touch_grab; struct weston_touch_grab_interface { - void (*down)(struct weston_touch_grab *grab, - const struct timespec *time, - int touch_id, - struct weston_coord_global c); - void (*up)(struct weston_touch_grab *grab, - const struct timespec *time, - int touch_id); - void (*motion)(struct weston_touch_grab *grab, - const struct timespec *time, - int touch_id, - struct weston_coord_global c); + void (*down)(struct weston_touch_grab *grab, const struct weston_touch_event *event); + void (*up)(struct weston_touch_grab *grab, const struct weston_touch_event *event); + void (*motion)(struct weston_touch_grab *grab, const struct weston_touch_event *event); void (*frame)(struct weston_touch_grab *grab); void (*cancel)(struct weston_touch_grab *grab); }; @@ -1052,6 +1052,12 @@ weston_pointer_axis_event_init(struct weston_pointer_axis_event *event, uint32_t axis, double value, bool has_value, int32_t discrete); +void +weston_touch_event_init(struct weston_touch_event *event, struct timespec *ts, + struct weston_seat *seat, struct weston_touch_device *device, + int32_t touch_type, int32_t touch_id, + const struct weston_coord_global *pos); + void weston_keyboard_send_modifiers(struct weston_keyboard *keyboard, uint32_t serial, uint32_t mods_depressed, @@ -1068,15 +1074,11 @@ void weston_touch_end_grab(struct weston_touch *touch); void -weston_touch_send_down(struct weston_touch *touch, const struct timespec *time, - int touch_id, struct weston_coord_global pos); +weston_touch_send_down(const struct weston_touch_event *event); void -weston_touch_send_up(struct weston_touch *touch, const struct timespec *time, - int touch_id); +weston_touch_send_up(const struct weston_touch_event *event); void -weston_touch_send_motion(struct weston_touch *touch, - const struct timespec *time, int touch_id, - struct weston_coord_global pos); +weston_touch_send_motion(const struct weston_touch_event *event); void weston_touch_send_frame(struct weston_touch *touch); diff --git a/ivi-shell/hmi-controller.c b/ivi-shell/hmi-controller.c index 7939c603b..7b4affbe5 100644 --- a/ivi-shell/hmi-controller.c +++ b/ivi-shell/hmi-controller.c @@ -1731,9 +1731,7 @@ pointer_move_grab_motion(struct weston_pointer_grab *grab, } static void -touch_move_grab_motion(struct weston_touch_grab *grab, - const struct timespec *time, int touch_id, - struct weston_coord_global c) +touch_move_grab_motion(struct weston_touch_grab *grab, const struct weston_touch_event *event) { struct touch_move_grab *tch_move_grab = (struct touch_move_grab *)grab; struct hmi_controller *hmi_ctrl = @@ -1766,20 +1764,16 @@ pointer_move_workspace_grab_button(struct weston_pointer_grab *grab, } static void -touch_nope_grab_down(struct weston_touch_grab *grab, - const struct timespec *time, - int touch_id, struct weston_coord_global c) +touch_nope_grab_down(struct weston_touch_grab *grab, const struct weston_touch_event *event) { } static void -touch_move_workspace_grab_up(struct weston_touch_grab *grab, - const struct timespec *time, - int touch_id) +touch_move_workspace_grab_up(struct weston_touch_grab *grab, const struct weston_touch_event *event) { struct touch_move_grab *tch_move_grab = (struct touch_move_grab *)grab; - if (0 == touch_id) + if (0 == event->touch_id) tch_move_grab->is_active = 0; if (0 == grab->touch->num_tp) { diff --git a/kiosk-shell/kiosk-shell-grab.c b/kiosk-shell/kiosk-shell-grab.c index 2508f8ee8..17fb002b1 100644 --- a/kiosk-shell/kiosk-shell-grab.c +++ b/kiosk-shell/kiosk-shell-grab.c @@ -128,20 +128,20 @@ static const struct weston_pointer_grab_interface pointer_move_grab_interface = */ static void -touch_move_grab_down(struct weston_touch_grab *grab, - const struct timespec *time, - int touch_id, struct weston_coord_global c) +touch_move_grab_down(struct weston_touch_grab *grab, const struct weston_touch_event *event) { } static void -touch_move_grab_up(struct weston_touch_grab *touch_grab, - const struct timespec *time, int touch_id) +touch_move_grab_up(struct weston_touch_grab *grab, const struct weston_touch_event *event) { + struct weston_touch *touch = event->base.seat->touch_state; + struct weston_touch_grab *touch_grab = + touch->grab; struct kiosk_shell_grab *shgrab = container_of(touch_grab, struct kiosk_shell_grab, touch_grab); - if (touch_id == 0) + if (event->touch_id == 0) shgrab->active = false; if (touch_grab->touch->num_tp == 0) @@ -149,13 +149,13 @@ touch_move_grab_up(struct weston_touch_grab *touch_grab, } static void -touch_move_grab_motion(struct weston_touch_grab *touch_grab, - const struct timespec *time, int touch_id, - struct weston_coord_global unused) +touch_move_grab_motion(struct weston_touch_grab *grab, const struct weston_touch_event *event) { + struct weston_seat *seat = event->base.seat; + struct weston_touch *touch = seat->touch_state; + struct weston_touch_grab *touch_grab = touch->grab; struct kiosk_shell_grab *shgrab = container_of(touch_grab, struct kiosk_shell_grab, touch_grab); - struct weston_touch *touch = touch_grab->touch; struct kiosk_shell_surface *shsurf = shgrab->shsurf; struct weston_surface *surface; struct weston_coord_global pos; diff --git a/libweston/backend-wayland/wayland.c b/libweston/backend-wayland/wayland.c index 0efb00ba1..60210fa66 100644 --- a/libweston/backend-wayland/wayland.c +++ b/libweston/backend-wayland/wayland.c @@ -2089,6 +2089,7 @@ input_handle_touch_down(void *data, struct wl_touch *wl_touch, struct weston_coord_global pos; double x, y; struct timespec ts; + struct weston_touch_event event; x = wl_fixed_to_double(fixed_x); y = wl_fixed_to_double(fixed_y); @@ -2129,7 +2130,9 @@ input_handle_touch_down(void *data, struct wl_touch *wl_touch, pos = weston_coord_global_from_output_point(x,y, &output->base); - notify_touch(input->touch_device, &ts, id, &pos, WL_TOUCH_DOWN); + weston_touch_event_init(&event, &ts, &input->base, input->touch_device, + WL_TOUCH_DOWN, id, &pos); + notify_touch(&event); input->touch_active = true; } @@ -2141,6 +2144,7 @@ input_handle_touch_up(void *data, struct wl_touch *wl_touch, struct wayland_output *output = input->touch_focus; bool active = input->touch_active; struct timespec ts; + struct weston_touch_event event; timespec_from_msec(&ts, time); @@ -2165,8 +2169,11 @@ input_handle_touch_up(void *data, struct wl_touch *wl_touch, weston_output_schedule_repaint(&output->base); } + weston_touch_event_init(&event, &ts, &input->base, input->touch_device, + WL_TOUCH_UP, id, NULL); + if (active) - notify_touch(input->touch_device, &ts, id, NULL, WL_TOUCH_UP); + notify_touch(&event); } static void @@ -2180,6 +2187,7 @@ input_handle_touch_motion(void *data, struct wl_touch *wl_touch, double x, y; struct weston_coord_global pos; struct timespec ts; + struct weston_touch_event event; x = wl_fixed_to_double(fixed_x); y = wl_fixed_to_double(fixed_y); @@ -2195,8 +2203,9 @@ input_handle_touch_motion(void *data, struct wl_touch *wl_touch, } pos = weston_coord_global_from_output_point(x, y, &output->base); - - notify_touch(input->touch_device, &ts, id, &pos, WL_TOUCH_MOTION); + weston_touch_event_init(&event, &ts, &input->base, input->touch_device, + WL_TOUCH_MOTION, id, &pos); + notify_touch(&event); } static void diff --git a/libweston/backend.h b/libweston/backend.h index db2c8196e..c851b9f96 100644 --- a/libweston/backend.h +++ b/libweston/backend.h @@ -267,22 +267,17 @@ clear_pointer_focus(struct weston_seat *seat); /* weston_touch_device */ void -notify_touch_normalized(struct weston_touch_device *device, - const struct timespec *time, - int touch_id, - const struct weston_coord_global *pos, - const struct weston_point2d_device_normalized *norm, - int touch_type); +notify_touch_normalized(const struct weston_touch_event *event, + const struct weston_point2d_device_normalized *norm); /** Feed in touch down, motion, and up events, non-calibratable device. * * @sa notify_touch_cal */ static inline void -notify_touch(struct weston_touch_device *device, const struct timespec *time, - int touch_id, const struct weston_coord_global *pos, int touch_type) +notify_touch(const struct weston_touch_event *event) { - notify_touch_normalized(device, time, touch_id, pos, NULL, touch_type); + notify_touch_normalized(event, NULL); } void @@ -292,10 +287,8 @@ void notify_touch_cancel(struct weston_touch_device *device); void -notify_touch_calibrator(struct weston_touch_device *device, - const struct timespec *time, int32_t slot, - const struct weston_point2d_device_normalized *norm, - int touch_type); +notify_touch_calibrator(const struct weston_touch_event *event, + const struct weston_point2d_device_normalized *norm); void notify_touch_calibrator_cancel(struct weston_touch_device *device); void diff --git a/libweston/data-device.c b/libweston/data-device.c index 2051fb254..d41d43f19 100644 --- a/libweston/data-device.c +++ b/libweston/data-device.c @@ -730,9 +730,7 @@ static const struct weston_pointer_grab_interface pointer_drag_grab_interface = }; static void -drag_grab_touch_down(struct weston_touch_grab *grab, - const struct timespec *time, int touch_id, - struct weston_coord_global c) +drag_grab_touch_down(struct weston_touch_grab *grab, const struct weston_touch_event *event) { } @@ -750,14 +748,13 @@ data_device_end_touch_drag_grab(struct weston_touch_drag *drag) } static void -drag_grab_touch_up(struct weston_touch_grab *grab, - const struct timespec *time, int touch_id) +drag_grab_touch_up(struct weston_touch_grab *grab, const struct weston_touch_event *event) { + struct weston_touch *touch = grab->touch; struct weston_touch_drag *touch_drag = container_of(grab, struct weston_touch_drag, grab); - struct weston_touch *touch = grab->touch; - if (touch_id != touch->grab_touch_id) + if (event->touch_id != touch->grab_touch_id) return; if (touch_drag->base.focus_resource) @@ -778,16 +775,14 @@ drag_grab_touch_focus(struct weston_touch_drag *drag) } static void -drag_grab_touch_motion(struct weston_touch_grab *grab, - const struct timespec *time, - int touch_id, struct weston_coord_global unused) +drag_grab_touch_motion(struct weston_touch_grab *grab, const struct weston_touch_event *event) { + struct weston_touch *touch = grab->touch; struct weston_touch_drag *touch_drag = container_of(grab, struct weston_touch_drag, grab); - struct weston_touch *touch = grab->touch; uint32_t msecs; - if (touch_id != touch->grab_touch_id) + if (event->touch_id != touch->grab_touch_id) return; drag_grab_touch_focus(touch_drag); @@ -799,7 +794,7 @@ drag_grab_touch_motion(struct weston_touch_grab *grab, if (touch_drag->base.focus_resource) { struct weston_coord_surface surf_pos; - msecs = timespec_to_msec(time); + msecs = timespec_to_msec(&event->base.ts); surf_pos = weston_coord_global_to_surface(touch_drag->base.focus, touch->grab_pos); wl_data_device_send_motion(touch_drag->base.focus_resource, diff --git a/libweston/desktop/seat.c b/libweston/desktop/seat.c index 2fe9e3b34..c0a37ecb5 100644 --- a/libweston/desktop/seat.c +++ b/libweston/desktop/seat.c @@ -185,28 +185,23 @@ static const struct weston_pointer_grab_interface weston_desktop_seat_pointer_po static void weston_desktop_seat_popup_grab_touch_down(struct weston_touch_grab *grab, - const struct timespec *time, - int touch_id, - struct weston_coord_global pos) + const struct weston_touch_event *event) { - weston_touch_send_down(grab->touch, time, touch_id, pos); + weston_touch_send_down(event); } static void weston_desktop_seat_popup_grab_touch_up(struct weston_touch_grab *grab, - const struct timespec *time, - int touch_id) + const struct weston_touch_event *event) { - weston_touch_send_up(grab->touch, time, touch_id); + weston_touch_send_up(event); } static void weston_desktop_seat_popup_grab_touch_motion(struct weston_touch_grab *grab, - const struct timespec *time, - int touch_id, - struct weston_coord_global pos) + const struct weston_touch_event *event) { - weston_touch_send_motion(grab->touch, time, touch_id, pos); + weston_touch_send_motion(event); } static void diff --git a/libweston/input.c b/libweston/input.c index 024fb90b4..1e24554e6 100644 --- a/libweston/input.c +++ b/libweston/input.c @@ -178,13 +178,13 @@ weston_touch_device_destroy(struct weston_touch_device *device) /** Is it possible to run calibration on this touch device? */ WL_EXPORT bool -weston_touch_device_can_calibrate(struct weston_touch_device *device) +weston_touch_device_can_calibrate(const struct weston_touch_device *device) { return !!device->ops; } static enum weston_touch_mode -weston_touch_device_get_mode(struct weston_touch_device *device) +weston_touch_device_get_mode(const struct weston_touch_device *device) { return device->aggregate->seat->compositor->touch_mode; } @@ -886,19 +886,16 @@ weston_touch_has_focus_resource(struct weston_touch *touch) /** Send wl_touch.down events to focused resources. * - * \param touch The touch where the down events originates from. - * \param time The timestamp of the event - * \param touch_id The touch_id value of the event - * \param pos The global coordinate of the event + * \param event The weston_touch_event * * For every resource that is currently in focus, send a wl_touch.down event * with the passed parameters. The focused resources are the wl_touch * resources of the client which currently has the surface with touch focus. */ WL_EXPORT void -weston_touch_send_down(struct weston_touch *touch, const struct timespec *time, - int touch_id, struct weston_coord_global pos) +weston_touch_send_down(const struct weston_touch_event *event) { + struct weston_touch *touch = event->base.seat->touch_state; struct wl_display *display = touch->seat->compositor->wl_display; uint32_t serial; struct wl_resource *resource; @@ -909,45 +906,42 @@ weston_touch_send_down(struct weston_touch *touch, const struct timespec *time, if (!weston_touch_has_focus_resource(touch)) return; - surf_pos = weston_coord_global_to_surface(touch->focus, pos); + surf_pos = weston_coord_global_to_surface(touch->focus, event->pos); + weston_view_update_transform(touch->focus); resource_list = &touch->focus_resource_list; serial = wl_display_next_serial(display); - msecs = timespec_to_msec(time); + msecs = timespec_to_msec(&event->base.ts); wl_resource_for_each(resource, resource_list) { send_timestamps_for_input_resource(resource, &touch->timestamps_list, - time); + &event->base.ts); wl_touch_send_down(resource, serial, msecs, touch->focus->surface->resource, - touch_id, + event->touch_id, wl_fixed_from_double(surf_pos.c.x), wl_fixed_from_double(surf_pos.c.y)); } } static void -default_grab_touch_down(struct weston_touch_grab *grab, - const struct timespec *time, int touch_id, - struct weston_coord_global pos) +default_grab_touch_down(struct weston_touch_grab *grab, const struct weston_touch_event *event) { - weston_touch_send_down(grab->touch, time, touch_id, pos); + weston_touch_send_down(event); } /** Send wl_touch.up events to focused resources. * - * \param touch The touch where the up events originates from. - * \param time The timestamp of the event - * \param touch_id The touch_id value of the event + * \param event The weston_touch_event * * For every resource that is currently in focus, send a wl_touch.up event * with the passed parameters. The focused resources are the wl_touch * resources of the client which currently has the surface with touch focus. */ WL_EXPORT void -weston_touch_send_up(struct weston_touch *touch, const struct timespec *time, - int touch_id) +weston_touch_send_up(const struct weston_touch_event *event) { + struct weston_touch *touch = event->base.seat->touch_state; struct wl_display *display = touch->seat->compositor->wl_display; uint32_t serial; struct wl_resource *resource; @@ -959,66 +953,60 @@ weston_touch_send_up(struct weston_touch *touch, const struct timespec *time, resource_list = &touch->focus_resource_list; serial = wl_display_next_serial(display); - msecs = timespec_to_msec(time); + msecs = timespec_to_msec(&event->base.ts); wl_resource_for_each(resource, resource_list) { send_timestamps_for_input_resource(resource, &touch->timestamps_list, - time); - wl_touch_send_up(resource, serial, msecs, touch_id); + &event->base.ts); + wl_touch_send_up(resource, serial, msecs, event->touch_id); } } static void -default_grab_touch_up(struct weston_touch_grab *grab, - const struct timespec *time, int touch_id) +default_grab_touch_up(struct weston_touch_grab *grab, const struct weston_touch_event *event) { - weston_touch_send_up(grab->touch, time, touch_id); + weston_touch_send_up(event); } /** Send wl_touch.motion events to focused resources. * - * \param touch The touch where the motion events originates from. - * \param time The timestamp of the event - * \param touch_id The touch_id value of the event - * \param pos The global coordinate of the event + * \param event The weston_touch_event * * For every resource that is currently in focus, send a wl_touch.motion event * with the passed parameters. The focused resources are the wl_touch * resources of the client which currently has the surface with touch focus. */ WL_EXPORT void -weston_touch_send_motion(struct weston_touch *touch, - const struct timespec *time, int touch_id, - struct weston_coord_global pos) +weston_touch_send_motion(const struct weston_touch_event *event) { struct wl_resource *resource; struct wl_list *resource_list; uint32_t msecs; struct weston_coord_surface surf_pos; + struct weston_touch *touch = event->base.seat->touch_state; if (!weston_touch_has_focus_resource(touch)) return; - surf_pos = weston_coord_global_to_surface(touch->focus, pos); + surf_pos = weston_coord_global_to_surface(touch->focus, event->pos); + weston_view_update_transform(touch->focus); resource_list = &touch->focus_resource_list; - msecs = timespec_to_msec(time); + msecs = timespec_to_msec(&event->base.ts); wl_resource_for_each(resource, resource_list) { send_timestamps_for_input_resource(resource, &touch->timestamps_list, - time); - wl_touch_send_motion(resource, msecs, touch_id, + &event->base.ts); + wl_touch_send_motion(resource, msecs, event->touch_id, wl_fixed_from_double(surf_pos.c.x), wl_fixed_from_double(surf_pos.c.y)); } } static void -default_grab_touch_motion(struct weston_touch_grab *grab, - const struct timespec *time, int touch_id, - struct weston_coord_global pos) +default_grab_touch_motion(struct weston_touch_grab *grab, const struct weston_touch_event *event) { - weston_touch_send_motion(grab->touch, time, touch_id, pos); + weston_touch_send_motion(event); } @@ -2835,29 +2823,25 @@ weston_touch_set_focus(struct weston_touch *touch, struct weston_view *view) } static void -process_touch_normal(struct weston_touch_device *device, - const struct timespec *time, int touch_id, - const struct weston_coord_global *pos, int touch_type) +process_touch_normal(const struct weston_touch_device *device, + const struct weston_touch_event *event) { struct weston_touch *touch = device->aggregate; struct weston_touch_grab *grab = device->aggregate->grab; struct weston_compositor *ec = device->aggregate->seat->compositor; struct weston_view *ev; - if (touch_type != WL_TOUCH_UP) - assert(pos); - /* Update grab's global coordinates. */ - if (touch_id == touch->grab_touch_id && touch_type != WL_TOUCH_UP) - touch->grab_pos = *pos; + if (event->touch_id == touch->grab_touch_id && event->touch_type != WL_TOUCH_UP) + touch->grab_pos = event->pos; - switch (touch_type) { + switch (event->touch_type) { case WL_TOUCH_DOWN: /* the first finger down picks the view, and all further go * to that view for the remainder of the touch session i.e. * until all touch points are up again. */ if (touch->num_tp == 1) { - ev = weston_compositor_pick_view(ec, *pos); + ev = weston_compositor_pick_view(ec, event->pos); weston_touch_set_focus(touch, ev); } else if (!touch->focus) { /* Unexpected condition: We have non-initial touch but @@ -2869,15 +2853,16 @@ process_touch_normal(struct weston_touch_device *device, } weston_compositor_run_touch_binding(ec, touch, - time, touch_type); + &event->base.ts, + event->touch_type); - grab->interface->down(grab, time, touch_id, *pos); + grab->interface->down(grab, event); if (touch->num_tp == 1) { touch->grab_serial = wl_display_get_serial(ec->wl_display); - touch->grab_touch_id = touch_id; - touch->grab_time = *time; - touch->grab_pos = *pos; + touch->grab_touch_id = event->touch_id; + touch->grab_time = event->base.ts; + touch->grab_pos = event->pos; } break; @@ -2886,10 +2871,10 @@ process_touch_normal(struct weston_touch_device *device, if (!ev) break; - grab->interface->motion(grab, time, touch_id, *pos); + grab->interface->motion(grab, event); break; case WL_TOUCH_UP: - grab->interface->up(grab, time, touch_id); + grab->interface->up(grab, event); touch->pending_focus_reset = true; break; } @@ -3000,12 +2985,8 @@ weston_compositor_set_touch_mode_calib(struct weston_compositor *compositor) * → touch_update → ... → touch_update → touch_end. The driver is responsible * for sending along such order. * - * \param device The physical device that generated the event. - * \param time The event timestamp. - * \param touch_id ID for the touch point of this event (multi-touch). - * \param pos X,Y coordinate in compositor global space, or NULL for WL_TOUCH_UP. + * \param event The weston_touch_event event * \param norm Normalized device X, Y coordinates in calibration space, or NULL. - * \param touch_type Either WL_TOUCH_DOWN, WL_TOUCH_UP, or WL_TOUCH_MOTION. * * Coordinates double_x and double_y are used for normal operation. * @@ -3018,29 +2999,21 @@ weston_compositor_set_touch_mode_calib(struct weston_compositor *compositor) * weston_output. */ WL_EXPORT void -notify_touch_normalized(struct weston_touch_device *device, - const struct timespec *time, - int touch_id, - const struct weston_coord_global *pos, - const struct weston_point2d_device_normalized *norm, - int touch_type) +notify_touch_normalized(const struct weston_touch_event *event, + const struct weston_point2d_device_normalized *norm) { - struct weston_seat *seat = device->aggregate->seat; - struct weston_touch *touch = device->aggregate; + struct weston_seat *seat = event->base.seat; + struct weston_touch *touch = seat->touch_state; - if (touch_type != WL_TOUCH_UP) { - assert(pos); - - if (weston_touch_device_can_calibrate(device)) + if (event->touch_type != WL_TOUCH_UP) { + if (weston_touch_device_can_calibrate(event->device)) assert(norm != NULL); else assert(norm == NULL); - } else { - assert(!pos); } /* Update touchpoints count regardless of the current mode. */ - switch (touch_type) { + switch (event->touch_type) { case WL_TOUCH_DOWN: weston_compositor_idle_inhibit(seat->compositor); @@ -3053,7 +3026,7 @@ notify_touch_normalized(struct weston_touch_device *device, * case we didn't get the corresponding down * event. */ weston_log("Unmatched touch up event on seat %s, device %s\n", - seat->seat_name, device->syspath); + seat->seat_name, event->device->syspath); return; } weston_compositor_idle_release(seat->compositor); @@ -3065,15 +3038,14 @@ notify_touch_normalized(struct weston_touch_device *device, } /* Properly forward the touch event */ - switch (weston_touch_device_get_mode(device)) { + switch (weston_touch_device_get_mode(event->device)) { case WESTON_TOUCH_MODE_NORMAL: case WESTON_TOUCH_MODE_PREP_CALIB: - process_touch_normal(device, time, touch_id, pos, touch_type); + process_touch_normal(event->device, event); break; case WESTON_TOUCH_MODE_CALIB: case WESTON_TOUCH_MODE_PREP_NORMAL: - notify_touch_calibrator(device, time, touch_id, - norm, touch_type); + notify_touch_calibrator(event, norm); break; } } @@ -6068,3 +6040,24 @@ weston_pointer_axis_event_init(struct weston_pointer_axis_event *event, event->has_discrete = has_discrete; event->discrete = discrete; } + +WL_EXPORT void +weston_touch_event_init(struct weston_touch_event *event, struct timespec *ts, + struct weston_seat *seat, struct weston_touch_device *device, + int32_t touch_type, int32_t touch_id, + const struct weston_coord_global *pos) +{ + weston_input_event_init(&event->base, ts, seat); + + weston_assert_ptr_not_null(event->base.seat->compositor, device); + + event->touch_type = touch_type; + event->touch_id = touch_id; + event->device = device; + event->pos.c = weston_coord(0, 0); + + if (touch_type == WL_TOUCH_DOWN || touch_type == WL_TOUCH_MOTION) { + weston_assert_ptr_not_null(event->base.seat->compositor, pos); + event->pos = *pos; + } +} diff --git a/libweston/libinput-device.c b/libweston/libinput-device.c index 7fb38e5b3..dfd7517ec 100644 --- a/libweston/libinput-device.c +++ b/libweston/libinput-device.c @@ -458,15 +458,16 @@ handle_touch_with_coords(struct libinput_device *libinput_device, struct weston_point2d_device_normalized norm; uint32_t width, height; struct timespec time; - int32_t slot; + int32_t touch_id; struct weston_coord_global pos; + struct weston_touch_event event; if (!device->output) return; timespec_from_usec(&time, libinput_event_touch_get_time_usec(touch_event)); - slot = libinput_event_touch_get_seat_slot(touch_event); + touch_id = libinput_event_touch_get_seat_slot(touch_event); width = device->output->current_mode->width; height = device->output->current_mode->height; @@ -475,14 +476,15 @@ handle_touch_with_coords(struct libinput_device *libinput_device, pos = weston_coord_global_from_output_point(x, y, device->output); + weston_touch_event_init(&event, &time, device->seat, device->touch_device, + touch_type, touch_id, &pos); + if (weston_touch_device_can_calibrate(device->touch_device)) { norm.x = libinput_event_touch_get_x_transformed(touch_event, 1); norm.y = libinput_event_touch_get_y_transformed(touch_event, 1); - notify_touch_normalized(device->touch_device, &time, slot, - &pos, &norm, touch_type); + notify_touch_normalized(&event, &norm); } else { - notify_touch(device->touch_device, &time, slot, - &pos, touch_type); + notify_touch(&event); } } @@ -507,15 +509,19 @@ handle_touch_up(struct libinput_device *libinput_device, struct evdev_device *device = libinput_device_get_user_data(libinput_device); struct timespec time; - int32_t slot = libinput_event_touch_get_seat_slot(touch_event); + struct weston_touch_event event; + struct weston_seat *seat; if (!device->output) return; + seat = device->touch_device->aggregate->seat; timespec_from_usec(&time, libinput_event_touch_get_time_usec(touch_event)); - notify_touch(device->touch_device, &time, slot, NULL, WL_TOUCH_UP); + weston_touch_event_init(&event, &time, seat, device->touch_device, WL_TOUCH_UP, + libinput_event_touch_get_seat_slot(touch_event), NULL); + notify_touch(&event); } static void diff --git a/libweston/libweston-internal.h b/libweston/libweston-internal.h index 52fd47af9..b6897b0bf 100644 --- a/libweston/libweston-internal.h +++ b/libweston/libweston-internal.h @@ -498,7 +498,7 @@ weston_touch_start_drag(struct weston_touch *touch, /* weston_touch_device */ bool -weston_touch_device_can_calibrate(struct weston_touch_device *device); +weston_touch_device_can_calibrate(const struct weston_touch_device *device); /* weston_tablet */ diff --git a/libweston/touch-calibration.c b/libweston/touch-calibration.c index f4c9366a0..ef0a8986f 100644 --- a/libweston/touch-calibration.c +++ b/libweston/touch-calibration.c @@ -64,7 +64,7 @@ struct weston_touch_calibrator { }; static struct weston_touch_calibrator * -calibrator_from_device(struct weston_touch_device *device) +calibrator_from_device(const struct weston_touch_device *device) { return device->aggregate->seat->compositor->touch_calibrator; } @@ -86,10 +86,8 @@ normalized_is_valid(const struct weston_point2d_device_normalized *p) } WL_EXPORT void -notify_touch_calibrator(struct weston_touch_device *device, - const struct timespec *time, int32_t slot, - const struct weston_point2d_device_normalized *norm, - int touch_type) +notify_touch_calibrator(const struct weston_touch_event *event, + const struct weston_point2d_device_normalized *norm) { struct weston_touch_calibrator *calibrator; struct wl_resource *res; @@ -97,15 +95,15 @@ notify_touch_calibrator(struct weston_touch_device *device, uint32_t x = 0; uint32_t y = 0; - calibrator = calibrator_from_device(device); + calibrator = calibrator_from_device(event->device); if (!calibrator) return; res = calibrator->resource; /* Ignore any touch events coming from another device */ - if (device != calibrator->device) { - if (touch_type == WL_TOUCH_DOWN) + if (event->device != calibrator->device) { + if (event->touch_type == WL_TOUCH_DOWN) weston_touch_calibrator_send_invalid_touch(res); return; } @@ -115,20 +113,20 @@ notify_touch_calibrator(struct weston_touch_device *device, */ if (calibrator->touch_cancelled) { if (calibrator->device->aggregate->num_tp == 0) { - assert(touch_type == WL_TOUCH_UP); + assert(event->touch_type == WL_TOUCH_UP); calibrator->touch_cancelled = false; } return; } - msecs = timespec_to_msec(time); - if (touch_type != WL_TOUCH_UP) { + msecs = timespec_to_msec(&event->base.ts); + if (event->touch_type != WL_TOUCH_UP) { if (normalized_is_valid(norm)) { x = wire_uint_from_double(norm->x); y = wire_uint_from_double(norm->y); } else { /* Coordinates are out of bounds */ - if (touch_type == WL_TOUCH_MOTION) { + if (event->touch_type == WL_TOUCH_MOTION) { weston_touch_calibrator_send_cancel(res); calibrator->touch_cancelled = true; } @@ -137,15 +135,15 @@ notify_touch_calibrator(struct weston_touch_device *device, } } - switch (touch_type) { + switch (event->touch_type) { case WL_TOUCH_UP: - weston_touch_calibrator_send_up(res, msecs, slot); + weston_touch_calibrator_send_up(res, msecs, event->touch_id); break; case WL_TOUCH_DOWN: - weston_touch_calibrator_send_down(res, msecs, slot, x, y); + weston_touch_calibrator_send_down(res, msecs, event->touch_id, x, y); break; case WL_TOUCH_MOTION: - weston_touch_calibrator_send_motion(res, msecs, slot, x, y); + weston_touch_calibrator_send_motion(res, msecs, event->touch_id, x, y); break; default: return; diff --git a/tests/harness/weston-test.c b/tests/harness/weston-test.c index e631ee8d1..81b9d17e6 100644 --- a/tests/harness/weston-test.c +++ b/tests/harness/weston-test.c @@ -555,9 +555,12 @@ send_touch(struct wl_client *client, struct wl_resource *resource, struct weston_touch_device *device = test->touch_device[0]; struct timespec time; struct weston_coord_global pos; + struct weston_touch_event event; + struct weston_seat *seat; assert(device); + seat = get_seat(test); timespec_from_proto(&time, tv_sec_hi, tv_sec_lo, tv_nsec); if (touch_type == WL_TOUCH_UP) { @@ -569,11 +572,14 @@ send_touch(struct wl_client *client, struct wl_resource *resource, return; } - - notify_touch(device, &time, touch_id, NULL, touch_type); + weston_touch_event_init(&event, &time, seat, device, + touch_type, touch_id, NULL); + notify_touch(&event); } else { pos.c = weston_coord_from_fixed(x, y); - notify_touch(device, &time, touch_id, &pos, touch_type); + weston_touch_event_init(&event, &time, seat, device, + touch_type, touch_id, &pos); + notify_touch(&event); } }