[sushi/wip/cosimoc/no-clutter: 40/50] Resize window when renderer is ready



commit 608540983064d77f01a27459c58af37d45854122
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Sat Jun 15 12:19:28 2019 -0700

    Resize window when renderer is ready
    
    We add a Renderer interface with a 'ready' property that can be
    used to determine when it's time to resize the window.

 src/ui/fallbackRenderer.js | 12 ++++++++++--
 src/ui/mainWindow.js       | 23 ++++++++++++-----------
 src/ui/renderer.js         | 22 ++++++++++++++++++++++
 src/viewers/audio.js       | 10 +++++++++-
 src/viewers/evince.js      | 14 +++++++++-----
 src/viewers/font.js        | 16 ++++++++++------
 src/viewers/gst.js         | 12 ++++++++++--
 src/viewers/html.js        | 14 +++++++++-----
 src/viewers/image.js       | 10 +++++++++-
 src/viewers/text.js        | 14 +++++++++-----
 10 files changed, 109 insertions(+), 38 deletions(-)
---
diff --git a/src/ui/fallbackRenderer.js b/src/ui/fallbackRenderer.js
index 97193d0..ca6fd8a 100644
--- a/src/ui/fallbackRenderer.js
+++ b/src/ui/fallbackRenderer.js
@@ -27,8 +27,15 @@ const {Gio, GObject, Gtk, Pango, Sushi} = imports.gi;
 
 const Renderer = imports.ui.renderer;
 
