[PATCH weston] compositor-wayland: Port to xdg-shell

Armin Krezović krezovic.armin at gmail.com
Sun Oct 9 13:06:52 UTC 2016


Signed-off-by: Armin Krezović <krezovic.armin at gmail.com>
---
 Makefile.am                    |   8 ++-
 libweston/compositor-wayland.c | 155 ++++++++++++++++++++++++++---------------
 2 files changed, 102 insertions(+), 61 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index c94c211..f75aa46 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -391,9 +391,11 @@ wayland_backend_la_CFLAGS =			\
 	$(CAIRO_CFLAGS)				\
 	$(WAYLAND_COMPOSITOR_CFLAGS)		\
 	$(AM_CFLAGS)
-wayland_backend_la_SOURCES = 			\
-	libweston/compositor-wayland.c		\
-	libweston/compositor-wayland.h		\
+wayland_backend_la_SOURCES = 					\
+	libweston/compositor-wayland.c				\
+	libweston/compositor-wayland.h				\
+	protocol/xdg-shell-unstable-v6-protocol.c		\
+	protocol/xdg-shell-unstable-v6-client-protocol.h	\
 	shared/helpers.h
 nodist_wayland_backend_la_SOURCES =			\
 	protocol/fullscreen-shell-unstable-v1-protocol.c		\
diff --git a/libweston/compositor-wayland.c b/libweston/compositor-wayland.c
index 46fdde1..2c33daf 100644
--- a/libweston/compositor-wayland.c
+++ b/libweston/compositor-wayland.c
@@ -51,6 +51,7 @@
 #include "shared/os-compatibility.h"
 #include "shared/cairo-util.h"
 #include "fullscreen-shell-unstable-v1-client-protocol.h"
+#include "xdg-shell-unstable-v6-client-protocol.h"
 #include "presentation-time-server-protocol.h"
 #include "linux-dmabuf.h"
 #include "windowed-output-api.h"
