From 0bf2d82e0c4509aa5c09442cd3159d8191a0dbc6 Mon Sep 17 00:00:00 2001 From: Derek Foreman Date: Mon, 7 Feb 2022 13:56:28 -0600 Subject: [PATCH] libweston: Use weston_coord in struct weston_touch Convert the grab coordinate to a weston_coord. Signed-off-by: Derek Foreman --- desktop-shell/shell.c | 16 ++++++++-------- include/libweston/libweston.h | 2 +- ivi-shell/hmi-controller.c | 13 ++++++++----- kiosk-shell/kiosk-shell-grab.c | 13 +++++++------ libweston/data-device.c | 22 ++++++++++------------ libweston/input.c | 9 +++------ 6 files changed, 37 insertions(+), 38 deletions(-) diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c index 56d89ed13..a8b1d10cc 100644 --- a/desktop-shell/shell.c +++ b/desktop-shell/shell.c @@ -973,16 +973,15 @@ touch_move_grab_motion(struct weston_touch_grab *grab, struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; struct shell_surface *shsurf = move->base.shsurf; struct weston_surface *es; - int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx); - int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy); - struct weston_coord_global pos; + struct weston_coord_global pos = grab->touch->grab_pos; if (!shsurf || !shsurf->desktop_surface || !move->active) return; es = weston_desktop_surface_get_surface(shsurf->desktop_surface); - pos.c = weston_coord(dx, dy); + pos.c.x = (int)(pos.c.x + wl_fixed_to_double(move->dx)); + pos.c.y = (int)(pos.c.y + wl_fixed_to_double(move->dy)); weston_view_set_position(shsurf->view, pos); weston_compositor_schedule_repaint(es->compositor); @@ -1016,6 +1015,7 @@ static int surface_touch_move(struct shell_surface *shsurf, struct weston_touch *touch) { struct weston_touch_move_grab *move; + struct weston_coord_global pos; if (!shsurf) return -1; @@ -1029,10 +1029,10 @@ surface_touch_move(struct shell_surface *shsurf, struct weston_touch *touch) return -1; move->active = 1; - move->dx = wl_fixed_from_double(shsurf->view->geometry.pos_offset.x) - - touch->grab_x; - move->dy = wl_fixed_from_double(shsurf->view->geometry.pos_offset.y) - - touch->grab_y; + pos.c = weston_coord_sub(shsurf->view->geometry.pos_offset, + touch->grab_pos.c); + move->dx = wl_fixed_from_double(pos.c.x); + move->dy = wl_fixed_from_double(pos.c.y); shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf, touch); diff --git a/include/libweston/libweston.h b/include/libweston/libweston.h index 77242a28b..c0c7b4356 100644 --- a/include/libweston/libweston.h +++ b/include/libweston/libweston.h @@ -876,7 +876,7 @@ struct weston_touch { struct weston_touch_grab *grab; struct weston_touch_grab default_grab; int grab_touch_id; - wl_fixed_t grab_x, grab_y; + struct weston_coord_global grab_pos; uint32_t grab_serial; struct timespec grab_time; diff --git a/ivi-shell/hmi-controller.c b/ivi-shell/hmi-controller.c index 4629b80f9..f867d176d 100644 --- a/ivi-shell/hmi-controller.c +++ b/ivi-shell/hmi-controller.c @@ -1603,7 +1603,8 @@ touch_move_workspace_grab_end(struct touch_grab *grab) struct ivi_layout_layer *layer = tch_move_grab->base.layer; move_workspace_grab_end(&tch_move_grab->move, grab->resource, - grab->grab.touch->grab_x, layer); + wl_fixed_from_double(grab->grab.touch->grab_pos.c.x), + layer); weston_touch_end_grab(grab->grab.touch); } @@ -1721,8 +1722,8 @@ touch_move_grab_motion(struct weston_touch_grab *grab, return; wl_fixed_t pointer_pos[2] = { - grab->touch->grab_x, - grab->touch->grab_y + wl_fixed_from_double(grab->touch->grab_pos.c.x), + wl_fixed_from_double(grab->touch->grab_pos.c.y) }; move_grab_update(&tch_move_grab->move, pointer_pos); @@ -1907,8 +1908,10 @@ create_workspace_touch_move(struct weston_touch *touch, tch_move_grab->base.resource = resource; tch_move_grab->is_active = 1; - move_grab_init_workspace(&tch_move_grab->move, touch->grab_x, - touch->grab_y, resource); + move_grab_init_workspace(&tch_move_grab->move, + wl_fixed_from_double(touch->grab_pos.c.x), + wl_fixed_from_double(touch->grab_pos.c.y), + resource); return tch_move_grab; } diff --git a/kiosk-shell/kiosk-shell-grab.c b/kiosk-shell/kiosk-shell-grab.c index 86363f82d..8193b2507 100644 --- a/kiosk-shell/kiosk-shell-grab.c +++ b/kiosk-shell/kiosk-shell-grab.c @@ -171,8 +171,8 @@ touch_move_grab_motion(struct weston_touch_grab *touch_grab, surface = weston_desktop_surface_get_surface(shsurf->desktop_surface); - dx = wl_fixed_to_int(touch->grab_x + shgrab->dx); - dy = wl_fixed_to_int(touch->grab_y + shgrab->dy); + dx = (int)(touch->grab_pos.c.x + wl_fixed_to_double(shgrab->dx)); + dy = (int)(touch->grab_pos.c.y + wl_fixed_to_double(shgrab->dy)); pos.c = weston_coord(dx, dy); weston_view_set_position(shsurf->view, pos); @@ -274,6 +274,7 @@ kiosk_shell_grab_start_for_touch_move(struct kiosk_shell_surface *shsurf, struct weston_touch *touch) { struct kiosk_shell_grab *shgrab; + struct weston_coord_global pos; if (!shsurf) return KIOSK_SHELL_GRAB_RESULT_ERROR; @@ -287,10 +288,10 @@ kiosk_shell_grab_start_for_touch_move(struct kiosk_shell_surface *shsurf, if (!shgrab) return KIOSK_SHELL_GRAB_RESULT_ERROR; - shgrab->dx = wl_fixed_from_double(shsurf->view->geometry.pos_offset.x) - - touch->grab_x; - shgrab->dy = wl_fixed_from_double(shsurf->view->geometry.pos_offset.y) - - touch->grab_y; + pos.c = weston_coord_sub(shsurf->view->geometry.pos_offset, + touch->grab_pos.c); + shgrab->dx = wl_fixed_from_double(pos.c.x); + shgrab->dy = wl_fixed_from_double(pos.c.y); shgrab->active = true; weston_seat_break_desktop_grabs(touch->seat); diff --git a/libweston/data-device.c b/libweston/data-device.c index e786eb89e..48bb4bd15 100644 --- a/libweston/data-device.c +++ b/libweston/data-device.c @@ -444,7 +444,7 @@ drag_surface_configure(struct weston_drag *drag, if (pointer) pos = pointer->pos; else if (touch) - pos.c = weston_coord_from_fixed(touch->grab_x, touch->grab_y); + pos = touch->grab_pos; pos.c = weston_coord_add(pos.c, drag->offset.c); weston_view_set_position(drag->icon, pos); @@ -797,10 +797,8 @@ static void drag_grab_touch_focus(struct weston_touch_drag *drag) { struct weston_touch *touch = drag->grab.touch; - struct weston_coord_global pos; - pos.c = weston_coord_from_fixed(touch->grab_x, touch->grab_y); - drag_grab_focus_internal(&drag->base, touch->seat, pos); + drag_grab_focus_internal(&drag->base, touch->seat, touch->grab_pos); } static void @@ -820,22 +818,22 @@ drag_grab_touch_motion(struct weston_touch_grab *grab, if (touch_drag->base.icon) { struct weston_coord_global pos; - pos.c = weston_coord_from_fixed(touch->grab_x, touch->grab_y); - pos.c = weston_coord_add(pos.c, touch_drag->base.offset.c); + pos.c = weston_coord_add(touch_drag->base.offset.c, + touch->grab_pos.c); weston_view_set_position(touch_drag->base.icon, pos); weston_view_schedule_repaint(touch_drag->base.icon); } if (touch_drag->base.focus_resource) { - struct weston_coord_global tmp_g; - struct weston_coord_surface c; + struct weston_coord_surface surf_pos; - tmp_g.c = weston_coord_from_fixed(touch->grab_x, touch->grab_y); msecs = timespec_to_msec(time); - c = weston_coord_global_to_surface(touch_drag->base.focus, tmp_g); + surf_pos = weston_coord_global_to_surface(touch_drag->base.focus, + touch->grab_pos); wl_data_device_send_motion(touch_drag->base.focus_resource, - msecs, wl_fixed_from_double(c.c.x), - wl_fixed_from_double(c.c.y)); + msecs, + wl_fixed_from_double(surf_pos.c.x), + wl_fixed_from_double(surf_pos.c.y)); } } diff --git a/libweston/input.c b/libweston/input.c index dd814cc80..0e6749245 100644 --- a/libweston/input.c +++ b/libweston/input.c @@ -2888,10 +2888,8 @@ process_touch_normal(struct weston_touch_device *device, } /* Update grab's global coordinates. */ - if (touch_id == touch->grab_touch_id && touch_type != WL_TOUCH_UP) { - touch->grab_x = x; - touch->grab_y = y; - } + if (touch_id == touch->grab_touch_id && touch_type != WL_TOUCH_UP) + touch->grab_pos = *pos; switch (touch_type) { case WL_TOUCH_DOWN: @@ -2919,8 +2917,7 @@ process_touch_normal(struct weston_touch_device *device, wl_display_get_serial(ec->wl_display); touch->grab_touch_id = touch_id; touch->grab_time = *time; - touch->grab_x = x; - touch->grab_y = y; + touch->grab_pos = *pos; } break;