[gnome-shell] workspace: Make room for a second geometry to keep track of



commit b925322e9e57b46390f3d34372f449eef34f1631
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Mon Feb 25 18:25:27 2013 -0500

    workspace: Make room for a second geometry to keep track of
    
    As we want to eventually track two geometries, we need to rename
    our very plain "_x, _y, _width, _height". While we could just prefix
    them, I think that stuffing them in an object makes more sense.
    
    At the same time, make the variable and method name more descriptive
    by adding such a prefix, as well as a bit of documentation.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=694469

 js/ui/overviewControls.js |  2 +-
 js/ui/viewSelector.js     |  4 ++--
 js/ui/workspace.js        | 28 +++++++++++-----------
 js/ui/workspacesView.js   | 59 +++++++++++++++++++++++++----------------------
 4 files changed, 48 insertions(+), 45 deletions(-)
---
diff --git a/js/ui/overviewControls.js b/js/ui/overviewControls.js
index 7563975..313c450 100644
--- a/js/ui/overviewControls.js
+++ b/js/ui/overviewControls.js
@@ -556,7 +556,7 @@ const ControlsManager = new Lang.Class({
         else
             geometry.x += thumbnailsWidth;
 
-        this.viewSelector.setWorkspacesGeometry(geometry);
+        this.viewSelector.setWorkspacesFullGeometry(geometry);
     },
 
     _setVisibility: function() {
diff --git a/js/ui/viewSelector.js b/js/ui/viewSelector.js
index a7ad1b5..ade52d0 100644
--- a/js/ui/viewSelector.js
+++ b/js/ui/viewSelector.js
@@ -186,8 +186,8 @@ const ViewSelector = new Lang.Class({
             Main.overview.fadeInDesktop();
     },
 
-    setWorkspacesGeometry: function(geom) {
-        this._workspacesDisplay.setWorkspacesGeometry(geom);
+    setWorkspacesFullGeometry: function(geom) {
+        this._workspacesDisplay.setWorkspacesFullGeometry(geom);
     },
 
     hide: function() {
diff --git a/js/ui/workspace.js b/js/ui/workspace.js
index d3c380e..30c09fa 100644
--- a/js/ui/workspace.js
+++ b/js/ui/workspace.js
@@ -901,10 +901,11 @@ const Workspace = new Lang.Class({
         // When dragging a window, we use this slot for reserve space.
         this._reservedSlot = null;
         this.metaWorkspace = metaWorkspace;
-        this._x = 0;
-        this._y = 0;
-        this._width = 0;
-        this._height = 0;
+
+        // The full geometry is the geometry we should try and position
+        // windows for. The actual geometry we allocate may be less than
+        // this, like if the workspace switcher is slid out.
+        this._fullGeometry = null;
 
         this.monitorIndex = monitorIndex;
         this._monitor = Main.layoutManager.monitors[this.monitorIndex];
@@ -956,11 +957,8 @@ const Workspace = new Lang.Class({
         this._positionWindowsId = 0;
     },
 
-    setGeometry: function(geom) {
-        this._x = geom.x;
-        this._y = geom.y;
-        this._width = geom.width;
-        this._height = geom.height;
+    setFullGeometry: function(geom) {
+        this._fullGeometry = geom;
 
         Meta.later_add(Meta.LaterType.BEFORE_REDRAW, Lang.bind(this, function() {
             this._dropRect.set_position(geom.x, geom.y);
@@ -1148,8 +1146,8 @@ const Workspace = new Lang.Class({
         let [x, y, mask] = global.get_pointer();
 
         let pointerHasMoved = (this._cursorX != x && this._cursorY != y);
-        let inWorkspace = (this._x < x && x < this._x + this._width &&
-                           this._y < y && y < this._y + this._height);
+        let inWorkspace = (this._fullGeometry.x < x && x < this._fullGeometry.x + this._fullGeometry.width &&
+                           this._fullGeometry.y < y && y < this._fullGeometry.y + this._fullGeometry.height);
 
         if (pointerHasMoved && inWorkspace) {
             // store current cursor position
@@ -1538,10 +1536,10 @@ const Workspace = new Lang.Class({
         padding.right += rightBorder;
 
         let area = {
-            x: this._x + padding.left,
-            y: this._y + padding.top,
-            width: this._width - padding.left - padding.right,
-            height: this._height - padding.top - padding.bottom,
+            x: this._fullGeometry.x + padding.left,
+            y: this._fullGeometry.y + padding.top,
+            width: this._fullGeometry.width - padding.left - padding.right,
+            height: this._fullGeometry.height - padding.top - padding.bottom,
         };
 
         let layout = this._computeLayout(windows, area, rowSpacing, columnSpacing);
diff --git a/js/ui/workspacesView.js b/js/ui/workspacesView.js
index 7cb3b7e..c6a998c 100644
--- a/js/ui/workspacesView.js
+++ b/js/ui/workspacesView.js
@@ -23,6 +23,18 @@ const MAX_WORKSPACES = 16;
 
 const OVERRIDE_SCHEMA = 'org.gnome.shell.overrides';
 
+function rectEqual(one, two) {
+    if (one == two)
+        return true;
+
+    if (!one || !two)
+        return false;
+
+    return (one.x == two.x &&
+            one.y == two.y &&
+            one.width == two.width &&
+            one.height == two.height);
+}
 
 const WorkspacesView = new Lang.Class({
     Name: 'WorkspacesView',
@@ -43,10 +55,8 @@ const WorkspacesView = new Lang.Class({
                 this._updateWorkspaceActors(false);
             }));
 
-        this._width = 0;
-        this._height = 0;
-        this._x = 0;
-        this._y = 0;
+        this._fullGeometry = null;
+
         this._spacing = 0;
         this._animating = false; // tweening
         this._scrolling = false; // swipe-scrolling
@@ -85,8 +95,8 @@ const WorkspacesView = new Lang.Class({
         this._overviewShownId =
             Main.overview.connect('shown',
                                  Lang.bind(this, function() {
-                this.actor.set_clip(this._x, this._y,
-                                    this._width, this._height);
+                this.actor.set_clip(this._fullGeometry.x, this._fullGeometry.y,
+                                    this._fullGeometry.width, this._fullGeometry.height);
         }));
 
         this.scrollAdjustment = new St.Adjustment({ value: activeWorkspaceIndex,
@@ -124,7 +134,7 @@ const WorkspacesView = new Lang.Class({
                 continue;
 
             let ws = new Workspace.Workspace(null, i);
-            ws.setGeometry(monitors[i]);
+            ws.setFullGeometry(monitors[i]);
             global.overlay_group.add_actor(ws.actor);
             this._extraWorkspaces.push(ws);
         }
@@ -136,18 +146,14 @@ const WorkspacesView = new Lang.Class({
         this._extraWorkspaces = [];
     },
 
-    setGeometry: function(geom) {
-        if (this._x == geom.x && this._y == geom.y &&
-            this._width == geom.width && this._height == geom.height)
+    setFullGeometry: function(geom) {
+        if (rectEqual(this._fullGeometry, geom))
             return;
 
-        this._width = geom.width;
-        this._height = geom.height;
-        this._x = geom.x;
-        this._y = geom.y;
+        this._fullGeometry = geom;
 
         for (let i = 0; i < this._workspaces.length; i++)
-            this._workspaces[i].setGeometry(geom);
+            this._workspaces[i].setFullGeometry(geom);
     },
 
     _lookupWorkspaceForMetaWindow: function (metaWindow) {
@@ -207,7 +213,7 @@ const WorkspacesView = new Lang.Class({
 
             Tweener.removeTweens(workspace.actor);
 
-            let y = (w - active) * (this._height + this._spacing);
+            let y = (w - active) * (this._fullGeometry.height + this._spacing);
 
             if (showAnimation) {
                 let params = { y: y,
@@ -278,10 +284,7 @@ const WorkspacesView = new Lang.Class({
 
         if (newNumWorkspaces > oldNumWorkspaces) {
             for (let w = oldNumWorkspaces; w < newNumWorkspaces; w++) {
-                this._workspaces[w].setGeometry({ x: this._x,
-                                                  y: this._y,
-                                                  width: this._width,
-                                                  height: this._height });
+                this._workspaces[w].setFullGeometry(this._fullGeometry);
                 this.actor.add_actor(this._workspaces[w].actor);
             }
 
@@ -482,6 +485,8 @@ const WorkspacesDisplay = new Lang.Class({
 
         this._notifyOpacityId = 0;
         this._scrollEventId = 0;
+
+        this._fullGeometry = null;
     },
 
     _onPan: function(action) {
@@ -570,7 +575,7 @@ const WorkspacesDisplay = new Lang.Class({
             this._workspacesViews.push(view);
         }
 
-        this._updateWorkspacesGeometry();
+        this._updateWorkspacesFullGeometry();
 
         for (let i = 0; i < this._workspacesViews.length; i++)
             global.overlay_group.add_actor(this._workspacesViews[i].actor);
@@ -633,12 +638,12 @@ const WorkspacesDisplay = new Lang.Class({
     // This geometry should always be the fullest geometry
     // the workspaces switcher can ever be allocated, as if
     // the sliding controls were never slid in at all.
-    setWorkspacesGeometry: function(geom) {
-        this._geometry = geom;
-        this._updateWorkspacesGeometry();
+    setWorkspacesFullGeometry: function(geom) {
+        this._fullGeometry = geom;
+        this._updateWorkspacesFullGeometry();
     },
 
-    _updateWorkspacesGeometry: function() {
+    _updateWorkspacesFullGeometry: function() {
         if (!this._workspacesViews.length)
             return;
 
@@ -646,10 +651,10 @@ const WorkspacesDisplay = new Lang.Class({
         let m = 0;
         for (let i = 0; i < monitors.length; i++) {
             if (i == this._primaryIndex) {
-                this._workspacesViews[m].setGeometry(this._geometry);
+                this._workspacesViews[m].setFullGeometry(this._fullGeometry);
                 m++;
             } else if (!this._workspacesOnlyOnPrimary) {
-                this._workspacesViews[m].setGeometry(monitors[i]);
+                this._workspacesViews[m].setFullGeometry(monitors[i]);
                 m++;
             }
         }


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