mirror of
https://github.com/brl/mutter.git
synced 2024-11-25 01:20:42 -05:00
wayland: Clean up surface role assignment
Use a better name, use GNOME conventions for error handling, open code the client error reporting and send the error to the correct resource. wl_subcompositor doesn't have a role error yet, so continue use some other error. The only effect of this is error received in the client will be a bit confusing, it will still be disconnected. https://bugzilla.gnome.org/show_bug.cgi?id=754215
This commit is contained in:
parent
0aa4c4d43e
commit
94513726de
@ -537,11 +537,14 @@ data_device_start_drag (struct wl_client *client,
|
||||
drag_source = wl_resource_get_user_data (source_resource);
|
||||
|
||||
if (icon_resource &&
|
||||
meta_wayland_surface_set_role (icon_surface,
|
||||
META_WAYLAND_SURFACE_ROLE_DND,
|
||||
resource,
|
||||
WL_DATA_DEVICE_ERROR_ROLE) != 0)
|
||||
return;
|
||||
!meta_wayland_surface_assign_role (icon_surface,
|
||||
META_WAYLAND_SURFACE_ROLE_DND))
|
||||
{
|
||||
wl_resource_post_error (resource, WL_DATA_DEVICE_ERROR_ROLE,
|
||||
"wl_surface@%d already has a different role",
|
||||
wl_resource_get_id (icon_resource));
|
||||
return;
|
||||
}
|
||||
|
||||
meta_wayland_pointer_set_focus (&seat->pointer, NULL);
|
||||
meta_wayland_data_device_start_drag (data_device, client,
|
||||
|
@ -776,11 +776,14 @@ pointer_set_cursor (struct wl_client *client,
|
||||
|
||||
if (surface)
|
||||
{
|
||||
if (meta_wayland_surface_set_role (surface,
|
||||
META_WAYLAND_SURFACE_ROLE_CURSOR,
|
||||
resource,
|
||||
WL_POINTER_ERROR_ROLE) != 0)
|
||||
return;
|
||||
if (!meta_wayland_surface_assign_role (surface,
|
||||
META_WAYLAND_SURFACE_ROLE_CURSOR))
|
||||
{
|
||||
wl_resource_post_error (resource, WL_POINTER_ERROR_ROLE,
|
||||
"wl_surface@%d already has a different role",
|
||||
wl_resource_get_id (surface_resource));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
pointer->hotspot_x = x;
|
||||
|
@ -72,24 +72,19 @@ GType meta_wayland_surface_get_type (void) G_GNUC_CONST;
|
||||
|
||||
G_DEFINE_TYPE (MetaWaylandSurface, meta_wayland_surface, G_TYPE_OBJECT);
|
||||
|
||||
int
|
||||
meta_wayland_surface_set_role (MetaWaylandSurface *surface,
|
||||
MetaWaylandSurfaceRole role,
|
||||
struct wl_resource *error_resource,
|
||||
uint32_t error_code)
|
||||
gboolean
|
||||
meta_wayland_surface_assign_role (MetaWaylandSurface *surface,
|
||||
MetaWaylandSurfaceRole role)
|
||||
{
|
||||
if (surface->role == META_WAYLAND_SURFACE_ROLE_NONE ||
|
||||
surface->role == role)
|
||||
{
|
||||
surface->role = role;
|
||||
return 0;
|
||||
return TRUE;
|
||||
}
|
||||
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;
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1283,11 +1278,14 @@ 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;
|
||||
if (!meta_wayland_surface_assign_role (surface,
|
||||
META_WAYLAND_SURFACE_ROLE_XDG_SURFACE))
|
||||
{
|
||||
wl_resource_post_error (resource, XDG_SHELL_ERROR_ROLE,
|
||||
"wl_surface@%d already has a different role",
|
||||
wl_resource_get_id (surface->resource));
|
||||
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);
|
||||
@ -1391,11 +1389,14 @@ 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;
|
||||
if (!meta_wayland_surface_assign_role (surface,
|
||||
META_WAYLAND_SURFACE_ROLE_XDG_POPUP))
|
||||
{
|
||||
wl_resource_post_error (resource, XDG_SHELL_ERROR_ROLE,
|
||||
"wl_surface@%d already has a different role",
|
||||
wl_resource_get_id (surface->resource));
|
||||
return;
|
||||
}
|
||||
|
||||
if (parent_surf == NULL ||
|
||||
parent_surf->window == NULL ||
|
||||
@ -1731,11 +1732,14 @@ 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;
|
||||
if (!meta_wayland_surface_assign_role (surface,
|
||||
META_WAYLAND_SURFACE_ROLE_WL_SHELL_SURFACE))
|
||||
{
|
||||
wl_resource_post_error (resource, WL_SHELL_ERROR_ROLE,
|
||||
"wl_surface@%d already has a different role",
|
||||
wl_resource_get_id (surface->resource));
|
||||
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);
|
||||
@ -2080,11 +2084,17 @@ 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;
|
||||
if (!meta_wayland_surface_assign_role (surface,
|
||||
META_WAYLAND_SURFACE_ROLE_SUBSURFACE))
|
||||
{
|
||||
/* FIXME: There is no subcompositor "role" error yet, so lets just use something
|
||||
* similar until there is.
|
||||
*/
|
||||
wl_resource_post_error (resource, WL_SHELL_ERROR_ROLE,
|
||||
"wl_surface@%d already has a different role",
|
||||
wl_resource_get_id (surface->resource));
|
||||
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);
|
||||
|
@ -174,10 +174,8 @@ 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);
|
||||
gboolean meta_wayland_surface_assign_role (MetaWaylandSurface *surface,
|
||||
MetaWaylandSurfaceRole role);
|
||||
|
||||
void meta_wayland_surface_set_window (MetaWaylandSurface *surface,
|
||||
MetaWindow *window);
|
||||
|
Loading…
Reference in New Issue
Block a user