Remember and restore last window dimensions on launch

This commit is contained in:
Rafostar
2020-10-31 09:04:41 +01:00
parent 36145adf1a
commit a019ef90ca
4 changed files with 32 additions and 3 deletions

View File

@@ -1,9 +1,12 @@
const { Gio, GObject, Gtk } = imports.gi;
const { HeaderBar } = imports.clapper_src.headerbar;
const { Widget } = imports.clapper_src.widget;
const Debug = imports.clapper_src.debug;
const Menu = imports.clapper_src.menu;
const Misc = imports.clapper_src.misc;
let { debug } = Debug;
const APP_NAME = 'Clapper';
const APP_ID = 'com.github.rafostar.Clapper';
@@ -52,6 +55,20 @@ class ClapperApp extends Gtk.Application
window.set_titlebar(headerBar);
let clapperWidget = new Widget();
let size = clapperWidget.player.settings.get_string('window-size');
try {
size = JSON.parse(size);
}
catch(err) {
debug(err);
size = null;
}
if(size) {
window.set_default_size(size[0], size[1]);
debug(`restored window dimensions: ${size[0]}x${size[1]}`);
}
window.set_child(clapperWidget);
}

View File

@@ -605,6 +605,15 @@ class ClapperPlayer extends PlayerBase
if(this.state !== GstPlayer.PlayerState.STOPPED)
this.stop();
let clapperWidget = this.widget.get_ancestor(Gtk.Grid);
if(!clapperWidget.fullscreenMode) {
let size = window.get_size();
if(size[0] > 0 && size[1] > 0) {
this.settings.set_string('window-size', JSON.stringify(size));
debug(`saved window dimensions: ${size[0]}x${size[1]}`);
}
}
let app = window.get_application();
if(app) app.quit();
}

View File

@@ -56,9 +56,6 @@ var Widget = GObject.registerClass({
this.mapSignal = this.connect('map', this._onMap.bind(this));
this.player = new Player();
this.player.widget.width_request = 960;
this.player.widget.height_request = 540;
this.player.selfConnect('position-updated', this._onPlayerPositionUpdated.bind(this));
this.player.selfConnect('duration-changed', this._onPlayerDurationChanged.bind(this));
this.player.selfConnect('volume-changed', this._onPlayerVolumeChanged.bind(this));

View File

@@ -34,5 +34,11 @@
<default>'[{"apply":false,"name":"vah264dec","rank":300}]'</default>
<summary>Custom values for GStreamer plugin ranking</summary>
</key>
<!-- Other -->
<key name="window-size" type="s">
<default>'[960, 583]'</default>
<summary>Stores window size to restore on next launch</summary>
</key>
</schema>
</schemalist>