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
This commit is contained in:
Adel Gadllah 2014-04-17 10:23:30 +02:00
parent 4a6b89d44c
commit 5c3f9f6999
4 changed files with 62 additions and 37 deletions

View File

@ -55,7 +55,7 @@ let screenShield = null;
let notificationDaemon = null; let notificationDaemon = null;
let windowAttentionHandler = null; let windowAttentionHandler = null;
let ctrlAltTabManager = null; let ctrlAltTabManager = null;
let osdWindow = null; let osdWindowManager = null;
let sessionMode = null; let sessionMode = null;
let shellDBusService = null; let shellDBusService = null;
let shellMountOpDBusService = null; let shellMountOpDBusService = null;
@ -155,7 +155,7 @@ function _initializeUI() {
screencastService = new Screencast.ScreencastService(); screencastService = new Screencast.ScreencastService();
xdndHandler = new XdndHandler.XdndHandler(); xdndHandler = new XdndHandler.XdndHandler();
ctrlAltTabManager = new CtrlAltTab.CtrlAltTabManager(); ctrlAltTabManager = new CtrlAltTab.CtrlAltTabManager();
osdWindow = new OsdWindow.OsdWindow(); osdWindowManager = new OsdWindow.OsdWindowManager();
overview = new Overview.Overview(); overview = new Overview.Overview();
wm = new WindowManager.WindowManager(); wm = new WindowManager.WindowManager();
magnifier = new Magnifier.Magnifier(); magnifier = new Magnifier.Magnifier();

View File

@ -73,14 +73,17 @@ const LevelBar = new Lang.Class({
const OsdWindow = new Lang.Class({ const OsdWindow = new Lang.Class({
Name: 'OsdWindow', Name: 'OsdWindow',
_init: function() { _init: function(monitorIndex) {
this._popupSize = 0; this._popupSize = 0;
this.actor = new St.Widget({ x_expand: true, this.actor = new St.Widget({ x_expand: true,
y_expand: true, y_expand: true,
x_align: Clutter.ActorAlign.CENTER, x_align: Clutter.ActorAlign.CENTER,
y_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', this._box = new St.BoxLayout({ style_class: 'osd-window',
vertical: true }); vertical: true });
this.actor.add_actor(this._box); this.actor.add_actor(this._box);
@ -109,7 +112,6 @@ const OsdWindow = new Lang.Class({
Main.layoutManager.connect('monitors-changed', Main.layoutManager.connect('monitors-changed',
Lang.bind(this, this._monitorsChanged)); Lang.bind(this, this._monitorsChanged));
this._monitorsChanged(); this._monitorsChanged();
Main.uiGroup.add_child(this.actor); Main.uiGroup.add_child(this.actor);
}, },
@ -189,12 +191,7 @@ const OsdWindow = new Lang.Class({
_monitorsChanged: function() { _monitorsChanged: function() {
/* assume 110x110 on a 640x480 display and scale from there */ /* assume 110x110 on a 640x480 display and scale from there */
let monitor; let monitor = Main.layoutManager.monitors[this._monitorIndex];
if (this._currentMonitor >= 0)
monitor = Main.layoutManager.monitors[this._currentMonitor];
else
monitor = Main.layoutManager.primaryMonitor;
let scalew = monitor.width / 640.0; let scalew = monitor.width / 640.0;
let scaleh = monitor.height / 480.0; let scaleh = monitor.height / 480.0;
@ -223,23 +220,56 @@ const OsdWindow = new Lang.Class({
// but the theme takes measures in unscaled dimensions // but the theme takes measures in unscaled dimensions
let scaleFactor = St.ThemeContext.get_for_stage(global.stage).scale_factor; let scaleFactor = St.ThemeContext.get_for_stage(global.stage).scale_factor;
this._box.style = 'min-height: %dpx;'.format(Math.max(minWidth, minHeight) / scaleFactor); this._box.style = 'min-height: %dpx;'.format(Math.max(minWidth, minHeight) / scaleFactor);
}, }
});
setMonitor: function(index) {
let constraint; const OsdWindowManager = new Lang.Class({
Name: 'OsdWindowManager',
if (index < 0)
index = -1; _init: function() {
if (this._currentMonitor == index) this._osdWindows = [];
return; Main.layoutManager.connect('monitors-changed',
Lang.bind(this, this._monitorsChanged));
if (index < 0) this._monitorsChanged();
constraint = new Layout.MonitorConstraint({ primary: true }); },
else
constraint = new Layout.MonitorConstraint({ index: index }); _monitorsChanged: function() {
for (let i = 0; i < Main.layoutManager.monitors.length; i++) {
this.actor.clear_constraints(); if (this._osdWindows[i] == undefined)
this.actor.add_constraint(constraint); this._osdWindows[i] = new OsdWindow(i);
this._currentMonitor = index; }
for (let i = Main.layoutManager.monitors.length; i < this._osdWindows.length; i++) {
this._osdWindows[i].actor.destroy();
this._osdWindows[i] = null;
}
this._osdWindows.length = Main.layoutManager.monitors.length;
},
_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();
} }
}); });

View File

@ -141,12 +141,7 @@ const GnomeShell = new Lang.Class({
if (params['icon']) if (params['icon'])
icon = Gio.Icon.new_for_string(params['icon']); icon = Gio.Icon.new_for_string(params['icon']);
Main.osdWindow.setIcon(icon); Main.osdWindowManager.show(monitorIndex, icon, params['label'], params['level']);
Main.osdWindow.setMonitor (monitorIndex);
Main.osdWindow.setLabel(params['label']);
Main.osdWindow.setLevel(params['level']);
Main.osdWindow.show();
}, },
FocusApp: function(id) { FocusApp: function(id) {

View File

@ -161,7 +161,7 @@ const SwitcherPopup = new Lang.Class({
// disturbed by the popup briefly flashing. // disturbed by the popup briefly flashing.
this._initialDelayTimeoutId = Mainloop.timeout_add(POPUP_DELAY_TIMEOUT, this._initialDelayTimeoutId = Mainloop.timeout_add(POPUP_DELAY_TIMEOUT,
Lang.bind(this, function () { Lang.bind(this, function () {
Main.osdWindow.cancel(); Main.osdWindowManager.hideAll();
this.actor.opacity = 255; this.actor.opacity = 255;
this._initialDelayTimeoutId = 0; this._initialDelayTimeoutId = 0;
return GLib.SOURCE_REMOVE; return GLib.SOURCE_REMOVE;