diff --git a/libweston/compositor.h b/libweston/compositor.h index 09a9dab8..083c154d 100644 --- a/libweston/compositor.h +++ b/libweston/compositor.h @@ -64,6 +64,12 @@ struct weston_transform { struct wl_list link; }; +/** 2D device coordinates normalized to [0, 1] range */ +struct weston_point2d_device_normalized { + double x; + double y; +}; + struct weston_surface; struct weston_buffer; struct shell_surface; @@ -1543,8 +1549,24 @@ void notify_keyboard_focus_out(struct weston_seat *seat); void +notify_touch_normalized(struct weston_touch_device *device, + const struct timespec *time, + int touch_id, + double x, double y, + const struct weston_point2d_device_normalized *norm, + int touch_type); + +/** 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, double x, double y, int touch_type); + int touch_id, double x, double y, int touch_type) +{ + notify_touch_normalized(device, time, touch_id, x, y, NULL, touch_type); +} + void notify_touch_frame(struct weston_touch_device *device); diff --git a/libweston/input.c b/libweston/input.c index e02b3060..a5838225 100644 --- a/libweston/input.c +++ b/libweston/input.c @@ -2338,17 +2338,10 @@ weston_touch_set_focus(struct weston_touch *touch, struct weston_view *view) touch->focus = view; } -/** - * notify_touch - emulates button touches and notifies surfaces accordingly. - * - * It assumes always the correct cycle sequence until it gets here: touch_down - * → touch_update → ... → touch_update → touch_end. The driver is responsible - * for sending along such order. - * - */ -WL_EXPORT void -notify_touch(struct weston_touch_device *device, const struct timespec *time, - int touch_id, double double_x, double double_y, int touch_type) +static void +process_touch_normal(struct weston_touch_device *device, + const struct timespec *time, int touch_id, + double double_x, double double_y, int touch_type) { struct weston_touch *touch = device->aggregate; struct weston_touch_grab *grab = device->aggregate->grab; @@ -2425,6 +2418,48 @@ notify_touch(struct weston_touch_device *device, const struct timespec *time, } } +/** Feed in touch down, motion, and up events, calibratable device. + * + * It assumes always the correct cycle sequence until it gets here: touch_down + * → 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 double_x X coordinate in compositor global space. + * \param double_y Y coordinate in compositor global space. + * \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. + * + * Coordinates norm are only used for touch device calibration. If and only if + * the weston_touch_device does not support calibrating, norm must be NULL. + * + * The calibration space is the normalized coordinate space + * [0.0, 1.0]×[0.0, 1.0] of the weston_touch_device. This is assumed to + * map to the similar normalized coordinate space of the associated + * weston_output. + */ +WL_EXPORT void +notify_touch_normalized(struct weston_touch_device *device, + const struct timespec *time, + int touch_id, + double x, double y, + const struct weston_point2d_device_normalized *norm, + int touch_type) +{ + if (touch_type != WL_TOUCH_UP) { + if (weston_touch_device_can_calibrate(device)) + assert(norm != NULL); + else + assert(norm == NULL); + } + + process_touch_normal(device, time, touch_id, x, y, touch_type); +} + WL_EXPORT void notify_touch_frame(struct weston_touch_device *device) { diff --git a/libweston/libinput-device.c b/libweston/libinput-device.c index dda28fdc..e25df144 100644 --- a/libweston/libinput-device.c +++ b/libweston/libinput-device.c @@ -419,6 +419,7 @@ handle_touch_with_coords(struct libinput_device *libinput_device, libinput_device_get_user_data(libinput_device); double x; double y; + struct weston_point2d_device_normalized norm; uint32_t width, height; struct timespec time; int32_t slot; @@ -438,7 +439,14 @@ handle_touch_with_coords(struct libinput_device *libinput_device, weston_output_transform_coordinate(device->output, x, y, &x, &y); - notify_touch(device->touch_device, &time, slot, x, y, touch_type); + 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, + x, y, &norm, touch_type); + } else { + notify_touch(device->touch_device, &time, slot, x, y, touch_type); + } } static void