-var FallbackRenderer = GObject.registerClass(class FallbackRenderer extends Gtk.Box {
-    _init(file, mainWindow) {
+var FallbackRenderer = GObject.registerClass({
+    Implements: [Renderer.Renderer],
+    Properties: {
+        ready: GObject.ParamSpec.boolean('ready', '', '',
+                                         GObject.ParamFlags.READABLE,
+                                         false)
+    },
+}, class FallbackRenderer extends Gtk.Box {
+    _init(file) {
         super._init({ orientation: Gtk.Orientation.HORIZONTAL,
                       spacing: 6 });
 
@@ -78,6 +85,7 @@ var FallbackRenderer = GObject.registerClass(class FallbackRenderer extends Gtk.
         this._applyLabels();
 
         this.connect('destroy', this._onDestroy.bind(this));
+        this.isReady();
     }
 
     _applyLabels() {
diff --git a/src/ui/mainWindow.js b/src/ui/mainWindow.js
index 929f67e..93df039 100644
--- a/src/ui/mainWindow.js
+++ b/src/ui/mainWindow.js
@@ -32,9 +32,7 @@ const MimeHandler = imports.ui.mimeHandler;
 const Renderer = imports.ui.renderer;
 const Utils = imports.ui.utils;
 
-const Embed = GObject.registerClass({
-    Signals: { 'size-request': {} }
-}, class Embed extends Gtk.Overlay {
+const Embed = GObject.registerClass(class Embed extends Gtk.Overlay {
     vfunc_get_request_mode() {
         return Gtk.SizeRequestMode.HEIGHT_FOR_WIDTH;
     }
@@ -45,10 +43,6 @@ const Embed = GObject.registerClass({
         min = Math.max(min, Constants.VIEW_MIN);
         nat = Math.max(nat, Constants.VIEW_MIN);
 
-        // FIXME: this is wrong, we should only be doing this
-        // when the renderer signals us to do so
-        this.emit('size-request');
-
         return [min, nat];
     }
 
@@ -95,7 +89,6 @@ var MainWindow = GObject.registerClass(class MainWindow extends Gtk.Window {
         this.add(eventBox);
 
         this._embed = new Embed();
-        this._embed.connect('size-request', this._onEmbedSizeRequest.bind(this));
         eventBox.add(this._embed);
     }
 
@@ -151,8 +144,14 @@ var MainWindow = GObject.registerClass(class MainWindow extends Gtk.Window {
     /**************************************************************************
      *********************** texture allocation *******************************
      **************************************************************************/
-    _onEmbedSizeRequest() {
-        this._resizeWindow();
+    _onRendererReady() {
+        if (this._renderer.ready) {
+            this._resizeWindow();
+            this.queue_resize();
+        }
+
+        if (!this.visible)
+            this.show_all();
     }
 
     _resizeWindow() {
@@ -215,6 +214,9 @@ var MainWindow = GObject.registerClass(class MainWindow extends Gtk.Window {
         this._renderer.show_all();
         this._renderer.expand = true;
         this._embed.add(this._renderer);
+
+        this._renderer.connect('notify::ready', this._onRendererReady.bind(this));
+        this._onRendererReady();
     }
 
     /**************************************************************************
@@ -280,7 +282,6 @@ var MainWindow = GObject.registerClass(class MainWindow extends Gtk.Window {
         this.realize();
         if (this._parent)
             this.get_window().set_transient_for(this._parent);
-        this.show_all();
 
         if (this.get_window().move_to_current_desktop)
             this.get_window().move_to_current_desktop();
diff --git a/src/ui/renderer.js b/src/ui/renderer.js
index d64435e..adfe17d 100644
--- a/src/ui/renderer.js
+++ b/src/ui/renderer.js
@@ -7,6 +7,28 @@ var ResizePolicy = {
     STRETCHED: 3
 };
 
+var Renderer = GObject.registerClass({
+    Requires: [Gtk.Widget],
+    Properties: {
+        ready: GObject.ParamSpec.boolean('ready', '', '',
+                                         GObject.ParamFlags.READABLE,
+                                         false)
+    },
+}, class Renderer extends GObject.Interface {
+    isReady() {
+        this._ready = true;
+        this.notify('ready');
+    }
+
+    get ready() {
+        return !!this._ready;
+    }
+
+    get resizePolicy() {
+        return ResizePolicy.MAX_SIZE;
+    }
+});
+
 var RendererToolbar = GObject.registerClass({
     CssName: 'toolbar',
 }, class RendererToolbar extends Gtk.Box {
diff --git a/src/viewers/audio.js b/src/viewers/audio.js
index 81d5e8c..954519e 100644
--- a/src/viewers/audio.js
+++ b/src/viewers/audio.js
@@ -47,7 +47,14 @@ function _formatTimeString(timeVal) {
     return str;
 }
 
-var Klass = GObject.registerClass(class AudioRenderer extends Gtk.Box {
+var Klass = GObject.registerClass({
+    Implements: [Renderer.Renderer],
+    Properties: {
+        ready: GObject.ParamSpec.boolean('ready', '', '',
+                                         GObject.ParamFlags.READABLE,
+                                         false)
+    },
+}, class AudioRenderer extends Gtk.Box {
     _init(file, mainWindow) {
         super._init({ orientation: Gtk.Orientation.HORIZONTAL,
                       spacing: 6 });
@@ -84,6 +91,7 @@ var Klass = GObject.registerClass(class AudioRenderer extends Gtk.Box {
         vbox.pack_start(this._albumLabel, false, false, 0);
 
         this.connect('destroy', this._onDestroy.bind(this));
+        this.isReady();
     }
 
     _createPlayer(file) {
diff --git a/src/viewers/evince.js b/src/viewers/evince.js
index add0343..cf481a9 100644
--- a/src/viewers/evince.js
+++ b/src/viewers/evince.js
@@ -29,7 +29,14 @@ const Constants = imports.util.constants;
 const Renderer = imports.ui.renderer;
 const Utils = imports.ui.utils;
 
-var Klass = GObject.registerClass(class EvinceRenderer extends Gtk.ScrolledWindow {
+var Klass = GObject.registerClass({
+    Implements: [Renderer.Renderer],
+    Properties: {
+        ready: GObject.ParamSpec.boolean('ready', '', '',
+                                         GObject.ParamFlags.READABLE,
+                                         false)
+    },
+}, class EvinceRenderer extends Gtk.ScrolledWindow {
     _init(file, mainWindow) {
         super._init({ visible: true,
                       min_content_height: Constants.VIEW_MIN,
@@ -50,6 +57,7 @@ var Klass = GObject.registerClass(class EvinceRenderer extends Gtk.ScrolledWindo
         this.add(this._view);
 
         this.connect('destroy', this._onDestroy.bind(this));
+        this.isReady();
     }
 
     _updatePageLabel() {
@@ -73,10 +81,6 @@ var Klass = GObject.registerClass(class EvinceRenderer extends Gtk.ScrolledWindo
         this._view.set_model(this._model);
     }
 
-    get resizePolicy() {
-        return Renderer.ResizePolicy.MAX_SIZE;
-    }
-
     populateToolbar(toolbar) {
         this._toolbarBack = Utils.createToolButton('go-previous-symbolic', () => {
             this._view.previous_page();
diff --git a/src/viewers/font.js b/src/viewers/font.js
index b4e073c..9eee4cc 100644
--- a/src/viewers/font.js
+++ b/src/viewers/font.js
@@ -27,18 +27,22 @@ const {GLib, GObject, Gtk, Sushi} = imports.gi;
 
 const Renderer = imports.ui.renderer;
 
-var Klass = GObject.registerClass(class FontRenderer extends Sushi.FontWidget {
-    _init(file, mainWindow) {
+var Klass = GObject.registerClass({
+    Implements: [Renderer.Renderer],
+    Properties: {
+        ready: GObject.ParamSpec.boolean('ready', '', '',
+                                         GObject.ParamFlags.READABLE,
+                                         false)
+    },
+}, class FontRenderer extends Sushi.FontWidget {
+    _init(file) {
         super._init({ uri: file.get_uri(),
                       visible: true })
 
         this.moveOnClick = true;
         this.canFullScreen = true;
-        this._file = file;
-    }
 
-    get resizePolicy() {
-        return Renderer.ResizePolicy.MAX_SIZE;
+        this.isReady();
     }
 });
 
diff --git a/src/viewers/gst.js b/src/viewers/gst.js
index d32c4ef..f3537e6 100644
--- a/src/viewers/gst.js
+++ b/src/viewers/gst.js
@@ -29,8 +29,15 @@ const Renderer = imports.ui.renderer;
 const TotemMimeTypes = imports.util.totemMimeTypes;
 const Utils = imports.ui.utils;
 
-var Klass = GObject.registerClass(class GstRenderer extends Sushi.MediaBin {
-    _init(file, mainWindow) {
+var Klass = GObject.registerClass({
+    Implements: [Renderer.Renderer],
+    Properties: {
+        ready: GObject.ParamSpec.boolean('ready', '', '',
+                                         GObject.ParamFlags.READABLE,
+                                         false)
+    },
+}, class GstRenderer extends Sushi.MediaBin {
+    _init(file) {
         super._init({ uri: file.get_uri() });
 
         this.moveOnClick = true;
@@ -44,6 +51,7 @@ var Klass = GObject.registerClass(class GstRenderer extends Sushi.MediaBin {
         });
 
         this.connect('destroy', this._onDestroy.bind(this));
+        this.connect('size-change', this.isReady.bind(this));
     }
 
     _onDestroy() {
diff --git a/src/viewers/html.js b/src/viewers/html.js
index 62f2049..0bb7148 100644
--- a/src/viewers/html.js
+++ b/src/viewers/html.js
@@ -28,7 +28,14 @@ const {Gtk, GLib, GObject, Sushi, WebKit2} = imports.gi;
 const Renderer = imports.ui.renderer;
 const Utils = imports.ui.utils;
 
-var Klass = GObject.registerClass(class HTMLRenderer extends WebKit2.WebView {
+var Klass = GObject.registerClass({
+    Implements: [Renderer.Renderer],
+    Properties: {
+        ready: GObject.ParamSpec.boolean('ready', '', '',
+                                         GObject.ParamFlags.READABLE,
+                                         false)
+    },
+}, class HTMLRenderer extends WebKit2.WebView {
     _init(file, mainWindow) {
         super._init();
 
@@ -43,10 +50,7 @@ var Klass = GObject.registerClass(class HTMLRenderer extends WebKit2.WebView {
                      function() {return true;});
 
         this.load_uri(file.get_uri());
-    }
-
-    get resizePolicy() {
-        return Renderer.ResizePolicy.MAX_SIZE;
+        this.isReady();
     }
 
     populateToolbar(toolbar) {
diff --git a/src/viewers/image.js b/src/viewers/image.js
index 6f6f47f..bc75e70 100644
--- a/src/viewers/image.js
+++ b/src/viewers/image.js
@@ -115,7 +115,14 @@ const Image = GObject.registerClass({
     }
 });
 
-var Klass = GObject.registerClass(class ImageRenderer extends Image {
+var Klass = GObject.registerClass({
+    Implements: [Renderer.Renderer],
+    Properties: {
+        ready: GObject.ParamSpec.boolean('ready', '', '',
+                                         GObject.ParamFlags.READABLE,
+                                         false)
+    },
+}, class ImageRenderer extends Image {
     _init(file, mainWindow) {
         super._init();
 
@@ -148,6 +155,7 @@ var Klass = GObject.registerClass(class ImageRenderer extends Image {
 
             this._iter = anim.get_iter(null);
             this.pix = this._iter.get_pixbuf().apply_embedded_orientation();
+            this.isReady();
 
             if (!anim.is_static_image())
                 this._startTimeout();
diff --git a/src/viewers/text.js b/src/viewers/text.js
index a244043..240e6f5 100644
--- a/src/viewers/text.js
+++ b/src/viewers/text.js
@@ -42,7 +42,14 @@ function _getGeditScheme() {
     return geditScheme;
 }
 
-var Klass = GObject.registerClass(class TextRenderer extends Gtk.ScrolledWindow {
+var Klass = GObject.registerClass({
+    Implements: [Renderer.Renderer],
+    Properties: {
+        ready: GObject.ParamSpec.boolean('ready', '', '',
+                                         GObject.ParamFlags.READABLE,
+                                         false)
+    },
+}, class TextRenderer extends Gtk.ScrolledWindow {
     _init(file, mainWindow) {
         super._init();
 
@@ -68,6 +75,7 @@ var Klass = GObject.registerClass(class TextRenderer extends Gtk.ScrolledWindow
         });
 
         this.add(this._view);
+        this.isReady();
     }
 
     _onBufferLoaded(loader, buffer) {
@@ -83,10 +91,6 @@ var Klass = GObject.registerClass(class TextRenderer extends Gtk.ScrolledWindow
             this._view.set_show_line_numbers(true);
     }
 
-    get resizePolicy() {
-        return Renderer.ResizePolicy.MAX_SIZE;
-    }
-
     populateToolbar(toolbar) {
         let toolbarRun = Utils.createOpenButton(this._file, this._mainWindow);
         toolbar.add(toolbarRun);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]