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:
Jonas Ådahl 2015-08-28 12:15:21 +08:00
parent 0aa4c4d43e
commit 94513726de
4 changed files with 58 additions and 44 deletions

View File

@ -537,11 +537,14 @@ data_device_start_drag (struct wl_client *client,
drag_source = wl_resource_get_user_data (source_resource); drag_source = wl_resource_get_user_data (source_resource);
if (icon_resource && if (icon_resource &&
meta_wayland_surface_set_role (icon_surface, !meta_wayland_surface_assign_role (icon_surface,
META_WAYLAND_SURFACE_ROLE_DND, META_WAYLAND_SURFACE_ROLE_DND))
resource, {
WL_DATA_DEVICE_ERROR_ROLE) != 0) wl_resource_post_error (resource, WL_DATA_DEVICE_ERROR_ROLE,
return; "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_pointer_set_focus (&seat->pointer, NULL);
meta_wayland_data_device_start_drag (data_device, client, meta_wayland_data_device_start_drag (data_device, client,

View File

@ -776,11 +776,14 @@ pointer_set_cursor (struct wl_client *client,
if (surface) if (surface)
{ {
if (meta_wayland_surface_set_role (surface, if (!meta_wayland_surface_assign_role (surface,
META_WAYLAND_SURFACE_ROLE_CURSOR, META_WAYLAND_SURFACE_ROLE_CURSOR))
resource, {
WL_POINTER_ERROR_ROLE) != 0) wl_resource_post_error (resource, WL_POINTER_ERROR_ROLE,
return; "wl_surface@%d already has a different role",
wl_resource_get_id (surface_resource));
return;
}
} }
pointer->hotspot_x = x; pointer->hotspot_x = x;

View File

@ -72,24 +72,19 @@ GType meta_wayland_surface_get_type (void) G_GNUC_CONST;
G_DEFINE_TYPE (MetaWaylandSurface, meta_wayland_surface, G_TYPE_OBJECT); G_DEFINE_TYPE (MetaWaylandSurface, meta_wayland_surface, G_TYPE_OBJECT);
int gboolean
meta_wayland_surface_set_role (MetaWaylandSurface *surface, meta_wayland_surface_assign_role (MetaWaylandSurface *surface,
MetaWaylandSurfaceRole role, MetaWaylandSurfaceRole role)
struct wl_resource *error_resource,
uint32_t error_code)
{ {
if (surface->role == META_WAYLAND_SURFACE_ROLE_NONE || if (surface->role == META_WAYLAND_SURFACE_ROLE_NONE ||
surface->role == role) surface->role == role)
{ {
surface->role = role; surface->role = role;
return 0; return TRUE;
} }
else else
{ {
wl_resource_post_error (error_resource, error_code, return FALSE;
"wl_surface@%d already has a different role",
wl_resource_get_id (surface->resource));
return -1;
} }
} }
@ -1283,11 +1278,14 @@ xdg_shell_get_xdg_surface (struct wl_client *client,
return; return;
} }
if (meta_wayland_surface_set_role (surface, if (!meta_wayland_surface_assign_role (surface,
META_WAYLAND_SURFACE_ROLE_XDG_SURFACE, META_WAYLAND_SURFACE_ROLE_XDG_SURFACE))
surface_resource, {
XDG_SHELL_ERROR_ROLE) != 0) wl_resource_post_error (resource, XDG_SHELL_ERROR_ROLE,
return; "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); 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); 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; return;
} }
if (meta_wayland_surface_set_role (surface, if (!meta_wayland_surface_assign_role (surface,
META_WAYLAND_SURFACE_ROLE_XDG_POPUP, META_WAYLAND_SURFACE_ROLE_XDG_POPUP))
surface_resource, {
XDG_SHELL_ERROR_ROLE) != 0) wl_resource_post_error (resource, XDG_SHELL_ERROR_ROLE,
return; "wl_surface@%d already has a different role",
wl_resource_get_id (surface->resource));
return;
}
if (parent_surf == NULL || if (parent_surf == NULL ||
parent_surf->window == NULL || parent_surf->window == NULL ||
@ -1731,11 +1732,14 @@ wl_shell_get_shell_surface (struct wl_client *client,
return; return;
} }
if (meta_wayland_surface_set_role (surface, if (!meta_wayland_surface_assign_role (surface,
META_WAYLAND_SURFACE_ROLE_WL_SHELL_SURFACE, META_WAYLAND_SURFACE_ROLE_WL_SHELL_SURFACE))
surface_resource, {
WL_SHELL_ERROR_ROLE) != 0) wl_resource_post_error (resource, WL_SHELL_ERROR_ROLE,
return; "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); 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); 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; return;
} }
if (meta_wayland_surface_set_role (surface, if (!meta_wayland_surface_assign_role (surface,
META_WAYLAND_SURFACE_ROLE_SUBSURFACE, META_WAYLAND_SURFACE_ROLE_SUBSURFACE))
surface_resource, {
WL_SHELL_ERROR_ROLE) != 0) /* FIXME: There is no subcompositor "role" error yet, so lets just use something
return; * 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); 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); wl_resource_set_implementation (surface->wl_subsurface, &meta_wayland_wl_subsurface_interface, surface, wl_subsurface_destructor);

View File

@ -174,10 +174,8 @@ MetaWaylandSurface *meta_wayland_surface_create (MetaWaylandCompositor *composit
struct wl_resource *compositor_resource, struct wl_resource *compositor_resource,
guint32 id); guint32 id);
int meta_wayland_surface_set_role (MetaWaylandSurface *surface, gboolean meta_wayland_surface_assign_role (MetaWaylandSurface *surface,
MetaWaylandSurfaceRole role, MetaWaylandSurfaceRole role);
struct wl_resource *error_resource,
uint32_t error_code);
void meta_wayland_surface_set_window (MetaWaylandSurface *surface, void meta_wayland_surface_set_window (MetaWaylandSurface *surface,
MetaWindow *window); MetaWindow *window);