[five-or-more/gsoc-vala-port: 25/29] Save window dimensions between runs
- From: Robert Roth <robertroth src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [five-or-more/gsoc-vala-port: 25/29] Save window dimensions between runs
- Date: Mon, 13 Aug 2018 05:51:18 +0000 (UTC)
commit 288bc9c2542b0f3d2b3aa51b1d7706811394f230
Author: Ruxandra Simion <ruxandra simion93 gmail com>
Date: Mon Aug 6 02:28:20 2018 +0300
Save window dimensions between runs
src-vala/main.vala | 9 +++++++++
src-vala/window.vala | 33 +++++++++++++++++++++++++++++++++
2 files changed, 42 insertions(+)
---
diff --git a/src-vala/main.vala b/src-vala/main.vala
index 7f37848..83a3618 100644
--- a/src-vala/main.vala
+++ b/src-vala/main.vala
@@ -129,4 +129,13 @@ public class FiveOrMoreApp: Gtk.Application
"translator-credits", _("translator-credits"),
"website", "https://wiki.gnome.org/Apps/Five%20or%20more");
}
+
+ public override void shutdown ()
+ {
+ settings.set_int ("window-width", window.window_width);
+ settings.set_int ("window-height", window.window_height);
+ settings.set_boolean ("window-is-maximized", window.window_maximized);
+
+ base.shutdown ();
+ }
}
diff --git a/src-vala/window.vala b/src-vala/window.vala
index 33866e1..6bc3388 100644
--- a/src-vala/window.vala
+++ b/src-vala/window.vala
@@ -16,6 +16,12 @@ public class GameWindow : Gtk.ApplicationWindow
[GtkChild]
private Gtk.Label scorelabel;
+ private Settings? settings = null;
+ private bool window_tiled;
+ public bool window_maximized { get; private set; }
+ public int window_width { get; private set; }
+ public int window_height { get; private set; }
+
private Game? game = null;
private ThemeRenderer? theme = null;
@@ -31,9 +37,14 @@ public class GameWindow : Gtk.ApplicationWindow
{
Object (application: app);
+ this.settings = settings;
game = new Game (settings);
theme = new ThemeRenderer (settings);
+ set_default_size (settings.get_int ("window-width"), settings.get_int ("window-height"));
+ if (settings.get_boolean ("window-is-maximized"))
+ maximize ();
+
NextPiecesWidget next_pieces_widget = new NextPiecesWidget (settings, game, theme);
preview_hbox.pack_start (next_pieces_widget);
next_pieces_widget.realize ();
@@ -64,6 +75,28 @@ public class GameWindow : Gtk.ApplicationWindow
game.game_over.connect (score_cb);
}
+ protected override bool window_state_event (Gdk.EventWindowState event)
+ {
+ if ((event.changed_mask & Gdk.WindowState.MAXIMIZED) != 0)
+ window_maximized = (event.new_window_state & Gdk.WindowState.MAXIMIZED) != 0;
+
+ if ((event.changed_mask & Gdk.WindowState.TILED) != 0)
+ window_tiled = (event.new_window_state & Gdk.WindowState.TILED) != 0;
+
+ return false;
+ }
+
+ protected override void size_allocate (Gtk.Allocation allocation)
+ {
+ base.size_allocate (allocation);
+
+ if (window_maximized || window_tiled)
+ return;
+
+ window_width = allocation.width;
+ window_height = allocation.height;
+ }
+
private void score_cb ()
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]