[RFC weston 4/6] desktop-shell: Remove xdg_shell and wl_shell protocol bits

Quentin Glidic sardemff7+wayland at sardemff7.net
Sun Jul 17 08:59:21 UTC 2016


From: Quentin Glidic <sardemff7+git at sardemff7.net>

Signed-off-by: Quentin Glidic <sardemff7+git at sardemff7.net>
---
 desktop-shell/shell.c | 954 +-------------------------------------------------
 1 file changed, 14 insertions(+), 940 deletions(-)

diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c
index 0dd492a..d077883 100644
--- a/desktop-shell/shell.c
+++ b/desktop-shell/shell.c
@@ -296,8 +296,15 @@ shell_surface_get_label(struct weston_surface *surface, char *buf, size_t len)
 	if (!shsurf)
 		return snprintf(buf, len, "unidentified window");
 
-	t = shsurf->title;
-	c = shsurf->class;
+	if (weston_surface_is_desktop_surface(surface)) {
+		struct weston_desktop_surface *desktop_surface =
+			weston_surface_get_desktop_surface(surface);
+		t = weston_desktop_surface_get_title(desktop_surface);
+		c = weston_desktop_surface_get_app_id(desktop_surface);
+	} else {
+		t = shsurf->title;
+		c = shsurf->class;
+	}
 
 	return snprintf(buf, len, "%s window%s%s%s%s%s",
 		typestr[shsurf->type],
@@ -1740,41 +1747,6 @@ surface_move(struct shell_surface *shsurf, struct weston_pointer *pointer,
 	return 0;
 }
 
-static void
-common_surface_move(struct wl_resource *resource,
-		    struct wl_resource *seat_resource, uint32_t serial)
-{
-	struct weston_seat *seat = wl_resource_get_user_data(seat_resource);
-	struct weston_pointer *pointer = weston_seat_get_pointer(seat);
-	struct weston_touch *touch = weston_seat_get_touch(seat);
-	struct shell_surface *shsurf = wl_resource_get_user_data(resource);
-	struct weston_surface *surface;
-
-	if (pointer &&
-	    pointer->focus &&
-	    pointer->button_count > 0 &&
-	    pointer->grab_serial == serial) {
-		surface = weston_surface_get_main_surface(pointer->focus->surface);
-		if ((surface == shsurf->surface) &&
-		    (surface_move(shsurf, pointer, true) < 0))
-			wl_resource_post_no_memory(resource);
-	} else if (touch &&
-		   touch->focus &&
-		   touch->grab_serial == serial) {
-		surface = weston_surface_get_main_surface(touch->focus->surface);
-		if ((surface == shsurf->surface) &&
-		    (surface_touch_move(shsurf, touch) < 0))
-			wl_resource_post_no_memory(resource);
-	}
-}
-
-static void
-shell_surface_move(struct wl_client *client, struct wl_resource *resource,
-		   struct wl_resource *seat_resource, uint32_t serial)
-{
-	common_surface_move(resource, seat_resource, serial);
-}
-
 struct weston_resize_grab {
 	struct shell_grab base;
 	uint32_t edges;
@@ -1949,38 +1921,6 @@ surface_resize(struct shell_surface *shsurf,
 	return 0;
 }
 
-static void
-common_surface_resize(struct wl_resource *resource,
-		      struct wl_resource *seat_resource, uint32_t serial,
-		      uint32_t edges)
-{
-	struct weston_seat *seat = wl_resource_get_user_data(seat_resource);
-	struct weston_pointer *pointer = weston_seat_get_pointer(seat);
-	struct shell_surface *shsurf = wl_resource_get_user_data(resource);
-	struct weston_surface *surface;
-
-	if (!pointer ||
-	    pointer->button_count == 0 ||
-	    pointer->grab_serial != serial ||
-	    pointer->focus == NULL)
-		return;
-
-	surface = weston_surface_get_main_surface(pointer->focus->surface);
-	if (surface != shsurf->surface)
-		return;
-
-	if (surface_resize(shsurf, pointer, edges) < 0)
-		wl_resource_post_no_memory(resource);
-}
-
-static void
-shell_surface_resize(struct wl_client *client, struct wl_resource *resource,
-		     struct wl_resource *seat_resource, uint32_t serial,
-		     uint32_t edges)
-{
-	common_surface_resize(resource, seat_resource, serial, edges);
-}
-
 static void
 busy_cursor_grab_focus(struct weston_pointer_grab *base)
 {
@@ -2062,31 +2002,6 @@ set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer)
 	shsurf->grabbed = 0;
 }
 
-static void
-end_busy_cursor(struct weston_compositor *compositor, struct wl_client *client)
-{
-	struct shell_grab *grab;
-	struct weston_seat *seat;
-
-	wl_list_for_each(seat, &compositor->seat_list, link) {
-		struct weston_pointer *pointer = weston_seat_get_pointer(seat);
-
-		if (!pointer)
-			continue;
-
-		grab = (struct shell_grab *) pointer->grab;
-		if (grab->grab.interface == &busy_cursor_grab_interface &&
-		    grab->shsurf->resource &&
-		    wl_resource_get_client(grab->shsurf->resource) == client) {
-			shell_grab_end(grab);
-			free(grab);
-		}
-	}
-}
-
-static void
-handle_shell_client_destroy(struct wl_listener *listener, void *data);
-
 static int
 xdg_ping_timeout_handler(void *data)
 {
@@ -2213,32 +2128,6 @@ handle_keyboard_focus(struct wl_listener *listener, void *data)
 	}
 }
 
