[five-or-more/arnaudb/wip/gtk4: 80/80] Improve state and size handling.




commit 4392eb35782c07ad9d882c69e387bf53651f6b5d
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Fri Oct 2 17:43:57 2020 +0200

    Improve state and size handling.
    
    See also gtk#3226.

 src/main.vala   |  2 +-
 src/window.vala | 27 ++++++++++++++++-----------
 2 files changed, 17 insertions(+), 12 deletions(-)
---
diff --git a/src/main.vala b/src/main.vala
index a1ebdab..1c98e9c 100644
--- a/src/main.vala
+++ b/src/main.vala
@@ -134,7 +134,7 @@ private class FiveOrMoreApp: Gtk.Application
 
     protected override void shutdown ()
     {
-        window.on_shutdown ();
+        window.destroy ();
         base.shutdown ();
     }
 }
diff --git a/src/window.vala b/src/window.vala
index fe50338..a899603 100644
--- a/src/window.vala
+++ b/src/window.vala
@@ -36,8 +36,8 @@ private class GameWindow : ApplicationWindow
     private AspectFrame grid_frame;
 
     private GLib.Settings settings = new GLib.Settings ("org.gnome.five-or-more");
-    private bool window_tiled;
-    private bool window_maximized;
+    private bool window_is_tiled;
+    private bool window_is_maximized;
     private int window_width;
     private int window_height;
 
@@ -75,6 +75,7 @@ private class GameWindow : ApplicationWindow
         add_action_entries (win_actions, this);
 
         map.connect (init_state_watcher);
+        unmap.connect (on_unmap);
 
         SimpleAction theme_action = (SimpleAction) lookup_action ("change-theme");
         string theme_value = settings.get_string (FiveOrMoreApp.KEY_THEME);
@@ -101,9 +102,12 @@ private class GameWindow : ApplicationWindow
         game = new Game (board_size);
         theme = new ThemeRenderer (settings);
 
-        set_default_size (settings.get_int ("window-width"), settings.get_int ("window-height"));
-        if (settings.get_boolean ("window-is-maximized"))
+        window_width = settings.get_int ("window-width");
+        window_height = settings.get_int ("window-height");
+        window_is_maximized = settings.get_boolean ("window-is-maximized");
+        if (window_is_maximized)
             maximize ();
+        set_default_size (window_width, window_height);
 
         NextPiecesWidget next_pieces_widget = new NextPiecesWidget (settings, game, theme);
         preview_hbox.prepend (next_pieces_widget);
@@ -141,25 +145,26 @@ private class GameWindow : ApplicationWindow
     {
         Gdk.ToplevelState state = surface.get_state ();
 
-        window_maximized =  (state & Gdk.ToplevelState.MAXIMIZED) != 0;
-        window_tiled =      (state & tiled_state)                 != 0;
+        window_is_maximized =   (state & Gdk.ToplevelState.MAXIMIZED)   != 0;
+        window_is_tiled =       (state & tiled_state)                   != 0;
     }
 
     private inline void on_size_changed (int width, int height)
     {
-        if (window_maximized || window_tiled)
+        if (window_is_maximized || window_is_tiled)
             return;
-        window_width  = width;
-        window_height = height;
+        get_size (out window_width, out window_height);
     }
 
-    internal inline void on_shutdown ()
+    private inline void on_unmap ()
     {
         settings.delay ();
         settings.set_int ("window-width", window_width);
         settings.set_int ("window-height", window_height);
-        settings.set_boolean ("window-is-maximized", window_maximized);
+        settings.set_boolean ("window-is-maximized", window_is_maximized);
         settings.apply ();
+
+        application.quit ();
     }
 
     private void set_status_message (string? message)


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