[gnome-shell] osdWindow: Show on all monitors



commit 5c3f9f6999f543bfa327659be5647ceeacc73988
Author: Adel Gadllah <adel gadllah gmail com>
Date:   Thu Apr 17 10:23:30 2014 +0200

    osdWindow: Show on all monitors
    
    We had one osdWindow that we displayed either on the primary monitor or on
    whatever monitor index got passed over dbus.
    
    Change that to show the osd on all monitors when no explicit monitor is
    requested. A monitor should be requested in cases like display brightness where it makes sense to only 
show the osd on the affected monitor.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=722684

 js/ui/main.js          |    4 +-
 js/ui/osdWindow.js     |   76 +++++++++++++++++++++++++++++++++--------------
 js/ui/shellDBus.js     |    7 +----
 js/ui/switcherPopup.js |    2 +-
 4 files changed, 57 insertions(+), 32 deletions(-)
---
diff --git a/js/ui/main.js b/js/ui/main.js
index bf25401..22a561f 100644
--- a/js/ui/main.js
+++ b/js/ui/main.js
@@ -55,7 +55,7 @@ let screenShield = null;
 let notificationDaemon = null;
 let windowAttentionHandler = null;
 let ctrlAltTabManager = null;
-let osdWindow = null;
+let osdWindowManager = null;
 let sessionMode = null;
 let shellDBusService = null;
 let shellMountOpDBusService = null;
