backend: Make input notification functions use weston_coord

Push weston_coord into the notification functions instead of passing
two doubles.

The touch handlers are passed a pointer to a weston_coord, which is
unusual. This is done so we can pass a NULL pointer instead of a
fabricated invalid coordinate when the touch type is TOUCH_UP.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
This commit is contained in:
Derek Foreman 2023-02-07 07:08:54 -06:00 committed by Pekka Paalanen
parent 3ef8bb9935
commit 8031b9d57f
9 changed files with 55 additions and 41 deletions

View File

@ -150,14 +150,15 @@ ss_seat_handle_motion(void *data, struct wl_pointer *pointer,
{
struct ss_seat *seat = data;
struct timespec ts;
struct weston_coord_global pos;
timespec_from_msec(&ts, time);
/* No transformation of input position is required here because we are
* always receiving the input in the same coordinates as the output. */
notify_motion_absolute(&seat->base, &ts,
wl_fixed_to_double(x), wl_fixed_to_double(y));
pos.c = weston_coord_from_fixed(x, y);
notify_motion_absolute(&seat->base, &ts, pos);
notify_pointer_frame(&seat->base);
}

View File

@ -1175,6 +1175,7 @@ xf_peer_post_connect(freerdp_peer *client)
static bool
rdp_translate_and_notify_mouse_position(RdpPeerContext *peerContext, UINT16 x, UINT16 y)
{
struct weston_coord_global pos;
struct timespec time;
int sx, sy;
@ -1195,8 +1196,9 @@ rdp_translate_and_notify_mouse_position(RdpPeerContext *peerContext, UINT16 x, U
different scaling. In such case, hit test to that window area on
non primary-resident monitor (surface->output) dosn't work. */
if (to_weston_coordinate(peerContext, &sx, &sy)) {
pos.c = weston_coord(sx, sy);
weston_compositor_get_time(&time);
notify_motion_absolute(peerContext->item.seat, &time, sx, sy);
notify_motion_absolute(peerContext->item.seat, &time, pos);
return TRUE;
}
return FALSE;
@ -1403,6 +1405,7 @@ xf_extendedMouseEvent(rdpInput *input, UINT16 flags, UINT16 x, UINT16 y)
bool need_frame = false;
struct rdp_output *output;
struct timespec time;
struct weston_coord_global pos;
dump_mouseinput(peerContext, flags, x, y, true);
@ -1427,7 +1430,8 @@ xf_extendedMouseEvent(rdpInput *input, UINT16 flags, UINT16 x, UINT16 y)
output = rdp_get_first_output(peerContext->rdpBackend);
if (x < output->base.width && y < output->base.height) {
weston_compositor_get_time(&time);
notify_motion_absolute(peerContext->item.seat, &time, x, y);
pos.c = weston_coord(x, y);
notify_motion_absolute(peerContext->item.seat, &time, pos);
need_frame = true;
}

View File

@ -374,7 +374,7 @@ vnc_pointer_event(struct nvnc_client *client, uint16_t x, uint16_t y,
struct weston_coord_global pos;
pos = weston_coord_global_from_output_point(x, y, &output->base);
notify_motion_absolute(peer->seat, &time, pos.c.x, pos.c.y);
notify_motion_absolute(peer->seat, &time, pos);
}
changed_button_mask = peer->last_button_mask ^ button_mask;

View File

@ -1634,8 +1634,7 @@ input_handle_pointer_enter(void *data, struct wl_pointer *pointer,
if (location == THEME_LOCATION_CLIENT_AREA) {
input->has_focus = true;
notify_pointer_focus(&input->base, &input->output->base,
pos.c.x, pos.c.y);
notify_pointer_focus(&input->base, &input->output->base, pos);
wl_pointer_set_cursor(input->parent.pointer,
input->enter_serial, NULL, 0, 0);
} else {
@ -1709,15 +1708,14 @@ input_handle_motion(void *data, struct wl_pointer *pointer,
location == THEME_LOCATION_CLIENT_AREA) {
wl_pointer_set_cursor(input->parent.pointer,
input->enter_serial, NULL, 0, 0);
notify_pointer_focus(&input->base, &input->output->base,
pos.c.x, pos.c.y);
notify_pointer_focus(&input->base, &input->output->base, pos);
input->has_focus = true;
want_frame = true;
}
if (location == THEME_LOCATION_CLIENT_AREA) {
timespec_from_msec(&ts, time);
notify_motion_absolute(&input->base, &ts, pos.c.x, pos.c.y);
notify_motion_absolute(&input->base, &ts, pos);
want_frame = true;
}
@ -2110,8 +2108,7 @@ 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.c.x, pos.c.y, WL_TOUCH_DOWN);
notify_touch(input->touch_device, &ts, id, &pos, WL_TOUCH_DOWN);
input->touch_active = true;
}
@ -2148,7 +2145,7 @@ input_handle_touch_up(void *data, struct wl_touch *wl_touch,
}
if (active)
notify_touch(input->touch_device, &ts, id, 0, 0, WL_TOUCH_UP);
notify_touch(input->touch_device, &ts, id, NULL, WL_TOUCH_UP);
}
static void
@ -2178,8 +2175,7 @@ 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.c.x, pos.c.y, WL_TOUCH_MOTION);
notify_touch(input->touch_device, &ts, id, &pos, WL_TOUCH_MOTION);
}
static void

