ui: Improve handling being headless

Don't assume there will always be a primary (logical) monitor, or any
(logical) monitor at all. This includes not allocating / layouting /
styling correctly when being headless.

The initial background loading will also be delayed until there are any
(logical) monitors connected.

https://bugzilla.gnome.org/show_bug.cgi?id=730551
This commit is contained in:
Jonas Ådahl 2017-04-12 14:46:54 +08:00
parent 59fc26f821
commit 5c37facc08
4 changed files with 64 additions and 12 deletions

View File

@ -129,6 +129,9 @@ var MonitorConstraint = new Lang.Class({
if (!this._primary && this._index < 0) if (!this._primary && this._index < 0)
return; return;
if (!Main.layoutManager.primaryMonitor)
return;
let index; let index;
if (this._primary) if (this._primary)
index = Main.layoutManager.primaryIndex; index = Main.layoutManager.primaryIndex;
@ -189,6 +192,7 @@ var LayoutManager = new Lang.Class({
this._topActors = []; this._topActors = [];
this._isPopupWindowVisible = false; this._isPopupWindowVisible = false;
this._startingUp = true; this._startingUp = true;
this._pendingLoadBackground = false;
// We don't want to paint the stage background color because either // We don't want to paint the stage background color because either
// the SystemBackground we create or the MetaBackgroundActor inside // the SystemBackground we create or the MetaBackgroundActor inside
@ -323,7 +327,9 @@ var LayoutManager = new Lang.Class({
for (let i = 0; i < nMonitors; i++) for (let i = 0; i < nMonitors; i++)
this.monitors.push(new Monitor(i, screen.get_monitor_geometry(i))); this.monitors.push(new Monitor(i, screen.get_monitor_geometry(i)));
if (nMonitors == 1) { if (nMonitors == 0) {
this.primaryIndex = this.bottomIndex = -1;
} else if (nMonitors == 1) {
this.primaryIndex = this.bottomIndex = 0; this.primaryIndex = this.bottomIndex = 0;
} else { } else {
// If there are monitors below the primary, then we need // If there are monitors below the primary, then we need
@ -337,8 +343,15 @@ var LayoutManager = new Lang.Class({
} }
} }
} }
if (this.primaryIndex != -1) {
this.primaryMonitor = this.monitors[this.primaryIndex]; this.primaryMonitor = this.monitors[this.primaryIndex];
this.bottomMonitor = this.monitors[this.bottomIndex]; this.bottomMonitor = this.monitors[this.bottomIndex];
if (this._pendingLoadBackground) {
this._loadBackground();
this._pendingLoadBackground = false;
}
}
}, },
_updateHotCorners: function() { _updateHotCorners: function() {
@ -458,6 +471,9 @@ var LayoutManager = new Lang.Class({
this.screenShieldGroup.set_position(0, 0); this.screenShieldGroup.set_position(0, 0);
this.screenShieldGroup.set_size(global.screen_width, global.screen_height); this.screenShieldGroup.set_size(global.screen_width, global.screen_height);
if (!this.primaryMonitor)
return;
this.panelBox.set_position(this.primaryMonitor.x, this.primaryMonitor.y); this.panelBox.set_position(this.primaryMonitor.x, this.primaryMonitor.y);
this.panelBox.set_size(this.primaryMonitor.width, -1); this.panelBox.set_size(this.primaryMonitor.width, -1);
@ -480,6 +496,9 @@ var LayoutManager = new Lang.Class({
this._rightPanelBarrier = null; this._rightPanelBarrier = null;
} }
if (!this.primaryMonitor)
return;
if (this.panelBox.height) { if (this.panelBox.height) {
let primary = this.primaryMonitor; let primary = this.primaryMonitor;
@ -549,6 +568,10 @@ var LayoutManager = new Lang.Class({
}, },
_loadBackground: function() { _loadBackground: function() {
if (!this.primaryMonitor) {
this._pendingLoadBackground = true;
return;
}
this._systemBackground = new Background.SystemBackground(); this._systemBackground = new Background.SystemBackground();
this._systemBackground.actor.hide(); this._systemBackground.actor.hide();

View File

@ -392,6 +392,9 @@ var Overview = new Lang.Class({
// when it is next shown. // when it is next shown.
this.hide(); this.hide();
if (!Main.layoutManager.primaryMonitor)
return;
let workArea = Main.layoutManager.getWorkAreaForMonitor(Main.layoutManager.primaryIndex); let workArea = Main.layoutManager.getWorkAreaForMonitor(Main.layoutManager.primaryIndex);
this._coverPane.set_position(0, workArea.y); this._coverPane.set_position(0, workArea.y);

View File

@ -839,8 +839,14 @@ var Panel = new Lang.Class({
}, },
_getPreferredWidth: function(actor, forHeight, alloc) { _getPreferredWidth: function(actor, forHeight, alloc) {
let primaryMonitor = Main.layoutManager.primaryMonitor;
alloc.min_size = -1; alloc.min_size = -1;
alloc.natural_size = Main.layoutManager.primaryMonitor.width;
if (primaryMonitor)
alloc.natural_size = primaryMonitor.width;
else
alloc.natural_size = -1;
}, },
_getPreferredHeight: function(actor, forWidth, alloc) { _getPreferredHeight: function(actor, forWidth, alloc) {
@ -859,15 +865,16 @@ var Panel = new Lang.Class({
let sideWidth, centerWidth; let sideWidth, centerWidth;
centerWidth = centerNaturalWidth; centerWidth = centerNaturalWidth;
sideWidth = (allocWidth - centerWidth) / 2; sideWidth = Math.max(0, (allocWidth - centerWidth) / 2);
let childBox = new Clutter.ActorBox(); let childBox = new Clutter.ActorBox();
childBox.y1 = 0; childBox.y1 = 0;
childBox.y2 = allocHeight; childBox.y2 = allocHeight;
if (this.actor.get_text_direction() == Clutter.TextDirection.RTL) { if (this.actor.get_text_direction() == Clutter.TextDirection.RTL) {
childBox.x1 = allocWidth - Math.min(Math.floor(sideWidth), childBox.x1 = Math.max(allocWidth - Math.min(Math.floor(sideWidth),
leftNaturalWidth); leftNaturalWidth),
0);
childBox.x2 = allocWidth; childBox.x2 = allocWidth;
} else { } else {
childBox.x1 = 0; childBox.x1 = 0;
@ -889,8 +896,9 @@ var Panel = new Lang.Class({
childBox.x2 = Math.min(Math.floor(sideWidth), childBox.x2 = Math.min(Math.floor(sideWidth),
rightNaturalWidth); rightNaturalWidth);
} else { } else {
childBox.x1 = allocWidth - Math.min(Math.floor(sideWidth), childBox.x1 = Math.max(allocWidth - Math.min(Math.floor(sideWidth),
rightNaturalWidth); rightNaturalWidth),
0);
childBox.x2 = allocWidth; childBox.x2 = allocWidth;
} }
this._rightBox.allocate(childBox, flags); this._rightBox.allocate(childBox, flags);
@ -1044,6 +1052,9 @@ var Panel = new Lang.Class({
return; return;
} }
if (!Main.layoutManager.primaryMonitor)
return;
/* Get all the windows in the active workspace that are in the primary monitor and visible */ /* Get all the windows in the active workspace that are in the primary monitor and visible */
let activeWorkspace = global.screen.get_active_workspace(); let activeWorkspace = global.screen.get_active_workspace();
let windows = activeWorkspace.list_windows().filter(function(metaWindow) { let windows = activeWorkspace.list_windows().filter(function(metaWindow) {

View File

@ -937,7 +937,8 @@ var ThumbnailsBox = new Lang.Class({
}, },
addThumbnails: function(start, count) { addThumbnails: function(start, count) {
this._ensurePorthole(); if (!this._ensurePorthole())
return;
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);
@ -1125,7 +1126,12 @@ var 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.
this._ensurePorthole(); if (!this._ensurePorthole()) {
alloc.min_size = -1;
alloc.natural_size = -1;
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');
@ -1137,7 +1143,11 @@ var ThumbnailsBox = new Lang.Class({
}, },
_getPreferredWidth: function(actor, forHeight, alloc) { _getPreferredWidth: function(actor, forHeight, alloc) {
this._ensurePorthole(); if (!this._ensurePorthole()) {
alloc.min_size = -1;
alloc.natural_size = -1;
return;
}
let themeNode = this.actor.get_theme_node(); let themeNode = this.actor.get_theme_node();
@ -1158,8 +1168,13 @@ var ThumbnailsBox = new Lang.Class({
// The "porthole" is the portion of the screen that we show in the // The "porthole" is the portion of the screen that we show in the
// workspaces // workspaces
_ensurePorthole: function() { _ensurePorthole: function() {
if (!Main.layoutManager.primaryMonitor)
return false;
if (!this._porthole) if (!this._porthole)
this._porthole = Main.layoutManager.getWorkAreaForMonitor(Main.layoutManager.primaryIndex); this._porthole = Main.layoutManager.getWorkAreaForMonitor(Main.layoutManager.primaryIndex);
return true;
}, },
_allocate: function(actor, box, flags) { _allocate: function(actor, box, flags) {