[gnome-games] chess: Remember window size



commit dbb9f305fa94ca2d6e0b895adbe069b9703f0b15
Author: Robert Ancell <robert ancell canonical com>
Date:   Sun May 8 18:04:33 2011 +0200

    chess: Remember window size

 glchess/data/glchess.ui                       |    1 +
 glchess/data/org.gnome.glchess.gschema.xml.in |    6 +++---
 glchess/src/glchess.vala                      |   20 ++++++++++++++++++++
 3 files changed, 24 insertions(+), 3 deletions(-)
---
diff --git a/glchess/data/glchess.ui b/glchess/data/glchess.ui
index 4ec183b..5d38687 100644
--- a/glchess/data/glchess.ui
+++ b/glchess/data/glchess.ui
@@ -11,6 +11,7 @@
       <group name="accelgroup"/>
     </accel-groups>
     <signal name="window-state-event" handler="glchess_app_window_state_event_cb" swapped="no"/>
+    <signal name="configure-event" handler="glchess_app_configure_event_cb" swapped="no"/>
     <signal name="delete-event" handler="glchess_app_delete_event_cb" swapped="no"/>
     <child>
       <object class="GtkVBox" id="main_vbox">
diff --git a/glchess/data/org.gnome.glchess.gschema.xml.in b/glchess/data/org.gnome.glchess.gschema.xml.in
index 1c7ecd1..aaf9bf2 100644
--- a/glchess/data/org.gnome.glchess.gschema.xml.in
+++ b/glchess/data/org.gnome.glchess.gschema.xml.in
@@ -41,10 +41,10 @@
       <_summary>The height of the window</_summary>
       <_description>The height of the main window in pixels.</_description>
     </key>
-    <key name="maximised" type="b">
+    <key name="maximized" type="b">
       <default>false</default>
-      <_summary>A flag to enable maximised mode</_summary>
-      <_description>A flag to enable maximised mode</_description>
+      <_summary>A flag to enable maximized mode</_summary>
+      <_description>A flag to enable maximized mode</_description>
     </key>
     <key name="fullscreen" type="b">
       <default>false</default>
diff --git a/glchess/src/glchess.vala b/glchess/src/glchess.vala
index ad22291..65e9ed0 100644
--- a/glchess/src/glchess.vala
+++ b/glchess/src/glchess.vala
@@ -403,8 +403,11 @@ public class Application
         else
             load_game (game, false);
 
+        window.set_default_size (settings.get_int ("width"), settings.get_int ("height"));        
         if (settings.get_boolean ("fullscreen"))
             window.fullscreen ();
+        else if (settings.get_boolean ("maximized"))
+            window.maximize ();
         show ();
     }
 
@@ -794,9 +797,26 @@ public class Application
         return false;
     }
 
+    [CCode (cname = "G_MODULE_EXPORT glchess_app_configure_event_cb", instance_pos = -1)]
+    public bool glchess_app_configure_event_cb (Gtk.Widget widget, Gdk.EventConfigure event)
+    {
+        if (!settings.get_boolean ("maximized") && !settings.get_boolean ("fullscreen"))
+        {
+            settings.set_int ("width", event.width);
+            settings.set_int ("height", event.height);
+        }
+
+        return false;
+    }
+
     [CCode (cname = "G_MODULE_EXPORT glchess_app_window_state_event_cb", instance_pos = -1)]
     public bool glchess_app_window_state_event_cb (Gtk.Widget widget, Gdk.EventWindowState event)
     {
+        if ((event.changed_mask & Gdk.WindowState.MAXIMIZED) != 0)
+        {
+            var is_maximized = (event.new_window_state & Gdk.WindowState.MAXIMIZED) != 0;
+            settings.set_boolean ("maximized", is_maximized);
+        }
         if ((event.changed_mask & Gdk.WindowState.FULLSCREEN) != 0)
         {
             bool is_fullscreen = (event.new_window_state & Gdk.WindowState.FULLSCREEN) != 0;



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