wayland: Introduce MetaWaylandSurfaceRole

Introduce surface roles and use it to ensure a surface never changes
role.

https://bugzilla.gnome.org/show_bug.cgi?id=744452
This commit is contained in:
Jonas Ådahl 2015-02-06 16:12:21 +08:00
parent f6869bbbc2
commit 945bf626c6
4 changed files with 77 additions and 0 deletions

View File

@ -410,6 +410,12 @@ data_device_start_drag (struct wl_client *client,
seat->pointer.grab != &seat->pointer.default_grab)
return;
if (meta_wayland_surface_set_role (surface,
META_WAYLAND_SURFACE_ROLE_DND,
resource,
WL_DATA_DEVICE_ERROR_ROLE) != 0)
return;
data_device->current_grab = drag_grab = g_slice_new0 (MetaWaylandDragGrab);
drag_grab->generic.interface = &drag_grab_interface;

View File

@ -786,6 +786,15 @@ pointer_set_cursor (struct wl_client *client,
if (pointer->focus_serial - serial > G_MAXUINT32 / 2)
return;
if (surface)
{
if (meta_wayland_surface_set_role (surface,
META_WAYLAND_SURFACE_ROLE_CURSOR,
resource,
WL_POINTER_ERROR_ROLE) != 0)
return;
}
pointer->hotspot_x = x;
pointer->hotspot_y = y;
set_cursor_surface (pointer, surface);

View File

@ -63,6 +63,27 @@ typedef struct
struct wl_listener sibling_destroy_listener;
} MetaWaylandSubsurfacePlacementOp;
int
meta_wayland_surface_set_role (MetaWaylandSurface *surface,
MetaWaylandSurfaceRole role,
struct wl_resource *error_resource,
uint32_t error_code)
{
if (surface->role == META_WAYLAND_SURFACE_ROLE_NONE ||
surface->role == role)
{
surface->role = role;
return 0;
}
else
{
wl_resource_post_error (error_resource, error_code,
"wl_surface@%d already has a different role",
wl_resource_get_id (surface->resource));
return -1;
}
}
static void
surface_set_buffer (MetaWaylandSurface *surface,
MetaWaylandBuffer *buffer)
@ -979,6 +1000,12 @@ xdg_shell_get_xdg_surface (struct wl_client *client,
return;
}
if (meta_wayland_surface_set_role (surface,
META_WAYLAND_SURFACE_ROLE_XDG_SURFACE,
surface_resource,
XDG_SHELL_ERROR_ROLE) != 0)
return;
surface->xdg_surface = wl_resource_create (client, &xdg_surface_interface, wl_resource_get_version (resource), id);
wl_resource_set_implementation (surface->xdg_surface, &meta_wayland_xdg_surface_interface, surface, xdg_surface_destructor);
@ -1036,6 +1063,12 @@ xdg_shell_get_xdg_popup (struct wl_client *client,
return;
}
if (meta_wayland_surface_set_role (surface,
META_WAYLAND_SURFACE_ROLE_XDG_POPUP,
surface_resource,
XDG_SHELL_ERROR_ROLE) != 0)
return;
surface->xdg_popup = wl_resource_create (client, &xdg_popup_interface, wl_resource_get_version (resource), id);
wl_resource_set_implementation (surface->xdg_popup, &meta_wayland_xdg_popup_interface, surface, xdg_popup_destructor);
@ -1303,6 +1336,12 @@ wl_shell_get_shell_surface (struct wl_client *client,
return;
}
if (meta_wayland_surface_set_role (surface,
META_WAYLAND_SURFACE_ROLE_WL_SHELL_SURFACE,
surface_resource,
WL_SHELL_ERROR_ROLE) != 0)
return;
surface->wl_shell_surface = wl_resource_create (client, &wl_shell_surface_interface, wl_resource_get_version (resource), id);
wl_resource_set_implementation (surface->wl_shell_surface, &meta_wayland_wl_shell_surface_interface, surface, wl_shell_surface_destructor);
@ -1656,6 +1695,12 @@ wl_subcompositor_get_subsurface (struct wl_client *client,
return;
}
if (meta_wayland_surface_set_role (surface,
META_WAYLAND_SURFACE_ROLE_SUBSURFACE,
surface_resource,
WL_SHELL_ERROR_ROLE) != 0)
return;
surface->wl_subsurface = wl_resource_create (client, &wl_subsurface_interface, wl_resource_get_version (resource), id);
wl_resource_set_implementation (surface->wl_subsurface, &meta_wayland_wl_subsurface_interface, surface, wl_subsurface_destructor);

View File

@ -36,6 +36,17 @@ struct _MetaWaylandSerial {
uint32_t value;
};
typedef enum
{
META_WAYLAND_SURFACE_ROLE_NONE,
META_WAYLAND_SURFACE_ROLE_SUBSURFACE,
META_WAYLAND_SURFACE_ROLE_XDG_SURFACE,
META_WAYLAND_SURFACE_ROLE_XDG_POPUP,
META_WAYLAND_SURFACE_ROLE_WL_SHELL_SURFACE,
META_WAYLAND_SURFACE_ROLE_CURSOR,
META_WAYLAND_SURFACE_ROLE_DND,
} MetaWaylandSurfaceRole;
typedef struct
{
/* wl_surface.attach */
@ -66,6 +77,7 @@ struct _MetaWaylandSurface
struct wl_resource *resource;
MetaWaylandCompositor *compositor;
MetaSurfaceActor *surface_actor;
MetaWaylandSurfaceRole role;
MetaWindow *window;
MetaWaylandBuffer *buffer;
struct wl_listener buffer_destroy_listener;
@ -118,6 +130,11 @@ MetaWaylandSurface *meta_wayland_surface_create (MetaWaylandCompositor *composit
struct wl_resource *compositor_resource,
guint32 id);
int meta_wayland_surface_set_role (MetaWaylandSurface *surface,
MetaWaylandSurfaceRole role,
struct wl_resource *error_resource,
uint32_t error_code);
void meta_wayland_surface_set_window (MetaWaylandSurface *surface,
MetaWindow *window);