workspaceThumbnail: make ThumbnailsBox track workspace changes itself
Instead of having WorkspacesDisplay calling us. https://bugzilla.gnome.org/show_bug.cgi?id=690175
This commit is contained in:
parent
f61548234a
commit
2f7c0b1985
@ -1,6 +1,7 @@
|
|||||||
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
||||||
|
|
||||||
const Clutter = imports.gi.Clutter;
|
const Clutter = imports.gi.Clutter;
|
||||||
|
const Gio = imports.gi.Gio;
|
||||||
const Lang = imports.lang;
|
const Lang = imports.lang;
|
||||||
const Mainloop = imports.mainloop;
|
const Mainloop = imports.mainloop;
|
||||||
const Meta = imports.gi.Meta;
|
const Meta = imports.gi.Meta;
|
||||||
@ -27,6 +28,8 @@ const WORKSPACE_CUT_SIZE = 10;
|
|||||||
|
|
||||||
const WORKSPACE_KEEP_ALIVE_TIME = 100;
|
const WORKSPACE_KEEP_ALIVE_TIME = 100;
|
||||||
|
|
||||||
|
const OVERRIDE_SCHEMA = 'org.gnome.shell.overrides';
|
||||||
|
|
||||||
const WindowClone = new Lang.Class({
|
const WindowClone = new Lang.Class({
|
||||||
Name: 'WindowClone',
|
Name: 'WindowClone',
|
||||||
|
|
||||||
@ -554,6 +557,16 @@ const ThumbnailsBox = new Lang.Class({
|
|||||||
Lang.bind(this, this._onDragEnd));
|
Lang.bind(this, this._onDragEnd));
|
||||||
Main.overview.connect('window-drag-cancelled',
|
Main.overview.connect('window-drag-cancelled',
|
||||||
Lang.bind(this, this._onDragCancelled));
|
Lang.bind(this, this._onDragCancelled));
|
||||||
|
|
||||||
|
this._settings = new Gio.Settings({ schema: OVERRIDE_SCHEMA });
|
||||||
|
this._settings.connect('changed::dynamic-workspaces',
|
||||||
|
Lang.bind(this, this._updateSwitcherVisibility));
|
||||||
|
},
|
||||||
|
|
||||||
|
_updateSwitcherVisibility: function() {
|
||||||
|
this.actor.visible =
|
||||||
|
this._settings.get_boolean('dynamic-workspaces') ||
|
||||||
|
global.screen.n_workspaces > 1;
|
||||||
},
|
},
|
||||||
|
|
||||||
_onButtonRelease: function(actor, event) {
|
_onButtonRelease: function(actor, event) {
|
||||||
@ -723,6 +736,9 @@ const ThumbnailsBox = new Lang.Class({
|
|||||||
this._switchWorkspaceNotifyId =
|
this._switchWorkspaceNotifyId =
|
||||||
global.window_manager.connect('switch-workspace',
|
global.window_manager.connect('switch-workspace',
|
||||||
Lang.bind(this, this._activeWorkspaceChanged));
|
Lang.bind(this, this._activeWorkspaceChanged));
|
||||||
|
this._nWorkspacesNotifyId =
|
||||||
|
global.screen.connect('notify::n-workspaces',
|
||||||
|
Lang.bind(this, this._workspacesChanged));
|
||||||
|
|
||||||
this._targetScale = 0;
|
this._targetScale = 0;
|
||||||
this._scale = 0;
|
this._scale = 0;
|
||||||
@ -744,6 +760,8 @@ const ThumbnailsBox = new Lang.Class({
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.addThumbnails(0, global.screen.n_workspaces);
|
this.addThumbnails(0, global.screen.n_workspaces);
|
||||||
|
|
||||||
|
this._updateSwitcherVisibility();
|
||||||
},
|
},
|
||||||
|
|
||||||
hide: function() {
|
hide: function() {
|
||||||
@ -751,12 +769,40 @@ const ThumbnailsBox = new Lang.Class({
|
|||||||
global.window_manager.disconnect(this._switchWorkspaceNotifyId);
|
global.window_manager.disconnect(this._switchWorkspaceNotifyId);
|
||||||
this._switchWorkspaceNotifyId = 0;
|
this._switchWorkspaceNotifyId = 0;
|
||||||
}
|
}
|
||||||
|
if (this._nWorkspacesNotifyId > 0) {
|
||||||
|
global.screen.disconnect(this._nWorkspacesNotifyId);
|
||||||
|
this._nWorkspacesNotifyId = 0;
|
||||||
|
}
|
||||||
|
|
||||||
for (let w = 0; w < this._thumbnails.length; w++)
|
for (let w = 0; w < this._thumbnails.length; w++)
|
||||||
this._thumbnails[w].destroy();
|
this._thumbnails[w].destroy();
|
||||||
this._thumbnails = [];
|
this._thumbnails = [];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_workspacesChanged: function() {
|
||||||
|
let oldNumWorkspaces = this._thumbnails.length;
|
||||||
|
let newNumWorkspaces = global.screen.n_workspaces;
|
||||||
|
let active = global.screen.get_active_workspace_index();
|
||||||
|
|
||||||
|
if (newNumWorkspaces > oldNumWorkspaces) {
|
||||||
|
this.addThumbnails(oldNumWorkspaces, newNumWorkspaces - oldNumWorkspaces);
|
||||||
|
} else {
|
||||||
|
let removedIndex;
|
||||||
|
let removedNum = oldNumWorkspaces - newNumWorkspaces;
|
||||||
|
for (let w = 0; w < oldNumWorkspaces; w++) {
|
||||||
|
let metaWorkspace = global.screen.get_workspace_by_index(w);
|
||||||
|
if (this._thumbnails[w].metaWorkspace != metaWorkspace) {
|
||||||
|
removedIndex = w;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.removeThumbnails(removedIndex, removedNum);
|
||||||
|
}
|
||||||
|
|
||||||
|
this._updateSwitcherVisibility();
|
||||||
|
},
|
||||||
|
|
||||||
addThumbnails: function(start, count) {
|
addThumbnails: function(start, count) {
|
||||||
for (let k = start; k < start + count; k++) {
|
for (let k = start; k < start + count; k++) {
|
||||||
let metaWorkspace = global.screen.get_workspace_by_index(k);
|
let metaWorkspace = global.screen.get_workspace_by_index(k);
|
||||||
|
@ -547,10 +547,6 @@ const WorkspacesDisplay = new Lang.Class({
|
|||||||
this._notifyOpacityId = 0;
|
this._notifyOpacityId = 0;
|
||||||
this._swipeScrollBeginId = 0;
|
this._swipeScrollBeginId = 0;
|
||||||
this._swipeScrollEndId = 0;
|
this._swipeScrollEndId = 0;
|
||||||
|
|
||||||
this._settings = new Gio.Settings({ schema: OVERRIDE_SCHEMA });
|
|
||||||
this._settings.connect('changed::dynamic-workspaces',
|
|
||||||
Lang.bind(this, this._updateSwitcherVisibility));
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_onPan: function(action) {
|
_onPan: function(action) {
|
||||||
@ -560,12 +556,6 @@ const WorkspacesDisplay = new Lang.Class({
|
|||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
_updateSwitcherVisibility: function() {
|
|
||||||
this._thumbnailsBox.actor.visible =
|
|
||||||
this._settings.get_boolean('dynamic-workspaces') ||
|
|
||||||
global.screen.n_workspaces > 1;
|
|
||||||
},
|
|
||||||
|
|
||||||
show: function() {
|
show: function() {
|
||||||
if(!this._alwaysZoomOut) {
|
if(!this._alwaysZoomOut) {
|
||||||
let [mouseX, mouseY] = global.get_pointer();
|
let [mouseX, mouseY] = global.get_pointer();
|
||||||
@ -586,7 +576,6 @@ const WorkspacesDisplay = new Lang.Class({
|
|||||||
|
|
||||||
this._controls.show();
|
this._controls.show();
|
||||||
this._thumbnailsBox.show();
|
this._thumbnailsBox.show();
|
||||||
this._updateSwitcherVisibility();
|
|
||||||
|
|
||||||
this._updateWorkspacesViews();
|
this._updateWorkspacesViews();
|
||||||
|
|
||||||
@ -935,8 +924,6 @@ const WorkspacesDisplay = new Lang.Class({
|
|||||||
}
|
}
|
||||||
m++;
|
m++;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._thumbnailsBox.addThumbnails(oldNumWorkspaces, newNumWorkspaces - oldNumWorkspaces);
|
|
||||||
} else {
|
} else {
|
||||||
// Assume workspaces are only removed sequentially
|
// Assume workspaces are only removed sequentially
|
||||||
// (e.g. 2,3,4 - not 2,4,7)
|
// (e.g. 2,3,4 - not 2,4,7)
|
||||||
@ -959,14 +946,11 @@ const WorkspacesDisplay = new Lang.Class({
|
|||||||
lostWorkspaces[l].destroy();
|
lostWorkspaces[l].destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this._thumbnailsBox.removeThumbnails(removedIndex, removedNum);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < this._workspacesViews.length; i++)
|
for (let i = 0; i < this._workspacesViews.length; i++)
|
||||||
this._workspacesViews[i].updateWorkspaces(oldNumWorkspaces,
|
this._workspacesViews[i].updateWorkspaces(oldNumWorkspaces,
|
||||||
newNumWorkspaces);
|
newNumWorkspaces);
|
||||||
this._updateSwitcherVisibility();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_updateZoom : function() {
|
_updateZoom : function() {
|
||||||
|
Loading…
Reference in New Issue
Block a user