[RFC weston 3/6] desktop-shell: Rough port to libweston-desktop

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


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

Signed-off-by: Quentin Glidic <sardemff7+git at sardemff7.net>
---
 Makefile.am           |   2 +-
 desktop-shell/shell.c | 181 ++++++++++++++++++++++++++++++++++++++++++++++++--
 desktop-shell/shell.h |   2 +
 3 files changed, 177 insertions(+), 8 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 0edc605..59d22f5 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -877,7 +877,7 @@ desktop_shell_la_CPPFLAGS =			\
 	-DIN_WESTON
 
 desktop_shell_la_LDFLAGS = -module -avoid-version
-desktop_shell_la_LIBADD = $(COMPOSITOR_LIBS) libshared.la
+desktop_shell_la_LIBADD = libweston-desktop.la $(COMPOSITOR_LIBS) libshared.la
 desktop_shell_la_CFLAGS = $(AM_CFLAGS) $(COMPOSITOR_CFLAGS)
 desktop_shell_la_SOURCES =				\
 	desktop-shell/shell.h				\
diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c
index c72f801..0dd492a 100644
--- a/desktop-shell/shell.c
+++ b/desktop-shell/shell.c
@@ -41,6 +41,7 @@
 #include "shared/config-parser.h"
 #include "shared/helpers.h"
 #include "xdg-shell-unstable-v5-server-protocol.h"
+#include "libweston-desktop/libweston-desktop.h"
 
 #define DEFAULT_NUM_WORKSPACES 1
 #define DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH 200
