[gnome-games] ui: Save the window's size in the gschema



commit 8172dd5feec0eec9a3a7cc540f6ef2aafff85d80
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Sun Feb 26 21:12:39 2017 +0100

    ui: Save the window's size in the gschema
    
    Save the size of the window in the gschema and retrieve this parameter
    to automatically set it back.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=779095

 data/ui/application-window.ui  |    2 +-
 src/ui/application-window.vala |   40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+), 1 deletions(-)
---
diff --git a/data/ui/application-window.ui b/data/ui/application-window.ui
index 107ecc7..1f7e41a 100644
--- a/data/ui/application-window.ui
+++ b/data/ui/application-window.ui
@@ -4,7 +4,7 @@
   <requires lib="gtk+" version="3.16"/>
   <template class="GamesApplicationWindow" parent="GtkApplicationWindow">
     <property name="can_focus">False</property>
-    <property name="default_width">800</property>
+    <property name="default_width">768</property>
     <property name="default_height">600</property>
     <property name="show_menubar">False</property>
     <signal name="delete-event" after="yes" handler="on_delete_event"/>
diff --git a/src/ui/application-window.vala b/src/ui/application-window.vala
index 9cc7de4..3e8d57d 100644
--- a/src/ui/application-window.vala
+++ b/src/ui/application-window.vala
@@ -2,6 +2,7 @@
 
 [GtkTemplate (ui = "/org/gnome/Games/ui/application-window.ui")]
 private class Games.ApplicationWindow : Gtk.ApplicationWindow {
+       private const uint WINDOW_SIZE_UPDATE_DELAY_MILLISECONDS = 500;
        private const uint FOCUS_OUT_DELAY_MILLISECONDS = 500;
 
        private UiState _ui_state;
@@ -83,6 +84,7 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
        private Cancellable run_game_cancellable;
        private Cancellable quit_game_cancellable;
 
+       private long window_size_update_timeout;
        private long focus_out_timeout_id;
 
        private uint inhibit_cookie;
@@ -95,6 +97,15 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
        construct {
                settings = new Settings ("org.gnome.Games");
 
+               int width, height;
+               settings.get ("window-size", "(ii)", out width, out height);
+               Gdk.Screen? screen = get_screen ();
+               if (screen != null) {
+                       width = int.min (width, screen.get_width ());
+                       height = int.min (height, screen.get_height ());
+               }
+               resize (width, height);
+
                if (settings.get_boolean ("window-maximized"))
                        maximize ();
 
@@ -110,6 +121,7 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
                header_bar_fullscreen_binding = bind_property ("is-fullscreen", display_header_bar, 
"is-fullscreen",
                                                               BindingFlags.BIDIRECTIONAL);
 
+               window_size_update_timeout = -1;
                focus_out_timeout_id = -1;
                inhibit_cookie = 0;
                inhibit_flags = 0;
@@ -159,6 +171,13 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
                return result;
        }
 
+       public override void size_allocate (Gtk.Allocation allocation) {
+               base.size_allocate (allocation);
+
+               if (window_size_update_timeout == -1 && !is_maximized)
+                       window_size_update_timeout = Timeout.add (WINDOW_SIZE_UPDATE_DELAY_MILLISECONDS, 
store_window_size);
+       }
+
        [GtkCallback]
        public bool on_delete_event () {
                return !quit_game ();
@@ -377,6 +396,27 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
                update_pause (true);
        }
 
+       private bool store_window_size () {
+               Gdk.Screen? screen = get_screen ();
+               if (screen == null)
+                       return false;
+
+               int width = 0;
+               int height = 0;
+
+               get_size (out width, out height);
+
+               width = int.min (width, screen.get_width ());
+               height = int.min (height, screen.get_height ());
+
+               settings.set ("window-size", "(ii)", width, height);
+
+               Source.remove ((uint) window_size_update_timeout);
+               window_size_update_timeout = -1;
+
+               return false;
+       }
+
        private void update_pause (bool with_delay) {
                if (focus_out_timeout_id != -1) {
                        Source.remove ((uint) focus_out_timeout_id);


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