View File

@ -1480,7 +1480,7 @@ x11_backend_deliver_enter_event(struct x11_backend *b,
enter_notify->event_y,
&output->base);
notify_pointer_focus(&b->core_seat, &output->base, pos.c.x, pos.c.y);
notify_pointer_focus(&b->core_seat, &output->base, pos);
b->prev_x = pos.c.x;
b->prev_y = pos.c.y;

View File

@ -205,7 +205,7 @@ notify_motion(struct weston_seat *seat, const struct timespec *time,
struct weston_pointer_motion_event *event);
void
notify_motion_absolute(struct weston_seat *seat, const struct timespec *time,
double x, double y);
struct weston_coord_global pos);
void
notify_modifiers(struct weston_seat *seat, uint32_t serial);
@ -214,7 +214,7 @@ notify_pointer_frame(struct weston_seat *seat);
void
notify_pointer_focus(struct weston_seat *seat, struct weston_output *output,
double x, double y);
struct weston_coord_global pos);
void
clear_pointer_focus(struct weston_seat *seat);
@ -225,7 +225,7 @@ void
notify_touch_normalized(struct weston_touch_device *device,
const struct timespec *time,
int touch_id,
double x, double y,
const struct weston_coord_global *pos,
const struct weston_point2d_device_normalized *norm,
int touch_type);
@ -235,9 +235,9 @@ notify_touch_normalized(struct weston_touch_device *device,
*/
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, const struct weston_coord_global *pos, int touch_type)
{
notify_touch_normalized(device, time, touch_id, x, y, NULL, touch_type);
notify_touch_normalized(device, time, touch_id, pos, NULL, touch_type);
}
void

View File

