[gnome-shell/T27795: 16/138] Split Monitor and MonitorConstraint out of layout.js



commit 3d57d05dbd5274729ddf18db352a67df553c9a4c
Author: Mario Sanchez Prada <mario endlessm com>
Date:   Mon May 8 22:52:25 2017 +0100

    Split Monitor and MonitorConstraint out of layout.js
    
    These two classes are fairly independent from the rest of layout.js,
    and having them in there forces us to import the whole file in many
    places where only Monitor or MonitorConstraint is needed.
    
    So, let's move it to their own specific file so that we can avoid
    importing the whole of layout.js in those places. This should reduce
    the chances to hit circular imports if we, down the road, declare a
    class from some of the modules recursively imported from layout.js
    depending on modules that haven't been properly initialized yet,
    which would cause obscure errors in GJS < 1.48, and a syntax error
    in newer versions (which got stricter about const definitions).
    
    https://bugzilla.gnome.org/show_bug.cgi?id=782356

 js/gdm/loginDialog.js         |   4 +-
 js/js-resources.gresource.xml |   3 +
 js/ui/layout.js               | 141 ++----------------------------------------
 js/ui/messageTray.js          |   4 +-
 js/ui/modalDialog.js          |   4 +-
 js/ui/monitor.js              | 140 +++++++++++++++++++++++++++++++++++++++++
 js/ui/osdWindow.js            |   3 +-
 js/ui/overview.js             |   3 +-
 js/ui/padOsd.js               |   4 +-
 js/ui/screenShield.js         |   4 +-
 js/ui/unlockDialog.js         |   4 +-
 11 files changed, 163 insertions(+), 151 deletions(-)
---
diff --git a/js/gdm/loginDialog.js b/js/gdm/loginDialog.js
index c3f90dc584..3d5f06147e 100644
--- a/js/gdm/loginDialog.js
+++ b/js/gdm/loginDialog.js
@@ -26,9 +26,9 @@ const Batch = imports.gdm.batch;
 const BoxPointer = imports.ui.boxpointer;
 const CtrlAltTab = imports.ui.ctrlAltTab;
 const GdmUtil = imports.gdm.util;
-const Layout = imports.ui.layout;
 const LoginManager = imports.misc.loginManager;
 const Main = imports.ui.main;
+const Monitor = imports.ui.monitor;
 const PopupMenu = imports.ui.popupMenu;
 const Realmd = imports.gdm.realmd;
 const UserWidget = imports.ui.userWidget;
