From 868c39f1cfcae075cdff9872e16bf05c2977d17b Mon Sep 17 00:00:00 2001 From: Rafostar <40623528+Rafostar@users.noreply.github.com> Date: Fri, 6 Nov 2020 19:43:38 +0100 Subject: [PATCH] Store and restore floating window size --- clapper_src/app.js | 2 +- clapper_src/player.js | 5 ++- clapper_src/widget.js | 33 +++++++++++++++++++- data/com.github.rafostar.Clapper.gschema.xml | 4 +++ 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/clapper_src/app.js b/clapper_src/app.js index 8bce6cf9..1d26a150 100644 --- a/clapper_src/app.js +++ b/clapper_src/app.js @@ -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(); diff --git a/clapper_src/player.js b/clapper_src/player.js index 31635a29..6c76123c 100644 --- a/clapper_src/player.js +++ b/clapper_src/player.js @@ -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); } } diff --git a/clapper_src/widget.js b/clapper_src/widget.js index 3fc06112..443f29a9 100644 --- a/clapper_src/widget.js +++ b/clapper_src/widget.js @@ -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) { diff --git a/data/com.github.rafostar.Clapper.gschema.xml b/data/com.github.rafostar.Clapper.gschema.xml index 111dadd2..7174042a 100644 --- a/data/com.github.rafostar.Clapper.gschema.xml +++ b/data/com.github.rafostar.Clapper.gschema.xml @@ -40,5 +40,9 @@ '[960, 583]' Stores window size to restore on next launch + + '[480, 270]' + Stores floating window size to restore on next launch +