@@ -155,7 +155,7 @@ function _initializeUI() {
     screencastService = new Screencast.ScreencastService();
     xdndHandler = new XdndHandler.XdndHandler();
     ctrlAltTabManager = new CtrlAltTab.CtrlAltTabManager();
-    osdWindow = new OsdWindow.OsdWindow();
+    osdWindowManager = new OsdWindow.OsdWindowManager();
     overview = new Overview.Overview();
     wm = new WindowManager.WindowManager();
     magnifier = new Magnifier.Magnifier();
diff --git a/js/ui/osdWindow.js b/js/ui/osdWindow.js
index 2513aa8..1916812 100644
--- a/js/ui/osdWindow.js
+++ b/js/ui/osdWindow.js
@@ -73,14 +73,17 @@ const LevelBar = new Lang.Class({
 const OsdWindow = new Lang.Class({
     Name: 'OsdWindow',
 
-    _init: function() {
+    _init: function(monitorIndex) {
         this._popupSize = 0;
         this.actor = new St.Widget({ x_expand: true,
                                      y_expand: true,
                                      x_align: Clutter.ActorAlign.CENTER,
                                      y_align: Clutter.ActorAlign.CENTER });
-        this._currentMonitor = undefined;
-        this.setMonitor (-1);
+
+        this._monitorIndex = monitorIndex;
+        let constraint = new Layout.MonitorConstraint({ index: monitorIndex });
+        this.actor.add_constraint(constraint);
+
         this._box = new St.BoxLayout({ style_class: 'osd-window',
                                        vertical: true });
         this.actor.add_actor(this._box);
@@ -109,7 +112,6 @@ const OsdWindow = new Lang.Class({
         Main.layoutManager.connect('monitors-changed',
                                    Lang.bind(this, this._monitorsChanged));
         this._monitorsChanged();
-
         Main.uiGroup.add_child(this.actor);
     },
 
@@ -189,12 +191,7 @@ const OsdWindow = new Lang.Class({
 
     _monitorsChanged: function() {
         /* assume 110x110 on a 640x480 display and scale from there */
-        let monitor;
-
-        if (this._currentMonitor >= 0)
-            monitor = Main.layoutManager.monitors[this._currentMonitor];
-        else
-            monitor = Main.layoutManager.primaryMonitor;
+        let monitor = Main.layoutManager.monitors[this._monitorIndex];
 
         let scalew = monitor.width / 640.0;
         let scaleh = monitor.height / 480.0;
@@ -223,23 +220,56 @@ const OsdWindow = new Lang.Class({
         // but the theme takes measures in unscaled dimensions
         let scaleFactor = St.ThemeContext.get_for_stage(global.stage).scale_factor;
         this._box.style = 'min-height: %dpx;'.format(Math.max(minWidth, minHeight) / scaleFactor);
+    }
+});
+
+const OsdWindowManager = new Lang.Class({
+    Name: 'OsdWindowManager',
+
+    _init: function() {
+        this._osdWindows = [];
+        Main.layoutManager.connect('monitors-changed',
+                                    Lang.bind(this, this._monitorsChanged));
+        this._monitorsChanged();
     },
 
-    setMonitor: function(index) {
-        let constraint;
+    _monitorsChanged: function() {
+        for (let i = 0; i < Main.layoutManager.monitors.length; i++) {
+            if (this._osdWindows[i] == undefined)
+                this._osdWindows[i] = new OsdWindow(i);
+        }
 
-        if (index < 0)
-            index = -1;
-        if (this._currentMonitor == index)
-            return;
+        for (let i = Main.layoutManager.monitors.length; i < this._osdWindows.length; i++) {
+            this._osdWindows[i].actor.destroy();
+            this._osdWindows[i] = null;
+        }
 
-        if (index < 0)
-            constraint = new Layout.MonitorConstraint({ primary: true });
-        else
-            constraint = new Layout.MonitorConstraint({ index: index });
+        this._osdWindows.length = Main.layoutManager.monitors.length;
+    },
 
-        this.actor.clear_constraints();
-        this.actor.add_constraint(constraint);
-        this._currentMonitor = index;
+    _showOsdWindow: function(monitorIndex, icon, label, level) {
+        this._osdWindows[monitorIndex].setIcon(icon);
+        this._osdWindows[monitorIndex].setLabel(label);
+        this._osdWindows[monitorIndex].setLevel(level);
+        this._osdWindows[monitorIndex].show();
+    },
+
+    show: function(monitorIndex, icon, label, level) {
+        if (monitorIndex != -1) {
+            for (let i = 0; i < this._osdWindows.length; i++) {
+                if (i == monitorIndex)
+                    this._showOsdWindow(i, icon, label, level);
+                else
+                    this._osdWindows[i].cancel();
+            }
+        } else {
+            for (let i = 0; i < this._osdWindows.length; i++)
+                this._showOsdWindow(i, icon, label, level);
+        }
+    },
+
+    hideAll: function() {
+        for (let i = 0; i < this._osdWindows.length; i++)
+            this._osdWindows[i].cancel();
     }
 });
diff --git a/js/ui/shellDBus.js b/js/ui/shellDBus.js
index 52e9fa8..a87ea41 100644
--- a/js/ui/shellDBus.js
+++ b/js/ui/shellDBus.js
@@ -141,12 +141,7 @@ const GnomeShell = new Lang.Class({
         if (params['icon'])
             icon = Gio.Icon.new_for_string(params['icon']);
 
-        Main.osdWindow.setIcon(icon);
-        Main.osdWindow.setMonitor (monitorIndex);
-        Main.osdWindow.setLabel(params['label']);
-        Main.osdWindow.setLevel(params['level']);
-
-        Main.osdWindow.show();
+        Main.osdWindowManager.show(monitorIndex, icon, params['label'], params['level']);
     },
 
     FocusApp: function(id) {
diff --git a/js/ui/switcherPopup.js b/js/ui/switcherPopup.js
index bd7875f..f7b8897 100644
--- a/js/ui/switcherPopup.js
+++ b/js/ui/switcherPopup.js
@@ -161,7 +161,7 @@ const SwitcherPopup = new Lang.Class({
         // disturbed by the popup briefly flashing.
         this._initialDelayTimeoutId = Mainloop.timeout_add(POPUP_DELAY_TIMEOUT,
                                                            Lang.bind(this, function () {
-                                                               Main.osdWindow.cancel();
+                                                               Main.osdWindowManager.hideAll();
                                                                this.actor.opacity = 255;
                                                                this._initialDelayTimeoutId = 0;
                                                                return GLib.SOURCE_REMOVE;


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