[california] Save size and maximized state of window: Bug #729943
- From: Jim Nelson <jnelson src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [california] Save size and maximized state of window: Bug #729943
- Date: Thu, 5 Jun 2014 19:51:27 +0000 (UTC)
commit 953f2a5f5d0d85255631a40a823820c232c1c0b8
Author: Jim Nelson <jim yorba org>
Date: Thu Jun 5 12:49:51 2014 -0700
Save size and maximized state of window: Bug #729943
data/org.yorba.california.gschema.xml | 21 +++++++++++
src/application/california-settings.vala | 44 ++++++++++++++++++++++
src/host/host-main-window.vala | 58 ++++++++++++++++++++++++++++-
3 files changed, 121 insertions(+), 2 deletions(-)
---
diff --git a/data/org.yorba.california.gschema.xml b/data/org.yorba.california.gschema.xml
index 8ac56fc..d7eda5f 100644
--- a/data/org.yorba.california.gschema.xml
+++ b/data/org.yorba.california.gschema.xml
@@ -25,6 +25,27 @@
month.
</description>
</key>
+
+ <key name="window-width" type="i">
+ <default>1024</default>
+ <summary>Width of main window (in pixels)</summary>
+ <description>
+ </description>
+ </key>
+
+ <key name="window-height" type="i">
+ <default>768</default>
+ <summary>Height of main window (in pixels)</summary>
+ <description>
+ </description>
+ </key>
+
+ <key name="window-maximized" type="b">
+ <default>false</default>
+ <summary>true if the main window is maximized</summary>
+ <description>
+ </description>
+ </key>
</schema>
</schemalist>
diff --git a/src/application/california-settings.vala b/src/application/california-settings.vala
index 7c1fc57..59fe41b 100644
--- a/src/application/california-settings.vala
+++ b/src/application/california-settings.vala
@@ -14,6 +14,9 @@ public class Settings : BaseObject {
public const string PROP_CALENDAR_VIEW = "calendar-view";
public const string PROP_SMALL_FONT_PTS = "small-font-pts";
public const string PROP_NORMAL_FONT_PTS = "normal-font-pts";
+ public const string PROP_WINDOW_WIDTH = "window-width";
+ public const string PROP_WINDOW_HEIGHT = "window-height";
+ public const string PROP_WINDOW_MAXIMIZED = "window-maximized";
// GSettings schema identifier.
private const string SCHEMA_ID = "org.yorba.california";
@@ -23,6 +26,9 @@ public class Settings : BaseObject {
private const string KEY_CALENDAR_VIEW = "calendar-view";
private const string KEY_SMALL_FONT_PTS = "small-font-pts";
private const string KEY_NORMAL_FONT_PTS = "normal-font-pts";
+ private const string KEY_WINDOW_WIDTH = "window-width";
+ private const string KEY_WINDOW_HEIGHT = "window-height";
+ private const string KEY_WINDOW_MAXIMIZED = "window-maximized";
public static Settings instance { get; private set; }
@@ -63,6 +69,43 @@ public class Settings : BaseObject {
}
}
+ /**
+ * The width of the main window (in pixels).
+ *
+ * Do not directly map the window's configuration to this property. Only set the value after
+ * a reasonable delay of user input or when the window is closed (unmapped).
+ */
+ public int window_width {
+ get {
+ return settings.get_int(KEY_WINDOW_WIDTH).clamp(Host.MainWindow.MIN_WIDTH, int.MAX);
+ }
+
+ set {
+ settings.set_int(KEY_WINDOW_WIDTH, value.clamp(Host.MainWindow.MIN_WIDTH, int.MAX));
+ }
+ }
+
+ /**
+ * The height of the main window (in pixels).
+ *
+ * Do not directly map the window's configuration to this property. Only set the value after
+ * a reasonable delay of user input or when the window is closed (unmapped).
+ */
+ public int window_height {
+ get {
+ return settings.get_int(KEY_WINDOW_HEIGHT).clamp(Host.MainWindow.MIN_HEIGHT, int.MAX);
+ }
+
+ set {
+ settings.set_int(KEY_WINDOW_HEIGHT, value.clamp(Host.MainWindow.MIN_HEIGHT, int.MAX));
+ }
+ }
+
+ /**
+ * Set if the main window is maximized.
+ */
+ public bool window_maximized { get; set; }
+
private GLib.Settings settings;
private Settings() {
@@ -72,6 +115,7 @@ public class Settings : BaseObject {
// bind GSettings values to properties here, which callers may access directly or bind to
// themselves (with a bit more type safety)
settings.bind(KEY_CALENDAR_VIEW, this, PROP_CALENDAR_VIEW, SettingsBindFlags.DEFAULT);
+ settings.bind(KEY_WINDOW_MAXIMIZED, this, PROP_WINDOW_MAXIMIZED, SettingsBindFlags.DEFAULT);
}
internal static void init() throws Error {
diff --git a/src/host/host-main-window.vala b/src/host/host-main-window.vala
index a8de7e7..8b32178 100644
--- a/src/host/host-main-window.vala
+++ b/src/host/host-main-window.vala
@@ -11,6 +11,30 @@ namespace California.Host {
*/
public class MainWindow : Gtk.ApplicationWindow {
+ /**
+ * Minimum width of the main window (to be usable).
+ */
+ public const int MIN_WIDTH = 800;
+
+ /**
+ * Default width of the main window (to be usable).
+ *
+ * This value is also set in the GSettings XML file.
+ */
+ public const int DEFAULT_WIDTH = 1024;
+
+ /**
+ * Minimum height of the main window (to be usable).
+ */
+ public const int MIN_HEIGHT = 600;
+
+ /**
+ * Default height of the main window (to be usable).
+ *
+ * This value is also set in the GSettings XML file.
+ */
+ public const int DEFAULT_HEIGHT = 768;
+
private const string PROP_FIRST_OF_WEEK = "first-of-week";
private const string DETAILED_ACTION_QUICK_CREATE_EVENT = "win.quick-create-event";
@@ -75,15 +99,20 @@ public class MainWindow : Gtk.ApplicationWindow {
private Gtk.Button today = new Gtk.Button.with_label(_("_Today"));
private Binding view_stack_binding;
private Gee.HashSet<string> view_stack_ids = new Gee.HashSet<string>();
+ private int window_width = -1;
+ private int window_height = -1;
public MainWindow(Application app) {
Object (application: app);
title = Application.TITLE;
- set_size_request(800, 600);
- set_default_size(1024, 768);
+ set_size_request(MIN_WIDTH, MIN_HEIGHT);
set_default_icon_name(Application.ICON_NAME);
+ set_default_size(Settings.instance.window_width, Settings.instance.window_height);
+ if (Settings.instance.window_maximized)
+ maximize();
+
bool rtl = get_direction() == Gtk.TextDirection.RTL;
add_action_entries(action_entries, this);
@@ -226,6 +255,31 @@ public class MainWindow : Gtk.ApplicationWindow {
Settings.instance.notify[Settings.PROP_NORMAL_FONT_PTS].disconnect(on_font_size_changed);
}
+ public bool is_window_maximized() {
+ Gdk.Window? window = get_window();
+ if (window == null)
+ return false;
+
+ return (window.get_state() & Gdk.WindowState.MAXIMIZED) != 0;
+ }
+
+ public override void unmap() {
+ Settings.instance.window_width = window_width;
+ Settings.instance.window_height = window_height;
+ Settings.instance.window_maximized = is_window_maximized();
+
+ base.unmap();
+ }
+
+ public override bool configure_event(Gdk.EventConfigure event) {
+ // don't directly write to GSettings as these events can come in fast and furious,
+ // wait for unmap() to write them out
+ window_width = event.width;
+ window_height = event.height;
+
+ return base.configure_event(event);
+ }
+
// only allow known stack children ids through
private bool transform_setting_to_calendar_view(Binding binding, Value source, ref Value target) {
if (!view_stack_ids.contains(source.get_string()))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]