-static void
-shell_client_pong(struct shell_client *sc, uint32_t serial)
-{
-	if (sc->ping_serial != serial)
-		return;
-
-	sc->unresponsive = 0;
-	end_busy_cursor(sc->shell->compositor, sc->client);
-
-	if (sc->ping_timer) {
-		wl_event_source_remove(sc->ping_timer);
-		sc->ping_timer = NULL;
-	}
-
-}
-
-static void
-shell_surface_pong(struct wl_client *client,
-		   struct wl_resource *resource, uint32_t serial)
-{
-	struct shell_surface *shsurf = wl_resource_get_user_data(resource);
-	struct shell_client *sc = shsurf->owner;
-
-	shell_client_pong(sc, serial);
-}
-
 static void
 set_title(struct shell_surface *shsurf, const char *title)
 {
@@ -2271,26 +2160,6 @@ set_window_geometry(struct shell_surface *shsurf,
 	shsurf->has_next_geometry = true;
 }
 
-static void
-shell_surface_set_title(struct wl_client *client,
-			struct wl_resource *resource, const char *title)
-{
-	struct shell_surface *shsurf = wl_resource_get_user_data(resource);
-
-	set_title(shsurf, title);
-}
-
-static void
-shell_surface_set_class(struct wl_client *client,
-			struct wl_resource *resource, const char *class)
-{
-	struct shell_surface *shsurf = wl_resource_get_user_data(resource);
-
-	free(shsurf->class);
-	shsurf->class = strdup(class);
-	shsurf->surface->timeline.force_refresh = 1;
-}
-
 static void
 restore_output_mode(struct weston_output *output)
 {
@@ -2468,15 +2337,6 @@ set_toplevel(struct shell_surface *shsurf)
 	 * called from configure. */
 }
 
-static void
-shell_surface_set_toplevel(struct wl_client *client,
-			   struct wl_resource *resource)
-{
-	struct shell_surface *surface = wl_resource_get_user_data(resource);
-
-	set_toplevel(surface);
-}
-
 static void
 set_transient(struct shell_surface *shsurf,
 	      struct weston_surface *parent, int x, int y, uint32_t flags)
@@ -2499,19 +2359,6 @@ set_transient(struct shell_surface *shsurf,
 	 * called from configure. */
 }
 
-static void
-shell_surface_set_transient(struct wl_client *client,
-			    struct wl_resource *resource,
-			    struct wl_resource *parent_resource,
-			    int x, int y, uint32_t flags)
-{
-	struct shell_surface *shsurf = wl_resource_get_user_data(resource);
-	struct weston_surface *parent =
-		wl_resource_get_user_data(parent_resource);
-
-	set_transient(shsurf, parent, x, y, flags);
-}
-
 static void
 set_fullscreen(struct shell_surface *shsurf,
 	       uint32_t method,
@@ -2566,75 +2413,6 @@ unset_fullscreen(struct shell_surface *shsurf)
 	/* Layer is updated in set_surface_type(). */
 }
 
-static void
-shell_surface_set_fullscreen(struct wl_client *client,
-			     struct wl_resource *resource,
-			     uint32_t method,
-			     uint32_t framerate,
-			     struct wl_resource *output_resource)
-{
-	struct shell_surface *shsurf = wl_resource_get_user_data(resource);
-	struct weston_output *output;
-
-	if (shsurf->fullscreen_output == shsurf->output &&
-	    shsurf->fullscreen.type == method &&
-	    shsurf->fullscreen.framerate == framerate) {
-		send_configure_for_surface(shsurf);
-		return;
-	}
-
-	if (output_resource)
-		output = wl_resource_get_user_data(output_resource);
-	else
-		output = NULL;
-
-	shell_surface_set_parent(shsurf, NULL);
-
-	surface_clear_next_states(shsurf);
-	shsurf->next_state.fullscreen = true;
-	shsurf->state_changed = true;
-	set_fullscreen(shsurf, method, framerate, output);
-}
-
-static void
-set_popup(struct shell_surface *shsurf,
-          struct weston_surface *parent,
-          struct weston_seat *seat,
-          uint32_t serial,
-          int32_t x,
-          int32_t y)
-{
-	assert(parent != NULL);
-
-	shsurf->popup.shseat = get_shell_seat(seat);
-	shsurf->popup.serial = serial;
-	shsurf->popup.x = x;
-	shsurf->popup.y = y;
-
-	set_type(shsurf, SHELL_SURFACE_POPUP);
-}
-
-static void
-shell_surface_set_popup(struct wl_client *client,
-			struct wl_resource *resource,
-			struct wl_resource *seat_resource,
-			uint32_t serial,
-			struct wl_resource *parent_resource,
-			int32_t x, int32_t y, uint32_t flags)
-{
-	struct shell_surface *shsurf = wl_resource_get_user_data(resource);
-	struct weston_surface *parent =
-		wl_resource_get_user_data(parent_resource);
-
-	shell_surface_set_parent(shsurf, parent);
-
-	surface_clear_next_states(shsurf);
-	set_popup(shsurf,
-	          parent,
-	          wl_resource_get_user_data(seat_resource),
-	          serial, x, y);
-}
-
 static void
 unset_maximized(struct shell_surface *shsurf)
 {
@@ -2682,30 +2460,6 @@ set_minimized(struct weston_surface *surface)
 	weston_view_damage_below(view);
 }
 
-static void
-shell_surface_set_maximized(struct wl_client *client,
-                            struct wl_resource *resource,
-                            struct wl_resource *output_resource)
-{
-	struct shell_surface *shsurf = wl_resource_get_user_data(resource);
-	struct weston_output *output;
-
-	surface_clear_next_states(shsurf);
-	shsurf->next_state.maximized = true;
-	shsurf->state_changed = true;
-
-	set_type(shsurf, SHELL_SURFACE_TOPLEVEL);
-	shell_surface_set_parent(shsurf, NULL);
-
-	if (output_resource)
-		output = wl_resource_get_user_data(output_resource);
-	else
-		output = NULL;
-
-	shell_surface_set_output(shsurf, output);
-
-	send_configure_for_surface(shsurf);
-}
 
 /* This is only ever called from set_surface_type(), so there’s no need to
  * update layer_links here, since they’ll be updated when we return. */
@@ -3559,19 +3313,6 @@ shell_map_popup(struct shell_surface *shsurf)
 	return 0;
 }
 
