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



commit 7c76ad3ca80871332368c087de779690e45f5237
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 af738a5..17ef208 100644
--- a/src/js/ui/fallbackRenderer.js
+++ b/src/js/ui/fallbackRenderer.js
@@ -146,7 +146,7 @@ const 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 175ed68..69a24a1 100644
--- a/src/js/ui/mainWindow.js
+++ b/src/js/ui/mainWindow.js
@@ -100,7 +100,7 @@ const MainWindow = new Lang.Class({
         if (!this._renderer)
             return;
 
-        this._positionTexture();
+        this._resizeWindow();
     },
 
     _onKeyPressEvent : function(widget, event) {
@@ -141,33 +141,22 @@ const 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 &&
@@ -176,9 +165,7 @@ const 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) {
@@ -238,7 +225,7 @@ const MainWindow = new Lang.Class({
         this._texture.show();
 
         this._embed.add(this._texture);
-        this.refreshSize();
+        this._resizeWindow();
     },
 
     /**************************************************************************
@@ -331,10 +318,6 @@ const 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]