diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c index 8b6499656..8d93b18aa 100644 --- a/desktop-shell/shell.c +++ b/desktop-shell/shell.c @@ -758,20 +758,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) + 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 +779,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/li b/include/libweston/li new file mode 100644 index 000000000..e69de29bb diff --git a/include/libweston/libweston.h b/include/libweston/libweston.h index 9415fb793..7309df041 100644 --- a/include/libweston/libweston.h +++ b/include/libweston/libweston.h @@ -640,6 +640,13 @@ struct weston_key_event { enum weston_key_state_update key_update_state; }; +struct weston_touch_event { + struct weston_input_event base_event; + int32_t touch_type; + int32_t touch_id; + const struct weston_coord_global *pos; +}; + struct weston_pointer_grab; struct weston_pointer_grab_interface { @@ -678,16 +685,11 @@ 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); + const struct weston_touch_event *event); void (*up)(struct weston_touch_grab *grab, - const struct timespec *time, - int touch_id); + const struct weston_touch_event *event); void (*motion)(struct weston_touch_grab *grab, - const struct timespec *time, - int touch_id, - struct weston_coord_global c); + const struct weston_touch_event *event); void (*frame)(struct weston_touch_grab *grab); void (*cancel)(struct weston_touch_grab *grab); }; @@ -1048,6 +1050,10 @@ 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, 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, @@ -1064,15 +1070,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(struct weston_touch *touch, 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(struct weston_touch *touch, 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(struct weston_touch *touch, 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..c609dd8bf 100644 --- a/kiosk-shell/kiosk-shell-grab.c +++ b/kiosk-shell/kiosk-shell-grab.c @@ -129,19 +129,18 @@ 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) + 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) + const struct weston_touch_event *event) { 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) @@ -150,8 +149,7 @@ 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) + const struct weston_touch_event *event) { struct kiosk_shell_grab *shgrab = container_of(touch_grab, struct kiosk_shell_grab, touch_grab); diff --git a/libweston/backend-wayland/wayland.c b/libweston/backend-wayland/wayland.c index eb680f841..78a4a6abd 100644 --- a/libweston/backend-wayland/wayland.c +++ b/libweston/backend-wayland/wayland.c @@ -1679,6 +1679,7 @@ input_handle_motion(void *data, struct wl_pointer *pointer, struct weston_coord_global pos; struct weston_pointer_motion_event event; struct timespec ts; + struct weston_seat *seat; if (!input->output) return; @@ -1716,10 +1717,11 @@ input_handle_motion(void *data, struct wl_pointer *pointer, want_frame = true; } + seat = input->touch_device->aggregate->seat; if (location == THEME_LOCATION_CLIENT_AREA) { timespec_from_msec(&ts, time); - weston_input_event_init(&event.base_event, &ts, &input->base); + weston_input_event_init(&event.base_event, &ts, seat); weston_pointer_motion_event_init(&event, WESTON_POINTER_MOTION_ABS, &pos, NULL, NULL); notify_motion(&input->base, &event); @@ -2089,6 +2091,8 @@ 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; + struct weston_seat *seat; x = wl_fixed_to_double(fixed_x); y = wl_fixed_to_double(fixed_y); @@ -2103,6 +2107,7 @@ input_handle_touch_down(void *data, struct wl_touch *wl_touch, if (!first_touch && !input->touch_active) return; + seat = input->touch_device->aggregate->seat; if (output->frame) { location = frame_touch_down(output->frame, input, id, x, y); @@ -2129,7 +2134,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_input_event_init(&event.base_event, &ts, seat); + weston_touch_event_init(&event, WL_TOUCH_DOWN, id, &pos); + notify_touch(input->touch_device, &event); input->touch_active = true; } @@ -2141,6 +2148,8 @@ 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; + struct weston_seat *seat; timespec_from_msec(&ts, time); @@ -2149,6 +2158,7 @@ input_handle_touch_up(void *data, struct wl_touch *wl_touch, if (!output) return; + seat = input->touch_device->aggregate->seat; if (output->frame) { frame_touch_up(output->frame, input, id); @@ -2165,8 +2175,11 @@ input_handle_touch_up(void *data, struct wl_touch *wl_touch, weston_output_schedule_repaint(&output->base); } + weston_input_event_init(&event.base_event, &ts, seat); + weston_touch_event_init(&event, WL_TOUCH_UP, id, NULL); + if (active) - notify_touch(input->touch_device, &ts, id, NULL, WL_TOUCH_UP); + notify_touch(input->touch_device, &event); } static void @@ -2180,6 +2193,8 @@ 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; + struct weston_seat *seat; x = wl_fixed_to_double(fixed_x); y = wl_fixed_to_double(fixed_y); @@ -2188,6 +2203,7 @@ input_handle_touch_motion(void *data, struct wl_touch *wl_touch, if (!output || !input->touch_active) return; + seat = input->touch_device->aggregate->seat; if (output->frame) { frame_interior(output->frame, &fx, &fy, NULL, NULL); x -= fx; @@ -2195,8 +2211,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_input_event_init(&event.base_event, &ts, seat); + weston_touch_event_init(&event, WL_TOUCH_MOTION, id, &pos); + notify_touch(input->touch_device, &event); } static void diff --git a/libweston/backend.h b/libweston/backend.h index 2b87e4375..4fdd3d868 100644 --- a/libweston/backend.h +++ b/libweston/backend.h @@ -268,21 +268,17 @@ clear_pointer_focus(struct weston_seat *seat); 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); + 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(struct weston_touch_device *device, const struct weston_touch_event *event) { - notify_touch_normalized(device, time, touch_id, pos, NULL, touch_type); + notify_touch_normalized(device, event, NULL); } void @@ -292,10 +288,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(struct weston_touch_device *device, 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 9da912b31..1a3cc8f8c 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_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) @@ -779,15 +776,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) + const struct weston_touch_event *event) { 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 +795,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_event.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 3c0ac225e..4bdd016df 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(grab->touch, 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(grab->touch, 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(grab->touch, event); } static void diff --git a/libweston/input.c b/libweston/input.c index 1d5d184fc..244253101 100644 --- a/libweston/input.c +++ b/libweston/input.c @@ -888,17 +888,15 @@ 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(struct weston_touch *touch, + const struct weston_touch_event *event) { struct wl_display *display = touch->seat->compositor->wl_display; uint32_t serial; @@ -910,18 +908,19 @@ 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_event.ts); wl_resource_for_each(resource, resource_list) { send_timestamps_for_input_resource(resource, &touch->timestamps_list, - time); + event->base_event.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)); } @@ -929,25 +928,23 @@ weston_touch_send_down(struct weston_touch *touch, const struct timespec *time, static void default_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(grab->touch, 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(struct weston_touch *touch, + const struct weston_touch_event *event) { struct wl_display *display = touch->seat->compositor->wl_display; uint32_t serial; @@ -960,28 +957,26 @@ 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_event.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_event.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) + const struct weston_touch_event *event) { - weston_touch_send_up(grab->touch, time, touch_id); + weston_touch_send_up(grab->touch, 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 @@ -989,8 +984,7 @@ default_grab_touch_up(struct weston_touch_grab *grab, */ WL_EXPORT void weston_touch_send_motion(struct weston_touch *touch, - const struct timespec *time, int touch_id, - struct weston_coord_global pos) + const struct weston_touch_event *event) { struct wl_resource *resource; struct wl_list *resource_list; @@ -1000,15 +994,16 @@ weston_touch_send_motion(struct weston_touch *touch, 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_event.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_event.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)); } @@ -1016,10 +1011,9 @@ weston_touch_send_motion(struct weston_touch *touch, static void default_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(grab->touch, event); } @@ -2834,28 +2828,24 @@ 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) + 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 @@ -2867,15 +2857,16 @@ process_touch_normal(struct weston_touch_device *device, } weston_compositor_run_touch_binding(ec, touch, - time, touch_type); + event->base_event.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_event.ts; + touch->grab_pos = *event->pos; } break; @@ -2884,10 +2875,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; } @@ -2999,11 +2990,8 @@ weston_compositor_set_touch_mode_calib(struct weston_compositor *compositor) * 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. * @@ -3017,28 +3005,21 @@ weston_compositor_set_touch_mode_calib(struct weston_compositor *compositor) */ 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) + 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; - if (touch_type != WL_TOUCH_UP) { - assert(pos); - + if (event->touch_type != WL_TOUCH_UP) { if (weston_touch_device_can_calibrate(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); @@ -3066,12 +3047,11 @@ notify_touch_normalized(struct weston_touch_device *device, switch (weston_touch_device_get_mode(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(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(device, event, norm); break; } } @@ -6051,3 +6031,12 @@ 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, int32_t touch_type, + int32_t touch_id, const struct weston_coord_global *pos) +{ + event->touch_type = touch_type; + event->touch_id = touch_id; + event->pos = pos; +} diff --git a/libweston/libinput-device.c b/libweston/libinput-device.c index f89c7eb0d..d42991404 100644 --- a/libweston/libinput-device.c +++ b/libweston/libinput-device.c @@ -459,15 +459,18 @@ 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; + 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)); - 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; @@ -476,14 +479,15 @@ handle_touch_with_coords(struct libinput_device *libinput_device, pos = weston_coord_global_from_output_point(x, y, device->output); + weston_input_event_init(&event.base_event, &time, seat); + weston_touch_event_init(&event, 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(device->touch_device, &event, &norm); } else { - notify_touch(device->touch_device, &time, slot, - &pos, touch_type); + notify_touch(device->touch_device, &event); } } @@ -508,15 +512,20 @@ 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_input_event_init(&event.base_event, &time, seat); + weston_touch_event_init(&event, WL_TOUCH_UP, + libinput_event_touch_get_seat_slot(touch_event), NULL); + notify_touch(device->touch_device, &event); } static void diff --git a/libweston/touch-calibration.c b/libweston/touch-calibration.c index f4c9366a0..7851a2ebb 100644 --- a/libweston/touch-calibration.c +++ b/libweston/touch-calibration.c @@ -87,9 +87,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) + const struct weston_touch_event *event, + const struct weston_point2d_device_normalized *norm) { struct weston_touch_calibrator *calibrator; struct wl_resource *res; @@ -105,7 +104,7 @@ notify_touch_calibrator(struct weston_touch_device *device, /* Ignore any touch events coming from another device */ if (device != calibrator->device) { - if (touch_type == WL_TOUCH_DOWN) + if (event->touch_type == WL_TOUCH_DOWN) weston_touch_calibrator_send_invalid_touch(res); return; } @@ -115,20 +114,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_event.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 +136,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 581b4323f..3f977d058 100644 --- a/tests/harness/weston-test.c +++ b/tests/harness/weston-test.c @@ -556,10 +556,14 @@ 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 = device->aggregate->seat; timespec_from_proto(&time, tv_sec_hi, tv_sec_lo, tv_nsec); + weston_input_event_init(&event.base_event, &time, seat); if (touch_type == WL_TOUCH_UP) { if (x != 0 || y != 0) { @@ -570,11 +574,12 @@ 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, touch_type, touch_id, NULL); + notify_touch(device, &event); } else { pos.c = weston_coord_from_fixed(x, y); - notify_touch(device, &time, touch_id, &pos, touch_type); + weston_touch_event_init(&event, touch_type, touch_id, &pos); + notify_touch(device, &event); } }