[PATCH 09/10] desktop-shell: Invalidate saved position when output is destroyed

Ander Conselvan de Oliveira conselvan2 at gmail.com
Fri Dec 13 12:10:57 PST 2013


From: "Zhang, Xiong Y" <xiong.y.zhang at intel.com>

If the saved position for a fullscreen or maximized output view is in an
output that has been unplugged, the coordinates don't make sense
anymore. In that case, invalidate them and use the initial position
algorithm when changing them back to the basic state.

Signed-off-by: Zhang, Xiong Y <xiong.y.zhang at intel.com>
Signed-off-by: Ander Conselvan de Oliveira <ander.conselvan.de.oliveira at intel.com>
---
 desktop-shell/shell.c |   32 +++++++++++++++++++++++++++-----
 src/compositor.c      |    3 +++
 src/compositor.h      |    6 ++++++
 3 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c
index 9fbac00..f70b310 100644
--- a/desktop-shell/shell.c
+++ b/desktop-shell/shell.c
@@ -2206,6 +2206,10 @@ set_fullscreen(struct shell_surface *shsurf,
 }
 
 static void
+weston_view_set_initial_position(struct weston_view *view,
+				 struct desktop_shell *shell);
+
+static void
 unset_fullscreen(struct shell_surface *shsurf)
 {
 	/* Unset the fullscreen output, driver configuration and transforms. */
@@ -2225,8 +2229,12 @@ unset_fullscreen(struct shell_surface *shsurf)
 		weston_surface_destroy(shsurf->fullscreen.black_view->surface);
 	shsurf->fullscreen.black_view = NULL;
 
-	weston_view_set_position(shsurf->view,
-				 shsurf->saved_x, shsurf->saved_y);
+	if (shsurf->saved_position_valid)
+		weston_view_set_position(shsurf->view,
+					 shsurf->saved_x, shsurf->saved_y);
+	else
+		weston_view_set_initial_position(shsurf->view, shsurf->shell);
+
 	if (shsurf->saved_rotation_valid) {
 		wl_list_insert(&shsurf->view->geometry.transformation_list,
 		               &shsurf->rotation.transform.link);
@@ -2323,9 +2331,12 @@ unset_maximized(struct shell_surface *shsurf)
 {
 	/* undo all maximized things here */
 	shsurf->output = get_default_output(shsurf->surface->compositor);
-	weston_view_set_position(shsurf->view,
-				 shsurf->saved_x,
-				 shsurf->saved_y);
+
+	if (shsurf->saved_position_valid)
+		weston_view_set_position(shsurf->view,
+					 shsurf->saved_x, shsurf->saved_y);
+	else
+		weston_view_set_initial_position(shsurf->view, shsurf->shell);
 
 	if (shsurf->saved_rotation_valid) {
 		wl_list_insert(&shsurf->view->geometry.transformation_list,
@@ -2907,6 +2918,8 @@ shell_handle_surface_destroy(struct wl_listener *listener, void *data)
 
 static void
 shell_surface_configure(struct weston_surface *, int32_t, int32_t);
+static void
+shell_surface_output_destroyed(struct weston_surface *);
 
 struct shell_surface *
 get_shell_surface(struct weston_surface *surface)
@@ -2943,6 +2956,7 @@ create_common_surface(void *shell, struct weston_surface *surface,
 
 	surface->configure = shell_surface_configure;
 	surface->configure_private = shsurf;
+	surface->output_destroyed = shell_surface_output_destroyed;
 
 	shsurf->shell = (struct desktop_shell *) shell;
 	shsurf->unresponsive = 0;
@@ -4955,6 +4969,14 @@ shell_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy)
 	}
 }
 
+static void
+shell_surface_output_destroyed(struct weston_surface *es)
+{
+	struct shell_surface *shsurf = get_shell_surface(es);
+
+	shsurf->saved_position_valid = false;
+}
+
 static void launch_desktop_shell_process(void *data);
 
 static void
diff --git a/src/compositor.c b/src/compositor.c
index af33fda..c4ffb5e 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -409,6 +409,9 @@ weston_view_output_destroy_handler(struct wl_listener *listener,
 	}
 
 	weston_view_set_position(ev, x, y);
+
+	if (ev->surface->output_destroyed)
+		ev->surface->output_destroyed(ev->surface);
 }
 
 WL_EXPORT struct weston_view *
diff --git a/src/compositor.h b/src/compositor.h
index d344e37..f5a0ba4 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -885,6 +885,12 @@ struct weston_surface {
 	void (*configure)(struct weston_surface *es, int32_t sx, int32_t sy);
 	void *configure_private;
 
+	/* If non-NULL, this function will be called on surface->output::
+	 * destroy, after the output is removed from the compositor's
+	 * output list and the remaining outputs moved.
+	 */
+	void (*output_destroyed)(struct weston_surface *surface);
+
 	/* Parent's list of its sub-surfaces, weston_subsurface:parent_link.
 	 * Contains also the parent itself as a dummy weston_subsurface,
 	 * if the list is not empty.
-- 
1.7.9.5



More information about the wayland-devel mailing list