shells: Use weston_coord for shell API

Replaces a lot of x, y pairs with weston_coord.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
This commit is contained in:
Derek Foreman 2022-02-08 11:58:10 -06:00 committed by Marius Vlad
parent 0aae35bfc3
commit 9e12250707
11 changed files with 88 additions and 82 deletions

View File

@ -2351,7 +2351,7 @@ map(struct desktop_shell *shell, struct shell_surface *shsurf)
static void
desktop_surface_committed(struct weston_desktop_surface *desktop_surface,
int32_t sx, int32_t sy, void *data)
struct weston_coord_surface buf_offset, void *data)
{
struct shell_surface *shsurf =
weston_desktop_surface_get_user_data(desktop_surface);
@ -2393,7 +2393,7 @@ desktop_surface_committed(struct weston_desktop_surface *desktop_surface,
return;
}
if (sx == 0 && sy == 0 &&
if (buf_offset.c.x == 0 && buf_offset.c.y == 0 &&
shsurf->last_width == surface->width &&
shsurf->last_height == surface->height &&
was_fullscreen == shsurf->state.fullscreen &&
@ -2432,20 +2432,18 @@ desktop_surface_committed(struct weston_desktop_surface *desktop_surface,
set_maximized_position(shell, shsurf);
surface->output = shsurf->output;
} else {
struct weston_coord_surface offset;
struct weston_coord_surface offset = buf_offset;
struct weston_coord_global pos;
if (shsurf->resize_edges) {
sx = 0;
sy = 0;
offset.c.x = 0;
offset.c.y = 0;
}
if (shsurf->resize_edges & WESTON_DESKTOP_SURFACE_EDGE_LEFT)
sx = shsurf->last_width - surface->width;
offset.c.x = shsurf->last_width - surface->width;
if (shsurf->resize_edges & WESTON_DESKTOP_SURFACE_EDGE_TOP)
sy = shsurf->last_height - surface->height;
offset = weston_coord_surface(sx, sy, view->surface);
offset.c.y = shsurf->last_height - surface->height;
pos = weston_view_get_pos_offset_global(view);
weston_view_set_position_with_offset(shsurf->view, pos, offset);
@ -2759,12 +2757,12 @@ desktop_surface_pong(struct weston_desktop_client *desktop_client,
static void
desktop_surface_set_xwayland_position(struct weston_desktop_surface *surface,
int32_t x, int32_t y, void *shell_)
struct weston_coord_global pos, void *shell_)
{
struct shell_surface *shsurf =
weston_desktop_surface_get_user_data(surface);
shsurf->xwayland.pos.c = weston_coord(x, y);
shsurf->xwayland.pos = pos;
shsurf->xwayland.is_set = true;
}

View File

@ -68,9 +68,10 @@ struct weston_desktop_api {
void (*surface_removed)(struct weston_desktop_surface *surface,
void *user_data);
void (*committed)(struct weston_desktop_surface *surface,
int32_t sx, int32_t sy, void *user_data);
struct weston_coord_surface buf_offset, void *user_data);
void (*show_window_menu)(struct weston_desktop_surface *surface,
struct weston_seat *seat, int32_t x, int32_t y,
struct weston_seat *seat,
struct weston_coord_surface offset,
void *user_data);
void (*set_parent)(struct weston_desktop_surface *surface,
struct weston_desktop_surface *parent,
@ -120,7 +121,7 @@ struct weston_desktop_api {
* This callback can be NULL.
*/
void (*set_xwayland_position)(struct weston_desktop_surface *surface,
int32_t x, int32_t y, void *user_data);
struct weston_coord_global pos, void *user_data);
void (*get_position)(struct weston_desktop_surface *surface,
int32_t *x, int32_t *y,
void *user_data);

View File

@ -601,7 +601,7 @@ desktop_surface_removed(struct weston_desktop_surface *surface,
static void
desktop_surface_committed(struct weston_desktop_surface *surface,
int32_t sx, int32_t sy, void *user_data)
struct weston_coord_surface buf_offset, void *user_data)
{
struct ivi_shell_surface *ivisurf = (struct ivi_shell_surface *)
weston_desktop_surface_get_user_data(surface);
@ -684,7 +684,7 @@ desktop_surface_minimized_requested(struct weston_desktop_surface *surface,
static void
desktop_surface_set_xwayland_position(struct weston_desktop_surface *surface,
int32_t x, int32_t y, void *user_data)
struct weston_coord_global pos, void *user_data)
{
/* Not supported */
}

View File

@ -891,7 +891,7 @@ desktop_surface_removed(struct weston_desktop_surface *desktop_surface,
static void
desktop_surface_committed(struct weston_desktop_surface *desktop_surface,
int32_t sx, int32_t sy, void *data)
struct weston_coord_surface buf_offset, void *data)
{
struct kiosk_shell_surface *shsurf =
weston_desktop_surface_get_user_data(desktop_surface);
@ -979,24 +979,12 @@ desktop_surface_committed(struct weston_desktop_surface *desktop_surface,
WESTON_ACTIVATE_FLAG_NONE);
}
if (!is_fullscreen && (sx != 0 || sy != 0)) {
struct weston_coord_surface from_s, to_s;
struct weston_coord_global from_g, to_g;
struct weston_coord_global offset, pos;
if (!is_fullscreen && (buf_offset.c.x != 0 || buf_offset.c.y != 0)) {
struct weston_coord_global pos;
from_s = weston_coord_surface(0, 0,
shsurf->view->surface);
to_s = weston_coord_surface(sx, sy,
shsurf->view->surface);
from_g = weston_coord_surface_to_global(shsurf->view, from_s);
to_g = weston_coord_surface_to_global(shsurf->view, to_s);
offset = weston_coord_global_sub(to_g, from_g);
pos = weston_coord_global_add(
weston_view_get_pos_offset_global(shsurf->view),
offset);
weston_view_set_position(shsurf->view, pos);
pos = weston_view_get_pos_offset_global(shsurf->view);
weston_view_set_position_with_offset(shsurf->view,
pos, buf_offset);
weston_view_update_transform(shsurf->view);
}
@ -1121,12 +1109,12 @@ desktop_surface_pong(struct weston_desktop_client *desktop_client,
static void
desktop_surface_set_xwayland_position(struct weston_desktop_surface *desktop_surface,
int32_t x, int32_t y, void *shell)
struct weston_coord_global pos, void *shell)
{
struct kiosk_shell_surface *shsurf =
weston_desktop_surface_get_user_data(desktop_surface);
shsurf->xwayland.pos.c = weston_coord(x, y);
shsurf->xwayland.pos = pos;
shsurf->xwayland.is_set = true;
}

View File

@ -49,12 +49,12 @@ weston_desktop_api_surface_removed(struct weston_desktop *desktop,
void
weston_desktop_api_committed(struct weston_desktop *desktop,
struct weston_desktop_surface *surface,
int32_t sx, int32_t sy);
struct weston_coord_surface buf_offset);
void
weston_desktop_api_show_window_menu(struct weston_desktop *desktop,
struct weston_desktop_surface *surface,
struct weston_seat *seat,
int32_t x, int32_t y);
struct weston_coord_surface offset);
void
weston_desktop_api_set_parent(struct weston_desktop *desktop,
struct weston_desktop_surface *surface,
@ -84,7 +84,7 @@ weston_desktop_api_minimized_requested(struct weston_desktop *desktop,
void
weston_desktop_api_set_xwayland_position(struct weston_desktop *desktop,
struct weston_desktop_surface *surface,
int32_t x, int32_t y);
struct weston_coord_global pos);
void
weston_desktop_api_get_position(struct weston_desktop *desktop,
@ -108,7 +108,7 @@ struct weston_desktop_surface_implementation {
void (*set_orientation)(struct weston_desktop_surface *surface,
void *user_data, enum weston_top_level_tiled_orientation tiled_orientation);
void (*committed)(struct weston_desktop_surface *surface, void *user_data,
int32_t sx, int32_t sy);
struct weston_coord_surface buf_offset);
void (*update_position)(struct weston_desktop_surface *surface,
void *user_data);
void (*ping)(struct weston_desktop_surface *surface, uint32_t serial,
@ -213,7 +213,7 @@ weston_desktop_surface_set_geometry(struct weston_desktop_surface *surface,
void
weston_desktop_surface_set_relative_to(struct weston_desktop_surface *surface,
struct weston_desktop_surface *parent,
int32_t x, int32_t y, bool use_geometry);
struct weston_coord_surface offset, bool use_geometry);
void
weston_desktop_surface_unset_relative_to(struct weston_desktop_surface *surface);
void

View File

@ -153,20 +153,20 @@ weston_desktop_api_surface_removed(struct weston_desktop *desktop,
void
weston_desktop_api_committed(struct weston_desktop *desktop,
struct weston_desktop_surface *surface,
int32_t sx, int32_t sy)
struct weston_coord_surface buf_offset)
{
if (desktop->api.committed != NULL)
desktop->api.committed(surface, sx, sy, desktop->user_data);
desktop->api.committed(surface, buf_offset, desktop->user_data);
}
void
weston_desktop_api_show_window_menu(struct weston_desktop *desktop,
struct weston_desktop_surface *surface,
struct weston_seat *seat,
int32_t x, int32_t y)
struct weston_coord_surface offset)
{
if (desktop->api.show_window_menu != NULL)
desktop->api.show_window_menu(surface, seat, x, y,
desktop->api.show_window_menu(surface, seat, offset,
desktop->user_data);
}
@ -267,10 +267,10 @@ weston_desktop_minimize_supported(struct weston_desktop *desktop)
void
weston_desktop_api_set_xwayland_position(struct weston_desktop *desktop,
struct weston_desktop_surface *surface,
int32_t x, int32_t y)
struct weston_coord_global pos)
{
if (desktop->api.set_xwayland_position != NULL)
desktop->api.set_xwayland_position(surface, x, y,
desktop->api.set_xwayland_position(surface, pos,
desktop->user_data);
}

View File

@ -189,11 +189,11 @@ weston_desktop_surface_surface_committed(struct wl_listener *listener,
wl_container_of(listener, surface, surface_commit_listener);
struct weston_surface *wsurface = surface->surface;
if (surface->implementation->committed != NULL)
if (surface->implementation->committed != NULL) {
surface->implementation->committed(surface,
surface->implementation_data,
surface->buffer_move.c.x,
surface->buffer_move.c.y);
surface->buffer_move);
}
if (surface->parent != NULL) {
struct weston_desktop_view *view;
@ -789,15 +789,14 @@ weston_desktop_surface_set_geometry(struct weston_desktop_surface *surface,
void
weston_desktop_surface_set_relative_to(struct weston_desktop_surface *surface,
struct weston_desktop_surface *parent,
int32_t x, int32_t y, bool use_geometry)
struct weston_coord_surface offset, bool use_geometry)
{
struct weston_desktop_view *view, *parent_view;
struct wl_list *link, *tmp;
assert(parent);
surface->pos_offset.x = x;
surface->pos_offset.y = y;
surface->pos_offset = offset.c;
surface->use_geometry = use_geometry;
if (surface->parent == parent)

View File

@ -369,6 +369,8 @@ weston_desktop_xdg_toplevel_protocol_show_window_menu(struct wl_client *wl_clien
wl_resource_get_user_data(seat_resource);
struct weston_desktop_xdg_toplevel *toplevel =
weston_desktop_surface_get_implementation_data(dsurface);
struct weston_surface *wsurface;
struct weston_coord_surface offset;
if (!toplevel->base.configured) {
wl_resource_post_error(toplevel->resource,
@ -379,9 +381,10 @@ weston_desktop_xdg_toplevel_protocol_show_window_menu(struct wl_client *wl_clien
if (seat == NULL)
return;
wsurface = weston_desktop_surface_get_surface(dsurface);
offset = weston_coord_surface(x, y, wsurface);
weston_desktop_api_show_window_menu(toplevel->base.desktop,
dsurface, seat, x, y);
dsurface, seat, offset);
}
static void
@ -643,7 +646,7 @@ weston_desktop_xdg_toplevel_set_size(struct weston_desktop_surface *dsurface,
static void
weston_desktop_xdg_toplevel_committed(struct weston_desktop_xdg_toplevel *toplevel,
int32_t sx, int32_t sy)
struct weston_coord_surface buf_offset)
{
struct weston_surface *wsurface =
weston_desktop_surface_get_surface(toplevel->base.desktop_surface);
@ -656,7 +659,7 @@ weston_desktop_xdg_toplevel_committed(struct weston_desktop_xdg_toplevel *toplev
if (!weston_surface_has_content(wsurface)) {
if (weston_surface_is_unmapping(wsurface))
weston_desktop_api_committed(toplevel->base.desktop,
toplevel->base.desktop_surface, sx, sy);
toplevel->base.desktop_surface, buf_offset);
return;
}
@ -683,7 +686,7 @@ weston_desktop_xdg_toplevel_committed(struct weston_desktop_xdg_toplevel *toplev
weston_desktop_api_committed(toplevel->base.desktop,
toplevel->base.desktop_surface,
sx, sy);
buf_offset);
}
static void
@ -1110,6 +1113,7 @@ weston_desktop_xdg_surface_protocol_get_popup(struct wl_client *wl_client,
weston_desktop_surface_get_implementation_data(parent_surface);
struct weston_desktop_xdg_positioner *positioner =
wl_resource_get_user_data(positioner_resource);
struct weston_coord_surface offset;
/* Checking whether the size and anchor rect both have a positive size
* is enough to verify both have been correctly set */
@ -1140,10 +1144,12 @@ weston_desktop_xdg_surface_protocol_get_popup(struct wl_client *wl_client,
dsurface,
parent_surface);
offset = weston_coord_surface(popup->geometry.x,
popup->geometry.y,
popup->parent->surface);
weston_desktop_surface_set_relative_to(popup->base.desktop_surface,
parent_surface,
popup->geometry.x,
popup->geometry.y,
offset,
true);
}
@ -1256,7 +1262,7 @@ weston_desktop_xdg_surface_ping(struct weston_desktop_surface *dsurface,
static void
weston_desktop_xdg_surface_committed(struct weston_desktop_surface *dsurface,
void *user_data,
int32_t sx, int32_t sy)
struct weston_coord_surface buf_offset)
{
struct weston_desktop_xdg_surface *surface = user_data;
struct weston_surface *wsurface =
@ -1282,7 +1288,8 @@ weston_desktop_xdg_surface_committed(struct weston_desktop_surface *dsurface,
"xdg_surface must have a role");
break;
case WESTON_DESKTOP_XDG_SURFACE_ROLE_TOPLEVEL:
weston_desktop_xdg_toplevel_committed((struct weston_desktop_xdg_toplevel *) surface, sx, sy);
weston_desktop_xdg_toplevel_committed((struct weston_desktop_xdg_toplevel *) surface,
buf_offset);
break;
case WESTON_DESKTOP_XDG_SURFACE_ROLE_POPUP:
weston_desktop_xdg_popup_committed((struct weston_desktop_xdg_popup *) surface);

View File

@ -418,6 +418,8 @@ weston_desktop_xdg_toplevel_protocol_show_window_menu(struct wl_client *wl_clien
wl_resource_get_user_data(seat_resource);
struct weston_desktop_xdg_toplevel *toplevel =
weston_desktop_surface_get_implementation_data(dsurface);
struct weston_surface *wsurface;
struct weston_coord_surface offset;
if (!toplevel->base.configured) {
wl_resource_post_error(toplevel->resource,
@ -429,8 +431,10 @@ weston_desktop_xdg_toplevel_protocol_show_window_menu(struct wl_client *wl_clien
if (seat == NULL)
return;
wsurface = weston_desktop_surface_get_surface(dsurface);
offset = weston_coord_surface(x, y, wsurface);
weston_desktop_api_show_window_menu(toplevel->base.desktop,
dsurface, seat, x, y);
dsurface, seat, offset);
}
static void
@ -726,7 +730,7 @@ weston_desktop_xdg_toplevel_set_orientation(struct weston_desktop_surface *surfa
static void
weston_desktop_xdg_toplevel_committed(struct weston_desktop_xdg_toplevel *toplevel,
int32_t sx, int32_t sy)
struct weston_coord_surface buf_offset)
{
struct weston_surface *wsurface =
weston_desktop_surface_get_surface(toplevel->base.desktop_surface);
@ -739,7 +743,7 @@ weston_desktop_xdg_toplevel_committed(struct weston_desktop_xdg_toplevel *toplev
if (!weston_surface_has_content(wsurface)) {
if (weston_surface_is_unmapping(wsurface))
weston_desktop_api_committed(toplevel->base.desktop,
toplevel->base.desktop_surface, sx, sy);
toplevel->base.desktop_surface, buf_offset);
return;
}
@ -788,7 +792,7 @@ weston_desktop_xdg_toplevel_committed(struct weston_desktop_xdg_toplevel *toplev
weston_desktop_api_committed(toplevel->base.desktop,
toplevel->base.desktop_surface,
sx, sy);
buf_offset);
}
static void
@ -1059,12 +1063,15 @@ weston_desktop_xdg_popup_update_position(struct weston_desktop_surface *dsurface
struct weston_desktop_xdg_popup *popup =
weston_desktop_surface_get_implementation_data(dsurface);
struct weston_desktop_surface *parent_dsurface;
struct weston_coord_surface offset;
parent_dsurface = popup->parent->desktop_surface;
offset = weston_coord_surface(popup->geometry.x,
popup->geometry.y,
popup->parent->surface);
weston_desktop_surface_set_relative_to(popup->base.desktop_surface,
parent_dsurface,
popup->geometry.x,
popup->geometry.y,
offset,
true);
}
@ -1308,6 +1315,7 @@ weston_desktop_xdg_surface_protocol_get_popup(struct wl_client *wl_client,
struct weston_desktop_xdg_surface *parent;
struct weston_desktop_xdg_positioner *positioner =
wl_resource_get_user_data(positioner_resource);
struct weston_coord_surface offset;
/* Popup parents are allowed to be non-null, but only if a parent is
* specified 'using some other protocol' before committing. Since we
@ -1350,10 +1358,12 @@ weston_desktop_xdg_surface_protocol_get_popup(struct wl_client *wl_client,
dsurface,
parent_surface);
offset = weston_coord_surface(popup->geometry.x,
popup->geometry.y,
popup->parent->surface);
weston_desktop_surface_set_relative_to(popup->base.desktop_surface,
parent_surface,
popup->geometry.x,
popup->geometry.y,
offset,
true);
}
@ -1466,7 +1476,7 @@ weston_desktop_xdg_surface_ping(struct weston_desktop_surface *dsurface,
static void
weston_desktop_xdg_surface_committed(struct weston_desktop_surface *dsurface,
void *user_data,
int32_t sx, int32_t sy)
struct weston_coord_surface c)
{
struct weston_desktop_xdg_surface *surface = user_data;
struct weston_surface *wsurface =
@ -1492,7 +1502,7 @@ weston_desktop_xdg_surface_committed(struct weston_desktop_surface *dsurface,
"xdg_surface must have a role");
break;
case WESTON_DESKTOP_XDG_SURFACE_ROLE_TOPLEVEL:
weston_desktop_xdg_toplevel_committed((struct weston_desktop_xdg_toplevel *) surface, sx, sy);
weston_desktop_xdg_toplevel_committed((struct weston_desktop_xdg_toplevel *) surface, c);
break;
case WESTON_DESKTOP_XDG_SURFACE_ROLE_POPUP:
weston_desktop_xdg_popup_committed((struct weston_desktop_xdg_popup *) surface);

View File

@ -103,6 +103,9 @@ weston_desktop_xwayland_surface_change_state(struct weston_desktop_xwayland_surf
}
if (to_add) {
struct weston_coord_surface zero;
zero = weston_coord_surface(0, 0, wsurface);
weston_desktop_surface_unset_relative_to(surface->surface);
weston_desktop_api_surface_added(surface->desktop,
surface->surface);
@ -113,7 +116,7 @@ weston_desktop_xwayland_surface_change_state(struct weston_desktop_xwayland_surf
* surface */
weston_desktop_api_committed(surface->desktop,
surface->surface,
0, 0);
zero);
} else if (surface->added) {
weston_desktop_api_surface_removed(surface->desktop,
@ -147,18 +150,18 @@ weston_desktop_xwayland_surface_change_state(struct weston_desktop_xwayland_surf
psurface = weston_desktop_surface_get_surface(parent);
assert(offset->coordinate_space_id == psurface);
weston_desktop_surface_set_relative_to(surface->surface, parent,
offset->c.x,
offset->c.y, false);
*offset, false);
}
}
static void
weston_desktop_xwayland_surface_committed(struct weston_desktop_surface *dsurface,
void *user_data,
int32_t sx, int32_t sy)
struct weston_coord_surface buf_offset)
{
struct weston_desktop_xwayland_surface *surface = user_data;
struct weston_geometry oldgeom;
struct weston_coord_surface tmp;
assert(dsurface == surface->surface);
surface->committed = true;
@ -167,6 +170,7 @@ weston_desktop_xwayland_surface_committed(struct weston_desktop_surface *dsurfac
weston_log("%s: xwayland surface %p\n", __func__, surface);
#endif
tmp = buf_offset;
if (surface->has_next_geometry) {
oldgeom = weston_desktop_surface_get_geometry(surface->surface);
/* If we're transitioning away from fullscreen or maximized
@ -175,8 +179,8 @@ weston_desktop_xwayland_surface_committed(struct weston_desktop_surface *dsurfac
* the geometry in those cases.
*/
if (surface->state == surface->prev_state) {
sx -= surface->next_geometry.x - oldgeom.x;
sy -= surface->next_geometry.y - oldgeom.y;
tmp.c.x -= surface->next_geometry.x - oldgeom.x;
tmp.c.y -= surface->next_geometry.y - oldgeom.y;
}
surface->prev_state = surface->state;
@ -187,7 +191,7 @@ weston_desktop_xwayland_surface_committed(struct weston_desktop_surface *dsurfac
if (surface->added)
weston_desktop_api_committed(surface->desktop, surface->surface,
sx, sy);
tmp);
/* If we're an override redirect window, the shell has no knowledge of
* our existence, so it won't assign us an output.
@ -350,8 +354,7 @@ set_toplevel_with_position(struct weston_desktop_xwayland_surface *surface,
{
set_toplevel(surface);
weston_desktop_api_set_xwayland_position(surface->desktop,
surface->surface,
pos.c.x, pos.c.y);
surface->surface, pos);
}
static void

View File

@ -80,7 +80,7 @@ desktop_surface_removed(struct weston_desktop_surface *desktop_surface,
static void
desktop_surface_committed(struct weston_desktop_surface *desktop_surface,
int32_t sx, int32_t sy, void *shell)
struct weston_coord_surface unused, void *shell)
{
struct desktest_shell *dts = shell;
struct weston_surface *surface =