[gnome-boxes] Save/restore window position
- From: Marc-Andre Lureau <malureau src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes] Save/restore window position
- Date: Thu, 3 Nov 2011 16:00:44 +0000 (UTC)
commit 81446625d2f3e861f98368088bd4048f8eef03f6
Author: Marc-Andrà Lureau <marcandre lureau gmail com>
Date: Thu Nov 3 16:48:52 2011 +0100
Save/restore window position
Based on gnome-documents and discussion with Cosimo.
It's not a job for window manager (yet ;)
data/org.gnome.boxes.gschema.xml.in | 40 ++++++++++++++-----
src/app.vala | 74 ++++++++++++++++++++++++++++++++--
2 files changed, 99 insertions(+), 15 deletions(-)
---
diff --git a/data/org.gnome.boxes.gschema.xml.in b/data/org.gnome.boxes.gschema.xml.in
index 8c7b300..ac5adc8 100644
--- a/data/org.gnome.boxes.gschema.xml.in
+++ b/data/org.gnome.boxes.gschema.xml.in
@@ -2,22 +2,42 @@
<schema id="org.gnome.boxes" path="/org/gnome/boxes/" gettext-domain="gnome-boxes">
<key name="collections" type="as">
- <summary>Collections</summary>
- <description>
- The list of boxes collections. The default value is:
- Work.
- </description>
+ <_summary>Collections</_summary>
+ <_description>
+ The list of boxes collections
+ </_description>
<default>[ 'Work', 'Research', 'Gaming' ]</default>
</key>
<key name="screenshot-interval" type="i">
- <summary>Screenshot interval</summary>
- <description>
- The interval in seconds between screenshot updates.
- Default value: 5.
- </description>
+ <_summary>Screenshot interval</_summary>
+ <_description>
+ The interval in seconds between screenshot updates
+ </_description>
<default>5</default>
</key>
+ <key name="window-size" type="ai">
+ <default>[768, 600]</default>
+ <_summary>Window size</_summary>
+ <_description>
+ Window size (width and height)
+ </_description>
+ </key>
+ <key name="window-position" type="ai">
+ <default>[]</default>
+ <_summary>Window position</_summary>
+ <_description>
+ Window position (x and y)
+ </_description>
+ </key>
+ <key name="window-maximized" type="b">
+ <default>true</default>
+ <_summary>Window maximized</_summary>
+ <_description>
+ Window maximized state
+ </_description>
+ </key>
+
</schema>
</schemalist>
diff --git a/src/app.vala b/src/app.vala
index 4523272..2e56ba9 100644
--- a/src/app.vala
+++ b/src/app.vala
@@ -11,6 +11,8 @@ private enum Boxes.AppPage {
private class Boxes.App: Boxes.UI {
public override Clutter.Actor actor { get { return stage; } }
public Gtk.Window window;
+ private bool fullscreen { get { return WindowState.FULLSCREEN in window.get_window ().get_state (); } }
+ private bool maximized { get { return WindowState.MAXIMIZED in window.get_window ().get_state (); } }
public Gtk.Notebook notebook;
public GtkClutter.Embed embed;
public Clutter.Stage stage;
@@ -32,6 +34,9 @@ private class Boxes.App: Boxes.UI {
private HashTable<string,GVir.Connection> connections;
+ private uint configure_id;
+ public static const uint configure_id_timeout = 100; // 100ms
+
public App () {
settings = new GLib.Settings ("org.gnome.boxes");
setup_ui ();
@@ -136,10 +141,65 @@ private class Boxes.App: Boxes.UI {
}
}
+ private void save_window_geometry () {
+ int width, height, x, y;
+
+ if (maximized)
+ return;
+
+ window.get_size (out width, out height);
+ settings.set_value ("window-size", new int[] { width, height });
+
+ window.get_position (out x, out y);
+ settings.set_value ("window-position", new int[] { x, y });
+ }
+
private void setup_ui () {
window = new Gtk.Window ();
- window.set_default_size (680, 480);
- window.maximize ();
+
+ // restore window geometry/position
+ var size = settings.get_value ("window-size");
+ if (size.n_children () == 2) {
+ var width = (int32) size.get_child_value (0);
+ var height = (int32) size.get_child_value (1);
+
+ window.set_default_size (width, height);
+ }
+
+ if (settings.get_boolean ("window-maximized"))
+ window.maximize ();
+
+ var position = settings.get_value ("window-position");
+ if (position.n_children () == 2) {
+ var x = (int32) size.get_child_value (0);
+ var y = (int32) size.get_child_value (1);
+
+ window.move (x, y);
+ }
+
+ window.configure_event.connect (() => {
+ if (fullscreen)
+ return false;
+
+ if (configure_id != 0)
+ GLib.Source.remove (configure_id);
+ configure_id = Timeout.add (configure_id_timeout, () => {
+ configure_id = 0;
+ save_window_geometry ();
+
+ return false;
+ });
+
+ return false;
+ });
+ window.window_state_event.connect (() => {
+ if (fullscreen)
+ return false;
+
+ settings.set_boolean ("window-maximized", maximized);
+ return false;
+ });
+
notebook = new Gtk.Notebook ();
notebook.show_border = false;
notebook.show_tabs = false;
@@ -156,7 +216,8 @@ private class Boxes.App: Boxes.UI {
state = new Clutter.State ();
state.set_duration (null, null, duration);
- window.destroy.connect (quit);
+ window.delete_event.connect (() => { return quit (); });
+
window.key_press_event.connect (on_key_pressed);
box_table = new Clutter.TableLayout ();
@@ -220,13 +281,16 @@ private class Boxes.App: Boxes.UI {
}
}
- public void quit () {
+ public bool quit () {
+ save_window_geometry ();
Gtk.main_quit ();
+
+ return false;
}
private bool on_key_pressed (Widget widget, Gdk.EventKey event) {
if (event.keyval == F11_KEY) {
- if (WindowState.FULLSCREEN in window.get_window ().get_state ())
+ if (fullscreen)
window.unfullscreen ();
else
window.fullscreen ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]