Move workspace controls into a single object

Rename WorkspacesViewSwitch to WorkspacesControls and let it manage
all workspace controls. Do not destroy and recreate the controls bar
actor on each view change, but add it to the overview once and let it
update itself.

https://bugzilla.gnome.org/show_bug.cgi?id=610189
This commit is contained in:
Florian Müllner 2010-02-12 21:12:39 +01:00
parent 7183aac362
commit c02b57efc3
3 changed files with 174 additions and 153 deletions

View File

@ -216,7 +216,7 @@ StTooltip {
height: 48px; height: 48px;
} }
.workspaces-bar, .workspaces-bar * { .workspaces-bar {
spacing: 5px; spacing: 5px;
} }

View File

@ -197,8 +197,8 @@ Overview.prototype = {
this.infoBar = new InfoBar(); this.infoBar = new InfoBar();
this._group.add_actor(this.infoBar.actor); this._group.add_actor(this.infoBar.actor);
this._workspacesViewSwitch = new WorkspacesView.WorkspacesViewSwitch(); this._workspacesControls = new WorkspacesView.WorkspacesControls();
this._workspacesViewSwitch.connect('view-changed', Lang.bind(this, this._onViewChanged)); this._workspacesControls.connect('view-changed', Lang.bind(this, this._onViewChanged));
this.visible = false; this.visible = false;
this.animationInProgress = false; this.animationInProgress = false;
@ -251,41 +251,21 @@ Overview.prototype = {
this._workspaces = null; this._workspaces = null;
}, },
_createControlsBar: function() {
this._workspacesBar = new St.BoxLayout({ 'pack-start': true,
style_class: 'workspaces-bar' });
this._workspacesBar.move_by(this._workspacesBarX, this._workspacesBarY);
let controlsBar = this._workspacesViewSwitch.createControlsBar();
let bar = this._workspaces.createControllerBar();
this._workspacesBar.add(bar, { expand: true, 'x-fill': true, 'y-fill': true,
y_align: St.Align.MIDDLE, x_align: St.Align.START });
this._workspacesBar.add(controlsBar, {x_align: St.Align.END});
this._workspacesBar.width = this._workspacesBarWidth;
this._group.add_actor(this._workspacesBar);
this._workspacesBar.raise(this._workspaces.actor);
},
_onViewChanged: function() { _onViewChanged: function() {
if (!this.visible) if (!this.visible)
return; return;
//Remove old worspacesView // Remove old workspacesView
this._group.remove_actor(this._workspacesBar);
this._workspaces.hide(); this._workspaces.hide();
this._group.remove_actor(this._workspaces.actor); this._group.remove_actor(this._workspaces.actor);
this._workspaces.destroy(); this._workspaces.destroy();
this._workspacesBar.destroy();
this._workspaces = this._workspacesViewSwitch.createCurrentWorkspaceView(this._workspacesWidth, this._workspacesHeight, this._workspaces = this._workspacesControls.createCurrentWorkspaceView(this._workspacesWidth, this._workspacesHeight,
this._workspacesX, this._workspacesY, false); this._workspacesX, this._workspacesY, false);
//Show new workspacesView // Show new workspacesView
this._group.add_actor(this._workspaces.actor); this._group.add_actor(this._workspaces.actor);
this._dash.actor.raise(this._workspaces.actor); this._dash.actor.raise(this._workspaces.actor);
this._createControlsBar();
// Set new position and scale to workspaces. // Set new position and scale to workspaces.
this.emit('showing'); this.emit('showing');
}, },
@ -472,7 +452,7 @@ Overview.prototype = {
this._dash.show(); this._dash.show();
/* TODO: make this stuff dynamic */ /* TODO: make this stuff dynamic */
this._workspaces = this._workspacesViewSwitch.createCurrentWorkspaceView(this._workspacesWidth, this._workspacesHeight, this._workspaces = this._workspacesControls.createCurrentWorkspaceView(this._workspacesWidth, this._workspacesHeight,
this._workspacesX, this._workspacesY, true); this._workspacesX, this._workspacesY, true);
this._group.add_actor(this._workspaces.actor); this._group.add_actor(this._workspaces.actor);
@ -481,7 +461,13 @@ Overview.prototype = {
// be as big as the screen. // be as big as the screen.
this._dash.actor.raise(this._workspaces.actor); this._dash.actor.raise(this._workspaces.actor);
this._createControlsBar(); this._workspacesBar = this._workspacesControls.actor;
this._workspacesBar.set_position(this._workspacesBarX,
this._workspacesBarY);
this._workspacesBar.width = this._workspacesBarWidth;
this._group.add_actor(this._workspacesBar);
this._workspacesBar.raise(this._workspaces.actor);
// All the the actors in the window group are completely obscured, // All the the actors in the window group are completely obscured,
// hiding the group holding them while the Overview is displayed greatly // hiding the group holding them while the Overview is displayed greatly
@ -511,7 +497,7 @@ Overview.prototype = {
onCompleteScope: this onCompleteScope: this
}); });
// Make Dash fade in so that it doesn't appear to big. // Make Dash fade in so that it doesn't appear too big.
this._dash.actor.opacity = 0; this._dash.actor.opacity = 0;
Tweener.addTween(this._dash.actor, Tweener.addTween(this._dash.actor,
{ opacity: 255, { opacity: 255,
@ -533,9 +519,6 @@ Overview.prototype = {
this._activeDisplayPane.close(); this._activeDisplayPane.close();
this._workspaces.hide(); this._workspaces.hide();
this._workspacesBar.destroy();
this._workspacesBar = null;
// Create a zoom in effect by transforming the Overview group so that // Create a zoom in effect by transforming the Overview group so that
// the active workspace fills up the whole screen. The opposite // the active workspace fills up the whole screen. The opposite
// transition is used in show(). // transition is used in show().
@ -600,6 +583,9 @@ Overview.prototype = {
this._workspaces.destroy(); this._workspaces.destroy();
this._workspaces = null; this._workspaces = null;
this._workspacesBar.destroy();
this._workspacesBar = null;
this._dash.hide(); this._dash.hide();
this._group.hide(); this._group.hide();

View File

@ -234,19 +234,23 @@ GenericWorkspacesView.prototype = {
return [activeWorkspace.gridX, activeWorkspace.gridY]; return [activeWorkspace.gridX, activeWorkspace.gridY];
}, },
_setButtonSensitivity: function(button, sensitive) { createControllerBar: function() {
if (button == null) throw new Error("Not implemented");
return;
if (sensitive && !button.reactive) {
button.reactive = true;
button.opacity = 255;
} else if (!sensitive && button.reactive) {
button.reactive = false;
button.opacity = 85;
}
}, },
createControllerBar: function() { canAddWorkspace: function() {
return global.screen.n_workspaces < MAX_WORKSPACES;
},
addWorkspace: function() {
throw new Error("Not implemented");
},
canRemoveWorkspace: function() {
throw new Error("Not implemented");
},
removeWorkspace: function() {
throw new Error("Not implemented"); throw new Error("Not implemented");
}, },
@ -283,9 +287,6 @@ MosaicView.prototype = {
width + 2 * Workspace.FRAME_SIZE, width + 2 * Workspace.FRAME_SIZE,
height + 2 * Workspace.FRAME_SIZE); height + 2 * Workspace.FRAME_SIZE);
this._workspaces[global.screen.get_active_workspace_index()].setSelected(true); this._workspaces[global.screen.get_active_workspace_index()].setSelected(true);
this._removeButton = null;
this._addButton = null;
}, },
// Assign grid positions to workspaces. We can't just do a simple // Assign grid positions to workspaces. We can't just do a simple
@ -406,8 +407,6 @@ MosaicView.prototype = {
// this has the side effect of removing the frame border // this has the side effect of removing the frame border
let activeIndex = global.screen.get_active_workspace_index(); let activeIndex = global.screen.get_active_workspace_index();
this._workspaces[activeIndex].setSelected(true); this._workspaces[activeIndex].setSelected(true);
this._updateButtonsVisibility();
}, },
_activeWorkspaceChanged: function(wm, from, to, direction) { _activeWorkspaceChanged: function(wm, from, to, direction) {
@ -422,47 +421,23 @@ MosaicView.prototype = {
}, },
createControllerBar: function() { createControllerBar: function() {
let actor = new St.BoxLayout({ 'pack-start': true }); return null;
let bin = new St.Bin();
let addButton = new St.Button({ style_class: "workspace-controls add" });
this._addButton = addButton;
addButton.connect('clicked', Lang.bind(this, this._addNewWorkspace));
addButton._delegate = addButton;
addButton._delegate.acceptDrop = Lang.bind(this, function(source, actor, x, y, time) {
return this._acceptNewWorkspaceDrop(source, actor, x, y, time);
});
actor.add(bin, { x_align: St.Align.END });
bin.set_child(addButton);
bin.set_alignment(St.Align.END, St.Align.START);
bin = new St.Bin();
let removeButton = new St.Button({ style_class: "workspace-controls remove" });
this._removeButton = removeButton;
removeButton.connect('clicked', Lang.bind(this, function() {
if (this._workspaces.length <= 1)
return;
global.screen.remove_workspace(this._workspaces[this._workspaces.length - 1]._metaWorkspace, global.get_current_time());
}));
actor.add(bin, { expand: true, x_fill: true, x_align: St.Align.END });
this._updateButtonsVisibility();
bin.set_child(removeButton);
bin.set_alignment(St.Align.END, St.Align.START);
return actor;
}, },
_updateButtonsVisibility: function() { addWorkspace: function() {
let canRemove = (global.screen.n_workspaces > 1);
let canAdd = (global.screen.n_workspaces < MAX_WORKSPACES);
this._setButtonSensitivity(this._removeButton, canRemove);
this._setButtonSensitivity(this._addButton, canAdd);
},
_addNewWorkspace: function() {
global.screen.append_new_workspace(false, global.get_current_time()); global.screen.append_new_workspace(false, global.get_current_time());
}, },
canRemoveWorkspace: function() {
return global.screen.n_workspaces > 1;
},
removeWorkspace: function() {
let last = this._workspaces.length - 1;
global.screen.remove_workspace(this._workspaces[last]._metaWorkspace,
global.get_current_time());
},
_acceptNewWorkspaceDrop: function(source, dropActor, x, y, time) { _acceptNewWorkspaceDrop: function(source, dropActor, x, y, time) {
this._addNewWorkspace(); this._addNewWorkspace();
return this.acceptNewWorkspaceDrop(source, dropActor, x, y, time); return this.acceptNewWorkspaceDrop(source, dropActor, x, y, time);
@ -522,10 +497,8 @@ SingleView.prototype = {
this.actor.style_class = "workspaces single"; this.actor.style_class = "workspaces single";
this._actor.set_clip(x, y, width, height); this._actor.set_clip(x, y, width, height);
this._addButton = null;
this._removeButton = null;
this._indicatorsPanel = null; this._indicatorsPanel = null;
this._indicatorsPanelWidth = null; this._indicatorsPanelWidth = 0;
this._scroll = null; this._scroll = null;
this._lostWorkspaces = []; this._lostWorkspaces = [];
this._scrolling = false; this._scrolling = false;
@ -988,11 +961,10 @@ SingleView.prototype = {
}, },
createControllerBar: function() { createControllerBar: function() {
let panel = new St.BoxLayout({ style_class: 'single-view-controls', let actor = new St.BoxLayout({ style_class: 'single-view-controls',
pack_start: true, pack_start: true,
vertical: true }); vertical: true });
let actor = new St.BoxLayout({ 'pack-start': true });
let active = global.screen.get_active_workspace_index(); let active = global.screen.get_active_workspace_index();
let adj = new St.Adjustment({ value: active, let adj = new St.Adjustment({ value: active,
lower: 0, lower: 0,
@ -1024,34 +996,15 @@ SingleView.prototype = {
this._scrollToActive(true); this._scrollToActive(true);
})); }));
let addButton = new St.Button({ style_class: "workspace-controls add" }); actor.add(this._createPositionalIndicator(), { expand: true,
this._addButton = addButton; x_fill: true,
addButton.connect('clicked', Lang.bind(this, this._addNewWorkspace)); y_fill: true });
addButton._delegate = addButton; actor.add(this._scroll, { expand: true,
addButton._delegate.acceptDrop = Lang.bind(this, function(source, actor, x, y, time) { x_fill: true,
return this._acceptNewWorkspaceDrop(source, actor, x, y, time); y_fill: false,
});
actor.add(addButton, {x_align: St.Align.END, y_align: St.Align.START, 'y-fill': false});
let removeButton = new St.Button({ style_class: "workspace-controls remove" });
this._removeButton = removeButton;
removeButton.connect('clicked', Lang.bind(this, function() {
if (this._workspaces.length <= 1)
return;
let index = global.screen.get_active_workspace_index();
if (index == 0)
return;
global.screen.remove_workspace(this._workspaces[index]._metaWorkspace, global.get_current_time());
}));
actor.add(removeButton, { x_align: St.Align.END, y_align: St.Align.START, 'y-fill': false });
this._updatePanelVisibility();
panel.add(this._createPositionalIndicator(), {expand: true, 'x-fill': true, 'y-fill': true});
panel.add(this._scroll, { expand: true,
'x-fill': true,
'y-fill': false,
y_align: St.Align.START }); y_align: St.Align.START });
actor.add(panel, {expand: true, 'x-fill': true, 'y-fill': true});
this._updatePanelVisibility();
return actor; return actor;
}, },
@ -1087,7 +1040,7 @@ SingleView.prototype = {
}, },
_fillPositionalIndicator: function() { _fillPositionalIndicator: function() {
if (this._indicatorsPanel == null || this._indicatorsPanelWidth == null) if (this._indicatorsPanel == null || this._indicatorsPanelWidth == 0)
return; return;
let width = this._indicatorsPanelWidth; let width = this._indicatorsPanelWidth;
this._indicatorsPanel.remove_all(); this._indicatorsPanel.remove_all();
@ -1154,13 +1107,11 @@ SingleView.prototype = {
return actor; return actor;
}, },
canRemoveWorkspace: function() {
return global.screen.get_active_workspace_index() != 0;
},
_updatePanelVisibility: function() { _updatePanelVisibility: function() {
let canRemove = (global.screen.get_active_workspace_index() != 0);
let canAdd = (global.screen.n_workspaces < MAX_WORKSPACES);
this._setButtonSensitivity(this._removeButton, canRemove);
this._setButtonSensitivity(this._addButton, canAdd);
let showSwitches = (global.screen.n_workspaces > 1); let showSwitches = (global.screen.n_workspaces > 1);
if (this._scroll != null) { if (this._scroll != null) {
if (showSwitches) if (showSwitches)
@ -1177,34 +1128,46 @@ SingleView.prototype = {
this._fillPositionalIndicator(); this._fillPositionalIndicator();
}, },
_addNewWorkspace: function() { addWorkspace: function() {
let ws = global.screen.append_new_workspace(false, let ws = global.screen.append_new_workspace(false,
global.get_current_time()); global.get_current_time());
ws.activate(global.get_current_time()); ws.activate(global.get_current_time());
}, },
removeWorkspace: function() {
let active = global.screen.get_active_workspace_index();
global.screen.remove_workspace(this._workspaces[active]._metaWorkspace,
global.get_current_time());
},
_acceptNewWorkspaceDrop: function(source, dropActor, x, y, time) { _acceptNewWorkspaceDrop: function(source, dropActor, x, y, time) {
this._addNewWorkspace(); this.addWorkspace();
return this.acceptNewWorkspaceDrop(source, dropActor, x, y, time); return this.acceptNewWorkspaceDrop(source, dropActor, x, y, time);
} }
}; };
function WorkspacesViewSwitch() { function WorkspacesControls() {
this._init(); this._init();
} }
WorkspacesViewSwitch.prototype = { WorkspacesControls.prototype = {
_init: function() { _init: function() {
this.actor = null;
this._gconf = Shell.GConf.get_default(); this._gconf = Shell.GConf.get_default();
this._mosaicViewButton = null; this._mosaicViewButton = null;
this._singleViewButton = null; this._singleViewButton = null;
this._controlsBar = null; this._addButton = null;
this._removeButton = null;
let view = this._gconf.get_string(WORKSPACES_VIEW_KEY).toUpperCase(); let view = this._gconf.get_string(WORKSPACES_VIEW_KEY).toUpperCase();
if (view in WorkspacesViewType) if (view in WorkspacesViewType)
this._currentViewType = WorkspacesViewType[view]; this._currentViewType = WorkspacesViewType[view];
else else
this._currentViewType = WorkspacesViewType.SINGLE; this._currentViewType = WorkspacesViewType.SINGLE;
this._currentView = null;
this._nWorkspacesNotifyId = 0;
this._switchWorkspaceNotifyId = 0;
}, },
_setView: function(view) { _setView: function(view) {
@ -1221,58 +1184,130 @@ WorkspacesViewSwitch.prototype = {
createCurrentWorkspaceView: function(width, height, x, y, animate) { createCurrentWorkspaceView: function(width, height, x, y, animate) {
switch (this._currentViewType) { switch (this._currentViewType) {
case WorkspacesViewType.SINGLE: case WorkspacesViewType.SINGLE:
return new SingleView(width, height, x, y, animate); this._currentView = new SingleView(width, height, x, y, animate);
break;
case WorkspacesViewType.GRID: case WorkspacesViewType.GRID:
return new MosaicView(width, height, x, y, animate);
default: default:
return new MosaicView(width, height, x, y, animate); this._currentView = new MosaicView(width, height, x, y, animate);
break;
} }
this._updateControlsBar();
return this._currentView;
}, },
createControlsBar: function() { _updateControlsBar: function() {
let actor = new St.BoxLayout(); if (this.actor)
this.actor.remove_all();
else
this.actor = new St.BoxLayout({ style_class: 'workspaces-bar' });
this._mosaicViewButton = new St.Button({ style_class: "workspace-controls switch-mosaic" }); // View switcher buttons
this._mosaicViewButton.set_toggle_mode(true); this._mosaicViewButton = new St.Button({ style_class: 'workspace-controls switch-mosaic',
toggle_mode: true });
this._mosaicViewButton.connect('clicked', Lang.bind(this, function() { this._mosaicViewButton.connect('clicked', Lang.bind(this, function() {
this._setView(WorkspacesViewType.GRID); this._setView(WorkspacesViewType.GRID);
})); }));
actor.add(this._mosaicViewButton, {'y-fill' : false, 'y-align' : St.Align.START}); this.actor.add(this._mosaicViewButton, { y_fill: false,
y_align: St.Align.START });
this._singleViewButton = new St.Button({ style_class: "workspace-controls switch-single" }); this._singleViewButton = new St.Button({ style_class: 'workspace-controls switch-single',
this._singleViewButton.set_toggle_mode(true); toggle_mode: true });
this._singleViewButton.connect('clicked', Lang.bind(this, function() { this._singleViewButton.connect('clicked', Lang.bind(this, function() {
this._setView(WorkspacesViewType.SINGLE); this._setView(WorkspacesViewType.SINGLE);
})); }));
actor.add(this._singleViewButton, {'y-fill' : false, 'y-align' : St.Align.START}); this.actor.add(this._singleViewButton, { y_fill: false,
y_align: St.Align.START });
if (this._currentViewType == WorkspacesViewType.GRID) if (this._currentViewType == WorkspacesViewType.GRID)
this._mosaicViewButton.set_checked(true); this._mosaicViewButton.set_checked(true);
else else
this._singleViewButton.set_checked(true); this._singleViewButton.set_checked(true);
// View specific controls
let bar = this._currentView.createControllerBar();
if (!bar)
bar = new St.Bin();
this.actor.add(bar, { expand: true,
x_fill: true,
y_fill: true,
y_align: St.Align.MIDDLE,
x_align: St.Align.START });
// Add/remove workspace buttons
this._removeButton = new St.Button({ style_class: 'workspace-controls remove' });
this._removeButton.connect('clicked', Lang.bind(this, function() {
this._currentView.removeWorkspace();
}));
this.actor.add(this._removeButton, { y_fill: false,
y_align: St.Align.START });
this._addButton = new St.Button({ style_class: 'workspace-controls add' });
this._addButton.connect('clicked', Lang.bind(this, function() {
this._currentView.addWorkspace()
}));
this._addButton._delegate = this._addButton;
this._addButton._delegate.acceptDrop = Lang.bind(this,
function(source, actor, x, y, time) {
let view = this._currentView;
return view._acceptNewWorkspaceDrop(source, actor, x, y, time);
});
this.actor.add(this._addButton, { y_fill: false,
y_align: St.Align.START });
this._nWorkspacesNotifyId = this._nWorkspacesNotifyId =
global.screen.connect('notify::n-workspaces', global.screen.connect('notify::n-workspaces',
Lang.bind(this, this._workspacesChanged)); Lang.bind(this, this._workspacesChanged));
actor.connect('destroy', Lang.bind(this, function() { this._switchWorkspaceNotifyId =
this._controlsBar = null; global.window_manager.connect('switch-workspace',
global.screen.disconnect(this._nWorkspacesNotifyId); Lang.bind(this, this._updateButtonSensitivity));
}));
this.actor.connect('destroy', Lang.bind(this, this._onDestroy));
this._controlsBar = actor;
this._workspacesChanged(); this._workspacesChanged();
return actor; },
_onDestroy: function() {
this.actor = null;
if (this._nWorkspacesNotifyId > 0) {
global.screen.disconnect(this._nWorkspacesNotifyId);
this._nWorkspacesNotifyId = 0;
}
if (this._switchWorkspaceNotifyId > 0) {
global.window_manager.disconnect(this._switchWorkspaceNotifyId);
this._switchWorkspaceNotifyId = 0;
}
},
_setButtonSensitivity: function(button, sensitive) {
if (button == null)
return;
button.reactive = sensitive;
button.opacity = sensitive ? 255 : 85;
},
_updateButtonSensitivity: function() {
this._setButtonSensitivity(this._addButton,
this._currentView.canAddWorkspace());
this._setButtonSensitivity(this._removeButton,
this._currentView.canRemoveWorkspace());
}, },
_workspacesChanged: function() { _workspacesChanged: function() {
if (this._controlsBar == null) if (this.actor == null)
return; return;
if (global.screen.n_workspaces == 1)
this._controlsBar.set_opacity(0); this._updateButtonSensitivity();
else
this._controlsBar.set_opacity(255); if (global.screen.n_workspaces == 1) {
this._mosaicViewButton.hide();
this._singleViewButton.hide();
} else {
this._mosaicViewButton.show();
this._singleViewButton.show();
}
} }
}; };
Signals.addSignalMethods(WorkspacesViewSwitch.prototype); Signals.addSignalMethods(WorkspacesControls.prototype);