[polari] mainWindow: Only save window state/size on quit
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari] mainWindow: Only save window state/size on quit
- Date: Fri, 6 Mar 2015 03:00:27 +0000 (UTC)
commit 5c8c295eb67dc1c95b7555e7a09d97e4804b2811
Author: Florian Müllner <fmuellner gnome org>
Date: Thu Mar 5 22:41:11 2015 +0100
mainWindow: Only save window state/size on quit
Follow the recommendations[0] and cache window state and size until
the application quits rather than directly saving every change to
GSettings.
[0] https://wiki.gnome.org/HowDoI/SaveWindowState
https://bugzilla.gnome.org/show_bug.cgi?id=745717
src/mainWindow.js | 36 ++++++++++++------------------------
1 files changed, 12 insertions(+), 24 deletions(-)
---
diff --git a/src/mainWindow.js b/src/mainWindow.js
index a2fc85b..bcbf873 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -35,6 +35,10 @@ const MainWindow = new Lang.Class({
this._membersChangedId = 0;
this._configureId = 0;
+ this._currentSize = [-1, -1];
+ this._isMaximized = false;
+ this._isFullscreen = false;
+
this._createWidget(app);
let provider = new Gtk.CssProvider();
@@ -99,32 +103,14 @@ const MainWindow = new Lang.Class({
},
_onWindowStateEvent: function(widget, event) {
- let window = widget.get_window();
- let state = window.get_state();
-
- if (state & Gdk.WindowState.FULLSCREEN)
- return;
+ let state = event.get_window().get_state();
- let maximized = (state & Gdk.WindowState.MAXIMIZED);
- this._settings.set_boolean('window-maximized', maximized);
- },
-
- _saveGeometry: function() {
- let window = this.window.get_window();
- let state = window.get_state();
-
- if (state & Gdk.WindowState.MAXIMIZED)
- return;
-
- let size = this.window.get_size();
- this._settings.set_value('window-size', GLib.Variant.new('ai', size));
+ this._isFullscreen = (state & Gdk.WindowState.FULLSCREEN) != 0;
+ this._isMaximized = (state & Gdk.WindowState.MAXIMIZED) != 0;
},
_onConfigureEvent: function(widget, event) {
- let window = widget.get_window();
- let state = window.get_state();
-
- if (state & Gdk.WindowState.FULLSCREEN)
+ if (this._isFullscreen || this._isMaximized)
return;
if (this._configureId != 0) {
@@ -134,7 +120,7 @@ const MainWindow = new Lang.Class({
this._configureId = Mainloop.timeout_add(CONFIGURE_TIMEOUT,
Lang.bind(this, function() {
- this._saveGeometry();
+ this._currentSize = this.window.get_size();
this._configureId = 0;
return GLib.SOURCE_REMOVE;
}));
@@ -146,7 +132,9 @@ const MainWindow = new Lang.Class({
this._configureId = 0;
}
- this._saveGeometry();
+ this._settings.set_boolean ('window-maximized', this._isMaximized);
+ this._settings.set_value('window-size',
+ GLib.Variant.new('ai', this._currentSize));
},
_onAccountChanged: function(am, account) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]