[PATCH] Store the main window maximized state in the configuration

Lubomir I. Ivanov neolit123 at gmail.com
Sun Mar 3 05:41:43 PST 2013


From: "Lubomir I. Ivanov" <neolit123 at gmail.com>

In save_window_geometry() use gdk_window_get_state() to retrieve
the window maximized state and store it in the user configuration.
Then in restore_window_geometry() restore the maximized state with
gtk_window_maximize(), if needed.

A side effect is that the windows resize now only occurs if
the window wasn't maximized, otherwise clicking the "restore"
(or "un-maximize") button will simply remove the maximized state,
but the window will remain with fullscreen dimensions.

Signed-off-by: Lubomir I. Ivanov <neolit123 at gmail.com>
---
 gtk-gui.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/gtk-gui.c b/gtk-gui.c
index 5397903..c48bef2 100644
--- a/gtk-gui.c
+++ b/gtk-gui.c
@@ -337,9 +337,14 @@ void save_window_geometry(void)
 {
 	/* GDK_GRAVITY_NORTH_WEST assumed ( it is the default ) */
 	int window_width, window_height;
-	gtk_window_get_size(GTK_WINDOW (main_window), &window_width, &window_height);
+	gboolean is_maximized;
+
+	gtk_window_get_size(GTK_WINDOW(main_window), &window_width, &window_height);
+	is_maximized = gdk_window_get_state(gtk_widget_get_window(GTK_WIDGET(main_window))) &
+		GDK_WINDOW_STATE_MAXIMIZED;
 	subsurface_set_conf_int("window_width", window_width);
 	subsurface_set_conf_int("window_height", window_height);
+	subsurface_set_conf_bool("window_maximized", is_maximized);
 	save_pane_position();
 	subsurface_flush_conf();
 }
@@ -347,6 +352,7 @@ void save_window_geometry(void)
 void restore_window_geometry(void)
 {
 	int window_width, window_height;
+	gboolean is_maximized = subsurface_get_conf_bool("window_maximized");
 
 	window_height = subsurface_get_conf_int("window_height");
 	window_width = subsurface_get_conf_int("window_width");
@@ -356,7 +362,11 @@ void restore_window_geometry(void)
 
 	gtk_paned_set_position(GTK_PANED(vpane), subsurface_get_conf_int("vpane_position"));
 	gtk_paned_set_position(GTK_PANED(hpane), subsurface_get_conf_int("hpane_position"));
-	gtk_window_resize (GTK_WINDOW (main_window), window_width, window_height);
+	/* don't resize the window if in maximized state */
+	if (is_maximized)
+		gtk_window_maximize(GTK_WINDOW(main_window));
+	else
+		gtk_window_resize(GTK_WINDOW(main_window), window_width, window_height);
 }
 
 gboolean on_delete(GtkWidget* w, gpointer data)
-- 
1.7.11.msysgit.0



More information about the subsurface mailing list