[gnome-shell] layout: new file handling shell layout



commit 64b2b4a7d42bacc4be4f920699b339e9206946ae
Author: Dan Winship <danw gnome org>
Date:   Mon Jun 13 09:54:05 2011 -0400

    layout: new file handling shell layout
    
    Remove ShellGlobal's monitor-related methods, and have
    Main.layoutManager provide that information instead. Move
    Main._relayout() to LayoutManager, and have other objects connect to
    the layout manager's 'monitors-changed' signal to know when the screen
    geometry has changed.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=636963

 js/ui/altTab.js                 |   10 ++--
 js/ui/boxpointer.js             |    3 +-
 js/ui/chrome.js                 |   36 +++--------
 js/ui/ctrlAltTab.js             |    6 +-
 js/ui/layout.js                 |  130 +++++++++++++++++++++++++++++++++++++++
 js/ui/lookingGlass.js           |    4 +-
 js/ui/main.js                   |   89 ++-------------------------
 js/ui/messageTray.js            |    9 +--
 js/ui/modalDialog.js            |    2 +-
 js/ui/overview.js               |   15 +++-
 js/ui/panel.js                  |    7 ++-
 js/ui/panelMenu.js              |    2 +-
 js/ui/scripting.js              |   13 ++---
 js/ui/windowManager.js          |    2 +-
 js/ui/workspace.js              |    6 +-
 js/ui/workspaceSwitcherPopup.js |    6 +-
 js/ui/workspaceThumbnail.js     |    6 +-
 js/ui/workspacesView.js         |   16 +++---
 src/shell-global.c              |  103 -------------------------------
 src/shell-global.h              |    4 -
 20 files changed, 203 insertions(+), 266 deletions(-)
