[geary] Remember size of dettached composer window



commit c1de366210d3369a30c628d24b52bae0a86ee4cd
Author: Jiri Cerny <ji cerny gmail com>
Date:   Tue Oct 18 22:23:29 2016 +0200

    Remember size of dettached composer window

 desktop/org.gnome.Geary.gschema.xml      |    6 ++++
 src/client/application/geary-config.vala |   16 +++++++++++
 src/client/composer/composer-window.vala |   41 ++++++++++++++++++++++++++++-
 3 files changed, 61 insertions(+), 2 deletions(-)
---
diff --git a/desktop/org.gnome.Geary.gschema.xml b/desktop/org.gnome.Geary.gschema.xml
index bfaa3a0..a64c4bc 100644
--- a/desktop/org.gnome.Geary.gschema.xml
+++ b/desktop/org.gnome.Geary.gschema.xml
@@ -128,6 +128,12 @@
         <description>The zoom to apply on the conservation view.</description>
     </key>
 
+    <key name="composer-window-size" type="ai">
+        <default>[-1,-1]</default>
+        <summary>size of dettached composer window</summary>
+        <description>The last recorded size of the dettached composer window.</description>
+    </key>
+
     <key name="migrated-config" type="b">
         <default>false</default>
         <summary>Whether we migrated the old settings</summary>
diff --git a/src/client/application/geary-config.vala b/src/client/application/geary-config.vala
index a678240..639fec7 100644
--- a/src/client/application/geary-config.vala
+++ b/src/client/application/geary-config.vala
@@ -30,6 +30,7 @@ public class Configuration {
     public const string SPELL_CHECK_LANGUAGES = "spell-check-languages";
     public const string SEARCH_STRATEGY_KEY = "search-strategy";
     public const string CONVERSATION_VIEWER_ZOOM_KEY = "conversation-viewer-zoom";
+    public const string COMPOSER_WINDOW_SIZE_KEY = "composer-window-size";
 
 
     public enum DesktopEnvironment {
@@ -172,6 +173,21 @@ public class Configuration {
         set { settings.set_double(CONVERSATION_VIEWER_ZOOM_KEY, value); }
     }
 
+    public int[] composer_window_size {
+        owned get {
+            int[] size = new int[2];
+            var s = settings.get_value(COMPOSER_WINDOW_SIZE_KEY);
+            if (s.n_children () == 2) {
+                size = { (int) s.get_child_value(0), (int) s.get_child_value(1)};
+            } else {
+                size = {-1,-1};
+            }
+            return size;
+        }
+        set {
+            settings.set_value(COMPOSER_WINDOW_SIZE_KEY, value);
+        }
+    }
 
     // Creates a configuration object.
     public Configuration(string schema_id) {
diff --git a/src/client/composer/composer-window.vala b/src/client/composer/composer-window.vala
index 7c1e3b8..4c297c2 100644
--- a/src/client/composer/composer-window.vala
+++ b/src/client/composer/composer-window.vala
@@ -20,7 +20,6 @@ public class ComposerWindow : Gtk.ApplicationWindow, ComposerContainer {
 
     private bool closing = false;
 
-
     public ComposerWindow(ComposerWidget composer) {
         Object(type: Gtk.WindowType.TOPLEVEL);
         this.composer = composer;
@@ -52,10 +51,48 @@ public class ComposerWindow : Gtk.ApplicationWindow, ComposerContainer {
     }
 
     public override void show() {
-        set_default_size(680, 600);
+        Gdk.Screen? screen = get_screen();
+        if (screen != null) {
+            int screen_width = screen.get_width();
+            int screen_height = screen.get_height();
+            int[] size = GearyApplication.instance.config.composer_window_size;
+
+            //check if stored values are reasonable
+            if (size[0] >= 0 && size[0] <= screen_width &&
+                size[1] >= 0 && size[1] <= screen_height)
+                set_default_size(size[0], size[1]);
+            else
+                set_default_size(680, 600);
+        }
+
         base.show();
     }
 
+    private void save_window_geometry () {
+        Gdk.Screen? screen = get_screen();
+        if (screen != null && !this.is_maximized) {
+            int screen_width = screen.get_width();
+            int screen_height = screen.get_height();
+
+            int width = 0;
+            int height = 0;
+
+            get_size(out width, out height);
+
+            // Only store if the values are reasonable-looking.
+            if (width > 0 && width <= screen_width &&
+                height > 0 && height <= screen_height)
+                GearyApplication.instance.config.composer_window_size = { width, height };
+        }
+    }
+
+    // Fired on window resize. Save window size for the next start.
+    public override void size_allocate(Gtk.Allocation allocation) {
+        base.size_allocate(allocation);
+
+        this.save_window_geometry();
+    }
+
     public void close_container() {
         on_focus_out();
         this.composer.editor.focus_in_event.disconnect(on_focus_in);


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