[console/wip/msandova/remember-window-size: 2/2] schema: Add setting to remember size on close




commit 7b6c1dba9e2e97509008668978a9a0d64025aa2a
Author: Maximiliano Sandoval R <msandova gnome org>
Date:   Fri Aug 5 16:38:26 2022 +0200

    schema: Add setting to remember size on close
    
    Enabled by default. If this setting is disabled it will still load the
    saved size, but won't save it on close.

 data/org.gnome.Console.gschema.xml.in |  3 +++
 src/kgx-application.c                 | 23 ++++++++++++++++++-----
 2 files changed, 21 insertions(+), 5 deletions(-)
---
diff --git a/data/org.gnome.Console.gschema.xml.in b/data/org.gnome.Console.gschema.xml.in
index 7e87e13..5b06808 100644
--- a/data/org.gnome.Console.gschema.xml.in
+++ b/data/org.gnome.Console.gschema.xml.in
@@ -27,5 +27,8 @@
     <key name="window-height" type="i">
       <default>-1</default>
     </key>
+    <key name="remember-window-size" type="b">
+      <default>true</default>
+    </key>
   </schema>
 </schemalist>
diff --git a/src/kgx-application.c b/src/kgx-application.c
index c69c106..e4f102d 100644
--- a/src/kgx-application.c
+++ b/src/kgx-application.c
@@ -205,6 +205,15 @@ kgx_application_activate (GApplication *app)
 }
 
 
+static void
+remember_window_size_changed (KgxApplication *self)
+{
+  if (!g_settings_get_boolean (self->settings, "remember-window-size")) {
+    kgx_application_set_window_size (self, -1, -1);
+  }
+}
+
+
 static gboolean
 handle_watch_iter (gpointer pid,
                    gpointer val,
@@ -362,6 +371,8 @@ kgx_application_startup (GApplication *app)
   g_settings_bind (self->settings, "theme", app, "theme", G_SETTINGS_BIND_DEFAULT);
   g_settings_bind (self->settings, "font-scale", app, "font-scale", G_SETTINGS_BIND_DEFAULT);
   g_settings_bind (self->settings, "scrollback-lines", app, "scrollback-lines", G_SETTINGS_BIND_DEFAULT);
+  g_signal_connect_swapped (self->settings, "changed::remember-window-size",
+                            G_CALLBACK (remember_window_size_changed), self);
 
   settings_action = g_settings_create_action (self->settings, "theme");
   g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (settings_action));
@@ -1208,14 +1219,14 @@ KgxWindow *
 kgx_application_new_window (KgxApplication *self)
 {
   GtkWindow *active_window;
-  int width, height;
+  int width = -1, height = -1;
 
   g_return_val_if_fail (KGX_IS_APPLICATION (self), NULL);
 
   active_window = gtk_application_get_active_window (GTK_APPLICATION (self));
   if (active_window) {
     gtk_window_get_default_size (active_window, &width, &height);
-  } else {
+  } else if (g_settings_get_boolean (self->settings, "remember-window-size")) {
     kgx_application_get_window_size (self, &width, &height);
   }
 
@@ -1252,8 +1263,10 @@ kgx_application_set_window_size (KgxApplication *self,
 {
   g_return_if_fail (KGX_IS_APPLICATION (self));
 
-  g_debug ("Saving window geometry: %i×%i", width, height);
+  if (g_settings_get_boolean (self->settings, "remember-window-size")) {
+    g_debug ("Saving window geometry: %i×%i", width, height);
 
-  g_settings_set_int (self->settings, "window-width", width);
-  g_settings_set_int (self->settings, "window-height", height);
+    g_settings_set_int (self->settings, "window-width", width);
+    g_settings_set_int (self->settings, "window-height", height);
+  }
 }


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