---
diff --git a/js/ui/altTab.js b/js/ui/altTab.js
index 9a62432..8c01231 100644
--- a/js/ui/altTab.js
+++ b/js/ui/altTab.js
@@ -74,7 +74,7 @@ AltTabPopup.prototype = {
 
     _allocate: function (actor, box, flags) {
         let childBox = new Clutter.ActorBox();
-        let primary = global.get_primary_monitor();
+        let primary = Main.layoutManager.primaryMonitor;
 
         let leftPadding = this.actor.get_theme_node().get_padding(St.Side.LEFT);
         let rightPadding = this.actor.get_theme_node().get_padding(St.Side.RIGHT);
@@ -618,7 +618,7 @@ SwitcherList.prototype = {
                 this._items[this._highlighted].add_style_pseudo_class('selected');
         }
 
-        let monitor = global.get_primary_monitor();
+        let monitor = Main.layoutManager.primaryMonitor;
         let itemSize = this._items[index].allocation.x2 - this._items[index].allocation.x1;
         let [posX, posY] = this._items[index].get_transformed_position();
         posX += this.actor.x;
@@ -646,7 +646,7 @@ SwitcherList.prototype = {
 
     _scrollToRight : function() {
         this._scrollableLeft = true;
-        let monitor = global.get_primary_monitor();
+        let monitor = Main.layoutManager.primaryMonitor;
         let padding = this.actor.get_theme_node().get_horizontal_padding();
         let parentPadding = this.actor.get_parent().get_theme_node().get_horizontal_padding();
         let x = this._items[this._highlighted].allocation.x2 - monitor.width + padding + parentPadding;
@@ -743,7 +743,7 @@ SwitcherList.prototype = {
         let children = this._list.get_children();
         let childBox = new Clutter.ActorBox();
 
-        let primary = global.get_primary_monitor();
+        let primary = Main.layoutManager.primaryMonitor;
         let parentRightPadding = this.actor.get_parent().get_theme_node().get_padding(St.Side.RIGHT);
         if (this.actor.allocation.x2 == primary.x + primary.width - parentRightPadding) {
             if (this._squareItems)
@@ -873,7 +873,7 @@ AppSwitcher.prototype = {
            totalSpacing += this._separator.width + this._list.spacing;
 
         // We just assume the whole screen here due to weirdness happing with the passed width
-        let primary = global.get_primary_monitor();
+        let primary = Main.layoutManager.primaryMonitor;
         let parentPadding = this.actor.get_parent().get_theme_node().get_horizontal_padding();
         let availWidth = primary.width - parentPadding - this.actor.get_theme_node().get_horizontal_padding();
         let height = 0;
diff --git a/js/ui/boxpointer.js b/js/ui/boxpointer.js
index bc459fc..7051848 100644
--- a/js/ui/boxpointer.js
+++ b/js/ui/boxpointer.js
@@ -6,6 +6,7 @@ const Meta = imports.gi.Meta;
 const St = imports.gi.St;
 const Shell = imports.gi.Shell;
 
+const Main = imports.ui.main;
 const Tweener = imports.ui.tweener;
 
 const POPUP_ANIMATION_TIME = 0.15;
@@ -329,7 +330,7 @@ BoxPointer.prototype = {
         // We also want to keep it onscreen, and separated from the
         // edge by the same distance as the main part of the box is
         // separated from its sourceActor
-        let primary = global.get_primary_monitor();
+        let primary = Main.layoutManager.primaryMonitor;
         let themeNode = this.actor.get_theme_node();
         let borderWidth = themeNode.get_length('-arrow-border-width');
         let arrowBase = themeNode.get_length('-arrow-base');
diff --git a/js/ui/chrome.js b/js/ui/chrome.js
index 474deb9..f2a7d14 100644
--- a/js/ui/chrome.js
+++ b/js/ui/chrome.js
@@ -35,8 +35,8 @@ Chrome.prototype = {
 
         this._trackedActors = [];
 
-        global.screen.connect('monitors-changed',
-                              Lang.bind(this, this._monitorsChanged));
+        Main.layoutManager.connect('monitors-changed',
+                                   Lang.bind(this, this._relayout));
         global.screen.connect('restacked',
                               Lang.bind(this, this._windowsRestacked));
 
@@ -49,9 +49,7 @@ Chrome.prototype = {
         Main.overview.connect('hidden',
                              Lang.bind(this, this._overviewHidden));
 
-        this._updateMonitors();
-        this._updateFullscreen();
-        this._queueUpdateRegions();
+        this._relayout();
     },
 
     _allocated: function(actor, box, flags) {
@@ -205,18 +203,13 @@ Chrome.prototype = {
         this._queueUpdateRegions();
     },
 
-    _updateMonitors: function() {
-        let monitors = global.get_monitors();
-        let primary = global.get_primary_monitor();
-        this._monitors = monitors;
-        for (let i = 0; i < monitors.length; i++) {
-            let monitor = monitors[i];
-            if (monitor.x == primary.x &&
-                monitor.y == primary.y &&
-                monitor.width == primary.width &&
-                monitor.height == primary.height)
-                this._primaryMonitor = monitor;
-        }
+    _relayout: function() {
+        this._monitors = Main.layoutManager.monitors;
+        this._primaryMonitor = Main.layoutManager.primaryMonitor;
+
+        this._updateFullscreen();
+        this._updateVisibility();
+        this._queueUpdateRegions();
     },
 
     _findMonitorForRect: function(x, y, w, h) {
@@ -255,15 +248,6 @@ Chrome.prototype = {
         return this._primaryMonitor; // Not on any monitor, pretend its on the primary
     },
 
-    _monitorsChanged: function() {
-        this._updateMonitors();
-
-        // Update everything that depends on monitor positions
-        this._updateFullscreen();
-        this._updateVisibility();
-        this._queueUpdateRegions();
-    },
-
     _queueUpdateRegions: function() {
         if (!this._updateRegionIdle)
             this._updateRegionIdle = Mainloop.idle_add(Lang.bind(this, this._updateRegions),
diff --git a/js/ui/ctrlAltTab.js b/js/ui/ctrlAltTab.js
index cf76dfb..d0845a3 100644
--- a/js/ui/ctrlAltTab.js
+++ b/js/ui/ctrlAltTab.js
@@ -153,14 +153,14 @@ CtrlAltTabPopup.prototype = {
     },
 
     _getPreferredWidth: function (actor, forHeight, alloc) {
-        let primary = global.get_primary_monitor();
+        let primary = Main.layoutManager.primaryMonitor;
 
         alloc.min_size = primary.width;
         alloc.natural_size = primary.width;
     },
 
     _getPreferredHeight: function (actor, forWidth, alloc) {
-        let primary = global.get_primary_monitor();
+        let primary = Main.layoutManager.primaryMonitor;
 
         alloc.min_size = primary.height;
         alloc.natural_size = primary.height;
@@ -168,7 +168,7 @@ CtrlAltTabPopup.prototype = {
 
     _allocate: function (actor, box, flags) {
         let childBox = new Clutter.ActorBox();
-        let primary = global.get_primary_monitor();
+        let primary = Main.layoutManager.primaryMonitor;
 
         let leftPadding = this.actor.get_theme_node().get_padding(St.Side.LEFT);
         let vPadding = this.actor.get_theme_node().get_vertical_padding();
diff --git a/js/ui/layout.js b/js/ui/layout.js
new file mode 100644
index 0000000..0fd0eb5
--- /dev/null
+++ b/js/ui/layout.js
@@ -0,0 +1,130 @@
+/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
+
+const Lang = imports.lang;
+const Signals = imports.signals;
+const St = imports.gi.St;
+
+const Main = imports.ui.main;
+const Panel = imports.ui.panel;
+
+function LayoutManager() {
+    this._init.apply(this, arguments);
+}
+
+LayoutManager.prototype = {
+    _init: function () {
+        this._rtl = (St.Widget.get_default_direction() == St.TextDirection.RTL);
+        this.monitors = [];
+        this.primaryMonitor = null;
+        this.primaryIndex = -1;
+        this._hotCorners = [];
+
+        this._updateMonitors();
+    },
+
+    // This is called by Main after everything else is constructed;
+    // _updateHotCorners needs access to Main.panel, which didn't exist
+    // yet when the LayoutManager was constructed.
+    init: function() {
+        global.screen.connect('monitors-changed', Lang.bind(this, this._monitorsChanged));
+        this._updateHotCorners();
+    },
+
+    _updateMonitors: function() {
+        let screen = global.screen;
+
+        this.monitors = [];
+        let nMonitors = screen.get_n_monitors();
+        for (let i = 0; i < nMonitors; i++)
+            this.monitors.push(screen.get_monitor_geometry(i));
+
+        this.primaryIndex = screen.get_primary_monitor();
+        this.primaryMonitor = this.monitors[this.primaryIndex];
+    },
+
+    _updateHotCorners: function() {
+        // destroy old hot corners
+        for (let i = 0; i < this._hotCorners.length; i++)
+            this._hotCorners[i].destroy();
+        this._hotCorners = [];
+
+        // build new hot corners
+        for (let i = 0; i < this.monitors.length; i++) {
+            let monitor = this.monitors[i];
+            let cornerX = this._rtl ? monitor.x + monitor.width : monitor.x;
+            let cornerY = monitor.y;
+
+            let haveTopLeftCorner = true;
+
+            if (i != this.primaryIndex) {
+                // Check if we have a top left (right for RTL) corner.
+                // I.e. if there is no monitor directly above or to the left(right)
+                let besideX = this._rtl ? monitor.x + 1 : cornerX - 1;
+                let besideY = cornerY;
+                let aboveX = cornerX;
+                let aboveY = cornerY - 1;
+
+                for (let j = 0; j < this.monitors.length; j++) {
+                    if (i == j)
+                        continue;
+                    let otherMonitor = this.monitors[j];
+                    if (besideX >= otherMonitor.x &&
+                        besideX < otherMonitor.x + otherMonitor.width &&
+                        besideY >= otherMonitor.y &&
+                        besideY < otherMonitor.y + otherMonitor.height) {
+                        haveTopLeftCorner = false;
+                        break;
+                    }
+                    if (aboveX >= otherMonitor.x &&
+                        aboveX < otherMonitor.x + otherMonitor.width &&
+                        aboveY >= otherMonitor.y &&
+                        aboveY < otherMonitor.y + otherMonitor.height) {
+                        haveTopLeftCorner = false;
+                        break;
+                    }
+                }
+            }
+
+            if (!haveTopLeftCorner)
+                continue;
+
+            let corner = new Panel.HotCorner(i == this.primaryIndex ? Main.panel.button : null);
+            this._hotCorners.push(corner);
+            corner.actor.set_position(cornerX, cornerY);
+            if (i == this.primaryIndex)
+                Main.panel.setHotCorner(corner);
+        }
+    },
+
+    _monitorsChanged: function() {
+        this._updateMonitors();
+        this._updateHotCorners();
+
+        this.emit('monitors-changed');
+    },
+
+    get focusIndex() {
+        let screen = global.screen;
+        let display = screen.get_display();
+        let focusWindow = display.focus_window;
+
+        if (focusWindow) {
+            let wrect = focusWindow.get_outer_rect();
+            for (let i = 0; i < this.monitors.length; i++) {
+                let monitor = this.monitors[i];
+
+                if (monitor.x <= wrect.x && monitor.y <= wrect.y &&
+                    monitor.x + monitor.width > wrect.x &&
+                    monitor.y + monitor.height > wrect.y)
+                    return i;
+            }
+        }
+
+        return this.primaryIndex;
+    },
+
+    get focusMonitor() {
+        return this.monitors[this.focusIndex];
+    }
+};
+Signals.addSignalMethods(LayoutManager.prototype);
diff --git a/js/ui/lookingGlass.js b/js/ui/lookingGlass.js
index d7d50de..e40d86c 100644
--- a/js/ui/lookingGlass.js
+++ b/js/ui/lookingGlass.js
@@ -436,7 +436,7 @@ Inspector.prototype = {
         if (!this._eventHandler)
             return;
 
-        let primary = global.get_primary_monitor();
+        let primary = Main.layoutManager.primaryMonitor;
 
         let [minWidth, minHeight, natWidth, natHeight] =
             this._eventHandler.get_preferred_size();
@@ -907,7 +907,7 @@ LookingGlass.prototype = {
     },
 
     _resizeTo: function(actor) {
-        let primary = global.get_primary_monitor();
+        let primary = Main.layoutManager.primaryMonitor;
         let myWidth = primary.width * 0.7;
         let myHeight = primary.height * 0.7;
         let [srcX, srcY] = actor.get_transformed_position();
diff --git a/js/ui/main.js b/js/ui/main.js
index 43fcfa5..8ca9da9 100644
--- a/js/ui/main.js
+++ b/js/ui/main.js
@@ -23,6 +23,7 @@ const Overview = imports.ui.overview;
 const Panel = imports.ui.panel;
 const PlaceDisplay = imports.ui.placeDisplay;
 const RunDialog = imports.ui.runDialog;
+const Layout = imports.ui.layout;
 const LookingGlass = imports.ui.lookingGlass;
 const NotificationDaemon = imports.ui.notificationDaemon;
 const WindowAttentionHandler = imports.ui.windowAttentionHandler;
@@ -59,6 +60,7 @@ let uiGroup = null;
 let magnifier = null;
 let xdndHandler = null;
 let statusIconDispatcher = null;
+let layoutManager = null;
 let _errorLogStack = [];
 let _startDate;
 let _defaultCssStylesheet = null;
@@ -126,6 +128,7 @@ function start() {
     global.overlay_group.reparent(uiGroup);
     global.stage.add_actor(uiGroup);
 
+    layoutManager = new Layout.LayoutManager();
     placesManager = new PlaceDisplay.PlacesManager();
     xdndHandler = new XdndHandler.XdndHandler();
     ctrlAltTabManager = new CtrlAltTab.CtrlAltTabManager();
@@ -140,6 +143,7 @@ function start() {
     windowAttentionHandler = new WindowAttentionHandler.WindowAttentionHandler();
     telepathyClient = new TelepathyClient.Client();
 
+    layoutManager.init();
     overview.init();
     statusIconDispatcher.start(messageTray.actor);
 
@@ -178,14 +182,9 @@ function start() {
     // Attempt to become a PolicyKit authentication agent
     PolkitAuthenticationAgent.init()
 
-    global.screen.connect('monitors-changed', _relayout);
-
     ExtensionSystem.init();
     ExtensionSystem.loadExtensions();
 
-    // Perform initial relayout here
-    _relayout();
-
     panel.startStatusArea();
     panel.startupAnimation();
 
@@ -300,14 +299,14 @@ function _windowRemoved(workspace, window) {
 function _windowLeftMonitor(metaScreen, monitorIndex, metaWin) {
     // If the window left the primary monitor, that
     // might make that workspace empty
-    if (monitorIndex == global.get_primary_monitor_index())
+    if (monitorIndex == layoutManager.primaryIndex)
         _queueCheckWorkspaces();
 }
 
 function _windowEnteredMonitor(metaScreen, monitorIndex, metaWin) {
     // If the window entered the primary monitor, that
     // might make that workspace non-empty
-    if (monitorIndex == global.get_primary_monitor_index())
+    if (monitorIndex == layoutManager.primaryIndex)
         _queueCheckWorkspaces();
 }
 
@@ -481,82 +480,6 @@ function _getAndClearErrorStack() {
     return errors;
 }
 
-function _relayout() {
-    let monitors = global.get_monitors();
-    // destroy old corners
-    for (let i = 0; i < hotCorners.length; i++)
-        hotCorners[i].destroy();
-    hotCorners = [];
-
-
-    let primary = global.get_primary_monitor();
-    for (let i = 0; i < monitors.length; i++) {
-        let monitor = monitors[i];
-        let isPrimary = (monitor.x == primary.x &&
-                         monitor.y == primary.y &&
-                         monitor.width == primary.width &&
-                         monitor.height == primary.height);
-
-        let cornerX = monitor.x;
-        let cornerY = monitor.y;
-        if (St.Widget.get_default_direction() == St.TextDirection.RTL)
-            cornerX += monitor.width;
-
-
-        let haveTopLeftCorner = true;
-
-        /* Check if we have a top left (right for RTL) corner.
-         * I.e. if there is no monitor directly above or to the left(right) */
-        let besideX;
-        if (St.Widget.get_default_direction() == St.TextDirection.RTL)
-            besideX = monitor.x + 1;
-        else
-            besideX = cornerX - 1;
-        let besideY = cornerY;
-        let aboveX = cornerX;
-        let aboveY = cornerY - 1;
-
-        for (let j = 0; j < monitors.length; j++) {
-            if (i == j)
-                continue;
-            let otherMonitor = monitors[j];
-            if (besideX >= otherMonitor.x &&
-                besideX < otherMonitor.x + otherMonitor.width &&
-                besideY >= otherMonitor.y &&
-                besideY < otherMonitor.y + otherMonitor.height) {
-                haveTopLeftCorner = false;
-                break;
-            }
-            if (aboveX >= otherMonitor.x &&
-                aboveX < otherMonitor.x + otherMonitor.width &&
-                aboveY >= otherMonitor.y &&
-                aboveY < otherMonitor.y + otherMonitor.height) {
-                haveTopLeftCorner = false;
-                break;
-            }
-        }
-
-        /* We only want hot corners where there is a natural top-left
-         * corner, and on the primary monitor */
-        if (!isPrimary && !haveTopLeftCorner)
-            continue;
-
-        let corner = new Panel.HotCorner(isPrimary ? panel.button : null);
-        hotCorners.push(corner);
-        corner.actor.set_position(cornerX, cornerY);
-        if (isPrimary)
-            panel.setHotCorner(corner);
-    }
-
-    panel.relayout();
-    overview.relayout();
-
-    // To avoid updating the position and size of the workspaces
-    // in the overview, we just hide the overview. The positions
-    // will be updated when it is next shown.
-    overview.hide();
-}
-
 function isWindowActorDisplayedOnWorkspace(win, workspaceIndex) {
     return win.get_workspace() == workspaceIndex ||
         (win.get_meta_window() && win.get_meta_window().is_on_all_workspaces());
diff --git a/js/ui/messageTray.js b/js/ui/messageTray.js
index 383a68a..a1b99bf 100644
--- a/js/ui/messageTray.js
+++ b/js/ui/messageTray.js
@@ -1257,7 +1257,7 @@ MessageTray.prototype = {
         Main.chrome.trackActor(this._notificationBin);
         Main.chrome.trackActor(this._summaryBoxPointer.actor);
 
-        global.screen.connect('monitors-changed', Lang.bind(this, this._setSizePosition));
+        Main.layoutManager.connect('monitors-changed', Lang.bind(this, this._setSizePosition));
 
         this._setSizePosition();
 
@@ -1293,7 +1293,7 @@ MessageTray.prototype = {
     },
 
     _setSizePosition: function() {
-        let primary = global.get_primary_monitor();
+        let primary = Main.layoutManager.primaryMonitor;
         this.actor.x = primary.x;
         this.actor.y = primary.y + primary.height - 1;
         this.actor.width = primary.width;
@@ -1867,7 +1867,7 @@ MessageTray.prototype = {
     },
 
     _showTray: function() {
-        let primary = global.get_primary_monitor();
+        let primary = Main.layoutManager.primaryMonitor;
         this._tween(this.actor, '_trayState', State.SHOWN,
                     { y: primary.y + primary.height - this.actor.height,
                       time: ANIMATION_TIME,
@@ -1876,7 +1876,7 @@ MessageTray.prototype = {
     },
 
     _hideTray: function() {
-        let primary = global.get_primary_monitor();
+        let primary = Main.layoutManager.primaryMonitor;
         this._tween(this.actor, '_trayState', State.HIDDEN,
                     { y: primary.y + primary.height - 1,
                       time: ANIMATION_TIME,
@@ -2047,7 +2047,6 @@ MessageTray.prototype = {
     },
 
     _showSummary: function(timeout) {
-        let primary = global.get_primary_monitor();
         this._summaryBin.opacity = 0;
         this._summaryBin.y = this.actor.height;
         this._tween(this._summaryBin, '_summaryState', State.SHOWN,
diff --git a/js/ui/modalDialog.js b/js/ui/modalDialog.js
index 887475f..ce943b9 100644
--- a/js/ui/modalDialog.js
+++ b/js/ui/modalDialog.js
@@ -149,7 +149,7 @@ ModalDialog.prototype = {
     },
 
     _fadeOpen: function() {
-        let monitor = global.get_focus_monitor();
+        let monitor = Main.layoutManager.focusMonitor;
 
         this._backgroundBin.set_position(monitor.x, monitor.y);
         this._backgroundBin.set_size(monitor.width, monitor.height);
diff --git a/js/ui/overview.js b/js/ui/overview.js
index 420ce3f..085f292 100644
--- a/js/ui/overview.js
+++ b/js/ui/overview.js
@@ -121,7 +121,7 @@ Overview.prototype = {
                 let spacing = node.get_length('spacing');
                 if (spacing != this._spacing) {
                     this._spacing = spacing;
-                    this.relayout();
+                    this._relayout();
                 }
             }));
 
@@ -202,6 +202,8 @@ Overview.prototype = {
         // the left of the overview
         Main.ctrlAltTabManager.addGroup(this.dash.actor, _("Dash"), 'user-bookmarks');
 
+        Main.layoutManager.connect('monitors-changed', Lang.bind(this, this._relayout));
+        this._relayout();
     },
 
     _onDragBegin: function() {
@@ -391,7 +393,7 @@ Overview.prototype = {
                 [stageX, stageY] = event.get_coords();
                 let dx = this._dragX - stageX;
                 let dy = this._dragY - stageY;
-                let primary = global.get_primary_monitor();
+                let primary = Main.layoutManager.primaryMonitor;
 
                 this._dragX = stageX;
                 this._dragY = stageY;
@@ -438,8 +440,13 @@ Overview.prototype = {
         return clone;
     },
 
-    relayout: function () {
-        let primary = global.get_primary_monitor();
+    _relayout: function () {
+        // To avoid updating the position and size of the workspaces
+        // we just hide the overview. The positions will be updated
+        // when it is next shown.
+        this.hide();
+
+        let primary = Main.layoutManager.primaryMonitor;
         let rtl = (St.Widget.get_default_direction () == St.TextDirection.RTL);
 
         let contentY = Main.panel.actor.height;
diff --git a/js/ui/panel.js b/js/ui/panel.js
index 7df3e11..2f20167 100644
--- a/js/ui/panel.js
+++ b/js/ui/panel.js
@@ -1013,6 +1013,9 @@ Panel.prototype = {
 
         Main.ctrlAltTabManager.addGroup(this.actor, _("Top Bar"), 'start-here',
                                         { sortGroup: CtrlAltTab.SortGroup.TOP });
+
+        Main.layoutManager.connect('monitors-changed', Lang.bind(this, this._relayout));
+        this._relayout();
     },
 
     _xdndShowOverview: function (actor) {
@@ -1086,8 +1089,8 @@ Panel.prototype = {
                          });
     },
 
-    relayout: function() {
-        let primary = global.get_primary_monitor();
+    _relayout: function() {
+        let primary = Main.layoutManager.primaryMonitor;
 
         this.actor.set_position(primary.x, primary.y);
         this.actor.set_size(primary.width, -1);
diff --git a/js/ui/panelMenu.js b/js/ui/panelMenu.js
index 77999b2..dd559ca 100644
--- a/js/ui/panelMenu.js
+++ b/js/ui/panelMenu.js
@@ -35,7 +35,7 @@ Button.prototype = {
             // Setting the max-height won't do any good if the minimum height of the
             // menu is higher then the screen; it's useful if part of the menu is
             // scrollable so the minimum height is smaller than the natural height
-            let monitor = global.get_primary_monitor();
+            let monitor = Main.layoutManager.primaryMonitor;
             this.menu.actor.style = ('max-height: ' +
                                      Math.round(monitor.height - Main.panel.actor.height) +
                                      'px;');
diff --git a/js/ui/scripting.js b/js/ui/scripting.js
index 1fc583e..db7f58d 100644
--- a/js/ui/scripting.js
+++ b/js/ui/scripting.js
@@ -3,10 +3,11 @@
 const DBus = imports.dbus;
 const Gio = imports.gi.Gio;
 const Mainloop = imports.mainloop;
-
 const Meta = imports.gi.Meta;
 const Shell = imports.gi.Shell;
 
+const Main = imports.ui.main;
+
 // This module provides functionality for driving the shell user interface
 // in an automated fashion. The primary current use case for this is
 // automated performance testing (see runPerfScript()), but it could
@@ -246,18 +247,14 @@ function _collect(scriptModule, outputFile) {
         Shell.write_string_to_stream(out, '"events":\n');
         Shell.PerfLog.get_default().dump_events(out);
 
-        let monitors = global.get_monitors();
-        let primary = global.get_primary_monitor();
+        let monitors = Main.layoutManager.monitors;
+        let primary = Main.layoutManager.primaryIndex;
         Shell.write_string_to_stream(out, ',\n"monitors":\n[');
         for (let i = 0; i < monitors.length; i++) {
             let monitor = monitors[i];
-            let is_primary = (monitor.x == primary.x &&
-                              monitor.y == primary.y &&
-                              monitor.width == primary.width &&
-                              monitor.height == primary.height);
             if (i != 0)
                 Shell.write_string_to_stream(out, ', ');
-            Shell.write_string_to_stream(out, '"%s%dx%d+%d+%d"'.format(is_primary ? "*" : "",
+            Shell.write_string_to_stream(out, '"%s%dx%d+%d+%d"'.format(i == primary ? "*" : "",
                                                                        monitor.width, monitor.height,
                                                                        monitor.x, monitor.y));
         }
diff --git a/js/ui/windowManager.js b/js/ui/windowManager.js
index a3e2918..ea7c336 100644
--- a/js/ui/windowManager.js
+++ b/js/ui/windowManager.js
@@ -180,7 +180,7 @@ WindowManager.prototype = {
          */
         this._minimizing.push(actor);
 
-        let primary = global.get_primary_monitor();
+        let primary = Main.layoutManager.primaryMonitor;
         let xDest = primary.x;
         if (St.Widget.get_default_direction() == St.TextDirection.RTL)
             xDest += primary.width;
diff --git a/js/ui/workspace.js b/js/ui/workspace.js
index f1527f4..aaf3994 100644
--- a/js/ui/workspace.js
+++ b/js/ui/workspace.js
@@ -225,8 +225,8 @@ WindowClone.prototype = {
         let [width, height] = this.actor.get_transformed_size();
 
         let monitorIndex = this.metaWindow.get_monitor();
-        let availArea = global.get_monitors()[monitorIndex];
-        if (monitorIndex == global.get_primary_monitor_index()) {
+        let availArea = Main.layoutManager.monitors[monitorIndex];
+        if (monitorIndex == Main.layoutManager.primaryIndex) {
             availArea.y += Main.panel.actor.height;
             availArea.height -= Main.panel.actor.height;
         }
@@ -593,7 +593,7 @@ Workspace.prototype = {
         this._height = 0;
 
         this.monitorIndex = monitorIndex;
-        this._monitor = global.get_monitors()[this.monitorIndex];
+        this._monitor = Main.layoutManager.monitors[this.monitorIndex];
         this._windowOverlaysGroup = new Clutter.Group();
         // Without this the drop area will be overlapped.
         this._windowOverlaysGroup.set_size(0, 0);
diff --git a/js/ui/workspaceSwitcherPopup.js b/js/ui/workspaceSwitcherPopup.js
index 79e5db9..3bd35ca 100644
--- a/js/ui/workspaceSwitcherPopup.js
+++ b/js/ui/workspaceSwitcherPopup.js
@@ -56,7 +56,7 @@ WorkspaceSwitcherPopup.prototype = {
 
     _getPreferredHeight : function (actor, forWidth, alloc) {
         let children = this._list.get_children();
-        let primary = global.get_primary_monitor();
+        let primary = Main.layoutManager.primaryMonitor;
 
         let availHeight = primary.height;
         availHeight -= Main.panel.actor.height;
@@ -82,7 +82,7 @@ WorkspaceSwitcherPopup.prototype = {
     },
 
     _getPreferredWidth : function (actor, forHeight, alloc) {
-        let primary = global.get_primary_monitor();
+        let primary = Main.layoutManager.primaryMonitor;
         this._childWidth = Math.round(this._childHeight * primary.width / primary.height);
 
         alloc.min_size = this._childWidth;
@@ -125,7 +125,7 @@ WorkspaceSwitcherPopup.prototype = {
     },
 
     _position: function() {
-        let primary = global.get_primary_monitor();
+        let primary = Main.layoutManager.primaryMonitor;
         this._container.x = primary.x + Math.floor((primary.width - this._container.width) / 2);
         this._container.y = primary.y + Main.panel.actor.height +
                             Math.floor(((primary.height - Main.panel.actor.height) - this._container.height) / 2);
diff --git a/js/ui/workspaceThumbnail.js b/js/ui/workspaceThumbnail.js
index 97b449f..5123042 100644
--- a/js/ui/workspaceThumbnail.js
+++ b/js/ui/workspaceThumbnail.js
@@ -146,7 +146,7 @@ function WorkspaceThumbnail(metaWorkspace) {
 WorkspaceThumbnail.prototype = {
     _init : function(metaWorkspace) {
         this.metaWorkspace = metaWorkspace;
-        this.monitorIndex = global.get_primary_monitor_index();
+        this.monitorIndex = Main.layoutManager.primaryIndex;
 
         this.actor = new St.Group({ reactive: true,
                                     clip_to_allocation: true,
@@ -170,7 +170,7 @@ WorkspaceThumbnail.prototype = {
         this._background = new Clutter.Clone({ source: global.background_actor });
         this._contents.add_actor(this._background);
 
-        let monitor = global.get_primary_monitor();
+        let monitor = Main.layoutManager.primaryMonitor;
         this.setPorthole(monitor.x, monitor.y, monitor.width, monitor.height);
 
         let windows = global.get_window_actors().filter(this._isMyWindow, this);
@@ -528,7 +528,7 @@ ThumbnailsBox.prototype = {
 
         // The "porthole" is the portion of the screen that we show in the workspaces
         let panelHeight = Main.panel.actor.height;
-        let monitor = global.get_primary_monitor();
+        let monitor = Main.layoutManager.primaryMonitor;
         this._porthole = {
             x: monitor.x,
             y: monitor.y + panelHeight,
diff --git a/js/ui/workspacesView.js b/js/ui/workspacesView.js
index 7b7c05b..08138f7 100644
--- a/js/ui/workspacesView.js
+++ b/js/ui/workspacesView.js
@@ -70,10 +70,10 @@ WorkspacesView.prototype = {
         this._workspaces[activeWorkspaceIndex].actor.raise_top();
 
         this._extraWorkspaces = [];
-        let monitors = global.get_monitors();
+        let monitors = Main.layoutManager.monitors;
         let m = 0;
         for (let i = 0; i < monitors.length; i++) {
-            if (i == global.get_primary_monitor_index())
+            if (i == Main.layoutManager.primaryIndex)
                 continue;
             let ws = new Workspace.Workspace(null, i);
             this._extraWorkspaces[m++] = ws;
@@ -383,7 +383,7 @@ WorkspacesView.prototype = {
                 this._extraWorkspaces[i].setReservedSlot(dragEvent.dragActor._delegate);
         }
 
-        let primary = global.get_primary_monitor();
+        let primary = Main.layoutManager.primaryMonitor;
 
         let activeWorkspaceIndex = global.screen.get_active_workspace_index();
         let topWorkspace, bottomWorkspace;
@@ -550,8 +550,8 @@ WorkspacesDisplay.prototype = {
         controls.connect('scroll-event',
                          Lang.bind(this, this._onScrollEvent));
 
-        this._monitorIndex = global.get_primary_monitor_index();
-        this._monitor = global.get_monitors()[this._monitorIndex];
+        this._monitorIndex = Main.layoutManager.primaryIndex;
+        this._monitor = Main.layoutManager.monitors[this._monitorIndex];
 
         this._thumbnailsBox = new WorkspaceThumbnail.ThumbnailsBox();
         controls.add_actor(this._thumbnailsBox.actor);
@@ -567,7 +567,7 @@ WorkspacesDisplay.prototype = {
 
         this._updateAlwaysZoom();
 
-        global.screen.connect('monitors-changed', Lang.bind(this, this._updateAlwaysZoom));
+        Main.layoutManager.connect('monitors-changed', Lang.bind(this, this._updateAlwaysZoom));
         global.screen.connect('notify::n-workspaces',
                               Lang.bind(this, this._workspacesChanged));
 
@@ -694,8 +694,8 @@ WorkspacesDisplay.prototype = {
         if (this._alwaysZoomOut)
             return;
 
-        let monitors = global.get_monitors();
-        let primary = global.get_primary_monitor();
+        let monitors = Main.layoutManager.monitors;
+        let primary = Main.layoutManager.primaryMonitor;
 
         /* Look for any monitor to the right of the primary, if there is
          * one, we always keep zoom out, otherwise its hard to reach
diff --git a/src/shell-global.c b/src/shell-global.c
index 55875c7..8c00514 100644
--- a/src/shell-global.c
+++ b/src/shell-global.c
@@ -1194,109 +1194,6 @@ void shell_global_init_xdnd (ShellGlobal *global)
 }
 
 /**
- * shell_global_get_monitors:
- * @global: the #ShellGlobal
- *
- * Gets a list of the bounding boxes of the active screen's monitors.
- *
- * Return value: (transfer full) (element-type Meta.Rectangle): a list
- * of monitor bounding boxes.
- */
-GSList *
-shell_global_get_monitors (ShellGlobal *global)
-{
-  MetaScreen *screen = shell_global_get_screen (global);
-  GSList *monitors = NULL;
-  MetaRectangle rect;
-  int i;
-
-  for (i = meta_screen_get_n_monitors (screen) - 1; i >= 0; i--)
-    {
-      meta_screen_get_monitor_geometry (screen, i, &rect);
-      monitors = g_slist_prepend (monitors,
-                                  meta_rectangle_copy (&rect));
-    }
-  return monitors;
-}
-
-/**
- * shell_global_get_primary_monitor:
- * @global: the #ShellGlobal
- *
- * Gets the bounding box of the primary monitor (the one that the
- * panel is on).
- *
- * Return value: the bounding box of the primary monitor
- */
-MetaRectangle *
-shell_global_get_primary_monitor (ShellGlobal  *global)
-{
-  MetaScreen *screen = shell_global_get_screen (global);
-  MetaRectangle rect;
-  gint primary = 0;
-
-  primary = meta_screen_get_primary_monitor (screen);
-  meta_screen_get_monitor_geometry (screen, primary, &rect);
-
-  return meta_rectangle_copy (&rect);
-}
-
-/**
- * shell_global_get_primary_monitor_index:
- * @global: the #ShellGlobal
- *
- * Gets the index of the primary monitor (the one that the
- * panel is on).
- *
- * Return value: the index of the primary monitor
- */
-int
-shell_global_get_primary_monitor_index (ShellGlobal  *global)
-{
-  MetaScreen *screen = shell_global_get_screen (global);
-
-  return meta_screen_get_primary_monitor (screen);
-}
-
-/**
- * shell_global_get_focus_monitor:
- * @global: the #ShellGlobal
- *
- * Gets the bounding box of the monitor containing the window that
- * currently contains the keyboard focus.
- *
- * Return value: the bounding box of the focus monitor
- */
-MetaRectangle *
-shell_global_get_focus_monitor (ShellGlobal  *global)
-{
-  MetaScreen *screen = shell_global_get_screen (global);
-  MetaDisplay *display = meta_screen_get_display (screen);
-  MetaWindow *focus = meta_display_get_focus_window (display);
-  MetaRectangle rect, wrect;
-  int nmonitors, i;
-
-  if (focus)
-    {
-      meta_window_get_outer_rect (focus, &wrect);
-      nmonitors = meta_screen_get_n_monitors (screen);
-
-      /* Find the monitor that the top-left corner of @focus is on. */
-      for (i = 0; i < nmonitors; i++)
-        {
-          meta_screen_get_monitor_geometry (screen, i, &rect);
-
-          if (rect.x <= wrect.x && rect.y <= wrect.y &&
-              rect.x + rect.width > wrect.x &&
-              rect.y + rect.height > wrect.y)
-            return meta_rectangle_copy (&rect);
-        }
-    }
-
-  return shell_global_get_primary_monitor (global);
-}
-
-/**
  * shell_global_get_pointer:
  * @global: the #ShellGlobal
  * @x: (out): the X coordinate of the pointer, in global coordinates
diff --git a/src/shell-global.h b/src/shell-global.h
index 7c1c7bb..1f79cf5 100644
--- a/src/shell-global.h
+++ b/src/shell-global.h
@@ -32,10 +32,6 @@ ShellGlobal   *shell_global_get                       (void);
 MetaScreen    *shell_global_get_screen                (ShellGlobal *global);
 GdkScreen     *shell_global_get_gdk_screen            (ShellGlobal *global);
 GList         *shell_global_get_window_actors         (ShellGlobal *global);
-GSList        *shell_global_get_monitors              (ShellGlobal *global);
-MetaRectangle *shell_global_get_primary_monitor       (ShellGlobal *global);
-int            shell_global_get_primary_monitor_index (ShellGlobal *global);
-MetaRectangle *shell_global_get_focus_monitor         (ShellGlobal *global);
 GSettings     *shell_global_get_settings              (ShellGlobal *global);
 guint32        shell_global_get_current_time          (ShellGlobal *global);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]