From 4d0ce16669441812080ca7d941a646d8519cbdb8 Mon Sep 17 00:00:00 2001 From: Derek Foreman Date: Tue, 1 Feb 2022 17:44:40 -0600 Subject: [PATCH] libweston: replace weston_output_transform_coordinate This creates a global coordinate from a device coordinate. Replace it with weston_coord_global_from_output_point() which does the same thing and returns a weston_coord_global. Signed-off-by: Derek Foreman --- libweston/backend-vnc/vnc.c | 7 +++---- libweston/backend-wayland/wayland.c | 28 +++++++++++++++++-------- libweston/backend-x11/x11.c | 31 ++++++++++++++-------------- libweston/backend.h | 5 ----- libweston/compositor.c | 32 ----------------------------- libweston/libinput-device.c | 15 +++++++------- 6 files changed, 45 insertions(+), 73 deletions(-) diff --git a/libweston/backend-vnc/vnc.c b/libweston/backend-vnc/vnc.c index 5810f2c9e..cb567aa8f 100644 --- a/libweston/backend-vnc/vnc.c +++ b/libweston/backend-vnc/vnc.c @@ -371,11 +371,10 @@ vnc_pointer_event(struct nvnc_client *client, uint16_t x, uint16_t y, weston_compositor_get_time(&time); if (x < output->base.width && y < output->base.height) { - double global_x, global_y; + struct weston_coord_global pos; - weston_output_transform_coordinate(&output->base, x, y, - &global_x, &global_y); - notify_motion_absolute(peer->seat, &time, global_x, global_y); + pos = weston_coord_global_from_output_point(x, y, &output->base); + notify_motion_absolute(peer->seat, &time, pos.c.x, pos.c.y); } changed_button_mask = peer->last_button_mask ^ button_mask; diff --git a/libweston/backend-wayland/wayland.c b/libweston/backend-wayland/wayland.c index 9584c9bff..2b85809ca 100644 --- a/libweston/backend-wayland/wayland.c +++ b/libweston/backend-wayland/wayland.c @@ -1599,6 +1599,7 @@ input_handle_pointer_enter(void *data, struct wl_pointer *pointer, int32_t fx, fy; enum theme_location location; double x, y; + struct weston_coord_global pos; if (!surface) { input->output = NULL; @@ -1628,11 +1629,13 @@ input_handle_pointer_enter(void *data, struct wl_pointer *pointer, location = THEME_LOCATION_CLIENT_AREA; } - weston_output_transform_coordinate(&input->output->base, x, y, &x, &y); + pos = weston_coord_global_from_output_point(x, y, + &input->output->base); if (location == THEME_LOCATION_CLIENT_AREA) { input->has_focus = true; - notify_pointer_focus(&input->base, &input->output->base, x, y); + notify_pointer_focus(&input->base, &input->output->base, + pos.c.x, pos.c.y); wl_pointer_set_cursor(input->parent.pointer, input->enter_serial, NULL, 0, 0); } else { @@ -1672,6 +1675,7 @@ input_handle_motion(void *data, struct wl_pointer *pointer, enum theme_location location; bool want_frame = false; double x, y; + struct weston_coord_global pos; struct timespec ts; if (!input->output) @@ -1693,7 +1697,8 @@ input_handle_motion(void *data, struct wl_pointer *pointer, location = THEME_LOCATION_CLIENT_AREA; } - weston_output_transform_coordinate(&input->output->base, x, y, &x, &y); + pos = weston_coord_global_from_output_point(x, y, + &input->output->base); if (input->has_focus && location != THEME_LOCATION_CLIENT_AREA) { input_set_cursor(input); @@ -1704,14 +1709,15 @@ 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, x, y); + notify_pointer_focus(&input->base, &input->output->base, + pos.c.x, pos.c.y); input->has_focus = true; want_frame = true; } if (location == THEME_LOCATION_CLIENT_AREA) { timespec_from_msec(&ts, time); - notify_motion_absolute(&input->base, &ts, x, y); + notify_motion_absolute(&input->base, &ts, pos.c.x, pos.c.y); want_frame = true; } @@ -2061,6 +2067,7 @@ input_handle_touch_down(void *data, struct wl_touch *wl_touch, enum theme_location location; bool first_touch; int32_t fx, fy; + struct weston_coord_global pos; double x, y; struct timespec ts; @@ -2101,9 +2108,10 @@ input_handle_touch_down(void *data, struct wl_touch *wl_touch, return; } - weston_output_transform_coordinate(&output->base, x, y, &x, &y); + pos = weston_coord_global_from_output_point(x,y, &output->base); - notify_touch(input->touch_device, &ts, id, x, y, WL_TOUCH_DOWN); + notify_touch(input->touch_device, &ts, id, + pos.c.x, pos.c.y, WL_TOUCH_DOWN); input->touch_active = true; } @@ -2152,6 +2160,7 @@ input_handle_touch_motion(void *data, struct wl_touch *wl_touch, struct wayland_output *output = input->touch_focus; int32_t fx, fy; double x, y; + struct weston_coord_global pos; struct timespec ts; x = wl_fixed_to_double(fixed_x); @@ -2167,9 +2176,10 @@ input_handle_touch_motion(void *data, struct wl_touch *wl_touch, y -= fy; } - weston_output_transform_coordinate(&output->base, x, y, &x, &y); + pos = weston_coord_global_from_output_point(x, y, &output->base); - notify_touch(input->touch_device, &ts, id, x, y, WL_TOUCH_MOTION); + notify_touch(input->touch_device, &ts, id, + pos.c.x, pos.c.y, WL_TOUCH_MOTION); } static void diff --git a/libweston/backend-x11/x11.c b/libweston/backend-x11/x11.c index 897f87d82..ad49f6f7f 100644 --- a/libweston/backend-x11/x11.c +++ b/libweston/backend-x11/x11.c @@ -1429,7 +1429,7 @@ x11_backend_deliver_motion_event(struct x11_backend *b, xcb_generic_event_t *event) { struct x11_output *output; - double x, y; + struct weston_coord_global pos; struct weston_pointer_motion_event motion_event = { 0 }; xcb_motion_notify_event_t *motion_notify = (xcb_motion_notify_event_t *) event; @@ -1441,23 +1441,22 @@ x11_backend_deliver_motion_event(struct x11_backend *b, if (!output) return; - weston_output_transform_coordinate(&output->base, - motion_notify->event_x, - motion_notify->event_y, - &x, &y); + pos = weston_coord_global_from_output_point(motion_notify->event_x, + motion_notify->event_y, + &output->base); motion_event = (struct weston_pointer_motion_event) { .mask = WESTON_POINTER_MOTION_REL, - .dx = x - b->prev_x, - .dy = y - b->prev_y + .dx = pos.c.x - b->prev_x, + .dy = pos.c.y - b->prev_y }; weston_compositor_get_time(&time); notify_motion(&b->core_seat, &time, &motion_event); notify_pointer_frame(&b->core_seat); - b->prev_x = x; - b->prev_y = y; + b->prev_x = pos.c.x; + b->prev_y = pos.c.y; } static void @@ -1465,7 +1464,7 @@ x11_backend_deliver_enter_event(struct x11_backend *b, xcb_generic_event_t *event) { struct x11_output *output; - double x, y; + struct weston_coord_global pos; xcb_enter_notify_event_t *enter_notify = (xcb_enter_notify_event_t *) event; @@ -1477,14 +1476,14 @@ x11_backend_deliver_enter_event(struct x11_backend *b, if (!output) return; - weston_output_transform_coordinate(&output->base, - enter_notify->event_x, - enter_notify->event_y, &x, &y); + pos = weston_coord_global_from_output_point(enter_notify->event_x, + enter_notify->event_y, + &output->base); - notify_pointer_focus(&b->core_seat, &output->base, x, y); + notify_pointer_focus(&b->core_seat, &output->base, pos.c.x, pos.c.y); - b->prev_x = x; - b->prev_y = y; + b->prev_x = pos.c.x; + b->prev_y = pos.c.y; } static int diff --git a/libweston/backend.h b/libweston/backend.h index 3f8caff0a..376b2c5f7 100644 --- a/libweston/backend.h +++ b/libweston/backend.h @@ -170,11 +170,6 @@ struct weston_coord_global weston_coord_global_from_output_point(double x, double y, const struct weston_output *output); -void -weston_output_transform_coordinate(struct weston_output *output, - double device_x, double device_y, - double *x, double *y); - void weston_region_global_to_output(pixman_region32_t *dst, struct weston_output *output, diff --git a/libweston/compositor.c b/libweston/compositor.c index 57fdc5aa8..32ec67436 100644 --- a/libweston/compositor.c +++ b/libweston/compositor.c @@ -6493,38 +6493,6 @@ weston_coord_global_from_output_point(double x, double y, return tmp; } -/** Transform device coordinates into global coordinates - * - * \param output the weston_output object - * \param[in] device_x X coordinate in device units. - * \param[in] device_y Y coordinate in device units. - * \param[out] x X coordinate in the global space. - * \param[out] y Y coordinate in the global space. - * - * Transforms coordinates from the device coordinate space (physical pixel - * units) to the global coordinate space (logical pixel units). This takes - * into account output transform and scale. - * - * \ingroup output - * \internal - */ -WL_EXPORT void -weston_output_transform_coordinate(struct weston_output *output, - double device_x, double device_y, - double *x, double *y) -{ - struct weston_vector p = { { - device_x, - device_y, - 0.0, - 1.0 } }; - - weston_matrix_transform(&output->inverse_matrix, &p); - - *x = p.f[0] / p.f[3]; - *y = p.f[1] / p.f[3]; -} - static bool validate_float_range(float val, float min, float max) { diff --git a/libweston/libinput-device.c b/libweston/libinput-device.c index 78efd2e4a..cd4147c2b 100644 --- a/libweston/libinput-device.c +++ b/libweston/libinput-device.c @@ -142,6 +142,7 @@ handle_pointer_motion_absolute( struct evdev_device *device = libinput_device_get_user_data(libinput_device); struct weston_output *output = device->output; + struct weston_coord_global pos; struct timespec time; double x, y; uint32_t width, height; @@ -160,9 +161,8 @@ handle_pointer_motion_absolute( width); y = libinput_event_pointer_get_absolute_y_transformed(pointer_event, height); - - weston_output_transform_coordinate(device->output, x, y, &x, &y); - notify_motion_absolute(device->seat, &time, x, y); + pos = weston_coord_global_from_output_point(x, y, output); + notify_motion_absolute(device->seat, &time, pos.c.x, pos.c.y); return true; } @@ -445,6 +445,7 @@ handle_touch_with_coords(struct libinput_device *libinput_device, uint32_t width, height; struct timespec time; int32_t slot; + struct weston_coord_global pos; if (!device->output) return; @@ -458,16 +459,16 @@ handle_touch_with_coords(struct libinput_device *libinput_device, x = libinput_event_touch_get_x_transformed(touch_event, width); y = libinput_event_touch_get_y_transformed(touch_event, height); - weston_output_transform_coordinate(device->output, - x, y, &x, &y); + pos = weston_coord_global_from_output_point(x, y, device->output); 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); + pos.c.x, pos.c.y, &norm, touch_type); } else { - notify_touch(device->touch_device, &time, slot, x, y, touch_type); + notify_touch(device->touch_device, &time, slot, + pos.c.x, pos.c.y, touch_type); } }