[sushi/wip/cosimoc/no-clutter: 34/66] mainWindow: split minimum width logic into separate class



commit 7d6cbd5509e0ffd4a197a507dbf158664cce3804
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Sat Apr 8 21:16:59 2017 -0700

    mainWindow: split minimum width logic into separate class

 src/js/ui/mainWindow.js | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)
---
diff --git a/src/js/ui/mainWindow.js b/src/js/ui/mainWindow.js
index 5e3eb3c..6f8c8e4 100644
--- a/src/js/ui/mainWindow.js
+++ b/src/js/ui/mainWindow.js
@@ -37,6 +37,24 @@ const Constants = imports.util.constants;
 const MimeHandler = imports.ui.mimeHandler;
 const SpinnerBox = imports.ui.spinnerBox;
 
+const Embed = new Lang.Class({
+    Name: 'Embed',
+    Extends: Gtk.Overlay,
+
+    vfunc_get_request_mode: function() {
+        return Gtk.SizeRequestMode.HEIGHT_FOR_WIDTH;
+    },
+
+    vfunc_get_preferred_width: function() {
+        let [min, nat] = this.parent();
+
+        min = Math.max(min, Constants.VIEW_MIN);
+        nat = Math.max(nat, Constants.VIEW_MIN);
+
+        return [min, nat];
+    }
+});
+
 var MainWindow = new Lang.Class({
     Name: 'MainWindow',
     Extends: Gtk.Window,
@@ -77,7 +95,7 @@ var MainWindow = new Lang.Class({
         this.connect('size-allocate',
                      Lang.bind(this, this._onSizeAllocate));
 
-        this._embed = new Gtk.Overlay();
+        this._embed = new Embed();
         this.add(this._embed);
     },
 
@@ -141,15 +159,8 @@ var MainWindow = new Lang.Class({
      *********************** texture allocation *******************************
      **************************************************************************/
     _getWindowSize : function() {
-        let textureSize = this._renderer.getSizeForAllocation(
+        return 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)
-            windowSize = [ Constants.VIEW_MIN, Constants.VIEW_MIN ];
-
-        return windowSize;
     },
 
     _resizeWindow : function() {


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