[sushi/wip/cosimoc/no-clutter: 28/66] mainWindow: simplify code to size the window



commit 12e49269e0d4db2222a1d9a0a089907d1b781bc0
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Sun Apr 2 17:54:06 2017 -0700

    mainWindow: simplify code to size the window
    
    Now that we don't set a hardcoded size request, we can simplify this
    code.

 src/js/ui/fallbackRenderer.js |  2 +-
 src/js/ui/mainWindow.js       | 37 ++++++++++---------------------------
 src/js/viewers/audio.js       |  2 +-
 src/js/viewers/gst.js         |  2 +-
 4 files changed, 13 insertions(+), 30 deletions(-)
---
diff --git a/src/js/ui/fallbackRenderer.js b/src/js/ui/fallbackRenderer.js
index 00ec982..a6b4623 100644
--- a/src/js/ui/fallbackRenderer.js
+++ b/src/js/ui/fallbackRenderer.js
@@ -146,7 +146,7 @@ var FallbackRenderer = new Lang.Class({
             this._image.set_from_pixbuf(this._fileLoader.icon);
 
         this._applyLabels();
-        this._mainWindow.refreshSize();
+        this._mainWindow.queue_allocate();
     },
 
     clear : function() {
diff --git a/src/js/ui/mainWindow.js b/src/js/ui/mainWindow.js
index 78a67cf..7bcb205 100644
--- a/src/js/ui/mainWindow.js
+++ b/src/js/ui/mainWindow.js
@@ -102,7 +102,7 @@ var MainWindow = new Lang.Class({
         if (!this._renderer)
             return;
 
-        this._positionTexture();
+        this._resizeWindow();
     },
 
     _onKeyPressEvent : function(widget, event) {
@@ -143,33 +143,22 @@ var MainWindow = new Lang.Class({
     /**************************************************************************
      *********************** texture allocation *******************************
      **************************************************************************/
-    _getTextureSize : function() {
-        let screenSize = [ this.get_window().get_width(),
-                           this.get_window().get_height() ];
-
-        let availableWidth = this._isFullScreen ? screenSize[0] : Constants.VIEW_MAX_W;
-        let availableHeight = this._isFullScreen ? screenSize[1] : Constants.VIEW_MAX_H;
-
-        let textureSize = this._renderer.getSizeForAllocation([availableWidth, availableHeight], 
this._isFullScreen);
-
-        return textureSize;
-    },
-
     _getWindowSize : function() {
-        let textureSize = this._getTextureSize();
+        let textureSize = this._renderer.getSizeForAllocation(
+            [Constants.VIEW_MAX_W, Constants.VIEW_MAX_H]);
         let windowSize = textureSize;
 
         if (textureSize[0] < Constants.VIEW_MIN &&
-            textureSize[1] < Constants.VIEW_MIN) {
+            textureSize[1] < Constants.VIEW_MIN)
             windowSize = [ Constants.VIEW_MIN, Constants.VIEW_MIN ];
-        } else if (!this._isFullScreen) {
-            windowSize = [ windowSize[0], windowSize[1] ];
-        }
 
         return windowSize;
     },
 
-    _positionTexture : function() {
+    _resizeWindow : function() {
+        if (this._isFullScreen)
+            return;
+
         let windowSize = this._getWindowSize();
 
         if (this._lastWindowSize &&
@@ -178,9 +167,7 @@ var MainWindow = new Lang.Class({
             return;
 
         this._lastWindowSize = windowSize;
-
-        if (!this._isFullScreen)
-            this.resize(windowSize[0], windowSize[1]);
+        this.resize(windowSize[0], windowSize[1]);
     },
 
     _createRenderer : function(file) {
@@ -240,7 +227,7 @@ var MainWindow = new Lang.Class({
         this._texture.show();
 
         this._embed.add(this._texture);
-        this.refreshSize();
+        this._resizeWindow();
     },
 
     /**************************************************************************
@@ -333,10 +320,6 @@ var MainWindow = new Lang.Class({
         this.set_title(label);
     },
 
-    refreshSize : function() {
-        this._positionTexture();
-    },
-
     toggleFullScreen : function() {
         if (!this._renderer.canFullScreen)
             return false;
diff --git a/src/js/viewers/audio.js b/src/js/viewers/audio.js
index 4797652..69d31cc 100644
--- a/src/js/viewers/audio.js
+++ b/src/js/viewers/audio.js
@@ -188,7 +188,7 @@ const AudioRenderer = new Lang.Class({
 
         this._artFetcher.taglist = tags;
 
-        this._mainWindow.refreshSize();
+        this._mainWindow.queue_allocate();
     },
 
     _updateProgressBar : function() {
diff --git a/src/js/viewers/gst.js b/src/js/viewers/gst.js
index 858f391..5e12de1 100644
--- a/src/js/viewers/gst.js
+++ b/src/js/viewers/gst.js
@@ -44,7 +44,7 @@ const GstRenderer = new Lang.Class({
         this._player = new Sushi.MediaBin({ uri: file.get_uri() });
         this._player.play();
         this._player.connect('size-change', function() {
-            mainWindow.refreshSize();
+            mainWindow.queue_allocate();
         });
         callback();
     },


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