Blame SOURCES/support-headless-mode.patch

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