From cd90d4f6cecabf20aba082b4dc8b1eac45994238 Mon Sep 17 00:00:00 2001 From: Cassidy James Blaede Date: Mon, 16 Sep 2019 19:24:05 -0600 Subject: [PATCH 1/2] Try to save window position --- data/gschema.xml | 15 ++++++++++++++ src/MainWindow.vala | 48 ++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/data/gschema.xml b/data/gschema.xml index b0d72cf8..48340b57 100644 --- a/data/gschema.xml +++ b/data/gschema.xml @@ -48,6 +48,21 @@ Warn on no network connection Whether or not Ephemeral should warn when there is no network available connection + + false + Maximized + Whether the last-used window is maximized + + + (-1, -1) + Window position + Most recent window position (x, y) of the last-used window + + + (-1, -1) + Window size + Most recent window size (width, height) of the last-used window + 1.0 Zoom level diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 4399c38d..4b6201a1 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -35,6 +35,7 @@ public class Ephemeral.MainWindow : Gtk.Window { private BrowserButton browser_button; private Gtk.Button erase_button; private uint overlay_timeout_id = 0; + private uint configure_id; public MainWindow (Gtk.Application application, string? _uri = null) { Object ( @@ -49,9 +50,6 @@ public class Ephemeral.MainWindow : Gtk.Window { } construct { - default_height = 800; - default_width = 1280; - var header = new Gtk.HeaderBar (); header.show_close_button = true; header.has_subtitle = false; @@ -289,6 +287,22 @@ public class Ephemeral.MainWindow : Gtk.Window { set_titlebar (header); add (grid); + int window_x, window_y; + var rect = Gtk.Allocation (); + + Application.settings.get ("window-position", "(ii)", out window_x, out window_y); + Application.settings.get ("window-size", "(ii)", out rect.width, out rect.height); + + if (window_x != -1 || window_y != -1) { + move (window_x, window_y); + } + + set_allocation (rect); + + if (Application.settings.get_boolean ("window-maximized")) { + maximize (); + } + show_all (); if (uri != null && uri != "") { @@ -667,6 +681,34 @@ public class Ephemeral.MainWindow : Gtk.Window { add_accel_group (accel_group); } + public override bool configure_event (Gdk.EventConfigure event) { + if (configure_id != 0) { + GLib.Source.remove (configure_id); + } + + configure_id = Timeout.add (100, () => { + configure_id = 0; + + if (is_maximized) { + Application.settings.set_boolean ("window-maximized", true); + } else { + Application.settings.set_boolean ("window-maximized", false); + + Gdk.Rectangle rect; + get_allocation (out rect); + Application.settings.set ("window-size", "(ii)", rect.width, rect.height); + + int root_x, root_y; + get_position (out root_x, out root_y); + Application.settings.set ("window-position", "(ii)", root_x, root_y); + } + + return false; + }); + + return base.configure_event (event); + } + private void update_progress () { back_button.sensitive = web_view.can_go_back (); forward_button.sensitive = web_view.can_go_forward (); From 2b3fca2a7e561a751bb18aa9278563c6cb57d693 Mon Sep 17 00:00:00 2001 From: Cassidy James Blaede Date: Mon, 16 Sep 2019 19:25:22 -0600 Subject: [PATCH 2/2] Fix GSchema indentation --- data/gschema.xml | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/data/gschema.xml b/data/gschema.xml index 48340b57..842f43c9 100644 --- a/data/gschema.xml +++ b/data/gschema.xml @@ -49,20 +49,20 @@ Whether or not Ephemeral should warn when there is no network available connection - false - Maximized - Whether the last-used window is maximized - - - (-1, -1) - Window position - Most recent window position (x, y) of the last-used window - - - (-1, -1) - Window size - Most recent window size (width, height) of the last-used window - + false + Maximized + Whether the last-used window is maximized + + + (-1, -1) + Window position + Most recent window position (x, y) of the last-used window + + + (-1, -1) + Window size + Most recent window size (width, height) of the last-used window + 1.0 Zoom level