@@ -111,6 +112,7 @@ struct shell_surface {
 	struct shell_client *owner;
 	struct wl_resource *owner_resource;
 
+	struct weston_desktop_surface *desktop_surface;
 	struct weston_surface *surface;
 	struct weston_view *view;
 	int32_t last_width, last_height;
@@ -2354,6 +2356,13 @@ shell_surface_update_child_surface_layers (struct shell_surface *shsurf)
 	struct shell_surface *child;
 	struct weston_layer_entry *prev;
 
+	if (weston_surface_is_desktop_surface(shsurf->surface)) {
+		struct weston_desktop_surface* desktop_surface =
+			weston_surface_get_desktop_surface(shsurf->surface);
+		weston_desktop_surface_update_layer(desktop_surface);
+		return;
+	}
+
 	/* Move the child layers to the same workspace as shsurf. They will be
 	 * stacked above shsurf. */
 	wl_list_for_each_reverse(child, &shsurf->children_list, children_link) {
@@ -3677,6 +3686,13 @@ shell_surface_configure(struct weston_surface *, int32_t, int32_t);
 struct shell_surface *
 get_shell_surface(struct weston_surface *surface)
 {
+	if (weston_surface_is_desktop_surface(surface)) {
+		struct weston_desktop_surface *desktop_surface =
+			weston_surface_get_desktop_surface(surface);
+		return weston_desktop_surface_get_user_data(desktop_surface);
+	}
+
+
 	if (surface->configure == shell_surface_configure)
 		return surface->configure_private;
 	else
@@ -4152,6 +4168,8 @@ xdg_get_xdg_surface(struct wl_client *client,
 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,
@@ -4349,6 +4367,153 @@ xdg_shell_unversioned_dispatch(const void *implementation,
 /* end of xdg-shell implementation */
 /***********************************/
 
+/*
+ * libweston-desktop
+ */
+
+static void
+desktop_surface_configure(struct weston_surface *surface, int32_t width, int32_t height)
+{
+	struct weston_desktop_surface *desktop_surface =
+		weston_surface_get_desktop_surface(surface);
+	struct shell_surface *shsurf =
+		weston_desktop_surface_get_user_data(desktop_surface);
+
+	weston_desktop_surface_set_activated(desktop_surface, shsurf->focus_count > 0);
+	if (shsurf->state_requested) {
+		weston_desktop_surface_set_maximized(desktop_surface,
+						     shsurf->requested_state.maximized);
+		weston_desktop_surface_set_fullscreen(desktop_surface,
+						      shsurf->requested_state.fullscreen);
+	}
+	weston_desktop_surface_set_size(desktop_surface, width, height);
+}
+
+static const struct weston_shell_client desktop_surface_client = {
+	desktop_surface_configure,
+	NULL
+};
+
+static void
+desktop_surface_new(struct weston_desktop_surface *desktop_surface, void *shell)
+{
+	weston_log("NEW \\o/\n");
+	struct weston_surface *surface =
+		weston_desktop_surface_get_surface(desktop_surface);
+	struct shell_surface *shsurf;
+
+	void *one = surface->configure;
+	void *two = surface->configure_private;
+	surface->configure = NULL;
+	surface->configure_private = NULL;
+
+	shsurf = create_common_surface(NULL, shell, surface,
+				       &desktop_surface_client);
+	set_type(shsurf, SHELL_SURFACE_TOPLEVEL);
+
+	weston_view_destroy(shsurf->view);
+	shsurf->view = weston_desktop_surface_get_view(desktop_surface);
+	surface->configure = one;
+	surface->configure_private = two;
+	wl_list_remove(&shsurf->surface_destroy_listener.link);
+	wl_list_init(&shsurf->surface_destroy_listener.link);
+
+	weston_desktop_surface_set_user_data(desktop_surface, shsurf);
+}
+
+static void
+desktop_surface_free(struct weston_desktop_surface *desktop_surface, void *shell)
+{
+	weston_log("FREE \\o/\n");
+	struct shell_surface *shsurf =
+		weston_desktop_surface_get_user_data(desktop_surface);
+	struct weston_surface *surface =
+		weston_desktop_surface_get_surface(desktop_surface);
+	void *one = surface->configure;
+	destroy_shell_surface(shsurf);
+	surface->configure = one;
+}
+
+static void
+desktop_surface_configured(struct weston_desktop_surface *desktop_surface, void *shell)
+{
+	weston_log("CONFIGURED \\o/\n");
+	struct weston_surface *surface =
+		weston_desktop_surface_get_surface(desktop_surface);
+
+	shell_surface_configure(surface, 0, 0);
+}
+
+static void
+desktop_surface_ask_fullscreen(struct weston_desktop_surface *desktop_surface, bool fullscreen, void *shell)
+{
+	struct shell_surface *shsurf =
+		weston_desktop_surface_get_user_data(desktop_surface);
+
+	shsurf->state_requested = true;
+	shsurf->requested_state.maximized = fullscreen;
+	if (fullscreen) {
+		struct weston_output *output = NULL;
+
+		/* handle clients launching in fullscreen */
+		if (!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
+desktop_surface_ask_maximized(struct weston_desktop_surface *desktop_surface, bool maximized, void *shell)
+{
+	struct shell_surface *shsurf =
+		weston_desktop_surface_get_user_data(desktop_surface);
+
+	shsurf->state_requested = true;
+	shsurf->requested_state.maximized = maximized;
+	if (maximized) {
+		struct weston_output *output;
+
+		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
+desktop_surface_ask_minimized(struct weston_desktop_surface *desktop_surface, void *shell)
+{
+	struct shell_surface *shsurf =
+		weston_desktop_surface_get_user_data(desktop_surface);
+
+	 /* apply compositor's own minimization logic (hide) */
+	set_minimized(shsurf->surface);
+}
+
+static const struct weston_desktop_api shell_desktop_api = {
+	.struct_size = sizeof(struct weston_desktop_api),
+	.surface_new = desktop_surface_new,
+	.surface_free = desktop_surface_free,
+	.configured = desktop_surface_configured,
+	.ask_fullscreen = desktop_surface_ask_fullscreen,
+	.ask_maximized = desktop_surface_ask_maximized,
+	.ask_minimized = desktop_surface_ask_minimized,
+};
+
+/* ************************ *
+ * end of libweston-desktop *
+ * ************************ */
 static void
 shell_fade(struct desktop_shell *shell, enum fade_type type);
 
@@ -6770,14 +6935,16 @@ module_init(struct weston_compositor *ec,
 	wl_list_init(&shell->workspaces.animation.link);
 	shell->workspaces.animation.frame = animate_workspace_change_frame;
 
-	if (wl_global_create(ec->wl_display, &wl_shell_interface, 1,
-				  shell, bind_shell) == NULL)
-		return -1;
-
-	if (wl_global_create(ec->wl_display, &xdg_shell_interface, 1,
-				  shell, bind_xdg_shell) == NULL)
-		return -1;
+	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 (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)
diff --git a/desktop-shell/shell.h b/desktop-shell/shell.h
index a5fe194..c956824 100644
--- a/desktop-shell/shell.h
+++ b/desktop-shell/shell.h
@@ -122,8 +122,10 @@ struct shell_output {
 	struct wl_listener background_surface_listener;
 };
 
+struct weston_desktop;
 struct desktop_shell {
 	struct weston_compositor *compositor;
+	struct weston_desktop *desktop;
 
 	struct wl_listener idle_listener;
 	struct wl_listener wake_listener;
-- 
2.9.0



More information about the wayland-devel mailing list