summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Ådahl <jadahl@gmail.com>2015-08-28 12:15:21 +0800
committerJonas Ådahl <jadahl@gmail.com>2015-09-07 17:41:14 +0800
commit94513726dec6770d5109569fdd9f567f2ae18757 (patch)
treec374ed155201f6af7c6f49ff058751bf33219697
parent0aa4c4d43e356d706bb4517bbb5c2626c29f0234 (diff)
downloadmutter-94513726dec6770d5109569fdd9f567f2ae18757.tar.gz
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
-rw-r--r--src/wayland/meta-wayland-data-device.c13
-rw-r--r--src/wayland/meta-wayland-pointer.c13
-rw-r--r--src/wayland/meta-wayland-surface.c70
-rw-r--r--src/wayland/meta-wayland-surface.h6
4 files changed, 58 insertions, 44 deletions
diff --git a/src/wayland/meta-wayland-data-device.c b/src/wayland/meta-wayland-data-device.c
index 099f6c503..3771d1996 100644
--- a/src/wayland/meta-wayland-data-device.c
+++ b/src/wayland/meta-wayland-data-device.c
@@ -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,
diff --git a/src/wayland/meta-wayland-pointer.c b/src/wayland/meta-wayland-pointer.c
index 385a2985c..f1e4d2f05 100644
--- a/src/wayland/meta-wayland-pointer.c
+++ b/src/wayland/meta-wayland-pointer.c
@@ -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;
diff --git a/src/wayland/meta-wayland-surface.c b/src/wayland/meta-wayland-surface.c
index 2a9df0a50..369d01d84 100644
--- a/src/wayland/meta-wayland-surface.c
+++ b/src/wayland/meta-wayland-surface.c
@@ -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);
diff --git a/src/wayland/meta-wayland-surface.h b/src/wayland/meta-wayland-surface.h
index 25debefe5..7efb65f42 100644
--- a/src/wayland/meta-wayland-surface.h
+++ b/src/wayland/meta-wayland-surface.h
@@ -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);