From 191f8b08f0235b300fab68384abf4ecec2845a03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Thu, 16 Jul 2015 15:15:41 +0200 Subject: [PATCH] layout: Handle the no-monitor case --- js/ui/layout.js | 50 +++++++++++++++++++++++++++++++++------------ js/ui/lookingGlass.js | 4 ++++ js/ui/messageTray.js | 3 ++- js/ui/panel.js | 5 ++++- js/ui/workspaceThumbnail.js | 3 ++- 5 files changed, 49 insertions(+), 16 deletions(-) diff --git a/js/ui/layout.js b/js/ui/layout.js index aaf9da536..9e41d779e 100644 --- a/js/ui/layout.js +++ b/js/ui/layout.js @@ -136,7 +136,10 @@ const MonitorConstraint = new Lang.Class({ index = Math.min(this._index, Main.layoutManager.monitors.length - 1); let rect; - if (this._workArea) { + if (Main.layoutManager.monitors.length == 0) { + rect = new Meta.Rectangle({ width: global.screen_width, + height: global.screen_height }); + } else if (this._workArea) { let ws = global.screen.get_workspace_by_index(0); rect = ws.get_work_area_for_monitor(index); } else { @@ -323,7 +326,9 @@ const LayoutManager = new Lang.Class({ for (let i = 0; i < nMonitors; 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; } else { // If there are monitors below the primary, then we need @@ -337,8 +342,10 @@ const LayoutManager = new Lang.Class({ } } } - this.primaryMonitor = this.monitors[this.primaryIndex]; - this.bottomMonitor = this.monitors[this.bottomIndex]; + this.primaryMonitor = this.primaryIndex > -1 ? this.monitors[this.primaryIndex] + : null; + this.bottomMonitor = this.bottomIndex > -1 ? this.monitors[this.bottomIndex] + : null; }, _updateHotCorners: function() { @@ -449,6 +456,10 @@ const LayoutManager = new Lang.Class({ }, _updateKeyboardBox: function() { + this.keyboardBox.visible = this.keyboardMonitor != null; + if (!this.keyboardBox.visible) + return; + this.keyboardBox.set_position(this.keyboardMonitor.x, this.keyboardMonitor.y + this.keyboardMonitor.height); this.keyboardBox.set_size(this.keyboardMonitor.width, -1); @@ -458,8 +469,13 @@ const LayoutManager = new Lang.Class({ this.screenShieldGroup.set_position(0, 0); this.screenShieldGroup.set_size(global.screen_width, global.screen_height); - this.panelBox.set_position(this.primaryMonitor.x, this.primaryMonitor.y); - this.panelBox.set_size(this.primaryMonitor.width, -1); + if (this.primaryMonitor != null) { + this.panelBox.set_position(this.primaryMonitor.x, this.primaryMonitor.y); + this.panelBox.set_size(this.primaryMonitor.width, -1); + } else { + this.panelBox.set_position(0, 0); + this.panelBox.set_size(global.screen_width, -1); + } this.keyboardIndex = this.primaryIndex; }, @@ -480,9 +496,8 @@ const LayoutManager = new Lang.Class({ this._rightPanelBarrier = null; } - if (this.panelBox.height) { - let primary = this.primaryMonitor; - + let primary = this.primaryMonitor; + if (this.panelBox.height && primary) { this._rightPanelBarrier = new Meta.Barrier({ display: global.display, x1: primary.x + primary.width, y1: primary.y, x2: primary.x + primary.width, y2: primary.y + this.panelBox.height, @@ -522,7 +537,7 @@ const LayoutManager = new Lang.Class({ }, get keyboardMonitor() { - return this.monitors[this.keyboardIndex]; + return this.keyboardIndex > -1 ? this.monitors[this.keyboardIndex] : null; }, get focusIndex() { @@ -536,7 +551,7 @@ const LayoutManager = new Lang.Class({ }, get focusMonitor() { - return this.monitors[this.focusIndex]; + return this.focusIndex > -1 ? this.monitors[this.focusIndex] : null; }, set keyboardIndex(v) { @@ -591,7 +606,9 @@ const LayoutManager = new Lang.Class({ reactive: true }); this.addChrome(this._coverPane); - if (Meta.is_restart()) { + if (global.screen.get_n_monitors() == 0) { + // Don't do anything + } else if (Meta.is_restart()) { // On restart, we don't do an animation. Force an update of the // regions immediately so that maximized windows restore to the // right size taking struts into account. @@ -634,7 +651,7 @@ const LayoutManager = new Lang.Class({ }, _startupAnimation: function() { - if (Meta.is_restart()) + if (Meta.is_restart() || global.screen.get_n_monitors() == 0) this._startupAnimationComplete(); else if (Main.sessionMode.isGreeter) this._startupAnimationGreeter(); @@ -863,6 +880,8 @@ const LayoutManager = new Lang.Class({ _updateActorVisibility: function(actorData) { if (!actorData.trackFullscreen) return; + if (global.screen.get_n_monitors() == 0) + return; let monitor = this.findMonitorForActor(actorData.actor); actorData.actor.visible = !(global.window_group.visible && @@ -880,6 +899,9 @@ const LayoutManager = new Lang.Class({ }, getWorkAreaForMonitor: function(monitorIndex) { + if (monitorIndex < 0) + return new Meta.Rectangle(); + // Assume that all workspaces will have the same // struts and pick the first one. let ws = global.screen.get_workspace_by_index(0); @@ -985,6 +1007,8 @@ const LayoutManager = new Lang.Class({ let monitor = this.findMonitorForActor(actorData.actor); let side; + if (!monitor) + continue; if (x1 <= monitor.x && x2 >= monitor.x + monitor.width) { if (y1 <= monitor.y) side = Meta.Side.TOP; diff --git a/js/ui/lookingGlass.js b/js/ui/lookingGlass.js index 7dd8bd1c0..abca97600 100644 --- a/js/ui/lookingGlass.js +++ b/js/ui/lookingGlass.js @@ -538,6 +538,8 @@ const Inspector = new Lang.Class({ return; let primary = Main.layoutManager.primaryMonitor; + if (!primary) + return; let [minWidth, minHeight, natWidth, natHeight] = this._eventHandler.get_preferred_size(); @@ -1036,6 +1038,8 @@ const LookingGlass = new Lang.Class({ _resize: function() { let primary = Main.layoutManager.primaryMonitor; + if (!primary) + return; let myWidth = primary.width * 0.7; let availableHeight = primary.height - Main.layoutManager.keyboardBox.height; let myHeight = Math.min(primary.height * 0.7, availableHeight * 0.9); diff --git a/js/ui/messageTray.js b/js/ui/messageTray.js index 4f1ab7fea..16b9ef6bc 100644 --- a/js/ui/messageTray.js +++ b/js/ui/messageTray.js @@ -1224,7 +1224,8 @@ const MessageTray = new Lang.Class({ if (this._notificationState == State.HIDDEN) { let nextNotification = this._notificationQueue[0] || null; if (hasNotifications && nextNotification) { - let limited = this._busy || Main.layoutManager.bottomMonitor.inFullscreen; + let bottomMonitor = Main.layoutManager.bottomMonitor; + let limited = this._busy || (bottomMonitor && bottomMonitor.inFullscreen); let showNextNotification = (!limited || nextNotification.forFeedback || nextNotification.urgency == Urgency.CRITICAL); if (showNextNotification) this._showNotification(); diff --git a/js/ui/panel.js b/js/ui/panel.js index eededfae1..d07bbaa7b 100644 --- a/js/ui/panel.js +++ b/js/ui/panel.js @@ -820,7 +820,10 @@ const Panel = new Lang.Class({ _getPreferredWidth: function(actor, forHeight, alloc) { alloc.min_size = -1; - alloc.natural_size = Main.layoutManager.primaryMonitor.width; + if (Main.layoutManager.primaryMonitor) + alloc.natural_size = Main.layoutManager.primaryMonitor.width; + else + alloc.natural_size = 0; }, _getPreferredHeight: function(actor, forWidth, alloc) { diff --git a/js/ui/workspaceThumbnail.js b/js/ui/workspaceThumbnail.js index 980ffd665..d19ce1f6a 100644 --- a/js/ui/workspaceThumbnail.js +++ b/js/ui/workspaceThumbnail.js @@ -275,7 +275,8 @@ const WorkspaceThumbnail = new Lang.Class({ this._createBackground(); let monitor = Main.layoutManager.primaryMonitor; - this.setPorthole(monitor.x, monitor.y, monitor.width, monitor.height); + if (monitor) + this.setPorthole(monitor.x, monitor.y, monitor.width, monitor.height); let windows = global.get_window_actors().filter(Lang.bind(this, function(actor) { let win = actor.meta_window; -- 2.12.0