From d961e59d4aeb3e4b1c9f8cabdfe7e5a99f807da6 Mon Sep 17 00:00:00 2001 From: Derek Foreman Date: Tue, 13 Jun 2023 12:04:26 -0500 Subject: [PATCH] libweston: Add getters for view position/offset This is stored as an unadorned weston_coord internally, but with getter functions we can put together the appropriate global or surface coordinate. Use them where appropriate. Signed-off-by: Derek Foreman --- desktop-shell/shell.c | 46 +++++++++++++++++++--------------- include/libweston/libweston.h | 6 +++++ kiosk-shell/kiosk-shell-grab.c | 10 +++++--- kiosk-shell/kiosk-shell.c | 15 ++++++----- libweston/compositor.c | 30 +++++++++++++++++++--- 5 files changed, 74 insertions(+), 33 deletions(-) diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c index f3ff0a1d..a8fb451f 100644 --- a/desktop-shell/shell.c +++ b/desktop-shell/shell.c @@ -1032,8 +1032,9 @@ surface_touch_move(struct shell_surface *shsurf, struct weston_touch *touch) return -1; move->active = 1; - pos.c = weston_coord_sub(shsurf->view->geometry.pos_offset, - touch->grab_pos.c); + pos.c = weston_coord_sub( + weston_view_get_pos_offset_global(shsurf->view).c, + touch->grab_pos.c); move->dx = wl_fixed_from_double(pos.c.x); move->dy = wl_fixed_from_double(pos.c.y); @@ -1168,7 +1169,7 @@ surface_move(struct shell_surface *shsurf, struct weston_pointer *pointer, bool client_initiated) { struct weston_move_grab *move; - struct weston_coord offset; + struct weston_coord_global offset; if (!shsurf) return -1; @@ -1182,10 +1183,11 @@ surface_move(struct shell_surface *shsurf, struct weston_pointer *pointer, if (!move) return -1; - offset = weston_coord_sub(shsurf->view->geometry.pos_offset, - pointer->grab_pos.c); - move->dx = wl_fixed_from_double(offset.x); - move->dy = wl_fixed_from_double(offset.y); + offset.c = weston_coord_sub( + weston_view_get_pos_offset_global(shsurf->view).c, + pointer->grab_pos.c); + move->dx = wl_fixed_from_double(offset.c.x); + move->dy = wl_fixed_from_double(offset.c.y); move->client_initiated = client_initiated; weston_desktop_surface_set_orientation(shsurf->desktop_surface, @@ -1321,7 +1323,7 @@ static int surface_tablet_tool_move(struct shell_surface *shsurf, struct weston_tablet_tool *tool) { struct weston_tablet_tool_move_grab *move; - struct weston_coord offset; + struct weston_coord_global offset; if (!shsurf) return -1; @@ -1333,10 +1335,11 @@ surface_tablet_tool_move(struct shell_surface *shsurf, struct weston_tablet_tool if (!move) return -1; - offset = weston_coord_sub(shsurf->view->geometry.pos_offset, - tool->grab_pos.c); - move->dx = wl_fixed_from_double(offset.x); - move->dy = wl_fixed_from_double(offset.y); + offset.c = weston_coord_sub( + weston_view_get_pos_offset_global(shsurf->view).c, + tool->grab_pos.c); + move->dx = wl_fixed_from_double(offset.c.x); + move->dy = wl_fixed_from_double(offset.c.y); shell_tablet_tool_grab_start(&move->base, &tablet_tool_move_grab_interface, shsurf, tool); @@ -2278,7 +2281,7 @@ desktop_surface_removed(struct weston_desktop_surface *desktop_surface, * the view */ weston_view_set_output(shsurf->wview_anim_fade, shsurf->view->output); - pos.c = shsurf->view->geometry.pos_offset; + pos = weston_view_get_pos_offset_global(shsurf->view); weston_view_set_position(shsurf->wview_anim_fade, pos); weston_layer_entry_insert(&shsurf->view->layer_link, @@ -2449,7 +2452,7 @@ desktop_surface_committed(struct weston_desktop_surface *desktop_surface, if ((shsurf->state.fullscreen || shsurf->state.maximized) && !shsurf->saved_position_valid) { - shsurf->saved_pos.c = shsurf->view->geometry.pos_offset; + shsurf->saved_pos = weston_view_get_pos_offset_global(shsurf->view); shsurf->saved_position_valid = true; if (!wl_list_empty(&shsurf->rotation.transform.link)) { @@ -2496,7 +2499,9 @@ desktop_surface_committed(struct weston_desktop_surface *desktop_surface, to_g = weston_coord_surface_to_global(view, to_s); offset.c = weston_coord_sub(to_g.c, from_g.c); - pos.c = weston_coord_add(view->geometry.pos_offset, offset.c); + pos.c = weston_coord_add( + weston_view_get_pos_offset_global(view).c, + offset.c); weston_view_set_position(shsurf->view, pos); } @@ -3559,7 +3564,7 @@ rotate_grab_motion(struct weston_pointer_grab *grab, if (dposx != 0.0f || dposy != 0.0f) { struct weston_coord_global pos; - pos.c = shsurf->view->geometry.pos_offset; + pos = weston_view_get_pos_offset_global(shsurf->view); pos.c.x += dposx; pos.c.y += dposy; weston_view_set_position(shsurf->view, pos); @@ -4029,7 +4034,7 @@ shell_fade_create_fade_out_view(struct shell_surface *shsurf, /* set the initial position and output just in case we happen to not * move it around and just destroy it */ weston_view_set_output(view, woutput); - pos.c = shsurf->view->geometry.pos_offset; + pos = weston_view_get_pos_offset_global(shsurf->view); weston_view_set_position(view, pos); view->is_mapped = true; @@ -4671,7 +4676,7 @@ shell_reposition_view_on_output_change(struct weston_view *view) wl_list_for_each(output, &ec->output_list, link) { struct weston_coord_global pos; - pos.c = view->geometry.pos_offset; + pos = weston_view_get_pos_offset_global(view); if (weston_output_contains_coord(output, pos)) { visible = 1; break; @@ -4838,8 +4843,9 @@ handle_output_move_layer(struct desktop_shell *shell, if (view->output != output) continue; - pos.c = weston_coord_add(view->geometry.pos_offset, - output->move.c); + pos.c = weston_coord_add( + weston_view_get_pos_offset_global(view).c, + output->move.c); weston_view_set_position(view, pos); } } diff --git a/include/libweston/libweston.h b/include/libweston/libweston.h index c0c7b435..c120f09f 100644 --- a/include/libweston/libweston.h +++ b/include/libweston/libweston.h @@ -2158,6 +2158,12 @@ void weston_view_set_position(struct weston_view *view, struct weston_coord_global pos); +struct weston_coord_surface +weston_view_get_pos_offset_rel(struct weston_view *view); + +struct weston_coord_global +weston_view_get_pos_offset_global(struct weston_view *view); + void weston_view_set_transform_parent(struct weston_view *view, struct weston_view *parent); diff --git a/kiosk-shell/kiosk-shell-grab.c b/kiosk-shell/kiosk-shell-grab.c index 73bf44b1..12313caa 100644 --- a/kiosk-shell/kiosk-shell-grab.c +++ b/kiosk-shell/kiosk-shell-grab.c @@ -256,8 +256,9 @@ kiosk_shell_grab_start_for_pointer_move(struct kiosk_shell_surface *shsurf, if (!shgrab) return KIOSK_SHELL_GRAB_RESULT_ERROR; - offset.c = weston_coord_sub(shsurf->view->geometry.pos_offset, - pointer->grab_pos.c); + offset.c = weston_coord_sub( + weston_view_get_pos_offset_global(shsurf->view).c, + pointer->grab_pos.c); shgrab->dx = wl_fixed_from_double(offset.c.x); shgrab->dy = wl_fixed_from_double(offset.c.y); shgrab->active = true; @@ -289,8 +290,9 @@ kiosk_shell_grab_start_for_touch_move(struct kiosk_shell_surface *shsurf, if (!shgrab) return KIOSK_SHELL_GRAB_RESULT_ERROR; - pos.c = weston_coord_sub(shsurf->view->geometry.pos_offset, - touch->grab_pos.c); + pos.c = weston_coord_sub( + weston_view_get_pos_offset_global(shsurf->view).c, + 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; diff --git a/kiosk-shell/kiosk-shell.c b/kiosk-shell/kiosk-shell.c index 0f66ed48..14bb78a5 100644 --- a/kiosk-shell/kiosk-shell.c +++ b/kiosk-shell/kiosk-shell.c @@ -821,8 +821,9 @@ desktop_surface_committed(struct weston_desktop_surface *desktop_surface, from_g = weston_coord_surface_to_global(shsurf->view, from_s); to_g = weston_coord_surface_to_global(shsurf->view, to_s); offset.c = weston_coord_sub(to_g.c, from_g.c); - pos.c = weston_coord_add(shsurf->view->geometry.pos_offset, - offset.c); + pos.c = weston_coord_add( + weston_view_get_pos_offset_global(shsurf->view).c, + offset.c); weston_view_set_position(shsurf->view, pos); weston_view_update_transform(shsurf->view); @@ -1138,8 +1139,9 @@ kiosk_shell_handle_output_moved(struct wl_listener *listener, void *data) if (view->output != output) continue; - pos.c = weston_coord_add(view->geometry.pos_offset, - output->move.c); + pos.c = weston_coord_add( + weston_view_get_pos_offset_global(view).c, + output->move.c); weston_view_set_position(view, pos); } @@ -1150,8 +1152,9 @@ kiosk_shell_handle_output_moved(struct wl_listener *listener, void *data) if (view->output != output) continue; - pos.c = weston_coord_add(view->geometry.pos_offset, - output->move.c); + pos.c = weston_coord_add( + weston_view_get_pos_offset_global(view).c, + output->move.c); weston_view_set_position(view, pos); } } diff --git a/libweston/compositor.c b/libweston/compositor.c index dd757ac7..c241ee35 100644 --- a/libweston/compositor.c +++ b/libweston/compositor.c @@ -1615,6 +1615,32 @@ weston_view_set_position(struct weston_view *view, weston_view_geometry_dirty(view); } +WL_EXPORT struct weston_coord_surface +weston_view_get_pos_offset_rel(struct weston_view *view) +{ + struct weston_coord_surface out; + + assert(view->geometry.parent); + + out.c = view->geometry.pos_offset; + out.coordinate_space_id = view->geometry.parent->surface; + + return out; +} + +WL_EXPORT struct weston_coord_global +weston_view_get_pos_offset_global(struct weston_view *view) +{ + struct weston_coord_global out; + + assert(view->surface->committed != subsurface_committed); + assert(!view->geometry.parent); + + out.c = view->geometry.pos_offset; + + return out; +} + static void transform_parent_handle_parent_destroy(struct wl_listener *listener, void *data) @@ -4560,9 +4586,7 @@ subsurface_committed(struct weston_surface *surface, continue; } - tmp = weston_coord_surface(view->geometry.pos_offset.x, - view->geometry.pos_offset.y, - view->geometry.parent->surface); + tmp = weston_view_get_pos_offset_rel(view); tmp.c = weston_coord_add(tmp.c, new_origin.c); weston_view_set_rel_position(view, tmp); }