From d2a97e7f1d8e225fa2349c9cd837b1a5898b11bd Mon Sep 17 00:00:00 2001 From: Didier Roche Date: Tue, 31 Jul 2018 08:02:04 +0200 Subject: [PATCH] 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`. --- js/ui/status/volume.js | 36 ++++++++++++++++++++++++++++++++++-- meson.build | 2 +- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/js/ui/status/volume.js b/js/ui/status/volume.js index d814ef665..b337e752d 100644 --- a/js/ui/status/volume.js +++ b/js/ui/status/volume.js @@ -12,6 +12,8 @@ const PanelMenu = imports.ui.panelMenu; const PopupMenu = imports.ui.popupMenu; const Slider = imports.ui.slider; +const ALLOW_AMPLIFIED_VOLUME_KEY = 'allow-volume-above-100-percent'; + var VOLUME_NOTIFY_ID = 1; // 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._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('drag-end', this._notifyVolumeChange.bind(this)); @@ -135,6 +142,18 @@ var StreamSlider = new Lang.Class({ 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() { if (!this._stream) return null; @@ -157,6 +176,14 @@ var StreamSlider = new Lang.Class({ return null; 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); @@ -310,6 +337,10 @@ var VolumeMenu = new Lang.Class({ getLevel() { return this._output.getLevel(); + }, + + getMaxLevel() { + return this._output.getMaxLevel(); } }); @@ -346,8 +377,9 @@ var Indicator = new Lang.Class({ return result; let gicon = new Gio.ThemedIcon({ name: this._volumeMenu.getIcon() }); - let level = this._volumeMenu.getLevel(); - Main.osdWindowManager.show(-1, gicon, null, level); + let level = parseInt(this._volumeMenu.getLevel()); + let maxLevel = parseInt(this._volumeMenu.getMaxLevel()); + Main.osdWindowManager.show(-1, gicon, null, level, maxLevel); return result; } }); diff --git a/meson.build b/meson.build index cafba27a8..ad513a665 100644 --- a/meson.build +++ b/meson.build @@ -25,7 +25,7 @@ gtk_req = '>= 3.15.0' json_glib_req = '>= 0.13.2' mutter_req = '>= 3.29.4' polkit_req = '>= 0.100' -schemas_req = '>= 3.21.3' +schemas_req = '>= 3.27.90' startup_req = '>= 0.11' ibus_req = '>= 1.5.2'