Store and restore floating window size

This commit is contained in:
Rafostar
2020-11-06 19:43:38 +01:00
parent eb1a495907
commit 868c39f1cf
4 changed files with 39 additions and 5 deletions

View File

@@ -55,7 +55,7 @@ class ClapperApp extends Gtk.Application
}
if(size) {
window.set_default_size(size[0], size[1]);
debug(`restored window dimensions: ${size[0]}x${size[1]}`);
debug(`restored window size: ${size[0]}x${size[1]}`);
}
let clapperPath = Misc.getClapperPath();

View File

@@ -596,11 +596,10 @@ class ClapperPlayer extends PlayerBase
_onCloseRequest(window)
{
let clapperWidget = this.widget.get_ancestor(Gtk.Grid);
if(!clapperWidget.fullscreenMode && !clapperWidget.floatingMode) {
if(!clapperWidget.fullscreenMode) {
let size = window.get_size();
if(size[0] > 0 && size[1] > 0) {
settings.set_string('window-size', JSON.stringify(size));
debug(`saved window dimensions: ${size[0]}x${size[1]}`);
clapperWidget._saveWindowSize(size);
}
}

View File

@@ -6,6 +6,7 @@ const { Player } = imports.clapper_src.player;
const Revealers = imports.clapper_src.revealers;
let { debug } = Debug;
let { settings } = Misc;
var Widget = GObject.registerClass({
Signals: {
@@ -35,6 +36,9 @@ var Widget = GObject.registerClass({
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
);
this.windowSize = JSON.parse(settings.get_string('window-size'));
this.floatSize = JSON.parse(settings.get_string('float-size'));
this.fullscreenMode = false;
this.floatingMode = false;
this.isSeekable = false;
@@ -122,15 +126,32 @@ var Widget = GObject.registerClass({
if(this.floatingMode === isFloating)
return;
let root = this.get_root();
let size = root.get_size();
this._saveWindowSize(size);
if(isFloating)
this.windowSize = size;
else
this.floatSize = size;
this.floatingMode = isFloating;
this.revealerBottom.setFloatingClass(isFloating);
this._changeControlsPlacement(isFloating);
this.controls.setFloatingMode(isFloating);
this.controls.unfloatButton.set_visible(isFloating);
this.revealerBottom.showChild(isFloating);
this._setWindowFloating(isFloating);
let resize = (isFloating)
? this.floatSize
: this.windowSize;
root.resize(resize[0], resize[1]);
debug(`resized window: ${resize[0]}x${resize[1]}`);
this.revealerBottom.showChild(false);
this.player.widget.grab_focus();
}
@@ -146,6 +167,16 @@ var Widget = GObject.registerClass({
root[action + '_css_class'](cssClass);
}
_saveWindowSize(size)
{
let rootName = (this.floatingMode)
? 'float'
: 'window';
settings.set_string(`${rootName}-size`, JSON.stringify(size));
debug(`saved ${rootName} size: ${size[0]}x${size[1]}`);
}
_changeControlsPlacement(isOnTop)
{
if(isOnTop) {

View File

@@ -40,5 +40,9 @@
<default>'[960, 583]'</default>
<summary>Stores window size to restore on next launch</summary>
</key>
<key name="float-size" type="s">
<default>'[480, 270]'</default>
<summary>Stores floating window size to restore on next launch</summary>
</key>
</schema>
</schemalist>