libweston: Use weston_coord in struct weston_view

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
This commit is contained in:
Derek Foreman 2022-02-03 17:47:41 -06:00
parent 989cdcb86e
commit 5e353d523f
6 changed files with 82 additions and 72 deletions

View file

@ -67,8 +67,10 @@ calc_input_panel_position(struct input_panel_surface *ip_surface, float *x, floa
struct weston_view *view = get_default_view(shell->text_input.surface); struct weston_view *view = get_default_view(shell->text_input.surface);
if (view == NULL) if (view == NULL)
return -1; return -1;
*x = view->geometry.x + shell->text_input.cursor_rectangle.x2; *x = view->geometry.pos_offset.x +
*y = view->geometry.y + shell->text_input.cursor_rectangle.y2; shell->text_input.cursor_rectangle.x2;
*y = view->geometry.pos_offset.y +
shell->text_input.cursor_rectangle.y2;
} else { } else {
*x = ip_surface->output->x + (ip_surface->output->width - ip_surface->surface->width) / 2; *x = ip_surface->output->x + (ip_surface->output->width - ip_surface->surface->width) / 2;
*y = ip_surface->output->y + ip_surface->output->height - ip_surface->surface->height; *y = ip_surface->output->y + ip_surface->output->height - ip_surface->surface->height;

View file

@ -973,9 +973,9 @@ surface_touch_move(struct shell_surface *shsurf, struct weston_touch *touch)
return -1; return -1;
move->active = 1; move->active = 1;
move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - move->dx = wl_fixed_from_double(shsurf->view->geometry.pos_offset.x) -
touch->grab_x; touch->grab_x;
move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - move->dy = wl_fixed_from_double(shsurf->view->geometry.pos_offset.y) -
touch->grab_y; touch->grab_y;
shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf, shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf,
@ -1107,6 +1107,7 @@ surface_move(struct shell_surface *shsurf, struct weston_pointer *pointer,
bool client_initiated) bool client_initiated)
{ {
struct weston_move_grab *move; struct weston_move_grab *move;
struct weston_coord offset;
if (!shsurf) if (!shsurf)
return -1; return -1;
@ -1120,10 +1121,10 @@ surface_move(struct shell_surface *shsurf, struct weston_pointer *pointer,
if (!move) if (!move)
return -1; return -1;
move->dx = wl_fixed_from_double(shsurf->view->geometry.x - offset = weston_coord_sub(shsurf->view->geometry.pos_offset,
pointer->grab_pos.c.x); pointer->grab_pos.c);
move->dy = wl_fixed_from_double(shsurf->view->geometry.y - move->dx = wl_fixed_from_double(offset.x);
pointer->grab_pos.c.y); move->dy = wl_fixed_from_double(offset.y);
move->client_initiated = client_initiated; move->client_initiated = client_initiated;
weston_desktop_surface_set_orientation(shsurf->desktop_surface, weston_desktop_surface_set_orientation(shsurf->desktop_surface,
@ -1942,8 +1943,8 @@ desktop_surface_removed(struct weston_desktop_surface *desktop_surface,
weston_view_set_output(shsurf->wview_anim_fade, weston_view_set_output(shsurf->wview_anim_fade,
shsurf->view->output); shsurf->view->output);
weston_view_set_position(shsurf->wview_anim_fade, weston_view_set_position(shsurf->wview_anim_fade,
shsurf->view->geometry.x, shsurf->view->geometry.pos_offset.x,
shsurf->view->geometry.y); shsurf->view->geometry.pos_offset.y);
weston_layer_entry_insert(&shsurf->view->layer_link, weston_layer_entry_insert(&shsurf->view->layer_link,
&shsurf->wview_anim_fade->layer_link); &shsurf->wview_anim_fade->layer_link);
@ -2111,8 +2112,8 @@ desktop_surface_committed(struct weston_desktop_surface *desktop_surface,
if ((shsurf->state.fullscreen || shsurf->state.maximized) && if ((shsurf->state.fullscreen || shsurf->state.maximized) &&
!shsurf->saved_position_valid) { !shsurf->saved_position_valid) {
shsurf->saved_x = shsurf->view->geometry.x; shsurf->saved_x = shsurf->view->geometry.pos_offset.x;
shsurf->saved_y = shsurf->view->geometry.y; shsurf->saved_y = shsurf->view->geometry.pos_offset.y;
shsurf->saved_position_valid = true; shsurf->saved_position_valid = true;
if (!wl_list_empty(&shsurf->rotation.transform.link)) { if (!wl_list_empty(&shsurf->rotation.transform.link)) {
@ -2133,7 +2134,7 @@ desktop_surface_committed(struct weston_desktop_surface *desktop_surface,
} else { } else {
struct weston_coord_surface from_s, to_s; struct weston_coord_surface from_s, to_s;
struct weston_coord_global to_g, from_g; struct weston_coord_global to_g, from_g;
float x, y; struct weston_coord_global offset, pos;
from_s = weston_coord_surface(0, 0, view->surface); from_s = weston_coord_surface(0, 0, view->surface);
@ -2151,10 +2152,11 @@ desktop_surface_committed(struct weston_desktop_surface *desktop_surface,
from_g = weston_coord_surface_to_global(view, from_s); from_g = weston_coord_surface_to_global(view, from_s);
to_g = weston_coord_surface_to_global(view, to_s); to_g = weston_coord_surface_to_global(view, to_s);
x = view->geometry.x + to_g.c.x - from_g.c.x;
y = view->geometry.y + to_g.c.y - from_g.c.y;
weston_view_set_position(shsurf->view, x, y); offset.c = weston_coord_sub(to_g.c, from_g.c);
pos.c = weston_coord_add(view->geometry.pos_offset, offset.c);
weston_view_set_position(shsurf->view, pos.c.x, pos.c.y);
} }
shsurf->last_width = surface->width; shsurf->last_width = surface->width;
@ -2480,8 +2482,8 @@ desktop_surface_get_position(struct weston_desktop_surface *surface,
{ {
struct shell_surface *shsurf = weston_desktop_surface_get_user_data(surface); struct shell_surface *shsurf = weston_desktop_surface_get_user_data(surface);
*x = shsurf->view->geometry.x; *x = shsurf->view->geometry.pos_offset.x;
*y = shsurf->view->geometry.y; *y = shsurf->view->geometry.pos_offset.y;
} }
static const struct weston_desktop_api shell_desktop_api = { static const struct weston_desktop_api shell_desktop_api = {
@ -3187,14 +3189,14 @@ rotate_grab_motion(struct weston_pointer_grab *grab,
/* We need to adjust the position of the surface /* We need to adjust the position of the surface
* in case it was resized in a rotated state before */ * in case it was resized in a rotated state before */
cposx = shsurf->view->geometry.x + cx; cposx = shsurf->view->geometry.pos_offset.x + cx;
cposy = shsurf->view->geometry.y + cy; cposy = shsurf->view->geometry.pos_offset.y + cy;
dposx = rotate->center.x - cposx; dposx = rotate->center.x - cposx;
dposy = rotate->center.y - cposy; dposy = rotate->center.y - cposy;
if (dposx != 0.0f || dposy != 0.0f) { if (dposx != 0.0f || dposy != 0.0f) {
weston_view_set_position(shsurf->view, weston_view_set_position(shsurf->view,
shsurf->view->geometry.x + dposx, shsurf->view->geometry.pos_offset.x + dposx,
shsurf->view->geometry.y + dposy); shsurf->view->geometry.pos_offset.y + dposy);
} }
/* Repaint implies weston_view_update_transform(), which /* Repaint implies weston_view_update_transform(), which
@ -3646,8 +3648,8 @@ shell_fade_create_fade_out_view(struct shell_surface *shsurf,
* move it around and just destroy it */ * move it around and just destroy it */
weston_view_set_output(view, woutput); weston_view_set_output(view, woutput);
weston_view_set_position(view, weston_view_set_position(view,
shsurf->view->geometry.x, shsurf->view->geometry.pos_offset.x,
shsurf->view->geometry.y); shsurf->view->geometry.pos_offset.y);
view->is_mapped = true; view->is_mapped = true;
return view; return view;
@ -3839,8 +3841,8 @@ transform_handler(struct wl_listener *listener, void *data)
if (!weston_view_is_mapped(shsurf->view)) if (!weston_view_is_mapped(shsurf->view))
return; return;
x = shsurf->view->geometry.x; x = shsurf->view->geometry.pos_offset.x;
y = shsurf->view->geometry.y; y = shsurf->view->geometry.pos_offset.y;
api->send_position(surface, x, y); api->send_position(surface, x, y);
} }
@ -4280,8 +4282,8 @@ shell_reposition_view_on_output_change(struct weston_view *view)
if (wl_list_empty(&ec->output_list)) if (wl_list_empty(&ec->output_list))
return; return;
x = view->geometry.x; x = view->geometry.pos_offset.x;
y = view->geometry.y; y = view->geometry.pos_offset.y;
/* At this point the destroyed output is not in the list anymore. /* At this point the destroyed output is not in the list anymore.
* If the view is still visible somewhere, we leave where it is, * If the view is still visible somewhere, we leave where it is,
@ -4447,8 +4449,8 @@ handle_output_move_layer(struct desktop_shell *shell,
if (view->output != output) if (view->output != output)
continue; continue;
x = view->geometry.x + output->move_x; x = view->geometry.pos_offset.x + output->move_x;
y = view->geometry.y + output->move_y; y = view->geometry.pos_offset.y + output->move_y;
weston_view_set_position(view, x, y); weston_view_set_position(view, x, y);
} }
} }

View file

@ -1497,7 +1497,11 @@ struct weston_view {
* That includes the transformations referenced from the list. * That includes the transformations referenced from the list.
*/ */
struct { struct {
float x, y; /* surface translation on display */ /* pos_offset is the surface's position in the global space
* if parent is NULL, or its offset in its parent's surface
* space if parent is set.
*/
struct weston_coord pos_offset;
/* struct weston_transform */ /* struct weston_transform */
struct wl_list transformation_list; struct wl_list transformation_list;

View file

@ -238,6 +238,7 @@ kiosk_shell_grab_start_for_pointer_move(struct kiosk_shell_surface *shsurf,
struct weston_pointer *pointer) struct weston_pointer *pointer)
{ {
struct kiosk_shell_grab *shgrab; struct kiosk_shell_grab *shgrab;
struct weston_coord_global offset;
if (!shsurf) if (!shsurf)
return KIOSK_SHELL_GRAB_RESULT_ERROR; return KIOSK_SHELL_GRAB_RESULT_ERROR;
@ -251,10 +252,10 @@ kiosk_shell_grab_start_for_pointer_move(struct kiosk_shell_surface *shsurf,
if (!shgrab) if (!shgrab)
return KIOSK_SHELL_GRAB_RESULT_ERROR; return KIOSK_SHELL_GRAB_RESULT_ERROR;
shgrab->dx = wl_fixed_from_double(shsurf->view->geometry.x - offset.c = weston_coord_sub(shsurf->view->geometry.pos_offset,
pointer->grab_pos.c.x); pointer->grab_pos.c);
shgrab->dy = wl_fixed_from_double(shsurf->view->geometry.y - shgrab->dx = wl_fixed_from_double(offset.c.x);
pointer->grab_pos.c.y); shgrab->dy = wl_fixed_from_double(offset.c.y);
shgrab->active = true; shgrab->active = true;
weston_seat_break_desktop_grabs(pointer->seat); weston_seat_break_desktop_grabs(pointer->seat);
@ -283,9 +284,9 @@ kiosk_shell_grab_start_for_touch_move(struct kiosk_shell_surface *shsurf,
if (!shgrab) if (!shgrab)
return KIOSK_SHELL_GRAB_RESULT_ERROR; return KIOSK_SHELL_GRAB_RESULT_ERROR;
shgrab->dx = wl_fixed_from_double(shsurf->view->geometry.x) - shgrab->dx = wl_fixed_from_double(shsurf->view->geometry.pos_offset.x) -
touch->grab_x; touch->grab_x;
shgrab->dy = wl_fixed_from_double(shsurf->view->geometry.y) - shgrab->dy = wl_fixed_from_double(shsurf->view->geometry.pos_offset.y) -
touch->grab_y; touch->grab_y;
shgrab->active = true; shgrab->active = true;

View file

@ -90,7 +90,6 @@ transform_handler(struct wl_listener *listener, void *data)
struct weston_surface *surface = data; struct weston_surface *surface = data;
struct kiosk_shell_surface *shsurf = get_kiosk_shell_surface(surface); struct kiosk_shell_surface *shsurf = get_kiosk_shell_surface(surface);
const struct weston_xwayland_surface_api *api; const struct weston_xwayland_surface_api *api;
int x, y;
if (!shsurf) if (!shsurf)
return; return;
@ -107,10 +106,9 @@ transform_handler(struct wl_listener *listener, void *data)
if (!weston_view_is_mapped(shsurf->view)) if (!weston_view_is_mapped(shsurf->view))
return; return;
x = shsurf->view->geometry.x; api->send_position(surface,
y = shsurf->view->geometry.y; shsurf->view->geometry.pos_offset.x,
shsurf->view->geometry.pos_offset.y);
api->send_position(surface, x, y);
} }
/* /*
@ -811,7 +809,7 @@ desktop_surface_committed(struct weston_desktop_surface *desktop_surface,
if (!is_fullscreen && (sx != 0 || sy != 0)) { if (!is_fullscreen && (sx != 0 || sy != 0)) {
struct weston_coord_surface from_s, to_s; struct weston_coord_surface from_s, to_s;
struct weston_coord_global from_g, to_g; struct weston_coord_global from_g, to_g;
float x, y; struct weston_coord_global offset, pos;
from_s = weston_coord_surface(0, 0, from_s = weston_coord_surface(0, 0,
shsurf->view->surface); shsurf->view->surface);
@ -820,10 +818,11 @@ desktop_surface_committed(struct weston_desktop_surface *desktop_surface,
from_g = weston_coord_surface_to_global(shsurf->view, from_s); from_g = weston_coord_surface_to_global(shsurf->view, from_s);
to_g = weston_coord_surface_to_global(shsurf->view, to_s); to_g = weston_coord_surface_to_global(shsurf->view, to_s);
x = shsurf->view->geometry.x + to_g.c.x - from_g.c.x; offset.c = weston_coord_sub(to_g.c, from_g.c);
y = shsurf->view->geometry.y + to_g.c.y - from_g.c.y; pos.c = weston_coord_add(shsurf->view->geometry.pos_offset,
offset.c);
weston_view_set_position(shsurf->view, x, y); weston_view_set_position(shsurf->view, pos.c.x, pos.c.y);
weston_view_update_transform(shsurf->view); weston_view_update_transform(shsurf->view);
} }
@ -965,8 +964,8 @@ desktop_surface_get_position(struct weston_desktop_surface *desktop_surface,
struct kiosk_shell_surface *shsurf = struct kiosk_shell_surface *shsurf =
weston_desktop_surface_get_user_data(desktop_surface); weston_desktop_surface_get_user_data(desktop_surface);
*x = shsurf->view->geometry.x; *x = shsurf->view->geometry.pos_offset.x;
*y = shsurf->view->geometry.y; *y = shsurf->view->geometry.pos_offset.y;
} }
static const struct weston_desktop_api kiosk_shell_desktop_api = { static const struct weston_desktop_api kiosk_shell_desktop_api = {
@ -1135,8 +1134,8 @@ kiosk_shell_handle_output_moved(struct wl_listener *listener, void *data)
if (view->output != output) if (view->output != output)
continue; continue;
weston_view_set_position(view, weston_view_set_position(view,
view->geometry.x + output->move_x, view->geometry.pos_offset.x + output->move_x,
view->geometry.y + output->move_y); view->geometry.pos_offset.y + output->move_y);
} }
wl_list_for_each(view, &shell->normal_layer.view_list.link, wl_list_for_each(view, &shell->normal_layer.view_list.link,
@ -1144,8 +1143,8 @@ kiosk_shell_handle_output_moved(struct wl_listener *listener, void *data)
if (view->output != output) if (view->output != output)
continue; continue;
weston_view_set_position(view, weston_view_set_position(view,
view->geometry.x + output->move_x, view->geometry.pos_offset.x + output->move_x,
view->geometry.y + output->move_y); view->geometry.pos_offset.y + output->move_y);
} }
} }

View file

@ -1338,19 +1338,19 @@ weston_view_update_transform_disable(struct weston_view *view)
view->transform.enabled = 0; view->transform.enabled = 0;
/* round off fractions when not transformed */ /* round off fractions when not transformed */
view->geometry.x = roundf(view->geometry.x); view->geometry.pos_offset.x = round(view->geometry.pos_offset.x);
view->geometry.y = roundf(view->geometry.y); view->geometry.pos_offset.y = round(view->geometry.pos_offset.y);
/* Otherwise identity matrix, but with x and y translation. */ /* Otherwise identity matrix, but with x and y translation. */
view->transform.position.matrix.type = WESTON_MATRIX_TRANSFORM_TRANSLATE; view->transform.position.matrix.type = WESTON_MATRIX_TRANSFORM_TRANSLATE;
view->transform.position.matrix.d[12] = view->geometry.x; view->transform.position.matrix.d[12] = view->geometry.pos_offset.x;
view->transform.position.matrix.d[13] = view->geometry.y; view->transform.position.matrix.d[13] = view->geometry.pos_offset.y;
view->transform.matrix = view->transform.position.matrix; view->transform.matrix = view->transform.position.matrix;
view->transform.inverse = view->transform.position.matrix; view->transform.inverse = view->transform.position.matrix;
view->transform.inverse.d[12] = -view->geometry.x; view->transform.inverse.d[12] = -view->geometry.pos_offset.x;
view->transform.inverse.d[13] = -view->geometry.y; view->transform.inverse.d[13] = -view->geometry.pos_offset.y;
pixman_region32_init_rect(&view->transform.boundingbox, pixman_region32_init_rect(&view->transform.boundingbox,
0, 0, 0, 0,
@ -1360,7 +1360,8 @@ weston_view_update_transform_disable(struct weston_view *view)
weston_view_update_transform_scissor(view, &view->transform.boundingbox); weston_view_update_transform_scissor(view, &view->transform.boundingbox);
pixman_region32_translate(&view->transform.boundingbox, pixman_region32_translate(&view->transform.boundingbox,
view->geometry.x, view->geometry.y); view->geometry.pos_offset.x,
view->geometry.pos_offset.y);
if (view->alpha == 1.0) { if (view->alpha == 1.0) {
if (view->surface->is_opaque) { if (view->surface->is_opaque) {
@ -1374,8 +1375,8 @@ weston_view_update_transform_disable(struct weston_view *view)
&view->transform.opaque, &view->transform.opaque,
&view->geometry.scissor); &view->geometry.scissor);
pixman_region32_translate(&view->transform.opaque, pixman_region32_translate(&view->transform.opaque,
view->geometry.x, view->geometry.pos_offset.x,
view->geometry.y); view->geometry.pos_offset.y);
} }
} }
} }
@ -1394,8 +1395,8 @@ weston_view_update_transform_enable(struct weston_view *view)
/* Otherwise identity matrix, but with x and y translation. */ /* Otherwise identity matrix, but with x and y translation. */
view->transform.position.matrix.type = WESTON_MATRIX_TRANSFORM_TRANSLATE; view->transform.position.matrix.type = WESTON_MATRIX_TRANSFORM_TRANSLATE;
view->transform.position.matrix.d[12] = view->geometry.x; view->transform.position.matrix.d[12] = view->geometry.pos_offset.x;
view->transform.position.matrix.d[13] = view->geometry.y; view->transform.position.matrix.d[13] = view->geometry.pos_offset.y;
weston_matrix_init(matrix); weston_matrix_init(matrix);
wl_list_for_each(tform, &view->geometry.transformation_list, link) wl_list_for_each(tform, &view->geometry.transformation_list, link)
@ -1585,11 +1586,11 @@ weston_view_set_rel_position(struct weston_view *view, float x, float y)
{ {
assert(view->geometry.parent); assert(view->geometry.parent);
if (view->geometry.x == x && view->geometry.y == y) if (view->geometry.pos_offset.x == x &&
view->geometry.pos_offset.y == y)
return; return;
view->geometry.x = x; view->geometry.pos_offset = weston_coord(x, y);
view->geometry.y = y;
weston_view_geometry_dirty(view); weston_view_geometry_dirty(view);
} }
@ -1599,11 +1600,11 @@ weston_view_set_position(struct weston_view *view, float x, float y)
assert(view->surface->committed != subsurface_committed); assert(view->surface->committed != subsurface_committed);
assert(!view->geometry.parent); assert(!view->geometry.parent);
if (view->geometry.x == x && view->geometry.y == y) if (view->geometry.pos_offset.x == x &&
view->geometry.pos_offset.y == y)
return; return;
view->geometry.x = x; view->geometry.pos_offset = weston_coord(x, y);
view->geometry.y = y;
weston_view_geometry_dirty(view); weston_view_geometry_dirty(view);
} }
@ -2717,7 +2718,8 @@ view_accumulate_damage(struct weston_view *view,
} else { } else {
pixman_region32_copy(&damage, &view->surface->damage); pixman_region32_copy(&damage, &view->surface->damage);
pixman_region32_translate(&damage, pixman_region32_translate(&damage,
view->geometry.x, view->geometry.y); view->geometry.pos_offset.x,
view->geometry.pos_offset.y);
} }
pixman_region32_intersect(&damage, &damage, pixman_region32_intersect(&damage, &damage,
@ -4530,8 +4532,8 @@ subsurface_committed(struct weston_surface *surface, int32_t dx, int32_t dy)
wl_list_for_each(view, &surface->views, surface_link) wl_list_for_each(view, &surface->views, surface_link)
weston_view_set_rel_position(view, weston_view_set_rel_position(view,
view->geometry.x + dx, view->geometry.pos_offset.x + dx,
view->geometry.y + dy); view->geometry.pos_offset.y + dy);
/* No need to check parent mappedness, because if parent is not /* No need to check parent mappedness, because if parent is not
* mapped, parent is not in a visible layer, so this sub-surface * mapped, parent is not in a visible layer, so this sub-surface