osdWindow: Allow levels above 100%

Allow osd representing levels that can be more than 100% by accepting
an optional parameter setting that maximum level.
gnome-settings-daemon will use this to indicate volume levels above 100%,
which our own volume indicator will soon support as well.
This commit is contained in:
Didier Roche 2018-07-31 16:47:05 +02:00 committed by Florian Müllner
parent 3f756dc608
commit aa75e89216
2 changed files with 26 additions and 6 deletions

View File

@ -22,6 +22,7 @@ var LevelBar = new Lang.Class({
_init() { _init() {
this._level = 0; this._level = 0;
this._maxLevel = 100;
let params = { let params = {
styleClass: 'level', styleClass: 'level',
@ -38,9 +39,19 @@ var LevelBar = new Lang.Class({
}, },
set level(value) { set level(value) {
this._level = Math.max(0, Math.min(value, 100)); this._level = Math.max(0, Math.min(value, this._maxLevel));
this.setValue(this._level / 100); this.setValue(this._level / 100);
},
get maxLevel() {
return this._maxLevel;
},
set maxLevel(value) {
this._maxLevel = Math.max(100, value);
this.setMaximumValue(this._maxLevel / 100);
} }
}); });
@ -139,6 +150,12 @@ var OsdWindow = new Lang.Class({
} }
}, },
setMaxLevel(maxLevel) {
if (maxLevel === undefined)
maxLevel = 100;
this._level.maxLevel = maxLevel;
},
show() { show() {
if (!this._icon.gicon) if (!this._icon.gicon)
return; return;
@ -188,6 +205,7 @@ var OsdWindow = new Lang.Class({
this.actor.hide(); this.actor.hide();
this.setLabel(null); this.setLabel(null);
this.setLevel(null); this.setLevel(null);
this.setMaxLevel(null);
}, },
_relayout() { _relayout() {
@ -232,24 +250,25 @@ var OsdWindowManager = new Lang.Class({
this._osdWindows.length = Main.layoutManager.monitors.length; this._osdWindows.length = Main.layoutManager.monitors.length;
}, },
_showOsdWindow(monitorIndex, icon, label, level) { _showOsdWindow(monitorIndex, icon, label, level, maxLevel) {
this._osdWindows[monitorIndex].setIcon(icon); this._osdWindows[monitorIndex].setIcon(icon);
this._osdWindows[monitorIndex].setLabel(label); this._osdWindows[monitorIndex].setLabel(label);
this._osdWindows[monitorIndex].setLevel(level); this._osdWindows[monitorIndex].setLevel(level);
this._osdWindows[monitorIndex].setMaxLevel(maxLevel);
this._osdWindows[monitorIndex].show(); this._osdWindows[monitorIndex].show();
}, },
show(monitorIndex, icon, label, level) { show(monitorIndex, icon, label, level, maxLevel) {
if (monitorIndex != -1) { if (monitorIndex != -1) {
for (let i = 0; i < this._osdWindows.length; i++) { for (let i = 0; i < this._osdWindows.length; i++) {
if (i == monitorIndex) if (i == monitorIndex)
this._showOsdWindow(i, icon, label, level); this._showOsdWindow(i, icon, label, level, maxLevel);
else else
this._osdWindows[i].cancel(); this._osdWindows[i].cancel();
} }
} else { } else {
for (let i = 0; i < this._osdWindows.length; i++) for (let i = 0; i < this._osdWindows.length; i++)
this._showOsdWindow(i, icon, label, level); this._showOsdWindow(i, icon, label, level, maxLevel);
} }
}, },

View File

@ -148,12 +148,13 @@ var GnomeShell = new Lang.Class({
let monitorIndex = params['monitor'] || -1; let monitorIndex = params['monitor'] || -1;
let label = params['label'] || undefined; let label = params['label'] || undefined;
let level = params['level'] || undefined; let level = params['level'] || undefined;
let maxLevel = params['max_level'] || undefined;
let icon = null; let icon = null;
if (params['icon']) if (params['icon'])
icon = Gio.Icon.new_for_string(params['icon']); icon = Gio.Icon.new_for_string(params['icon']);
Main.osdWindowManager.show(monitorIndex, icon, label, level); Main.osdWindowManager.show(monitorIndex, icon, label, level, maxLevel);
}, },
FocusApp(id) { FocusApp(id) {