@@ -396,7 +396,7 @@ var LoginDialog = GObject.registerClass({
 
         this.get_accessible().set_role(Atk.Role.WINDOW);
 
-        this.add_constraint(new Layout.MonitorConstraint({ primary: true }));
+        this.add_constraint(new Monitor.MonitorConstraint({ primary: true }));
         this.connect('destroy', this._onDestroy.bind(this));
         parentActor.add_child(this);
 
diff --git a/js/js-resources.gresource.xml b/js/js-resources.gresource.xml
index 624373c94d..64205e05f0 100644
--- a/js/js-resources.gresource.xml
+++ b/js/js-resources.gresource.xml
@@ -137,5 +137,8 @@
     <file>ui/status/screencast.js</file>
     <file>ui/status/system.js</file>
     <file>ui/status/thunderbolt.js</file>
+
+    <!-- Endless-specific files beyond this point -->
+    <file>ui/monitor.js</file>
   </gresource>
 </gresources>
diff --git a/js/ui/layout.js b/js/ui/layout.js
index 744a8f1192..facc814538 100644
--- a/js/ui/layout.js
+++ b/js/ui/layout.js
@@ -10,6 +10,7 @@ const LoginManager = imports.misc.loginManager;
 
 const DND = imports.ui.dnd;
 const Main = imports.ui.main;
+const Monitor = imports.ui.monitor;
 const Params = imports.misc.params;
 const Ripples = imports.ui.ripples;
 
@@ -31,140 +32,6 @@ function isPopupMetaWindow(actor) {
     }
 }
 
-var MonitorConstraint = GObject.registerClass({
-    Properties: {
-        'primary': GObject.ParamSpec.boolean('primary',
-                                             'Primary', 'Track primary monitor',
-                                             GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE,
-                                             false),
-        'index': GObject.ParamSpec.int('index',
-                                       'Monitor index', 'Track specific monitor',
-                                       GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE,
-                                       -1, 64, -1),
-        'work-area': GObject.ParamSpec.boolean('work-area',
-                                               'Work-area', 'Track monitor\'s work-area',
-                                               GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE,
-                                               false)
-    },
-}, class MonitorConstraint extends Clutter.Constraint {
-    _init(props) {
-        this._primary = false;
-        this._index = -1;
-        this._workArea = false;
-
-        super._init(props);
-    }
-
-    get primary() {
-        return this._primary;
-    }
-
-    set primary(v) {
-        if (v)
-            this._index = -1;
-        this._primary = v;
-        if (this.actor)
-            this.actor.queue_relayout();
-        this.notify('primary');
-    }
-
-    get index() {
-        return this._index;
-    }
-
-    set index(v) {
-        this._primary = false;
-        this._index = v;
-        if (this.actor)
-            this.actor.queue_relayout();
-        this.notify('index');
-    }
-
-    // eslint-disable-next-line camelcase
-    get work_area() {
-        return this._workArea;
-    }
-
-    // eslint-disable-next-line camelcase
-    set work_area(v) {
-        if (v == this._workArea)
-            return;
-        this._workArea = v;
-        if (this.actor)
-            this.actor.queue_relayout();
-        this.notify('work-area');
-    }
-
-    vfunc_set_actor(actor) {
-        if (actor) {
-            if (!this._monitorsChangedId) {
-                this._monitorsChangedId =
-                    Main.layoutManager.connect('monitors-changed', () => {
-                        this.actor.queue_relayout();
-                    });
-            }
-
-            if (!this._workareasChangedId) {
-                this._workareasChangedId =
-                    global.display.connect('workareas-changed', () => {
-                        if (this._workArea)
-                            this.actor.queue_relayout();
-                    });
-            }
-        } else {
-            if (this._monitorsChangedId)
-                Main.layoutManager.disconnect(this._monitorsChangedId);
-            this._monitorsChangedId = 0;
-
-            if (this._workareasChangedId)
-                global.display.disconnect(this._workareasChangedId);
-            this._workareasChangedId = 0;
-        }
-
-        super.vfunc_set_actor(actor);
-    }
-
-    vfunc_update_allocation(actor, actorBox) {
-        if (!this._primary && this._index < 0)
-            return;
-
-        if (!Main.layoutManager.primaryMonitor)
-            return;
-
-        let index;
-        if (this._primary)
-            index = Main.layoutManager.primaryIndex;
-        else
-            index = Math.min(this._index, Main.layoutManager.monitors.length - 1);
-
-        let rect;
-        if (this._workArea) {
-            let workspaceManager = global.workspace_manager;
-            let ws = workspaceManager.get_workspace_by_index(0);
-            rect = ws.get_work_area_for_monitor(index);
-        } else {
-            rect = Main.layoutManager.monitors[index];
-        }
-
-        actorBox.init_rect(rect.x, rect.y, rect.width, rect.height);
-    }
-});
-
-var Monitor = class Monitor {
-    constructor(index, geometry, geometryScale) {
-        this.index = index;
-        this.x = geometry.x;
-        this.y = geometry.y;
-        this.width = geometry.width;
-        this.height = geometry.height;
-        this.geometry_scale = geometryScale;
-    }
-
-    get inFullscreen() {
-        return global.display.get_monitor_in_fullscreen(this.index);
-    }
-};
-
 const UiActor = GObject.registerClass(
 class UiActor extends St.Widget {
     vfunc_get_preferred_width (_forHeight) {
@@ -345,9 +212,9 @@ var LayoutManager = GObject.registerClass({
         this.monitors = [];
         let nMonitors = display.get_n_monitors();
         for (let i = 0; i < nMonitors; i++)
-            this.monitors.push(new Monitor(i,
-                                           display.get_monitor_geometry(i),
-                                           display.get_monitor_scale(i)));
+            this.monitors.push(new Monitor.Monitor(i,
+                                                   display.get_monitor_geometry(i),
+                                                   display.get_monitor_scale(i)));
 
         if (nMonitors == 0) {
             this.primaryIndex = this.bottomIndex = -1;
diff --git a/js/ui/messageTray.js b/js/ui/messageTray.js
index 560deda6ff..acbfcd77a1 100644
--- a/js/ui/messageTray.js
+++ b/js/ui/messageTray.js
@@ -8,8 +8,8 @@ const Signals = imports.signals;
 
 const Calendar = imports.ui.calendar;
 const GnomeSession = imports.misc.gnomeSession;
-const Layout = imports.ui.layout;
 const Main = imports.ui.main;
+const Monitor = imports.ui.monitor;
 const Params = imports.misc.params;
 
 const SHELL_KEYBINDINGS_SCHEMA = 'org.gnome.shell.keybindings';
@@ -854,7 +854,7 @@ var MessageTray = class MessageTray {
         this.actor = new St.Widget({ visible: false,
                                      clip_to_allocation: true,
                                      layout_manager: new Clutter.BinLayout() });
-        let constraint = new Layout.MonitorConstraint({ primary: true });
+        let constraint = new Monitor.MonitorConstraint({ primary: true });
         Main.layoutManager.panelBox.bind_property('visible',
                                                   constraint, 'work-area',
                                                   GObject.BindingFlags.SYNC_CREATE);
diff --git a/js/ui/modalDialog.js b/js/ui/modalDialog.js
index 1eeb15a956..b9b8254acd 100644
--- a/js/ui/modalDialog.js
+++ b/js/ui/modalDialog.js
@@ -4,9 +4,9 @@
 const { Atk, Clutter, GObject, Shell, St } = imports.gi;
 
 const Dialog = imports.ui.dialog;
-const Layout = imports.ui.layout;
 const Lightbox = imports.ui.lightbox;
 const Main = imports.ui.main;
+const Monitor = imports.ui.monitor;
 const Params = imports.misc.params;
 
 var OPEN_AND_CLOSE_TIME = 100;
@@ -60,7 +60,7 @@ var ModalDialog = GObject.registerClass({
         this.backgroundStack = new St.Widget({ layout_manager: new Clutter.BinLayout() });
         this._backgroundBin = new St.Bin({ child: this.backgroundStack,
                                            x_fill: true, y_fill: true });
-        this._monitorConstraint = new Layout.MonitorConstraint();
+        this._monitorConstraint = new Monitor.MonitorConstraint();
         this._backgroundBin.add_constraint(this._monitorConstraint);
         this.add_actor(this._backgroundBin);
 
diff --git a/js/ui/monitor.js b/js/ui/monitor.js
new file mode 100644
index 0000000000..89a1a6d19d
--- /dev/null
+++ b/js/ui/monitor.js
@@ -0,0 +1,140 @@
+// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
+
+const { Clutter, GObject } = imports.gi;
+
+const Main = imports.ui.main;
+const Params = imports.misc.params;
+
+var MonitorConstraint = GObject.registerClass({
+    Properties: {
+        'primary': GObject.ParamSpec.boolean('primary',
+                                             'Primary', 'Track primary monitor',
+                                             GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE,
+                                             false),
+        'index': GObject.ParamSpec.int('index',
+                                       'Monitor index', 'Track specific monitor',
+                                       GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE,
+                                       -1, 64, -1),
+        'work-area': GObject.ParamSpec.boolean('work-area',
+                                               'Work-area', 'Track monitor\'s work-area',
+                                               GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE,
+                                               false)
+    },
+}, class MonitorConstraint extends Clutter.Constraint {
+    _init(props) {
+        this._primary = false;
+        this._index = -1;
+        this._workArea = false;
+
+        super._init(props);
+    }
+
+    get primary() {
+        return this._primary;
+    }
+
+    set primary(v) {
+        if (v)
+            this._index = -1;
+        this._primary = v;
+        if (this.actor)
+            this.actor.queue_relayout();
+        this.notify('primary');
+    }
+
+    get index() {
+        return this._index;
+    }
+
+    set index(v) {
+        this._primary = false;
+        this._index = v;
+        if (this.actor)
+            this.actor.queue_relayout();
+        this.notify('index');
+    }
+
+    // eslint-disable-next-line camelcase
+    get work_area() {
+        return this._workArea;
+    }
+
+    // eslint-disable-next-line camelcase
+    set work_area(v) {
+        if (v == this._workArea)
+            return;
+        this._workArea = v;
+        if (this.actor)
+            this.actor.queue_relayout();
+        this.notify('work-area');
+    }
+
+    vfunc_set_actor(actor) {
+        if (actor) {
+            if (!this._monitorsChangedId) {
+                this._monitorsChangedId =
+                    Main.layoutManager.connect('monitors-changed', () => {
+                        this.actor.queue_relayout();
+                    });
+            }
+
+            if (!this._workareasChangedId) {
+                this._workareasChangedId =
+                    global.display.connect('workareas-changed', () => {
+                        if (this._workArea)
+                            this.actor.queue_relayout();
+                    });
+            }
+        } else {
+            if (this._monitorsChangedId)
+                Main.layoutManager.disconnect(this._monitorsChangedId);
+            this._monitorsChangedId = 0;
+
+            if (this._workareasChangedId)
+                global.display.disconnect(this._workareasChangedId);
+            this._workareasChangedId = 0;
+        }
+
+        super.vfunc_set_actor(actor);
+    }
+
+    vfunc_update_allocation(actor, actorBox) {
+        if (!this._primary && this._index < 0)
+            return;
+
+        if (!Main.layoutManager.primaryMonitor)
+            return;
+
+        let index;
+        if (this._primary)
+            index = Main.layoutManager.primaryIndex;
+        else
+            index = Math.min(this._index, Main.layoutManager.monitors.length - 1);
+
+        let rect;
+        if (this._workArea) {
+            let workspaceManager = global.workspace_manager;
+            let ws = workspaceManager.get_workspace_by_index(0);
+            rect = ws.get_work_area_for_monitor(index);
+        } else {
+            rect = Main.layoutManager.monitors[index];
+        }
+
+        actorBox.init_rect(rect.x, rect.y, rect.width, rect.height);
+    }
+});
+
+var Monitor = class Monitor {
+    constructor(index, geometry, geometryScale) {
+        this.index = index;
+        this.x = geometry.x;
+        this.y = geometry.y;
+        this.width = geometry.width;
+        this.height = geometry.height;
+        this.geometry_scale = geometryScale;
+    }
+
+    get inFullscreen() {
+        return global.display.get_monitor_in_fullscreen(this.index);
+    }
+};
diff --git a/js/ui/osdWindow.js b/js/ui/osdWindow.js
index 8c92347909..ef056264b7 100644
--- a/js/ui/osdWindow.js
+++ b/js/ui/osdWindow.js
@@ -6,6 +6,7 @@ const { Clutter, GLib, GObject, Meta, St } = imports.gi;
 const BarLevel = imports.ui.barLevel;
 const Layout = imports.ui.layout;
 const Main = imports.ui.main;
+const Monitor = imports.ui.monitor;
 
 var HIDE_TIMEOUT = 1500;
 var FADE_TIME = 100;
@@ -49,7 +50,7 @@ var OsdWindow = class {
                                      y_align: Clutter.ActorAlign.CENTER });
 
         this._monitorIndex = monitorIndex;
-        let constraint = new Layout.MonitorConstraint({ index: monitorIndex });
+        let constraint = new Monitor.MonitorConstraint({ index: monitorIndex });
         this.actor.add_constraint(constraint);
 
         this._boxConstraint = new OsdWindowConstraint();
diff --git a/js/ui/overview.js b/js/ui/overview.js
index e4837c8211..ba76ce6426 100644
--- a/js/ui/overview.js
+++ b/js/ui/overview.js
@@ -10,6 +10,7 @@ const LayoutManager = imports.ui.layout;
 const Lightbox = imports.ui.lightbox;
 const Main = imports.ui.main;
 const MessageTray = imports.ui.messageTray;
+const Monitor = imports.ui.monitor;
 const OverviewControls = imports.ui.overviewControls;
 const Params = imports.misc.params;
 const WorkspaceThumbnail = imports.ui.workspaceThumbnail;
@@ -99,7 +100,7 @@ var Overview = class {
                                                activities. See also note for "Activities" string. */
                                             accessible_name: _("Overview"),
                                             vertical: true });
-        this._overview.add_constraint(new LayoutManager.MonitorConstraint({ primary: true }));
+        this._overview.add_constraint(new Monitor.MonitorConstraint({ primary: true }));
         this._overview._delegate = this;
 
         // The main Background actors are inside global.window_group which are
diff --git a/js/ui/padOsd.js b/js/ui/padOsd.js
index a900a01162..acdb3ba631 100644
--- a/js/ui/padOsd.js
+++ b/js/ui/padOsd.js
@@ -6,8 +6,8 @@ const { Atk, Clutter, GDesktopEnums, Gio,
 const Signals = imports.signals;
 
 const Main = imports.ui.main;
+const Monitor = imports.ui.monitor;
 const PopupMenu = imports.ui.popupMenu;
-const Layout = imports.ui.layout;
 
 const { loadInterfaceXML } = imports.misc.fileUtils;
 
@@ -662,7 +662,7 @@ var PadOsd = class {
         Main.uiGroup.add_actor(this.actor);
 
         this._monitorIndex = monitorIndex;
-        let constraint = new Layout.MonitorConstraint({ index: monitorIndex });
+        let constraint = new Monitor.MonitorConstraint({ index: monitorIndex });
         this.actor.add_constraint(constraint);
 
         this._titleBox = new St.BoxLayout({ style_class: 'pad-osd-title-box',
diff --git a/js/ui/screenShield.js b/js/ui/screenShield.js
index 2e2e95a387..a4c36a4e58 100644
--- a/js/ui/screenShield.js
+++ b/js/ui/screenShield.js
@@ -7,11 +7,11 @@ const Signals = imports.signals;
 
 const Background = imports.ui.background;
 const GnomeSession = imports.misc.gnomeSession;
-const Layout = imports.ui.layout;
 const OVirt = imports.gdm.oVirt;
 const LoginManager = imports.misc.loginManager;
 const Lightbox = imports.ui.lightbox;
 const Main = imports.ui.main;
+const Monitor = imports.ui.monitor;
 const Overview = imports.ui.overview;
 const MessageTray = imports.ui.messageTray;
 const ShellDBus = imports.ui.shellDBus;
@@ -446,7 +446,7 @@ var ScreenShield = class {
 
         this._lockScreenContents = new St.Widget({ layout_manager: new Clutter.BinLayout(),
                                                    name: 'lockScreenContents' });
-        this._lockScreenContents.add_constraint(new Layout.MonitorConstraint({ primary: true }));
+        this._lockScreenContents.add_constraint(new Monitor.MonitorConstraint({ primary: true }));
 
         this._lockScreenGroup.add_actor(this._lockScreenContents);
 
diff --git a/js/ui/unlockDialog.js b/js/ui/unlockDialog.js
index 5af1b4823f..541c4aae02 100644
--- a/js/ui/unlockDialog.js
+++ b/js/ui/unlockDialog.js
@@ -4,8 +4,8 @@
 const { AccountsService, Atk, Clutter,
         Gdm, Gio, GLib, GObject, Meta, Shell, St } = imports.gi;
 
-const Layout = imports.ui.layout;
 const Main = imports.ui.main;
+const Monitor = imports.ui.monitor;
 
 const AuthPrompt = imports.gdm.authPrompt;
 
@@ -23,7 +23,7 @@ var UnlockDialog = GObject.registerClass({
             visible: false,
         });
 
-        this.add_constraint(new Layout.MonitorConstraint({ primary: true }));
+        this.add_constraint(new Monitor.MonitorConstraint({ primary: true }));
         parentActor.add_child(this);
 
         this._userManager = AccountsService.UserManager.get_default();


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