volume: Allow volume above 100%

Depending on hardware and recorded volume level, turning up the speakers
to the maximum volume may not be enough and the user will want to amplify
the volume above 100%. Currently this requires opening the sound Settings
panel which gets cumbersome when required repeatedly.

To support this case better, allow raising the sound volume above 100%
directly from the system menu if the feature is enabled via the
`allow-volume-above-100-percent` key in `org.gnome.desktop.sound`.
This commit is contained in:
Didier Roche 2018-07-31 08:02:04 +02:00 committed by Florian Müllner
parent aa75e89216
commit d2a97e7f1d
2 changed files with 35 additions and 3 deletions

View File

@ -12,6 +12,8 @@ const PanelMenu = imports.ui.panelMenu;
const PopupMenu = imports.ui.popupMenu; const PopupMenu = imports.ui.popupMenu;
const Slider = imports.ui.slider; const Slider = imports.ui.slider;
const ALLOW_AMPLIFIED_VOLUME_KEY = 'allow-volume-above-100-percent';
var VOLUME_NOTIFY_ID = 1; var VOLUME_NOTIFY_ID = 1;
// Each Gvc.MixerControl is a connection to PulseAudio, // Each Gvc.MixerControl is a connection to PulseAudio,
@ -36,6 +38,11 @@ var StreamSlider = new Lang.Class({
this.item = new PopupMenu.PopupBaseMenuItem({ activate: false }); this.item = new PopupMenu.PopupBaseMenuItem({ activate: false });
this._slider = new Slider.Slider(0); this._slider = new Slider.Slider(0);
this._soundSettings = new Gio.Settings({ schema_id: 'org.gnome.desktop.sound' });
this._soundSettings.connect('changed::' + ALLOW_AMPLIFIED_VOLUME_KEY, this._amplifySettingsChanged.bind(this));
this._amplifySettingsChanged();
this._slider.connect('value-changed', this._sliderChanged.bind(this)); this._slider.connect('value-changed', this._sliderChanged.bind(this));
this._slider.connect('drag-end', this._notifyVolumeChange.bind(this)); this._slider.connect('drag-end', this._notifyVolumeChange.bind(this));
@ -135,6 +142,18 @@ var StreamSlider = new Lang.Class({
this.emit('stream-updated'); this.emit('stream-updated');
}, },
_amplifySettingsChanged() {
this._allowAmplified = this._soundSettings.get_boolean(ALLOW_AMPLIFIED_VOLUME_KEY);
if (this._allowAmplified)
this._slider.setMaximumValue(this.getMaxLevel() / 100);
else
this._slider.setMaximumValue(1);
if (this._stream)
this._updateVolume();
},
getIcon() { getIcon() {
if (!this._stream) if (!this._stream)
return null; return null;
@ -157,6 +176,14 @@ var StreamSlider = new Lang.Class({
return null; return null;
return 100 * this._stream.volume / this._control.get_vol_max_norm(); return 100 * this._stream.volume / this._control.get_vol_max_norm();
},
getMaxLevel() {
let maxVolume = this._control.get_vol_max_norm();
if (this._allowAmplified)
maxVolume = this._control.get_vol_max_amplified();
return 100 * maxVolume / this._control.get_vol_max_norm();
} }
}); });
Signals.addSignalMethods(StreamSlider.prototype); Signals.addSignalMethods(StreamSlider.prototype);
@ -310,6 +337,10 @@ var VolumeMenu = new Lang.Class({
getLevel() { getLevel() {
return this._output.getLevel(); return this._output.getLevel();
},
getMaxLevel() {
return this._output.getMaxLevel();
} }
}); });
@ -346,8 +377,9 @@ var Indicator = new Lang.Class({
return result; return result;
let gicon = new Gio.ThemedIcon({ name: this._volumeMenu.getIcon() }); let gicon = new Gio.ThemedIcon({ name: this._volumeMenu.getIcon() });
let level = this._volumeMenu.getLevel(); let level = parseInt(this._volumeMenu.getLevel());
Main.osdWindowManager.show(-1, gicon, null, level); let maxLevel = parseInt(this._volumeMenu.getMaxLevel());
Main.osdWindowManager.show(-1, gicon, null, level, maxLevel);
return result; return result;
} }
}); });

View File

@ -25,7 +25,7 @@ gtk_req = '>= 3.15.0'
json_glib_req = '>= 0.13.2' json_glib_req = '>= 0.13.2'
mutter_req = '>= 3.29.4' mutter_req = '>= 3.29.4'
polkit_req = '>= 0.100' polkit_req = '>= 0.100'
schemas_req = '>= 3.21.3' schemas_req = '>= 3.27.90'
startup_req = '>= 0.11' startup_req = '>= 0.11'
ibus_req = '>= 1.5.2' ibus_req = '>= 1.5.2'