@@ -65,7 +66,7 @@ struct wayland_backend {
 		struct wl_display *wl_display;
 		struct wl_registry *registry;
 		struct wl_compositor *compositor;
-		struct wl_shell *shell;
+		struct zxdg_shell_v6 *shell;
 		struct zwp_fullscreen_shell_v1 *fshell;
 		struct wl_shm *shm;
 
@@ -97,8 +98,10 @@ struct wayland_output {
 		struct wl_output *output;
 		uint32_t global_id;
 
-		struct wl_shell_surface *shell_surface;
+		struct zxdg_surface_v6 *xdg_surface;
+		struct zxdg_toplevel_v6 *xdg_toplevel;
 		int configure_width, configure_height;
+		bool wait_for_configure;
 	} parent;
 
 	int keyboard_count;
@@ -623,8 +626,11 @@ wayland_output_repaint_pixman(struct weston_output *output_base,
 static void
 wayland_backend_destroy_output_surface(struct wayland_output *output)
 {
-	if (output->parent.shell_surface)
-		wl_shell_surface_destroy(output->parent.shell_surface);
+	if (output->parent.xdg_toplevel)
+		zxdg_toplevel_v6_destroy(output->parent.xdg_toplevel);
+
+	if (output->parent.xdg_surface)
+		zxdg_surface_v6_destroy(output->parent.xdg_surface);
 
 	wl_surface_destroy(output->parent.surface);
 }
@@ -677,8 +683,6 @@ wayland_output_destroy(struct weston_output *base)
 	free(output);
 }
 
-static const struct wl_shell_surface_listener shell_surface_listener;
-
 static int
 wayland_output_init_gl_renderer(struct wayland_output *output)
 {
@@ -838,8 +842,6 @@ wayland_output_set_windowed(struct wayland_output *output)
 
 	wayland_output_resize_surface(output);
 
-	wl_shell_surface_set_toplevel(output->parent.shell_surface);
-
 	return 0;
 }
 
@@ -858,9 +860,8 @@ wayland_output_set_fullscreen(struct wayland_output *output,
 
 	wayland_output_resize_surface(output);
 
-	if (output->parent.shell_surface) {
-		wl_shell_surface_set_fullscreen(output->parent.shell_surface,
-						method, framerate, target);
+	if (output->parent.xdg_toplevel) {
+		zxdg_toplevel_v6_set_fullscreen(output->parent.xdg_toplevel, target);
 	} else if (b->parent.fshell) {
 		zwp_fullscreen_shell_v1_present_surface(b->parent.fshell,
 							output->parent.surface,
@@ -959,7 +960,7 @@ wayland_output_switch_mode(struct weston_output *output_base,
 
 	b = to_wayland_backend(output_base->compositor);
 
-	if (output->parent.shell_surface || !b->parent.fshell)
+	if (output->parent.xdg_surface || !b->parent.fshell)
 		return -1;
 
 	mode = wayland_output_choose_mode(output, mode);
@@ -1031,6 +1032,41 @@ err_output:
 	return -1;
 }
 
+static void
+handle_surface_configure(void *data, struct zxdg_surface_v6 *surface,
+			 uint32_t serial)
+{
+	zxdg_surface_v6_ack_configure(surface, serial);
+}
+
+static const struct zxdg_surface_v6_listener xdg_surface_listener = {
+	handle_surface_configure
+};
+
+static void
+handle_toplevel_configure(void *data, struct zxdg_toplevel_v6 *toplevel,
+			  int32_t width, int32_t height,
+			  struct wl_array *states)
+{
+	struct wayland_output *output = data;
+
+	output->parent.configure_width = width;
+	output->parent.configure_height = height;
+
+	output->parent.wait_for_configure = false;
+	/* FIXME: implement resizing */
+}
+
+static void
+handle_toplevel_close(void *data, struct zxdg_toplevel_v6 *xdg_toplevel)
+{
+}
+
+static const struct zxdg_toplevel_v6_listener xdg_toplevel_listener = {
+	handle_toplevel_configure,
+	handle_toplevel_close,
+};
+
 static int
 wayland_backend_create_output_surface(struct wayland_output *output)
 {
@@ -1046,16 +1082,35 @@ wayland_backend_create_output_surface(struct wayland_output *output)
 	output->parent.draw_initial_frame = 1;
 
 	if (b->parent.shell) {
-		output->parent.shell_surface =
-			wl_shell_get_shell_surface(b->parent.shell,
-						   output->parent.surface);
-		if (!output->parent.shell_surface) {
+		output->parent.xdg_surface =
+			zxdg_shell_v6_get_xdg_surface(b->parent.shell,
+						      output->parent.surface);
+		if (!output->parent.xdg_surface) {
+			wl_surface_destroy(output->parent.surface);
+			return -1;
+		}
+
+		zxdg_surface_v6_add_listener(output->parent.xdg_surface,
+					     &xdg_surface_listener, output);
+
+		output->parent.xdg_toplevel =
+			zxdg_surface_v6_get_toplevel(output->parent.xdg_surface);
+
+		if (!output->parent.xdg_toplevel) {
+			zxdg_surface_v6_destroy(output->parent.xdg_surface);
 			wl_surface_destroy(output->parent.surface);
 			return -1;
 		}
 
-		wl_shell_surface_add_listener(output->parent.shell_surface,
-					      &shell_surface_listener, output);
+		zxdg_toplevel_v6_add_listener(output->parent.xdg_toplevel,
+					      &xdg_toplevel_listener, output);
+
+		wl_surface_commit(output->parent.surface);
+
+		output->parent.wait_for_configure = true;
+
+		while (output->parent.wait_for_configure)
+			wl_display_dispatch(b->parent.wl_display);
 	}
 
 	return 0;
@@ -1098,10 +1153,9 @@ wayland_output_enable(struct weston_output *base)
 					      WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER,
 					      output->mode.refresh, output->parent.output);
 
-		if (output->parent.shell_surface) {
-			wl_shell_surface_set_fullscreen(output->parent.shell_surface,
-							WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER,
-							output->mode.refresh, output->parent.output);
+		if (output->parent.xdg_toplevel) {
+			zxdg_toplevel_v6_set_fullscreen(output->parent.xdg_toplevel,
+							output->parent.output);
 		} else if (b->parent.fshell) {
 			zwp_fullscreen_shell_v1_present_surface(b->parent.fshell,
 								output->parent.surface,
@@ -1291,8 +1345,8 @@ wayland_output_create_fullscreen(struct wayland_backend *b)
 
 	/* What should size be set if conditional is false? */
 	if (b->parent.shell) {
-		wl_shell_surface_set_fullscreen(output->parent.shell_surface,
-						0, 0, NULL);
+		zxdg_toplevel_v6_set_fullscreen(output->parent.xdg_toplevel,
+						NULL);
 		wl_display_roundtrip(b->parent.wl_display);
 
 		width = output->parent.configure_width;
@@ -1315,36 +1369,6 @@ err_surface:
 	return -1;
 }
 
-static void
-shell_surface_ping(void *data, struct wl_shell_surface *shell_surface,
-		   uint32_t serial)
-{
-	wl_shell_surface_pong(shell_surface, serial);
-}
-
-static void
-shell_surface_configure(void *data, struct wl_shell_surface *shell_surface,
-			uint32_t edges, int32_t width, int32_t height)
-{
-	struct wayland_output *output = data;
-
-	output->parent.configure_width = width;
-	output->parent.configure_height = height;
-
-	/* FIXME: implement resizing */
-}
-
-static void
-shell_surface_popup_done(void *data, struct wl_shell_surface *shell_surface)
-{
-}
-
-static const struct wl_shell_surface_listener shell_surface_listener = {
-	shell_surface_ping,
-	shell_surface_configure,
-	shell_surface_popup_done
-};
-
 /* Events received from the wayland-server this compositor is client of: */
 
 /* parent input interface */
@@ -1510,7 +1534,7 @@ input_handle_button(void *data, struct wl_pointer *pointer,
 
 		if (frame_status(input->output->frame) & FRAME_STATUS_MOVE) {
 
-			wl_shell_surface_move(input->output->parent.shell_surface,
+			zxdg_toplevel_v6_move(input->output->parent.xdg_toplevel,
 					      input->parent.seat, serial);
 			frame_status_clear(input->output->frame,
 					   FRAME_STATUS_MOVE);
@@ -1840,7 +1864,7 @@ input_handle_touch_down(void *data, struct wl_touch *wl_touch,
 
 		if (first_touch && (frame_status(output->frame) & FRAME_STATUS_MOVE)) {
 			input->touch_points--;
-			wl_shell_surface_move(output->parent.shell_surface,
+			zxdg_toplevel_v6_move(output->parent.xdg_toplevel,
 					      input->parent.seat, serial);
 			frame_status_clear(output->frame,
 					   FRAME_STATUS_MOVE);
@@ -2169,6 +2193,16 @@ wayland_parent_output_destroy(struct wayland_parent_output *output)
 }
 
 static void
+xdg_shell_ping(void *data, struct zxdg_shell_v6 *shell, uint32_t serial)
+{
+	zxdg_shell_v6_pong(shell, serial);
+}
+
+static const struct zxdg_shell_v6_listener xdg_shell_listener = {
+	xdg_shell_ping,
+};
+
+static void
 registry_handle_global(void *data, struct wl_registry *registry, uint32_t name,
 		       const char *interface, uint32_t version)
 {
@@ -2178,10 +2212,12 @@ registry_handle_global(void *data, struct wl_registry *registry, uint32_t name,
 		b->parent.compositor =
 			wl_registry_bind(registry, name,
 					 &wl_compositor_interface, 1);
-	} else if (strcmp(interface, "wl_shell") == 0) {
+	} else if (strcmp(interface, "zxdg_shell_v6") == 0) {
 		b->parent.shell =
 			wl_registry_bind(registry, name,
-					 &wl_shell_interface, 1);
+					 &zxdg_shell_v6_interface, 1);
+		zxdg_shell_v6_add_listener(b->parent.shell,
+					   &xdg_shell_listener, b);
 	} else if (strcmp(interface, "zwp_fullscreen_shell_v1") == 0) {
 		b->parent.fshell =
 			wl_registry_bind(registry, name,
@@ -2249,6 +2285,9 @@ wayland_destroy(struct weston_compositor *ec)
 
 	weston_compositor_shutdown(ec);
 
+	if (b->parent.shell)
+		zxdg_shell_v6_destroy(b->parent.shell);
+
 	if (b->parent.shm)
 		wl_shm_destroy(b->parent.shm);
 
-- 
2.10.1



More information about the wayland-devel mailing list