[gnome-shell] Port modal dialogs to the new MonitorConstraint



commit 1a65374e21fb15f1311418ceeceb9737f9e1db8e
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Thu Aug 16 21:37:27 2012 +0200

    Port modal dialogs to the new MonitorConstraint
    
    This commit makes ModalDialog use the new MonitorConstraint instead
    of custom code to force itself on the right monitor.
    At the same it ports wanda, which has something similar to a modal
    dialog, but is not using the ModalDialog module.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=681743

 js/ui/modalDialog.js |    8 ++++----
 js/ui/wanda.js       |   12 +++++++-----
 2 files changed, 11 insertions(+), 9 deletions(-)
---
diff --git a/js/ui/modalDialog.js b/js/ui/modalDialog.js
index b182ae9..cab2569 100644
--- a/js/ui/modalDialog.js
+++ b/js/ui/modalDialog.js
@@ -14,6 +14,7 @@ const Atk = imports.gi.Atk;
 
 const Params = imports.misc.params;
 
+const Layout = imports.ui.layout;
 const Lightbox = imports.ui.lightbox;
 const Main = imports.ui.main;
 const Tweener = imports.ui.tweener;
@@ -59,6 +60,8 @@ const ModalDialog = new Lang.Class({
         this._group.connect('key-release-event', Lang.bind(this, this._onKeyReleaseEvent));
 
         this._backgroundBin = new St.Bin();
+        this._monitorConstraint = new Layout.MonitorConstraint();
+        this._backgroundBin.add_constraint(this._monitorConstraint);
         this._group.add_actor(this._backgroundBin);
 
         this.dialogLayout = new St.BoxLayout({ style_class: 'modal-dialog',
@@ -196,10 +199,7 @@ const ModalDialog = new Lang.Class({
     },
 
     _fadeOpen: function() {
-        let monitor = Main.layoutManager.currentMonitor;
-
-        this._backgroundBin.set_position(monitor.x, monitor.y);
-        this._backgroundBin.set_size(monitor.width, monitor.height);
+        this._monitorConstraint.index = global.screen.get_current_monitor();
 
         this.state = State.OPENING;
 
diff --git a/js/ui/wanda.js b/js/ui/wanda.js
index 4a57bf8..e02e7f4 100644
--- a/js/ui/wanda.js
+++ b/js/ui/wanda.js
@@ -9,6 +9,7 @@ const Signals = imports.signals;
 const St = imports.gi.St;
 
 const IconGrid = imports.ui.iconGrid;
+const Layout = imports.ui.layout;
 const Main = imports.ui.main;
 const Search = imports.ui.search;
 
@@ -142,17 +143,18 @@ const FortuneDialog = new Lang.Class({
         this._button.connect('clicked', Lang.bind(this, this.destroy));
         this._button.child = this._box;
 
-        let monitor = Main.layoutManager.primaryMonitor;
+        this._bin = new St.Bin({ x_align: St.Align.MIDDLE,
+                                 y_align: St.Align.MIDDLE });
+        this._bin.add_constraint(new Layout.MonitorConstraint({ primary: true }));
+        this._bin.add_actor(this._button);
 
-        Main.layoutManager.addChrome(this._button);
-        this._button.set_position(Math.floor(monitor.width / 2 - this._button.width / 2),
-                                  Math.floor(monitor.height / 2 - this._button.height / 2));
+        Main.layoutManager.addChrome(this._bin);
 
         GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, 10, Lang.bind(this, this.destroy));
     },
 
     destroy: function() {
-        this._button.destroy();
+        this._bin.destroy();
     }
 });
 



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