From 4862438e15b074d8d2e3c23699ebeadac7ae36fe Mon Sep 17 00:00:00 2001 From: bleakgrey Date: Sat, 9 Mar 2019 21:20:11 +0300 Subject: [PATCH] Implement #99 --- data/com.github.bleakgrey.tootle.gschema.xml | 14 ++++++++ meson.build | 1 + src/ISavedWindow.vala | 38 ++++++++++++++++++++ src/MainWindow.vala | 4 ++- src/Settings.vala | 7 +++- 5 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 src/ISavedWindow.vala diff --git a/data/com.github.bleakgrey.tootle.gschema.xml b/data/com.github.bleakgrey.tootle.gschema.xml index df7caf4..2f308b7 100644 --- a/data/com.github.bleakgrey.tootle.gschema.xml +++ b/data/com.github.bleakgrey.tootle.gschema.xml @@ -56,5 +56,19 @@ Watched Hashtags Comma separated list of hashtags to notify you about + + + -1 + + + -1 + + + -1 + + + -1 + + diff --git a/meson.build b/meson.build index 25bd7d7..e7451b3 100644 --- a/meson.build +++ b/meson.build @@ -22,6 +22,7 @@ executable( 'src/Desktop.vala', 'src/Drawing.vala', 'src/Html.vala', + 'src/ISavedWindow.vala', 'src/MainWindow.vala', 'src/Settings.vala', 'src/Accounts.vala', diff --git a/src/ISavedWindow.vala b/src/ISavedWindow.vala new file mode 100644 index 0000000..2bc23cd --- /dev/null +++ b/src/ISavedWindow.vala @@ -0,0 +1,38 @@ +using Gtk; + +public interface Tootle.ISavedWindow : Gtk.Window { + + public void restore_state () { + settings = new Settings (); + configure_window (settings); + configure_event.connect ((ev) => on_configure (ev, settings)); + } + + public bool on_configure (Gdk.EventConfigure event, Settings settings) { + int x, y, w, h; + get_position (out x, out y); + get_size (out w, out h); + + settings.window_x = x; + settings.window_y = y; + settings.window_w = w; + settings.window_h = h; + return false; + } + + public void configure_window (Settings settings) { + var x = settings.window_x; + var y = settings.window_y; + var w = settings.window_w; + var h = settings.window_h; + + if (x + y > 0) + this.move (x, y); + + if (h + w > 0) { + this.default_width = w; + this.default_height = h; + } + } + +} diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 4b805c1..2467b3a 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -1,6 +1,6 @@ using Gtk; -public class Tootle.MainWindow: Gtk.Window { +public class Tootle.MainWindow: Gtk.Window, ISavedWindow { private Overlay overlay; private Granite.Widgets.Toast toast; @@ -89,6 +89,8 @@ public class Tootle.MainWindow: Gtk.Window { overlay.add_overlay (toast); overlay.set_size_request (450, 600); add (overlay); + + restore_state (); show_all (); } diff --git a/src/Settings.vala b/src/Settings.vala index b3d487d..2ac0bb7 100644 --- a/src/Settings.vala +++ b/src/Settings.vala @@ -1,5 +1,5 @@ public class Tootle.Settings : Granite.Services.Settings { - + public int current_account { get; set; } public bool notifications { get; set; } public bool always_online { get; set; } @@ -12,6 +12,11 @@ public class Tootle.Settings : Granite.Services.Settings { public string watched_users { get; set; } public string watched_hashtags { get; set; } + public int window_x { get; set; } + public int window_y { get; set; } + public int window_w { get; set; } + public int window_h { get; set; } + public Settings () { base ("com.github.bleakgrey.tootle"); }