@ -1870,7 +1870,7 @@ run_modifier_bindings(struct weston_seat *seat, uint32_t old, uint32_t new)
WL_EXPORT void
notify_motion_absolute(struct weston_seat *seat, const struct timespec *time,
double x, double y)
struct weston_coord_global pos)
{
struct weston_compositor *ec = seat->compositor;
struct weston_pointer *pointer = weston_seat_get_pointer(seat);
@ -1880,10 +1880,9 @@ notify_motion_absolute(struct weston_seat *seat, const struct timespec *time,
event = (struct weston_pointer_motion_event) {
.mask = WESTON_POINTER_MOTION_ABS,
.x = x,
.y = y,
.x = pos.c.x,
.y = pos.c.y,
};
pointer->grab->interface->motion(pointer->grab, time, &event);
}
@ -2292,15 +2291,15 @@ clear_pointer_focus(struct weston_seat *seat)
WL_EXPORT void
notify_pointer_focus(struct weston_seat *seat, struct weston_output *output,
double x, double y)
struct weston_coord_global pos)
{
struct weston_pointer *pointer = weston_seat_get_pointer(seat);
assert(output);
weston_pointer_move_to(pointer,
wl_fixed_from_double(x),
wl_fixed_from_double(y));
wl_fixed_from_double(pos.c.x),
wl_fixed_from_double(pos.c.y));
}
static void
@ -2424,14 +2423,21 @@ 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,
double double_x, double double_y, int touch_type)
const struct weston_coord_global *pos, int touch_type)
{
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;
wl_fixed_t x = wl_fixed_from_double(double_x);
wl_fixed_t y = wl_fixed_from_double(double_y);
wl_fixed_t x, y;
if (pos) {
assert(touch_type != WL_TOUCH_UP);
x = wl_fixed_from_double(pos->c.x);
y = wl_fixed_from_double(pos->c.y);
} else {
assert(touch_type == WL_TOUCH_UP);
}
/* Update grab's global coordinates. */
if (touch_id == touch->grab_touch_id && touch_type != WL_TOUCH_UP) {
@ -2592,8 +2598,7 @@ weston_compositor_set_touch_mode_calib(struct weston_compositor *compositor)
* \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 x X coordinate in compositor global space.
* \param y Y coordinate in compositor global space.
* \param pos X,Y coordinate in compositor global space, or NULL for WL_TOUCH_UP.
* \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.
*
@ -2611,7 +2616,7 @@ 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_coord_global *pos,
const struct weston_point2d_device_normalized *norm,
int touch_type)
{
@ -2619,10 +2624,14 @@ notify_touch_normalized(struct weston_touch_device *device,
struct weston_touch *touch = device->aggregate;
if (touch_type != WL_TOUCH_UP) {
assert(pos);
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. */
@ -2654,7 +2663,7 @@ 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, x, y, touch_type);
process_touch_normal(device, time, touch_id, pos, touch_type);
break;
case WESTON_TOUCH_MODE_CALIB:
case WESTON_TOUCH_MODE_PREP_NORMAL:

View File

@ -162,7 +162,7 @@ handle_pointer_motion_absolute(
y = libinput_event_pointer_get_absolute_y_transformed(pointer_event,
height);
pos = weston_coord_global_from_output_point(x, y, output);
notify_motion_absolute(device->seat, &time, pos.c.x, pos.c.y);
notify_motion_absolute(device->seat, &time, pos);
return true;
}
@ -465,10 +465,10 @@ handle_touch_with_coords(struct libinput_device *libinput_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.c.x, pos.c.y, &norm, touch_type);
&pos, &norm, touch_type);
} else {
notify_touch(device->touch_device, &time, slot,
pos.c.x, pos.c.y, touch_type);
&pos, touch_type);
}
}
@ -498,7 +498,7 @@ handle_touch_up(struct libinput_device *libinput_device,
timespec_from_usec(&time,
libinput_event_touch_get_time_usec(touch_event));
notify_touch(device->touch_device, &time, slot, 0, 0, WL_TOUCH_UP);
notify_touch(device->touch_device, &time, slot, NULL, WL_TOUCH_UP);
}
static void

View File

@ -421,6 +421,7 @@ send_touch(struct wl_client *client, struct wl_resource *resource,
struct weston_test *test = wl_resource_get_user_data(resource);
struct weston_touch_device *device = test->touch_device[0];
struct timespec time;
struct weston_coord_global pos;
assert(device);
@ -435,9 +436,12 @@ send_touch(struct wl_client *client, struct wl_resource *resource,
return;
}
}
notify_touch(device, &time, touch_id, x, y, touch_type);
notify_touch(device, &time, touch_id, NULL, touch_type);
} else {
pos.c = weston_coord_from_fixed(x, y);
notify_touch(device, &time, touch_id, &pos, touch_type);
}
}
static const struct weston_test_interface test_implementation = {