workspaceThumbnails: allow requesting size at any time

The slide of thumbnailWorkspace is shown when entering overview,
connecting to the same signal that creates the thumbnails, the showing
signal of overview, but, to make the slide animation we need to know how
much width the slider has.  To do that we ask the thumbnailsWorkspace
about its width, but given that it connects to the same signal it could
ask the width without having created the thumbnails yet, so reporting a
width of 0 and confusing the slide animation.

Currently it works because gjs calls the callbacks following the order
of the clients connecting that signal, and the thumbnailsWorskpace is
connected before the slide ones.

To avoid that we allow to request the preferred size of the
thumbnailsBox at any time with any number of thumbnails. The only thing
required is to make sure the porthole is accessible when requesting the
preferred size.

https://bugzilla.gnome.org/show_bug.cgi?id=732901
This commit is contained in:
Carlos Soriano 2014-07-31 17:35:27 +02:00
parent 5d12ab415c
commit 101daf6791

View File

@ -878,9 +878,6 @@ const ThumbnailsBox = new Lang.Class({
for (let key in ThumbnailState) for (let key in ThumbnailState)
this._stateCounts[ThumbnailState[key]] = 0; this._stateCounts[ThumbnailState[key]] = 0;
// The "porthole" is the portion of the screen that we show in the workspaces
this._porthole = Main.layoutManager.getWorkAreaForMonitor(Main.layoutManager.primaryIndex);
this.addThumbnails(0, global.screen.n_workspaces); this.addThumbnails(0, global.screen.n_workspaces);
this._updateSwitcherVisibility(); this._updateSwitcherVisibility();
@ -904,6 +901,7 @@ const ThumbnailsBox = new Lang.Class({
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 = [];
this._porthole = null;
}, },
_workspacesChanged: function() { _workspacesChanged: function() {
@ -934,6 +932,7 @@ const ThumbnailsBox = new Lang.Class({
}, },
addThumbnails: function(start, count) { addThumbnails: function(start, count) {
this._ensurePorthole();
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);
let thumbnail = new WorkspaceThumbnail(metaWorkspace); let thumbnail = new WorkspaceThumbnail(metaWorkspace);
@ -1121,9 +1120,7 @@ const ThumbnailsBox = new Lang.Class({
// the size request to our children because we know how big they are and know // the size request to our children because we know how big they are and know
// that the actors aren't depending on the virtual functions being called. // that the actors aren't depending on the virtual functions being called.
if (this._thumbnails.length == 0) this._ensurePorthole();
return;
let themeNode = this.actor.get_theme_node(); let themeNode = this.actor.get_theme_node();
let spacing = themeNode.get_length('spacing'); let spacing = themeNode.get_length('spacing');
@ -1135,8 +1132,7 @@ const ThumbnailsBox = new Lang.Class({
}, },
_getPreferredWidth: function(actor, forHeight, alloc) { _getPreferredWidth: function(actor, forHeight, alloc) {
if (this._thumbnails.length == 0) this._ensurePorthole();
return;
let themeNode = this.actor.get_theme_node(); let themeNode = this.actor.get_theme_node();
@ -1154,6 +1150,13 @@ const ThumbnailsBox = new Lang.Class({
alloc.natural_size = width; alloc.natural_size = width;
}, },
// The "porthole" is the portion of the screen that we show in the
// workspaces
_ensurePorthole: function() {
if (!this._porthole)
this._porthole = Main.layoutManager.getWorkAreaForMonitor(Main.layoutManager.primaryIndex);
},
_allocate: function(actor, box, flags) { _allocate: function(actor, box, flags) {
let rtl = (Clutter.get_default_text_direction () == Clutter.TextDirection.RTL); let rtl = (Clutter.get_default_text_direction () == Clutter.TextDirection.RTL);