[PATCH 6/6] desktop-shell: resize background, panel and lock surface on output resize

David Fort rdp.effort at gmail.com
Tue Apr 26 21:34:08 UTC 2016


When an output is resized (permanent mode switch), we should also notify the
shell client so that the panel, background and the lock screen fits to the
new screen dimensions.

Signed-off-by: David Fort <contact at hardening-consulting.com>
---
 desktop-shell/shell.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++
 desktop-shell/shell.h |  7 ++++++
 2 files changed, 67 insertions(+)

diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c
index cd269a8..99dcd3e 100644
--- a/desktop-shell/shell.c
+++ b/desktop-shell/shell.c
@@ -4375,6 +4375,16 @@ background_configure(struct weston_surface *es, int32_t sx, int32_t sy)
 }
 
 static void
+handle_background_surface_destroy(struct wl_listener *listener, void *data)
+{
+	struct desktop_shell *shell =
+	    container_of(listener, struct desktop_shell, background_surface_listener);
+
+	weston_log("background surface gone\n");
+	shell->background_surface = NULL;
+}
+
+static void
 desktop_shell_set_background(struct wl_client *client,
 			     struct wl_resource *resource,
 			     struct wl_resource *output_resource,
@@ -4405,6 +4415,10 @@ desktop_shell_set_background(struct wl_client *client,
 					    surface_resource,
 					    surface->output->width,
 					    surface->output->height);
+	shell->background_surface = surface;
+
+	shell->background_surface_listener.notify = handle_background_surface_destroy;
+	wl_signal_add(&surface->destroy_signal, &shell->background_surface_listener);
 }
 
 static int
@@ -4426,6 +4440,17 @@ panel_configure(struct weston_surface *es, int32_t sx, int32_t sy)
 }
 
 static void
+handle_panel_surface_destroy(struct wl_listener *listener, void *data)
+{
+	struct desktop_shell *shell =
+	    container_of(listener, struct desktop_shell, panel_surface_listener);
+
+	weston_log("panel surface gone\n");
+	shell->panel_surface = NULL;
+}
+
+
+static void
 desktop_shell_set_panel(struct wl_client *client,
 			struct wl_resource *resource,
 			struct wl_resource *output_resource,
@@ -4456,6 +4481,10 @@ desktop_shell_set_panel(struct wl_client *client,
 					    surface_resource,
 					    surface->output->width,
 					    surface->output->height);
+
+	shell->panel_surface_listener.notify = handle_panel_surface_destroy;
+	wl_signal_add(&surface->destroy_signal, &shell->panel_surface_listener);
+	shell->panel_surface = surface;
 }
 
 static int
@@ -6368,11 +6397,40 @@ handle_output_destroy(struct wl_listener *listener, void *data)
 	shell_for_each_layer(shell, shell_output_destroy_move_layer, output);
 
 	wl_list_remove(&output_listener->destroy_listener.link);
+	wl_list_remove(&output_listener->resized_listener.link);
 	wl_list_remove(&output_listener->link);
 	free(output_listener);
 }
 
 static void
+shell_resize_surface_to_output(struct desktop_shell *shell,
+				struct weston_surface *surface,
+				const struct weston_output *output)
+{
+	if (!surface)
+		return;
+
+	weston_desktop_shell_send_configure(shell->child.desktop_shell, 0,
+					surface->resource,
+					output->width,
+					output->height);
+}
+
+
+static void
+handle_output_resized(struct wl_listener *listener, void *data)
+{
+	struct shell_output *output_listener =
+		container_of(listener, struct shell_output, resized_listener);
+	struct weston_output *output = output_listener->output;
+	struct desktop_shell *shell = output_listener->shell;
+
+	shell_resize_surface_to_output(shell, shell->background_surface, output);
+	shell_resize_surface_to_output(shell, shell->panel_surface, output);
+	shell_resize_surface_to_output(shell, shell->lock_surface, output);
+}
+
+static void
 create_shell_output(struct desktop_shell *shell,
 					struct weston_output *output)
 {
@@ -6387,6 +6445,8 @@ create_shell_output(struct desktop_shell *shell,
 	shell_output->destroy_listener.notify = handle_output_destroy;
 	wl_signal_add(&output->destroy_signal,
 		      &shell_output->destroy_listener);
+	shell_output->resized_listener.notify = handle_output_resized;
+	wl_signal_add(&output->compositor->output_resized_signal, &shell_output->resized_listener);
 	wl_list_insert(shell->output_list.prev, &shell_output->link);
 }
 
diff --git a/desktop-shell/shell.h b/desktop-shell/shell.h
index b430fa2..88e8155 100644
--- a/desktop-shell/shell.h
+++ b/desktop-shell/shell.h
@@ -112,6 +112,7 @@ struct shell_output {
 	struct desktop_shell  *shell;
 	struct weston_output  *output;
 	struct exposay_output eoutput;
+	struct wl_listener    resized_listener;
 	struct wl_listener    destroy_listener;
 	struct wl_list        link;
 };
@@ -156,6 +157,12 @@ struct desktop_shell {
 		pixman_box32_t cursor_rectangle;
 	} text_input;
 
+	struct weston_surface *panel_surface;
+	struct wl_listener panel_surface_listener;
+
+	struct weston_surface *background_surface;
+	struct wl_listener background_surface_listener;
+
 	struct weston_surface *lock_surface;
 	struct wl_listener lock_surface_listener;
 
-- 
1.9.1



More information about the wayland-devel mailing list