[gnome-sudoku] Remember window size and state



commit ccb67c043e3b45e11521562b4883d96b7c5b36ec
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Tue Aug 12 00:18:56 2014 +0200

    Remember window size and state
    
    Default window width/height increased
    from 540x500 to 730x630 by Parin
    https://bugzilla.gnome.org/show_bug.cgi?id=733520

 data/org.gnome.sudoku.gschema.xml |   12 +++++++++++
 src/gnome-sudoku.vala             |   39 +++++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+), 0 deletions(-)
---
diff --git a/data/org.gnome.sudoku.gschema.xml b/data/org.gnome.sudoku.gschema.xml
index 39334f2..818ad8f 100644
--- a/data/org.gnome.sudoku.gschema.xml
+++ b/data/org.gnome.sudoku.gschema.xml
@@ -22,5 +22,17 @@
       <summary>Warn about unfillable squares and duplicate numbers</summary>
       <description>Displays a big red X in a square if it cannot possibly be filled by any number and 
duplicate numbers are highlighted in red</description>
     </key>
+    <key name="window-width" type="i">
+      <default>730</default>
+      <summary>Width of the window in pixels</summary>
+    </key>
+    <key name="window-height" type="i">
+      <default>630</default>
+      <summary>Height of the window in pixels</summary>
+    </key>
+    <key name="window-is-maximized" type="b">
+      <default>false</default>
+      <summary>true if the window is maximized</summary>
+    </key>
   </schema>
 </schemalist>
diff --git a/src/gnome-sudoku.vala b/src/gnome-sudoku.vala
index fdfbbc6..dc072d5 100644
--- a/src/gnome-sudoku.vala
+++ b/src/gnome-sudoku.vala
@@ -7,6 +7,10 @@ using Gdk;
 public class Sudoku : Gtk.Application
 {
     private GLib.Settings settings;
+    private bool is_fullscreen;
+    private bool is_maximized;
+    private int window_width;
+    private int window_height;
 
     private Builder builder;
 
@@ -138,6 +142,11 @@ public class Sudoku : Gtk.Application
             GLib.warning ("Could not load UI: %s", e.message);
         }
         window = (ApplicationWindow) builder.get_object ("sudoku_app");
+        window.configure_event.connect (window_configure_event_cb);
+        window.window_state_event.connect (window_state_event_cb);
+        window.set_default_size (settings.get_int ("window-width"), settings.get_int ("window-height"));
+        if (settings.get_boolean ("window-is-maximized"))
+            window.maximize ();
 
         add_window (window);
 
@@ -174,6 +183,36 @@ public class Sudoku : Gtk.Application
         });
     }
 
+    protected override void shutdown ()
+    {
+        base.shutdown ();
+
+        /* Save window state */
+        settings.set_int ("window-width", window_width);
+        settings.set_int ("window-height", window_height);
+        settings.set_boolean ("window-is-maximized", is_maximized);
+    }
+
+    private bool window_configure_event_cb (Gdk.EventConfigure event)
+    {
+        if (!is_maximized && !is_fullscreen)
+        {
+            window_width = event.width;
+            window_height = event.height;
+        }
+
+        return false;
+    }
+
+    private bool window_state_event_cb (Gdk.EventWindowState event)
+    {
+        if ((event.changed_mask & Gdk.WindowState.MAXIMIZED) != 0)
+            is_maximized = (event.new_window_state & Gdk.WindowState.MAXIMIZED) != 0;
+        if ((event.changed_mask & Gdk.WindowState.FULLSCREEN) != 0)
+            is_fullscreen = (event.new_window_state & Gdk.WindowState.FULLSCREEN) != 0;
+        return false;
+    }
+
     private void start_game (SudokuBoard board)
     {
         undo_action.set_enabled (false);


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