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
This commit is contained in:
Jasper St. Pierre 2013-02-25 18:25:27 -05:00
parent f0c2ad00f8
commit b925322e9e
4 changed files with 48 additions and 45 deletions

View File

@ -556,7 +556,7 @@ const ControlsManager = new Lang.Class({
else else
geometry.x += thumbnailsWidth; geometry.x += thumbnailsWidth;
this.viewSelector.setWorkspacesGeometry(geometry); this.viewSelector.setWorkspacesFullGeometry(geometry);
}, },
_setVisibility: function() { _setVisibility: function() {

View File

@ -186,8 +186,8 @@ const ViewSelector = new Lang.Class({
Main.overview.fadeInDesktop(); Main.overview.fadeInDesktop();
}, },
setWorkspacesGeometry: function(geom) { setWorkspacesFullGeometry: function(geom) {
this._workspacesDisplay.setWorkspacesGeometry(geom); this._workspacesDisplay.setWorkspacesFullGeometry(geom);
}, },
hide: function() { hide: function() {

View File

@ -901,10 +901,11 @@ const Workspace = new Lang.Class({
// When dragging a window, we use this slot for reserve space. // When dragging a window, we use this slot for reserve space.
this._reservedSlot = null; this._reservedSlot = null;
this.metaWorkspace = metaWorkspace; this.metaWorkspace = metaWorkspace;
this._x = 0;
this._y = 0; // The full geometry is the geometry we should try and position
this._width = 0; // windows for. The actual geometry we allocate may be less than
this._height = 0; // this, like if the workspace switcher is slid out.
this._fullGeometry = null;
this.monitorIndex = monitorIndex; this.monitorIndex = monitorIndex;
this._monitor = Main.layoutManager.monitors[this.monitorIndex]; this._monitor = Main.layoutManager.monitors[this.monitorIndex];
@ -956,11 +957,8 @@ const Workspace = new Lang.Class({
this._positionWindowsId = 0; this._positionWindowsId = 0;
}, },
setGeometry: function(geom) { setFullGeometry: function(geom) {
this._x = geom.x; this._fullGeometry = geom;
this._y = geom.y;
this._width = geom.width;
this._height = geom.height;
Meta.later_add(Meta.LaterType.BEFORE_REDRAW, Lang.bind(this, function() { Meta.later_add(Meta.LaterType.BEFORE_REDRAW, Lang.bind(this, function() {
this._dropRect.set_position(geom.x, geom.y); 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 [x, y, mask] = global.get_pointer();
let pointerHasMoved = (this._cursorX != x && this._cursorY != y); let pointerHasMoved = (this._cursorX != x && this._cursorY != y);
let inWorkspace = (this._x < x && x < this._x + this._width && let inWorkspace = (this._fullGeometry.x < x && x < this._fullGeometry.x + this._fullGeometry.width &&
this._y < y && y < this._y + this._height); this._fullGeometry.y < y && y < this._fullGeometry.y + this._fullGeometry.height);
if (pointerHasMoved && inWorkspace) { if (pointerHasMoved && inWorkspace) {
// store current cursor position // store current cursor position
@ -1538,10 +1536,10 @@ const Workspace = new Lang.Class({
padding.right += rightBorder; padding.right += rightBorder;
let area = { let area = {
x: this._x + padding.left, x: this._fullGeometry.x + padding.left,
y: this._y + padding.top, y: this._fullGeometry.y + padding.top,
width: this._width - padding.left - padding.right, width: this._fullGeometry.width - padding.left - padding.right,
height: this._height - padding.top - padding.bottom, height: this._fullGeometry.height - padding.top - padding.bottom,
}; };
let layout = this._computeLayout(windows, area, rowSpacing, columnSpacing); let layout = this._computeLayout(windows, area, rowSpacing, columnSpacing);

View File

@ -23,6 +23,18 @@ const MAX_WORKSPACES = 16;
const OVERRIDE_SCHEMA = 'org.gnome.shell.overrides'; 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({ const WorkspacesView = new Lang.Class({
Name: 'WorkspacesView', Name: 'WorkspacesView',
@ -43,10 +55,8 @@ const WorkspacesView = new Lang.Class({
this._updateWorkspaceActors(false); this._updateWorkspaceActors(false);
})); }));
this._width = 0; this._fullGeometry = null;
this._height = 0;
this._x = 0;
this._y = 0;
this._spacing = 0; this._spacing = 0;
this._animating = false; // tweening this._animating = false; // tweening
this._scrolling = false; // swipe-scrolling this._scrolling = false; // swipe-scrolling
@ -85,8 +95,8 @@ const WorkspacesView = new Lang.Class({
this._overviewShownId = this._overviewShownId =
Main.overview.connect('shown', Main.overview.connect('shown',
Lang.bind(this, function() { Lang.bind(this, function() {
this.actor.set_clip(this._x, this._y, this.actor.set_clip(this._fullGeometry.x, this._fullGeometry.y,
this._width, this._height); this._fullGeometry.width, this._fullGeometry.height);
})); }));
this.scrollAdjustment = new St.Adjustment({ value: activeWorkspaceIndex, this.scrollAdjustment = new St.Adjustment({ value: activeWorkspaceIndex,
@ -124,7 +134,7 @@ const WorkspacesView = new Lang.Class({
continue; continue;
let ws = new Workspace.Workspace(null, i); let ws = new Workspace.Workspace(null, i);
ws.setGeometry(monitors[i]); ws.setFullGeometry(monitors[i]);
global.overlay_group.add_actor(ws.actor); global.overlay_group.add_actor(ws.actor);
this._extraWorkspaces.push(ws); this._extraWorkspaces.push(ws);
} }
@ -136,18 +146,14 @@ const WorkspacesView = new Lang.Class({
this._extraWorkspaces = []; this._extraWorkspaces = [];
}, },
setGeometry: function(geom) { setFullGeometry: function(geom) {
if (this._x == geom.x && this._y == geom.y && if (rectEqual(this._fullGeometry, geom))
this._width == geom.width && this._height == geom.height)
return; return;
this._width = geom.width; this._fullGeometry = geom;
this._height = geom.height;
this._x = geom.x;
this._y = geom.y;
for (let i = 0; i < this._workspaces.length; i++) for (let i = 0; i < this._workspaces.length; i++)
this._workspaces[i].setGeometry(geom); this._workspaces[i].setFullGeometry(geom);
}, },
_lookupWorkspaceForMetaWindow: function (metaWindow) { _lookupWorkspaceForMetaWindow: function (metaWindow) {
@ -207,7 +213,7 @@ const WorkspacesView = new Lang.Class({
Tweener.removeTweens(workspace.actor); Tweener.removeTweens(workspace.actor);
let y = (w - active) * (this._height + this._spacing); let y = (w - active) * (this._fullGeometry.height + this._spacing);
if (showAnimation) { if (showAnimation) {
let params = { y: y, let params = { y: y,
@ -278,10 +284,7 @@ const WorkspacesView = new Lang.Class({
if (newNumWorkspaces > oldNumWorkspaces) { if (newNumWorkspaces > oldNumWorkspaces) {
for (let w = oldNumWorkspaces; w < newNumWorkspaces; w++) { for (let w = oldNumWorkspaces; w < newNumWorkspaces; w++) {
this._workspaces[w].setGeometry({ x: this._x, this._workspaces[w].setFullGeometry(this._fullGeometry);
y: this._y,
width: this._width,
height: this._height });
this.actor.add_actor(this._workspaces[w].actor); this.actor.add_actor(this._workspaces[w].actor);
} }
@ -482,6 +485,8 @@ const WorkspacesDisplay = new Lang.Class({
this._notifyOpacityId = 0; this._notifyOpacityId = 0;
this._scrollEventId = 0; this._scrollEventId = 0;
this._fullGeometry = null;
}, },
_onPan: function(action) { _onPan: function(action) {
@ -570,7 +575,7 @@ const WorkspacesDisplay = new Lang.Class({
this._workspacesViews.push(view); this._workspacesViews.push(view);
} }
this._updateWorkspacesGeometry(); this._updateWorkspacesFullGeometry();
for (let i = 0; i < this._workspacesViews.length; i++) for (let i = 0; i < this._workspacesViews.length; i++)
global.overlay_group.add_actor(this._workspacesViews[i].actor); 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 // This geometry should always be the fullest geometry
// the workspaces switcher can ever be allocated, as if // the workspaces switcher can ever be allocated, as if
// the sliding controls were never slid in at all. // the sliding controls were never slid in at all.
setWorkspacesGeometry: function(geom) { setWorkspacesFullGeometry: function(geom) {
this._geometry = geom; this._fullGeometry = geom;
this._updateWorkspacesGeometry(); this._updateWorkspacesFullGeometry();
}, },
_updateWorkspacesGeometry: function() { _updateWorkspacesFullGeometry: function() {
if (!this._workspacesViews.length) if (!this._workspacesViews.length)
return; return;
@ -646,10 +651,10 @@ const WorkspacesDisplay = new Lang.Class({
let m = 0; let m = 0;
for (let i = 0; i < monitors.length; i++) { for (let i = 0; i < monitors.length; i++) {
if (i == this._primaryIndex) { if (i == this._primaryIndex) {
this._workspacesViews[m].setGeometry(this._geometry); this._workspacesViews[m].setFullGeometry(this._fullGeometry);
m++; m++;
} else if (!this._workspacesOnlyOnPrimary) { } else if (!this._workspacesOnlyOnPrimary) {
this._workspacesViews[m].setGeometry(monitors[i]); this._workspacesViews[m].setFullGeometry(monitors[i]);
m++; m++;
} }
} }