-static const struct wl_shell_surface_interface shell_surface_implementation = {
-	shell_surface_pong,
-	shell_surface_move,
-	shell_surface_resize,
-	shell_surface_set_toplevel,
-	shell_surface_set_transient,
-	shell_surface_set_fullscreen,
-	shell_surface_set_popup,
-	shell_surface_set_maximized,
-	shell_surface_set_title,
-	shell_surface_set_class
-};
-
 static void
 destroy_shell_surface(struct shell_surface *shsurf)
 {
@@ -3608,18 +3349,6 @@ destroy_shell_surface(struct shell_surface *shsurf)
 	free(shsurf);
 }
 
-static void
-shell_destroy_shell_surface(struct wl_resource *resource)
-{
-	struct shell_surface *shsurf = wl_resource_get_user_data(resource);
-
-	if (!wl_list_empty(&shsurf->popup.grab_link))
-		remove_popup_grab(shsurf);
-	if (shsurf->resource)
-		wl_list_remove(wl_resource_get_link(shsurf->resource));
-	shsurf->resource = NULL;
-}
-
 static void
 shell_handle_surface_destroy(struct wl_listener *listener, void *data)
 {
@@ -3773,42 +3502,6 @@ create_shell_surface(void *shell, struct weston_surface *surface,
 		     const struct weston_shell_client *client)
 {
 	return create_common_surface(NULL, shell, surface, client);
-}
-
-static void
-shell_get_shell_surface(struct wl_client *client,
-			struct wl_resource *resource,
-			uint32_t id,
-			struct wl_resource *surface_resource)
-{
-	struct weston_surface *surface =
-		wl_resource_get_user_data(surface_resource);
-	struct shell_client *sc = wl_resource_get_user_data(resource);
-	struct desktop_shell *shell = sc->shell;
-	struct shell_surface *shsurf;
-
-	if (weston_surface_set_role(surface, "wl_shell_surface",
-				    resource, WL_SHELL_ERROR_ROLE) < 0)
-		return;
-
-	shsurf = create_common_surface(sc, shell, surface, &shell_client);
-	if (!shsurf) {
-		wl_resource_post_no_memory(surface_resource);
-		return;
-	}
-
-	shsurf->resource =
-		wl_resource_create(client,
-				   &wl_shell_surface_interface, 1, id);
-	if (!shsurf->resource) {
-		wl_resource_post_no_memory(surface_resource);
-	        return;
-	}
-	wl_resource_set_implementation(shsurf->resource,
-				       &shell_surface_implementation,
-				       shsurf, shell_destroy_shell_surface);
-	wl_list_insert(&sc->surface_list,
-		       wl_resource_get_link(shsurf->resource));
 }
 
 static bool
@@ -3816,557 +3509,22 @@ shell_surface_is_wl_shell_surface(struct shell_surface *shsurf)
 {
 	/* A shell surface without a resource is created from xwayland
 	 * and is considered a wl_shell surface for now. */
-
-	return shsurf->resource == NULL ||
-		wl_resource_instance_of(shsurf->resource,
-					&wl_shell_surface_interface,
-					&shell_surface_implementation);
-}
-
-static const struct wl_shell_interface shell_implementation = {
-	shell_get_shell_surface
-};
-
-/****************************
- * xdg-shell implementation */
-
-static void
-xdg_surface_destroy(struct wl_client *client,
-		    struct wl_resource *resource)
-{
-	wl_resource_destroy(resource);
-}
-
-static void
-xdg_surface_set_parent(struct wl_client *client,
-		       struct wl_resource *resource,
-		       struct wl_resource *parent_resource)
-{
-	struct shell_surface *shsurf = wl_resource_get_user_data(resource);
-	struct shell_surface *parent;
-
-	if (parent_resource) {
-		parent = wl_resource_get_user_data(parent_resource);
-		shell_surface_set_parent(shsurf, parent->surface);
-	} else {
-		shell_surface_set_parent(shsurf, NULL);
-	}
-}
-
-static void
-xdg_surface_set_app_id(struct wl_client *client,
-		       struct wl_resource *resource,
-		       const char *app_id)
-{
-	struct shell_surface *shsurf = wl_resource_get_user_data(resource);
-
-	free(shsurf->class);
-	shsurf->class = strdup(app_id);
-	shsurf->surface->timeline.force_refresh = 1;
-}
-
-static void
-xdg_surface_show_window_menu(struct wl_client *client,
-			     struct wl_resource *surface_resource,
-			     struct wl_resource *seat_resource,
-			     uint32_t serial,
-			     int32_t x,
-			     int32_t y)
-{
-	/* TODO */
-}
-
-static void
-xdg_surface_set_title(struct wl_client *client,
-			struct wl_resource *resource, const char *title)
-{
-	struct shell_surface *shsurf = wl_resource_get_user_data(resource);
-
-	set_title(shsurf, title);
-}
-
-static void
-xdg_surface_move(struct wl_client *client, struct wl_resource *resource,
-		 struct wl_resource *seat_resource, uint32_t serial)
-{
-	common_surface_move(resource, seat_resource, serial);
-}
-
-static void
-xdg_surface_resize(struct wl_client *client, struct wl_resource *resource,
-		   struct wl_resource *seat_resource, uint32_t serial,
-		   uint32_t edges)
-{
-	common_surface_resize(resource, seat_resource, serial, edges);
-}
-
-static void
-xdg_surface_ack_configure(struct wl_client *client,
-			  struct wl_resource *resource,
-			  uint32_t serial)
-{
-	struct shell_surface *shsurf = wl_resource_get_user_data(resource);
-
-	if (shsurf->state_requested) {
-		shsurf->next_state = shsurf->requested_state;
-		shsurf->state_changed = true;
-		shsurf->state_requested = false;
-	}
-}
-
-static void
-xdg_surface_set_window_geometry(struct wl_client *client,
-				struct wl_resource *resource,
-				int32_t x,
-				int32_t y,
-				int32_t width,
-				int32_t height)
-{
-	struct shell_surface *shsurf = wl_resource_get_user_data(resource);
-
-	set_window_geometry(shsurf, x, y, width, height);
-}
-
-static void
-xdg_surface_set_maximized(struct wl_client *client,
-			  struct wl_resource *resource)
-{
-	struct shell_surface *shsurf = wl_resource_get_user_data(resource);
-	struct weston_output *output;
-
-	shsurf->state_requested = true;
-	shsurf->requested_state.maximized = true;
-
-	if (!weston_surface_is_mapped(shsurf->surface))
-		output = get_focused_output(shsurf->surface->compositor);
-	else
-		output = shsurf->surface->output;
-
-	shell_surface_set_output(shsurf, output);
- 	send_configure_for_surface(shsurf);
-}
-
-static void
-xdg_surface_unset_maximized(struct wl_client *client,
-			    struct wl_resource *resource)
-{
-	struct shell_surface *shsurf = wl_resource_get_user_data(resource);
-
-	shsurf->state_requested = true;
-	shsurf->requested_state.maximized = false;
-	send_configure_for_surface(shsurf);
-}
-
-static void
-xdg_surface_set_fullscreen(struct wl_client *client,
-			   struct wl_resource *resource,
-			   struct wl_resource *output_resource)
-{
-	struct shell_surface *shsurf = wl_resource_get_user_data(resource);
-	struct weston_output *output;
-
-	shsurf->state_requested = true;
-	shsurf->requested_state.fullscreen = true;
-
-	if (output_resource)
-		output = wl_resource_get_user_data(output_resource);
-	else
-		output = NULL;
-
-	/* handle clients launching in fullscreen */
-	if (output == NULL && !weston_surface_is_mapped(shsurf->surface)) {
-		/* Set the output to the one that has focus currently. */
-		assert(shsurf->surface);
-		output = get_focused_output(shsurf->surface->compositor);
-	}
-
-	shell_surface_set_output(shsurf, output);
-	shsurf->fullscreen_output = shsurf->output;
-
-	send_configure_for_surface(shsurf);
-}
-
-static void
-xdg_surface_unset_fullscreen(struct wl_client *client,
-			     struct wl_resource *resource)
-{
-	struct shell_surface *shsurf = wl_resource_get_user_data(resource);
-
-	shsurf->state_requested = true;
-	shsurf->requested_state.fullscreen = false;
-	send_configure_for_surface(shsurf);
-}
-
-static void
-xdg_surface_set_minimized(struct wl_client *client,
-			    struct wl_resource *resource)
-{
-	struct shell_surface *shsurf = wl_resource_get_user_data(resource);
-
-	if (shsurf->type != SHELL_SURFACE_TOPLEVEL)
-		return;
-
-	 /* apply compositor's own minimization logic (hide) */
-	set_minimized(shsurf->surface);
-}
-
-static const struct xdg_surface_interface xdg_surface_implementation = {
-	xdg_surface_destroy,
-	xdg_surface_set_parent,
-	xdg_surface_set_title,
-	xdg_surface_set_app_id,
-	xdg_surface_show_window_menu,
-	xdg_surface_move,
-	xdg_surface_resize,
-	xdg_surface_ack_configure,
-	xdg_surface_set_window_geometry,
-	xdg_surface_set_maximized,
-	xdg_surface_unset_maximized,
-	xdg_surface_set_fullscreen,
-	xdg_surface_unset_fullscreen,
-	xdg_surface_set_minimized,
-};
-
-static void
-xdg_send_configure(struct weston_surface *surface,
-		   int32_t width, int32_t height)
-{
-	struct shell_surface *shsurf = get_shell_surface(surface);
-	uint32_t *s;
-	struct wl_array states;
-	uint32_t serial;
-
-	assert(shsurf);
-
-	if (!shsurf->resource)
-		return;
-
-	wl_array_init(&states);
-	if (shsurf->requested_state.fullscreen) {
-		s = wl_array_add(&states, sizeof *s);
-		*s = XDG_SURFACE_STATE_FULLSCREEN;
-	} else if (shsurf->requested_state.maximized) {
-		s = wl_array_add(&states, sizeof *s);
-		*s = XDG_SURFACE_STATE_MAXIMIZED;
-	}
-	if (shsurf->resize_edges != 0) {
-		s = wl_array_add(&states, sizeof *s);
-		*s = XDG_SURFACE_STATE_RESIZING;
-	}
-	if (shsurf->focus_count > 0) {
-		s = wl_array_add(&states, sizeof *s);
-		*s = XDG_SURFACE_STATE_ACTIVATED;
-	}
-
-	serial = wl_display_next_serial(shsurf->surface->compositor->wl_display);
-	xdg_surface_send_configure(shsurf->resource, width, height, &states, serial);
-
-	wl_array_release(&states);
-}
-
-static const struct weston_shell_client xdg_client = {
-	xdg_send_configure,
-	NULL
-};
-
-static void
-xdg_shell_destroy(struct wl_client *client,
-		  struct wl_resource *resource)
-{
-	struct shell_client *sc = wl_resource_get_user_data(resource);
-	struct wl_resource *shsurf_resource;
-	struct shell_surface *shsurf;
-
-	wl_resource_for_each(shsurf_resource, &sc->surface_list) {
-		shsurf = wl_resource_get_user_data(shsurf_resource);
-		if (shsurf->owner_resource == resource) {
-			wl_resource_post_error(
-				resource,
-				XDG_SHELL_ERROR_DEFUNCT_SURFACES,
-				"not all child surface objects destroyed");
-			return;
-		}
-	}
-
-	wl_resource_destroy(resource);
-}
-
-static void
-xdg_use_unstable_version(struct wl_client *client,
-			 struct wl_resource *resource,
-			 int32_t version)
-{
-	if (version > 1) {
-		wl_resource_post_error(resource,
-				       1,
-				       "xdg-shell:: version not implemented yet.");
-		return;
-	}
-}
-
-static struct shell_surface *
-create_xdg_surface(struct shell_client *owner, void *shell,
-		   struct weston_surface *surface,
-		   const struct weston_shell_client *client)
-{
-	struct shell_surface *shsurf;
-
-	shsurf = create_common_surface(owner, shell, surface, client);
-	if (!shsurf)
-		return NULL;
-
-	set_type(shsurf, SHELL_SURFACE_TOPLEVEL);
-
-	return shsurf;
+	return false;
 }
 
-static void
-xdg_get_xdg_surface(struct wl_client *client,
-		    struct wl_resource *resource,
-		    uint32_t id,
-		    struct wl_resource *surface_resource)
-{
-	struct weston_surface *surface =
-		wl_resource_get_user_data(surface_resource);
-	struct shell_client *sc = wl_resource_get_user_data(resource);
-	struct desktop_shell *shell = sc->shell;
-	struct shell_surface *shsurf;
-
-	shsurf = get_shell_surface(surface);
-	if (shsurf && shell_surface_is_xdg_surface(shsurf)) {
-		wl_resource_post_error(resource, XDG_SHELL_ERROR_ROLE,
-				       "This wl_surface is already an "
-				       "xdg_surface");
-		return;
-	}
-
-	if (weston_surface_set_role(surface, "xdg_surface",
-				    resource, XDG_SHELL_ERROR_ROLE) < 0)
-		return;
-
-	shsurf = create_xdg_surface(sc, shell, surface, &xdg_client);
-	if (!shsurf) {
-		wl_resource_post_no_memory(surface_resource);
-		return;
-	}
-
-	shsurf->resource =
-		wl_resource_create(client,
-				   &xdg_surface_interface, 1, id);
-	if (!shsurf->resource) {
-		wl_resource_post_no_memory(surface_resource);
-		return;
-	}
-	wl_resource_set_implementation(shsurf->resource,
-				       &xdg_surface_implementation,
-				       shsurf, shell_destroy_shell_surface);
-	shsurf->owner_resource = resource;
-	wl_list_insert(&sc->surface_list,
-		       wl_resource_get_link(shsurf->resource));
-}
 
 static bool
 shell_surface_is_xdg_surface(struct shell_surface *shsurf)
 {
-	if (weston_surface_is_desktop_surface(shsurf->surface))
-		return true;
-	return shsurf->resource &&
-		wl_resource_instance_of(shsurf->resource,
-					&xdg_surface_interface,
-					&xdg_surface_implementation);
-}
-
-/* xdg-popup implementation */
-
-static void
-xdg_popup_destroy(struct wl_client *client,
-		  struct wl_resource *resource)
-{
-	wl_resource_destroy(resource);
-}
-
-static const struct xdg_popup_interface xdg_popup_implementation = {
-	xdg_popup_destroy,
-};
-
-static void
-xdg_popup_send_configure(struct weston_surface *surface,
-			 int32_t width, int32_t height)
-{
-}
-
-static const struct weston_shell_client xdg_popup_client = {
-	xdg_popup_send_configure,
-	NULL
-};
-
-static struct shell_surface *
-create_xdg_popup(struct shell_client *owner, void *shell,
-		 struct weston_surface *surface,
-		 const struct weston_shell_client *client,
-		 struct weston_surface *parent,
-		 struct shell_seat *seat,
-		 uint32_t serial,
-		 int32_t x, int32_t y)
-{
-	struct shell_surface *shsurf;
-
-	shsurf = create_common_surface(owner, shell, surface, client);
-	if (!shsurf)
-		return NULL;
-
-	set_type(shsurf, SHELL_SURFACE_POPUP);
-	shsurf->popup.shseat = seat;
-	shsurf->popup.serial = serial;
-	shsurf->popup.x = x;
-	shsurf->popup.y = y;
-	shell_surface_set_parent(shsurf, parent);
-
-	return shsurf;
-}
-
-static void
-xdg_get_xdg_popup(struct wl_client *client,
-		  struct wl_resource *resource,
-		  uint32_t id,
-		  struct wl_resource *surface_resource,
-		  struct wl_resource *parent_resource,
-		  struct wl_resource *seat_resource,
-		  uint32_t serial,
-		  int32_t x, int32_t y)
-{
-	struct weston_surface *surface =
-		wl_resource_get_user_data(surface_resource);
-	struct shell_client *sc = wl_resource_get_user_data(resource);
-	struct desktop_shell *shell = sc->shell;
-	struct shell_surface *shsurf;
-	struct shell_surface *parent_shsurf;
-	struct weston_surface *parent;
-	struct shell_seat *seat;
-
-	shsurf = get_shell_surface(surface);
-	if (shsurf && shell_surface_is_xdg_popup(shsurf)) {
-		wl_resource_post_error(resource, XDG_SHELL_ERROR_ROLE,
-				       "This wl_surface is already an "
-				       "xdg_popup");
-		return;
-	}
-
-	if (weston_surface_set_role(surface, "xdg_popup",
-				    resource, XDG_SHELL_ERROR_ROLE) < 0)
-		return;
-
-	if (!parent_resource) {
-		wl_resource_post_error(surface_resource,
-				       WL_DISPLAY_ERROR_INVALID_OBJECT,
-				       "xdg_shell::get_xdg_popup requires a parent shell surface");
-		return;
-	}
-
-	parent = wl_resource_get_user_data(parent_resource);
-	seat = get_shell_seat(wl_resource_get_user_data(seat_resource));
-
-	/* Verify that we are creating the top most popup when mapping,
-	 * as it's not until then we know whether it was mapped as most
-	 * top level or not. */
-
-	parent_shsurf = get_shell_surface(parent);
-	if (!parent_shsurf ||
-	    (!shell_surface_is_xdg_popup(parent_shsurf) &&
-	     !shell_surface_is_xdg_surface(parent_shsurf))) {
-		wl_resource_post_error(resource,
-				       XDG_SHELL_ERROR_INVALID_POPUP_PARENT,
-				       "xdg_popup parent was invalid");
-		return;
-	}
-
-	shsurf = create_xdg_popup(sc, shell, surface, &xdg_popup_client,
-				  parent, seat, serial, x, y);
-	if (!shsurf) {
-		wl_resource_post_no_memory(surface_resource);
-		return;
-	}
-
-	shsurf->resource =
-		wl_resource_create(client,
-				   &xdg_popup_interface, 1, id);
-	if (!shsurf->resource) {
-		wl_resource_post_no_memory(surface_resource);
-		return;
-	}
-	wl_resource_set_implementation(shsurf->resource,
-				       &xdg_popup_implementation,
-				       shsurf, shell_destroy_shell_surface);
-	shsurf->owner_resource = resource;
-	wl_list_insert(&sc->surface_list,
-		       wl_resource_get_link(shsurf->resource));
-}
-
-static void
-xdg_pong(struct wl_client *client,
-	 struct wl_resource *resource, uint32_t serial)
-{
-	struct shell_client *sc = wl_resource_get_user_data(resource);
-
-	shell_client_pong(sc, serial);
+	return weston_surface_is_desktop_surface(shsurf->surface);
 }
 
 static bool
 shell_surface_is_xdg_popup(struct shell_surface *shsurf)
 {
-	return (shsurf->resource &&
-		wl_resource_instance_of(shsurf->resource,
-					&xdg_popup_interface,
-					&xdg_popup_implementation));
-}
-
-static const struct xdg_shell_interface xdg_implementation = {
-	xdg_shell_destroy,
-	xdg_use_unstable_version,
-	xdg_get_xdg_surface,
-	xdg_get_xdg_popup,
-	xdg_pong
-};
-
-static int
-xdg_shell_unversioned_dispatch(const void *implementation,
-			       void *_target, uint32_t opcode,
-			       const struct wl_message *message,
-			       union wl_argument *args)
-{
-	struct wl_resource *resource = _target;
-	struct shell_client *sc = wl_resource_get_user_data(resource);
-
-	if (opcode != 1 /* XDG_SHELL_USE_UNSTABLE_VERSION */) {
-		wl_resource_post_error(resource,
-				       WL_DISPLAY_ERROR_INVALID_OBJECT,
-				       "must call use_unstable_version first");
-		return 0;
-	}
-
-#define XDG_SERVER_VERSION 5
-
-	static_assert(XDG_SERVER_VERSION == XDG_SHELL_VERSION_CURRENT,
-		      "shell implementation doesn't match protocol version");
-
-	if (args[0].i != XDG_SERVER_VERSION) {
-		wl_resource_post_error(resource,
-				       WL_DISPLAY_ERROR_INVALID_OBJECT,
-				       "incompatible version, server is %d "
-				       "client wants %d",
-				       XDG_SERVER_VERSION, args[0].i);
-		return 0;
-	}
-
-	wl_resource_set_implementation(resource, &xdg_implementation,
-				       sc, NULL);
-
-	return 1;
+	return false;
 }
 
-/* end of xdg-shell implementation */
-/***********************************/
-
 /*
  * libweston-desktop
  */
@@ -6095,84 +5253,6 @@ launch_desktop_shell_process(void *data)
 				       &shell->child.client_destroy_listener);
 }
 
