From a019ef90ca82714f5c4a6eb96ddbfe8288c9cc80 Mon Sep 17 00:00:00 2001
From: Rafostar <40623528+Rafostar@users.noreply.github.com>
Date: Sat, 31 Oct 2020 09:04:41 +0100
Subject: [PATCH] Remember and restore last window dimensions on launch
---
clapper_src/app.js | 17 +++++++++++++++++
clapper_src/player.js | 9 +++++++++
clapper_src/widget.js | 3 ---
data/com.github.rafostar.Clapper.gschema.xml | 6 ++++++
4 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/clapper_src/app.js b/clapper_src/app.js
index c0aab679..1ff32931 100644
--- a/clapper_src/app.js
+++ b/clapper_src/app.js
@@ -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);
}
diff --git a/clapper_src/player.js b/clapper_src/player.js
index 031459d5..5fead4c7 100644
--- a/clapper_src/player.js
+++ b/clapper_src/player.js
@@ -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();
}
diff --git a/clapper_src/widget.js b/clapper_src/widget.js
index 33d4b710..723bf0a1 100644
--- a/clapper_src/widget.js
+++ b/clapper_src/widget.js
@@ -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));
diff --git a/data/com.github.rafostar.Clapper.gschema.xml b/data/com.github.rafostar.Clapper.gschema.xml
index 08e4b03c..111dadd2 100644
--- a/data/com.github.rafostar.Clapper.gschema.xml
+++ b/data/com.github.rafostar.Clapper.gschema.xml
@@ -34,5 +34,11 @@
'[{"apply":false,"name":"vah264dec","rank":300}]'
Custom values for GStreamer plugin ranking
+
+
+
+ '[960, 583]'
+ Stores window size to restore on next launch
+