wayland/surface: Add support for wl_surface.offset

This aims to replace the x,y arguments in wl_surface.attach(); meaning
it can be used more sanely together with EGL, and at all when using
Vulkan.

The most common use case for the offset is setting the hotspot of DND
surfaces.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1905>
This commit is contained in:
Jonas Ådahl
2021-03-22 11:49:11 +01:00
parent fadffe3fad
commit 370de58868
4 changed files with 35 additions and 5 deletions

View File

@@ -553,10 +553,11 @@ meta_wayland_surface_state_merge_into (MetaWaylandSurfaceState *from,
to->newly_attached = TRUE;
to->buffer = from->buffer;
to->dx = from->dx;
to->dy = from->dy;
}
to->dx += from->dx;
to->dy += from->dy;
wl_list_insert_list (&to->frame_callback_list, &from->frame_callback_list);
wl_list_init (&from->frame_callback_list);
@@ -1055,6 +1056,16 @@ wl_surface_attach (struct wl_client *client,
pending->buffer);
}
if (wl_resource_get_version (surface_resource) >=
WL_SURFACE_OFFSET_SINCE_VERSION &&
(dx != 0 || dy != 0))
{
wl_resource_post_error (surface_resource,
WL_SURFACE_ERROR_INVALID_OFFSET,
"Attaching with an offset is no longer allowed");
return;
}
pending->newly_attached = TRUE;
pending->buffer = buffer;
pending->dx = dx;
@@ -1259,6 +1270,19 @@ wl_surface_damage_buffer (struct wl_client *client,
cairo_region_union_rectangle (pending->buffer_damage, &rectangle);
}
static void
wl_surface_offset (struct wl_client *client,
struct wl_resource *surface_resource,
int32_t dx,
int32_t dy)
{
MetaWaylandSurface *surface = wl_resource_get_user_data (surface_resource);
MetaWaylandSurfaceState *pending = surface->pending_state;
pending->dx = dx;
pending->dy = dy;
}
static const struct wl_surface_interface meta_wayland_wl_surface_interface = {
wl_surface_destroy,
wl_surface_attach,
@@ -1270,6 +1294,7 @@ static const struct wl_surface_interface meta_wayland_wl_surface_interface = {
wl_surface_set_buffer_transform,
wl_surface_set_buffer_scale,
wl_surface_damage_buffer,
wl_surface_offset,
};
static void