-static void
-handle_shell_client_destroy(struct wl_listener *listener, void *data)
-{
-	struct shell_client *sc =
-		container_of(listener, struct shell_client, destroy_listener);
-	struct wl_resource *shsurf_resource;
-	struct shell_surface *shsurf;
-
-	if (sc->ping_timer)
-		wl_event_source_remove(sc->ping_timer);
-
-	/* Since we're about to free shell_client, we remove it from the
-	 * head of the surface list so we don't use that freed list node
-	 * during surface clean up later on.
-	 */
-	wl_resource_for_each(shsurf_resource, &sc->surface_list) {
-		shsurf = wl_resource_get_user_data(shsurf_resource);
-		shsurf->owner = NULL;
-	}
-	wl_list_remove(&sc->surface_list);
-
-	free(sc);
-}
-
-static struct shell_client *
-shell_client_create(struct wl_client *client, struct desktop_shell *shell,
-		    const struct wl_interface *interface, uint32_t id)
-{
-	struct shell_client *sc;
-
-	sc = zalloc(sizeof *sc);
-	if (sc == NULL) {
-		wl_client_post_no_memory(client);
-		return NULL;
-	}
-
-	sc->resource = wl_resource_create(client, interface, 1, id);
-	if (sc->resource == NULL) {
-		free(sc);
-		wl_client_post_no_memory(client);
-		return NULL;
-	}
-
-	sc->client = client;
-	sc->shell = shell;
-	sc->destroy_listener.notify = handle_shell_client_destroy;
-	wl_client_add_destroy_listener(client, &sc->destroy_listener);
-	wl_list_init(&sc->surface_list);
-
-	return sc;
-}
-
-static void
-bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
-{
-	struct desktop_shell *shell = data;
-	struct shell_client *sc;
-
-	sc = shell_client_create(client, shell, &wl_shell_interface, id);
-	if (sc)
-		wl_resource_set_implementation(sc->resource,
-					       &shell_implementation,
-					       sc, NULL);
-}
-
-static void
-bind_xdg_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
-{
-	struct desktop_shell *shell = data;
-	struct shell_client *sc;
-
-	sc = shell_client_create(client, shell, &xdg_shell_interface, id);
-	if (sc)
-		wl_resource_set_dispatcher(sc->resource,
-					   xdg_shell_unversioned_dispatch,
-					   NULL, sc, NULL);
-}
-
 static void
 unbind_desktop_shell(struct wl_resource *resource)
 {
@@ -6936,15 +6016,9 @@ module_init(struct weston_compositor *ec,
 	shell->workspaces.animation.frame = animate_workspace_change_frame;
 
 	shell->desktop = weston_desktop_create(ec, &shell_desktop_api, shell);
-	if (!shell->desktop) {
-		if (wl_global_create(ec->wl_display, &wl_shell_interface, 1,
-					  shell, bind_shell) == NULL)
-			return -1;
+	if (!shell->desktop)
+		return -1;
 
-		if (wl_global_create(ec->wl_display, &xdg_shell_interface, 1,
-					  shell, bind_xdg_shell) == NULL)
-			return -1;
-	}
 	if (wl_global_create(ec->wl_display,
 			     &weston_desktop_shell_interface, 1,
 			     shell, bind_desktop_shell) == NULL)
-- 
2.9.0



More information about the wayland-devel mailing list