From 57d9bd8d6e91db2c74ca99b18f44762f0b7a9e39 Mon Sep 17 00:00:00 2001
From: Dan Winship <danw@gnome.org>
Date: Mon, 13 Jun 2011 10:37:10 -0400
Subject: [PATCH] layout: deal better with vertically-stacked monitors

If there is a monitor above the "primary" monitor, then make the
topmost monitor be the primary. Likewise, figure out which monitor is
the bottom-most monitor below the primary monitor, and put the message
tray there, rather than necessarily on the primary.

https://bugzilla.gnome.org/show_bug.cgi?id=636963
---
 js/ui/layout.js      |   21 ++++++++++++++++++++-
 js/ui/messageTray.js |   24 ++++++++++++------------
 2 files changed, 32 insertions(+), 13 deletions(-)

diff --git a/js/ui/layout.js b/js/ui/layout.js
index 36e9c0e..a38db79 100644
--- a/js/ui/layout.js
+++ b/js/ui/layout.js
@@ -35,8 +35,27 @@ LayoutManager.prototype = {
         for (let i = 0; i < nMonitors; i++)
             this.monitors.push(screen.get_monitor_geometry(i));
 
-        this.primaryIndex = screen.get_primary_monitor();
+        if (nMonitors == 1) {
+            this.primaryIndex = this.bottomIndex = 0;
+        } else {
+            // If there are monitors above the primary, then we need
+            // to redeclare the topmost monitor to be the primary.
+            // Likewise, if there are monitors below it, we need to
+            // split primary from bottom.
+
+            this.primaryIndex = this.bottomIndex = screen.get_primary_monitor();
+            for (let i = 0; i < this.monitors.length; i++) {
+                let monitor = this.monitors[i];
+                if (this._isAboveOrBelowPrimary(monitor)) {
+                    if (monitor.y < this.monitors[this.primaryIndex].y)
+                        this.primaryIndex = i;
+                    else if (monitor.y > this.monitors[this.bottomIndex].y)
+                        this.bottomIndex = i;
+                }
+            }
+        }
         this.primaryMonitor = this.monitors[this.primaryIndex];
+        this.bottomMonitor = this.monitors[this.bottomIndex];
     },
 
     _updateHotCorners: function() {
diff --git a/js/ui/messageTray.js b/js/ui/messageTray.js
index 0e4c8bd..13a9c7d 100644
--- a/js/ui/messageTray.js
+++ b/js/ui/messageTray.js
@@ -1292,20 +1292,20 @@ MessageTray.prototype = {
     },
 
     _setSizePosition: function() {
-        let primary = Main.layoutManager.primaryMonitor;
-        this.actor.x = primary.x;
-        this.actor.y = primary.y + primary.height - 1;
-        this.actor.width = primary.width;
+        let monitor = Main.layoutManager.bottomMonitor;
+        this.actor.x = monitor.x;
+        this.actor.y = monitor.y + monitor.height - 1;
+        this.actor.width = monitor.width;
         this._notificationBin.x = 0;
-        this._notificationBin.width = primary.width;
+        this._notificationBin.width = monitor.width;
         this._summaryBin.x = 0;
-        this._summaryBin.width = primary.width;
+        this._summaryBin.width = monitor.width;
 
         if (this._pointerBarrier)
             global.destroy_pointer_barrier(this._pointerBarrier);
         this._pointerBarrier =
-            global.create_pointer_barrier(primary.x + primary.width, primary.y + primary.height - this.actor.height,
-                                          primary.x + primary.width, primary.y + primary.height,
+            global.create_pointer_barrier(monitor.x + monitor.width, monitor.y + monitor.height - this.actor.height,
+                                          monitor.x + monitor.width, monitor.y + monitor.height,
                                           4 /* BarrierNegativeX */);
 
 
@@ -1864,18 +1864,18 @@ MessageTray.prototype = {
     },
 
     _showTray: function() {
-        let primary = Main.layoutManager.primaryMonitor;
+        let monitor = Main.layoutManager.bottomMonitor;
         this._tween(this.actor, '_trayState', State.SHOWN,
-                    { y: primary.y + primary.height - this.actor.height,
+                    { y: monitor.y + monitor.height - this.actor.height,
                       time: ANIMATION_TIME,
                       transition: 'easeOutQuad'
                     });
     },
 
     _hideTray: function() {
-        let primary = Main.layoutManager.primaryMonitor;
+        let monitor = Main.layoutManager.bottomMonitor;
         this._tween(this.actor, '_trayState', State.HIDDEN,
-                    { y: primary.y + primary.height - 1,
+                    { y: monitor.y + monitor.height - 1,
                       time: ANIMATION_TIME,
                       transition: 'easeOutQuad'
                     });
-- 
1.7.5.2