[PATCH weston 7/7] shell: Use a dedicated variable for minimize state.

Scott Moreau oreaus at gmail.com
Sat Nov 3 22:31:37 PDT 2012


Minimize is a state, not a type. Maximize is also a state but it is stored in
a type enum in the shell plugin. Initially, the intent was to stay consistent
by using a minimized type. However, this causes problems when trying to keep
track of multiple states using a single type enum and simply won't work. This
patch separates minimize and maximize state completely by using a minimized
flag. The result is that toggling maximize works better while in a minimized
state now, whereas before the behavior was sporadic.
---
 clients/window.c | 27 +++++++++++++--------------
 src/shell.c      | 44 +++++++++++++++++++++++++-------------------
 2 files changed, 38 insertions(+), 33 deletions(-)

diff --git a/clients/window.c b/clients/window.c
index a9eb440..9a11571 100644
--- a/clients/window.c
+++ b/clients/window.c
@@ -132,7 +132,6 @@ enum {
 	TYPE_TOPLEVEL,
 	TYPE_FULLSCREEN,
 	TYPE_MAXIMIZED,
-	TYPE_MINIMIZED,
 	TYPE_TRANSIENT,
 	TYPE_MENU,
 	TYPE_CUSTOM
@@ -161,9 +160,10 @@ struct window {
 	int redraw_needed;
 	struct task redraw_task;
 	int resize_needed;
-	int type, saved_type;
+	int type;
 	int transparent;
 	int focus_count;
+	int minimized;
 
 	enum window_buffer_type buffer_type;
 
@@ -1565,7 +1565,7 @@ frame_button_button_handler(struct widget *widget,
 			display_exit(window->display);
 		break;
 	case FRAME_BUTTON_MINIMIZE:
-		window_set_minimized(window, window->type != TYPE_MINIMIZED);
+		window_set_minimized(window, !window->minimized);
 		break;
 	case FRAME_BUTTON_MAXIMIZE:
 		window_set_maximized(window, window->type != TYPE_MAXIMIZED);
@@ -2954,10 +2954,8 @@ handle_minimize(void *data, struct wl_shell_surface *shell_surface)
 {
 	struct window *window = data;
 
-	if (window->type != TYPE_MINIMIZED) {
-		window->saved_type = window->type;
-		window->type = TYPE_MINIMIZED;
-	}
+	if (!window->minimized)
+		window->minimized = 1;
 }
 
 static void
@@ -2965,8 +2963,8 @@ handle_unminimize(void *data, struct wl_shell_surface *shell_surface)
 {
 	struct window *window = data;
 
-	if (window->type == TYPE_MINIMIZED)
-		window->type = window->saved_type;
+	if (window->minimized)
+		window->minimized = 0;
 }
 
 static const struct wl_shell_surface_listener shell_surface_listener = {
@@ -3089,6 +3087,8 @@ window_set_maximized(struct window *window, int maximized)
 		return;
 
 	if (window->type == TYPE_TOPLEVEL) {
+		if (window->resize_needed)
+			return;
 		window->saved_allocation = window->allocation;
 		wl_shell_surface_set_maximized(window->shell_surface, NULL);
 		window->type = TYPE_MAXIMIZED;
@@ -3107,15 +3107,14 @@ window_set_minimized(struct window *window, int minimized)
 	if (!window->display->shell)
 		return;
 
-	if ((window->type == TYPE_MINIMIZED) == minimized)
+	if ((window->minimized) == minimized)
 		return;
 
-	if (window->type != TYPE_MINIMIZED) {
-		window->saved_type = window->type;
+	if (!window->minimized) {
 		wl_shell_surface_set_minimized(window->shell_surface);
-		window->type = TYPE_MINIMIZED;
+		window->minimized = 1;
 	} else
-		window->type = window->saved_type;
+		window->minimized = 0;
 }
 
 void
diff --git a/src/shell.c b/src/shell.c
index af1e0ba..aa1a503 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -146,7 +146,6 @@ enum shell_surface_type {
 	SHELL_SURFACE_TRANSIENT,
 	SHELL_SURFACE_FULLSCREEN,
 	SHELL_SURFACE_MAXIMIZED,
-	SHELL_SURFACE_MINIMIZED,
 	SHELL_SURFACE_POPUP
 };
 
@@ -173,6 +172,7 @@ struct shell_surface {
 	int32_t saved_x, saved_y;
 	bool saved_position_valid;
 	bool saved_rotation_valid;
+	bool minimized;
 	int unresponsive;
 
 	struct {
@@ -1468,7 +1468,7 @@ shell_surface_minimize(struct shell_surface *shsurf)
 	wl_list_remove(&surface->layer_link);
 	wl_list_insert(ws->layer.minimized_list.prev, &surface->layer_link);
 	shsurf->saved_type = shsurf->type;
-	shsurf->type = SHELL_SURFACE_MINIMIZED;
+	shsurf->minimized = true;
 
 	/* Focus next surface in stack */
 	if (!wl_list_empty(&ws->layer.surface_list)) {
@@ -1492,28 +1492,36 @@ shell_surface_minimize(struct shell_surface *shsurf)
 }
 
 static void
-shell_surface_unminimize(struct shell_surface *shsurf)
+surface_unminimize(struct shell_surface *shsurf, struct workspace *ws)
 {
 	struct desktop_shell *shell;
-	struct workspace *ws;
 	struct weston_compositor *compositor;
 	struct weston_surface *surface;
 
 	shell = shsurf->shell;
-	ws = get_current_workspace(shell);
 	compositor = shell->compositor;
 	surface = shsurf->surface;
 
-	if (shsurf->type == SHELL_SURFACE_MINIMIZED) {
-		wl_list_remove(&surface->layer_link);
-		wl_list_insert(ws->layer.surface_list.prev, &surface->layer_link);
-		shsurf->type = shsurf->saved_type;
-		shell_surface_focus(shsurf);
-		send_surface_data_focused_state(surface);
-		shsurf->type = shsurf->saved_type;
-		wl_shell_surface_send_unminimize(&shsurf->resource);
-		weston_compositor_damage_all(compositor);
-	}
+	wl_list_remove(&surface->layer_link);
+	wl_list_insert(ws->layer.surface_list.prev, &surface->layer_link);
+	shell_surface_focus(shsurf);
+	send_surface_data_focused_state(surface);
+	wl_shell_surface_send_unminimize(&shsurf->resource);
+	shsurf->minimized = false;
+	weston_compositor_damage_all(compositor);
+}
+
+static void
+shell_surface_unminimize(struct shell_surface *shsurf)
+{
+	struct weston_surface *surface;
+	struct workspace *ws = get_current_workspace(shsurf->shell);
+
+	wl_list_for_each(surface, &ws->layer.minimized_list, layer_link)
+		if (surface == shsurf->surface) {
+			surface_unminimize(shsurf, ws);
+			return;
+		}
 }
 
 static void
@@ -1679,7 +1687,6 @@ surface_is_window_list_candidate(struct weston_surface *surface,
 		return false;
 	case SHELL_SURFACE_FULLSCREEN:
 	case SHELL_SURFACE_MAXIMIZED:
-	case SHELL_SURFACE_MINIMIZED:
 	case SHELL_SURFACE_TOPLEVEL:
 		if (!shsurf->surface_data) {
 			if (create_surface_data(shell, shsurf))
@@ -1719,8 +1726,7 @@ send_surface_data_minimized_state(struct weston_surface *surface)
 
 	if (surface_is_window_list_candidate(surface, &shsurf))
 		surface_data_send_minimized(&shsurf.surface_data->resource,
-					shsurf.type == SHELL_SURFACE_MINIMIZED ?
-					true : false);
+					shsurf.minimized ? true : false);
 }
 
 static void
@@ -1817,7 +1823,6 @@ reset_shell_surface_type(struct shell_surface *surface)
 	case SHELL_SURFACE_NONE:
 	case SHELL_SURFACE_TOPLEVEL:
 	case SHELL_SURFACE_TRANSIENT:
-	case SHELL_SURFACE_MINIMIZED:
 	case SHELL_SURFACE_POPUP:
 		break;
 	}
@@ -2378,6 +2383,7 @@ create_shell_surface(void *shell, struct weston_surface *surface,
 
 	shsurf->shell = (struct desktop_shell *) shell;
 	shsurf->unresponsive = 0;
+	shsurf->minimized = false;
 	shsurf->saved_position_valid = false;
 	shsurf->saved_rotation_valid = false;
 	shsurf->surface = surface;
-- 
1.7.11.7



More information about the wayland-devel mailing list