workspaceThumbnail: Clean up porthole/workarea setting and updating

Instead of unnecessarily updating the porthole on every call to the
layout vfuncs and returning widths and heights of 0 when the overview is
hidden, only update it on actual workarea changes.

Also use the stage size for the porthole in case no monitor is available
to make sure we don't try to allocate a 0-sized box.

Fixes https://gitlab.gnome.org/GNOME/gnome-shell/issues/892, https://gitlab.gnome.org/GNOME/gnome-shell/issues/517

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/343
This commit is contained in:
verdre 2019-01-11 23:50:09 +01:00
parent 5f4e2749a2
commit f6da36ad3a

View File

@ -624,6 +624,10 @@ class ThumbnailsBox extends St.Widget {
this._indicator = indicator; this._indicator = indicator;
this.add_actor(indicator); this.add_actor(indicator);
// The porthole is the part of the screen we're showing in the thumbnails
this._porthole = { width: global.stage.width, height: global.stage.height,
x: global.stage.x, y: global.stage.y };
this._dropWorkspace = -1; this._dropWorkspace = -1;
this._dropPlaceholderPos = -1; this._dropPlaceholderPos = -1;
this._dropPlaceholder = new St.Bin({ style_class: 'placeholder' }); this._dropPlaceholder = new St.Bin({ style_class: 'placeholder' });
@ -675,6 +679,9 @@ class ThumbnailsBox extends St.Widget {
this._createThumbnails(); this._createThumbnails();
}); });
global.display.connect('workareas-changed',
this._updatePorthole.bind(this));
this._switchWorkspaceNotifyId = 0; this._switchWorkspaceNotifyId = 0;
this._nWorkspacesNotifyId = 0; this._nWorkspacesNotifyId = 0;
this._syncStackingId = 0; this._syncStackingId = 0;
@ -912,7 +919,6 @@ class ThumbnailsBox extends St.Widget {
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() { _workspacesChanged() {
@ -945,8 +951,6 @@ class ThumbnailsBox extends St.Widget {
addThumbnails(start, count) { addThumbnails(start, count) {
let workspaceManager = global.workspace_manager; let workspaceManager = global.workspace_manager;
if (!this._ensurePorthole())
return;
for (let k = start; k < start + count; k++) { for (let k = start; k < start + count; k++) {
let metaWorkspace = workspaceManager.get_workspace_by_index(k); let metaWorkspace = workspaceManager.get_workspace_by_index(k);
let thumbnail = new WorkspaceThumbnail(metaWorkspace); let thumbnail = new WorkspaceThumbnail(metaWorkspace);
@ -1126,10 +1130,6 @@ class ThumbnailsBox extends St.Widget {
// Note that for getPreferredWidth/Height we cheat a bit and skip propagating // Note that for getPreferredWidth/Height we cheat a bit and skip propagating
// 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._ensurePorthole())
return [0, 0];
let workspaceManager = global.workspace_manager; let workspaceManager = global.workspace_manager;
let themeNode = this.get_theme_node(); let themeNode = this.get_theme_node();
@ -1143,9 +1143,6 @@ class ThumbnailsBox extends St.Widget {
} }
vfunc_get_preferred_width(forHeight) { vfunc_get_preferred_width(forHeight) {
if (!this._ensurePorthole())
return [0, 0];
let workspaceManager = global.workspace_manager; let workspaceManager = global.workspace_manager;
let themeNode = this.get_theme_node(); let themeNode = this.get_theme_node();
@ -1165,16 +1162,14 @@ class ThumbnailsBox extends St.Widget {
return themeNode.adjust_preferred_width(width, width); return themeNode.adjust_preferred_width(width, width);
} }
// The "porthole" is the portion of the screen that we show in the _updatePorthole() {
// workspaces if (!Main.layoutManager.primaryMonitor)
_ensurePorthole() { this._porthole = { width: global.stage.width, height: global.stage.height,
if (!Main.layoutManager.primaryMonitor || !Main.overview.visible) x: global.stage.x, y: global.stage.y };
return false; else
if (!this._porthole)
this._porthole = Main.layoutManager.getWorkAreaForMonitor(Main.layoutManager.primaryIndex); this._porthole = Main.layoutManager.getWorkAreaForMonitor(Main.layoutManager.primaryIndex);
return true; this.queue_relayout();
} }
vfunc_allocate(box, flags) { vfunc_allocate(box, flags) {