[gnome-shell/wip/workspace: 6/9] workspacesView: Simplify the workspacesOnlyOnPrimary implementation
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/wip/workspace: 6/9] workspacesView: Simplify the workspacesOnlyOnPrimary implementation
- Date: Wed, 11 Sep 2013 19:04:58 +0000 (UTC)
commit d2b508b866558800bd5f60ba5f41c16a9399e0e3
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Wed Sep 11 12:12:42 2013 -0400
workspacesView: Simplify the workspacesOnlyOnPrimary implementation
Before, workspacesOnlyOnPrimary was implemented in quite a crazy manner:
* If workspacesOnlyOnPrimary was false, we'd create one WorkspacesView per
monitor, with the primary one being a bit special.
* If workspacesOnlyOnPrimary was true, we'd create one WorkspacesView, and
additional montiors would be handled inside that WorkspacesView as
"extra workspaces".
This caused numerous bugs as the two modes weren't consistently
implemented, and a lot of code was duplicated between all the modes. Fix
this by adding a new base class to handle all Workspace-handling code,
WorkspacesViewBase, and two subclasses: WorkspacesView handles the primary
views and additional monitors when workspacesOnlyOnPrimary, and a new class
ExtraWorkspacesView handles additional monitors when not
workspacesOnlyOnPrimary.
This breaks some drag handling right now; this will be fixed up soon.
js/ui/workspacesView.js | 169 +++++++++++++++++++++-------------------------
1 files changed, 77 insertions(+), 92 deletions(-)
---
diff --git a/js/ui/workspacesView.js b/js/ui/workspacesView.js
index e85fb51..46fa560 100644
--- a/js/ui/workspacesView.js
+++ b/js/ui/workspacesView.js
@@ -23,8 +23,8 @@ const MAX_WORKSPACES = 16;
const OVERRIDE_SCHEMA = 'org.gnome.shell.overrides';
-const WorkspacesView = new Lang.Class({
- Name: 'WorkspacesView',
+const WorkspacesViewBase = new Lang.Class({
+ Name: 'WorkspacesViewBase',
_init: function(monitorIndex) {
this.actor = new St.Widget({ style_class: 'workspaces-view',
@@ -33,8 +33,35 @@ const WorkspacesView = new Lang.Class({
// The actor itself isn't a drop target, so we don't want to pick on its area
this.actor.set_size(0, 0);
- this.actor.connect('destroy', Lang.bind(this, this._onDestroy));
+ this._monitorIndex = monitorIndex;
+
+ this._fullGeometry = null;
+ this._actualGeometry = null;
+ },
+
+ destroy: function() {
+ this.actor.destroy();
+ },
+
+ setFullGeometry: function(geom) {
+ this._fullGeometry = geom;
+ this._syncGeometry();
+ },
+
+ setActualGeometry: function(geom) {
+ this._actualGeometry = geom;
+ this._syncGeometry();
+ },
+});
+const WorkspacesView = new Lang.Class({
+ Name: 'WorkspacesView',
+ Extends: WorkspacesViewBase,
+
+ _init: function(monitorIndex) {
+ this.parent(monitorIndex);
+
+ this.actor.connect('destroy', Lang.bind(this, this._onDestroy));
this.actor.connect('style-changed', Lang.bind(this,
function() {
let node = this.actor.get_theme_node();
@@ -42,11 +69,6 @@ const WorkspacesView = new Lang.Class({
this._updateWorkspaceActors(false);
}));
- this._fullGeometry = null;
- this._actualGeometry = null;
-
- this._monitorIndex = monitorIndex;
-
this._spacing = 0;
this._animating = false; // tweening
this._scrolling = false; // swipe-scrolling
@@ -69,10 +91,6 @@ const WorkspacesView = new Lang.Class({
this._updateWorkspaces();
this._updateWorkspacesId = global.screen.connect('notify::n-workspaces', Lang.bind(this,
this._updateWorkspaces));
- this._extraWorkspaces = [];
- this._updateExtraWorkspaces();
- this._updateExtraWorkspacesId = this._settings.connect('changed::workspaces-only-on-primary',
Lang.bind(this, this._updateExtraWorkspaces));
-
this._overviewShownId =
Main.overview.connect('shown',
Lang.bind(this, function() {
@@ -94,31 +112,6 @@ const WorkspacesView = new Lang.Class({
Lang.bind(this, this._dragEnd));
},
- _updateExtraWorkspaces: function() {
- this._destroyExtraWorkspaces();
-
- if (!this._settings.get_boolean('workspaces-only-on-primary'))
- return;
-
- let monitors = Main.layoutManager.monitors;
- for (let i = 0; i < monitors.length; i++) {
- if (i == Main.layoutManager.primaryIndex)
- continue;
-
- let ws = new Workspace.Workspace(null, i);
- ws.setFullGeometry(monitors[i]);
- ws.setActualGeometry(monitors[i]);
- Main.layoutManager.overviewGroup.add_actor(ws.actor);
- this._extraWorkspaces.push(ws);
- }
- },
-
- _destroyExtraWorkspaces: function() {
- for (let m = 0; m < this._extraWorkspaces.length; m++)
- this._extraWorkspaces[m].destroy();
- this._extraWorkspaces = [];
- },
-
_syncGeometry: function() {
for (let i = 0; i < this._workspaces.length; i++)
this._workspaces[i].setFullGeometry(this._fullGeometry);
@@ -126,16 +119,6 @@ const WorkspacesView = new Lang.Class({
this._workspaces[i].setActualGeometry(this._actualGeometry);
},
- setFullGeometry: function(geom) {
- this._fullGeometry = geom;
- this._syncGeometry();
- },
-
- setActualGeometry: function(geom) {
- this._actualGeometry = geom;
- this._syncGeometry();
- },
-
getActiveWorkspace: function() {
let active = global.screen.get_active_workspace_index();
return this._workspaces[active];
@@ -144,8 +127,6 @@ const WorkspacesView = new Lang.Class({
zoomToOverview: function() {
for (let w = 0; w < this._workspaces.length; w++)
this._workspaces[w].zoomToOverview();
- for (let w = 0; w < this._extraWorkspaces.length; w++)
- this._extraWorkspaces[w].zoomToOverview();
},
zoomFromOverview: function() {
@@ -153,19 +134,11 @@ const WorkspacesView = new Lang.Class({
for (let w = 0; w < this._workspaces.length; w++)
this._workspaces[w].zoomFromOverview();
- for (let w = 0; w < this._extraWorkspaces.length; w++)
- this._extraWorkspaces[w].zoomFromOverview();
- },
-
- destroy: function() {
- this.actor.destroy();
},
syncStacking: function(stackIndices) {
for (let i = 0; i < this._workspaces.length; i++)
this._workspaces[i].syncStacking(stackIndices);
- for (let i = 0; i < this._extraWorkspaces.length; i++)
- this._extraWorkspaces[i].syncStacking(stackIndices);
},
_scrollToActive: function() {
@@ -282,12 +255,10 @@ const WorkspacesView = new Lang.Class({
},
_onDestroy: function() {
- this._destroyExtraWorkspaces();
this.scrollAdjustment.run_dispose();
Main.overview.disconnect(this._overviewShownId);
global.window_manager.disconnect(this._switchWorkspaceNotifyId);
global.screen.disconnect(this._updateWorkspacesId);
- this._settings.disconnect(this._updateExtraWorkspacesId);
if (this._inDrag)
this._dragEnd();
@@ -331,8 +302,6 @@ const WorkspacesView = new Lang.Class({
this._firstDragMotion = false;
for (let i = 0; i < this._workspaces.length; i++)
this._workspaces[i].setReservedSlot(dragEvent.dragActor._delegate);
- for (let i = 0; i < this._extraWorkspaces.length; i++)
- this._extraWorkspaces[i].setReservedSlot(dragEvent.dragActor._delegate);
}
return DND.DragMotionResult.CONTINUE;
@@ -344,8 +313,6 @@ const WorkspacesView = new Lang.Class({
for (let i = 0; i < this._workspaces.length; i++)
this._workspaces[i].setReservedSlot(null);
- for (let i = 0; i < this._extraWorkspaces.length; i++)
- this._extraWorkspaces[i].setReservedSlot(null);
},
startSwipeScroll: function() {
@@ -404,6 +371,38 @@ const WorkspacesView = new Lang.Class({
});
Signals.addSignalMethods(WorkspacesView.prototype);
+const ExtraWorkspaceView = new Lang.Class({
+ Name: 'ExtraWorkspaceView',
+ Extends: WorkspacesViewBase,
+
+ _init: function(monitorIndex) {
+ this.parent(monitorIndex);
+ this._workspace = new Workspace.Workspace(null, monitorIndex);
+ this.actor.add_actor(this._workspace.actor);
+ },
+
+ _syncGeometry: function() {
+ this._workspace.setFullGeometry(this._fullGeometry);
+ this._workspace.setActualGeometry(this._actualGeometry);
+ },
+
+ zoomToOverview: function() {
+ this._workspace.zoomToOverview();
+ },
+
+ zoomFromOverview: function() {
+ this._workspace.zoomFromOverview();
+ },
+
+ syncStacking: function(stackIndices) {
+ this._workspace.syncStacking(stackIndices);
+ },
+
+ startSwipeScroll: function() {
+ },
+ endSwipeScroll: function() {
+ },
+});
const WorkspacesDisplay = new Lang.Class({
Name: 'WorkspacesDisplay',
@@ -452,8 +451,7 @@ const WorkspacesDisplay = new Lang.Class({
this._settings = new Gio.Settings({ schema: OVERRIDE_SCHEMA });
this._settings.connect('changed::workspaces-only-on-primary',
- Lang.bind(this,
- this._workspacesOnlyOnPrimaryChanged));
+ Lang.bind(this, this._workspacesOnlyOnPrimaryChanged));
this._workspacesOnlyOnPrimaryChanged();
this._switchWorkspaceNotifyId = 0;
@@ -519,12 +517,14 @@ const WorkspacesDisplay = new Lang.Class({
this._workspacesViews = [];
let monitors = Main.layoutManager.monitors;
for (let i = 0; i < monitors.length; i++) {
+ let view;
if (this._workspacesOnlyOnPrimary && i != this._primaryIndex)
- continue; // we are only interested in the primary monitor
+ view = new ExtraWorkspaceView(i);
+ else
+ view = new WorkspacesView(i);
- let view = new WorkspacesView(i);
view.actor.connect('scroll-event', Lang.bind(this, this._onScrollEvent));
- if (this._workspacesOnlyOnPrimary || i == this._primaryIndex) {
+ if (i == this._primaryIndex) {
this._scrollAdjustment = view.scrollAdjustment;
this._scrollAdjustment.connect('notify::value',
Lang.bind(this, this._scrollValueChanged));
@@ -540,14 +540,14 @@ const WorkspacesDisplay = new Lang.Class({
},
_scrollValueChanged: function() {
- if (this._workspacesOnlyOnPrimary)
- return;
-
for (let i = 0; i < this._workspacesViews.length; i++) {
if (i == this._primaryIndex)
continue;
let adjustment = this._workspacesViews[i].scrollAdjustment;
+ if (!adjustment)
+ continue;
+
// the adjustments work in terms of workspaces, so the
// values map directly
adjustment.value = this._scrollAdjustment.value;
@@ -557,10 +557,7 @@ const WorkspacesDisplay = new Lang.Class({
_getPrimaryView: function() {
if (!this._workspacesViews.length)
return null;
- if (this._workspacesOnlyOnPrimary)
- return this._workspacesViews[0];
- else
- return this._workspacesViews[this._primaryIndex];
+ return this._workspacesViews[this._primaryIndex];
},
activeWorkspaceHasMaximizedWindows: function() {
@@ -606,15 +603,9 @@ const WorkspacesDisplay = new Lang.Class({
return;
let monitors = Main.layoutManager.monitors;
- let m = 0;
for (let i = 0; i < monitors.length; i++) {
- if (i == this._primaryIndex) {
- this._workspacesViews[m].setFullGeometry(this._fullGeometry);
- m++;
- } else if (!this._workspacesOnlyOnPrimary) {
- this._workspacesViews[m].setFullGeometry(monitors[i]);
- m++;
- }
+ let geometry = (i == this._primaryIndex) ? this._fullGeometry : monitors[i];
+ this._workspacesViews[i].setFullGeometry(geometry);
}
},
@@ -625,18 +616,12 @@ const WorkspacesDisplay = new Lang.Class({
let [x, y] = this.actor.get_transformed_position();
let width = this.actor.allocation.x2 - this.actor.allocation.x1;
let height = this.actor.allocation.y2 - this.actor.allocation.y1;
- let geometry = { x: x, y: y, width: width, height: height };
+ let primaryGeometry = { x: x, y: y, width: width, height: height };
let monitors = Main.layoutManager.monitors;
- let m = 0;
for (let i = 0; i < monitors.length; i++) {
- if (i == this._primaryIndex) {
- this._workspacesViews[m].setActualGeometry(geometry);
- m++;
- } else if (!this._workspacesOnlyOnPrimary) {
- this._workspacesViews[m].setActualGeometry(monitors[i]);
- m++;
- }
+ let geometry = (i == this._primaryIndex) ? primaryGeometry : monitors[i];
+ this._workspacesViews[i].setActualGeometry(geometry);
}
},
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]