[nautilus] window: Refactor nautilus_window_save_geometry



commit ac73fb7dd481c651d6dee2f7414397d53cbc1631
Author: Elias Projahn <johrpan gmail com>
Date:   Thu Dec 17 22:49:40 2020 +0100

    window: Refactor nautilus_window_save_geometry
    
    Replace a guard check if/else statement with an early return and
    minimize unnecessary function calls.

 src/nautilus-window.c | 57 +++++++++++++++++++++++++++++----------------------
 1 file changed, 32 insertions(+), 25 deletions(-)
---
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index 494e20eb8..b241034c2 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -2392,44 +2392,51 @@ nautilus_window_finalize (GObject *object)
 static void
 nautilus_window_save_geometry (NautilusWindow *window)
 {
+    GdkWindow *gdk_window;
+    GdkWindowState window_state;
     gboolean is_maximized;
 
     g_assert (NAUTILUS_IS_WINDOW (window));
 
-    if (gtk_widget_get_window (GTK_WIDGET (window)))
+    gdk_window = gtk_widget_get_window (GTK_WIDGET (window));
+
+    if (!gdk_window)
+    {
+        return;
+    }
+
+    window_state = gdk_window_get_state (gtk_widget_get_window (GTK_WIDGET (window)));
+
+    /* Don't save the window state for tiled windows. This is a special case,
+     * where the geometry only makes sense in combination with other tiled
+     * windows, that we can't possibly restore. */
+    if (window_state & GDK_WINDOW_STATE_TILED)
+    {
+        return;
+    }
+
+    is_maximized = window_state & GDK_WINDOW_STATE_MAXIMIZED;
+
+    /* Only save the initial size when the window is not maximized. If the
+     * window is maximized, a previously stored initial size will be more
+     * appropriate when unmaximizing the window in the future. */
+    if (!is_maximized)
     {
         gint width;
         gint height;
         GVariant *initial_size;
-        GdkWindowState window_state;
 
         gtk_window_get_size (GTK_WINDOW (window), &width, &height);
-
         initial_size = g_variant_new_parsed ("(%i, %i)", width, height);
 
-        window_state = gdk_window_get_state (gtk_widget_get_window (GTK_WIDGET (window)));
-
-        /* Don't save the window state for tiled windows. This is a special case,
-         * where the geometry only makes sense in combination with other tiled
-         * windows, that we can't possibly restore. */
-        if (window_state & GDK_WINDOW_STATE_TILED)
-        {
-            return;
-        }
-
-        is_maximized = window_state & GDK_WINDOW_STATE_MAXIMIZED;
-
-        if (!is_maximized)
-        {
-            g_settings_set_value (nautilus_window_state,
-                                  NAUTILUS_WINDOW_STATE_INITIAL_SIZE,
-                                  initial_size);
-        }
-
-        g_settings_set_boolean
-            (nautilus_window_state, NAUTILUS_WINDOW_STATE_MAXIMIZED,
-            is_maximized);
+        g_settings_set_value (nautilus_window_state,
+                              NAUTILUS_WINDOW_STATE_INITIAL_SIZE,
+                              initial_size);
     }
+
+    g_settings_set_boolean (nautilus_window_state,
+                            NAUTILUS_WINDOW_STATE_MAXIMIZED,
+                            is_maximized);
 }
 
 void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]