status/volume: Allow changing input volume by scrolling

Previously scrolling on the volume or input indicator would always
change the volume. This change lets you change the input volume if
you scroll over the input indicator.

https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/3273

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1566>
This commit is contained in:
Razze 2021-01-13 22:56:04 +01:00 committed by Kolja Lampe
parent d1468f7f6d
commit f87f9848c3

View File

@ -11,6 +11,11 @@ const Slider = imports.ui.slider;
const ALLOW_AMPLIFIED_VOLUME_KEY = 'allow-volume-above-100-percent'; const ALLOW_AMPLIFIED_VOLUME_KEY = 'allow-volume-above-100-percent';
const VolumeType = {
OUTPUT: 0,
INPUT: 1,
};
// Each Gvc.MixerControl is a connection to PulseAudio, // Each Gvc.MixerControl is a connection to PulseAudio,
// so it's better to make it a singleton // so it's better to make it a singleton
let _mixerControl; let _mixerControl;
@ -342,8 +347,10 @@ var VolumeMenu = class extends PopupMenu.PopupMenuSection {
this._onControlStateChanged(); this._onControlStateChanged();
} }
scroll(event) { scroll(type, event) {
return this._output.scroll(event); return type === VolumeType.INPUT
? this._input.scroll(event)
: this._output.scroll(event);
} }
_onControlStateChanged() { _onControlStateChanged() {
@ -363,20 +370,22 @@ var VolumeMenu = class extends PopupMenu.PopupMenuSection {
this._input.stream = this._control.get_default_source(); this._input.stream = this._control.get_default_source();
} }
getOutputIcon() { getIcon(type) {
return this._output.getIcon(); return type === VolumeType.INPUT
? this._input.getIcon()
: this._output.getIcon();
} }
getInputIcon() { getLevel(type) {
return this._input.getIcon(); return type === VolumeType.INPUT
? this._input.getLevel()
: this._output.getLevel();
} }
getLevel() { getMaxLevel(type) {
return this._output.getLevel(); return type === VolumeType.INPUT
} ? this._input.getMaxLevel()
: this._output.getMaxLevel();
getMaxLevel() {
return this._output.getMaxLevel();
} }
getInputVisible() { getInputVisible() {
@ -392,10 +401,18 @@ class Indicator extends PanelMenu.SystemIndicator {
this._primaryIndicator = this._addIndicator(); this._primaryIndicator = this._addIndicator();
this._inputIndicator = this._addIndicator(); this._inputIndicator = this._addIndicator();
this._primaryIndicator.reactive = true;
this._inputIndicator.reactive = true;
this._primaryIndicator.connect('scroll-event',
(actor, event) => this._handleScrollEvent(VolumeType.OUTPUT, event));
this._inputIndicator.connect('scroll-event',
(actor, event) => this._handleScrollEvent(VolumeType.INPUT, event));
this._control = getMixerControl(); this._control = getMixerControl();
this._volumeMenu = new VolumeMenu(this._control); this._volumeMenu = new VolumeMenu(this._control);
this._volumeMenu.connect('output-icon-changed', () => { this._volumeMenu.connect('output-icon-changed', () => {
let icon = this._volumeMenu.getOutputIcon(); let icon = this._volumeMenu.getIcon(VolumeType.OUTPUT);
if (icon != null) if (icon != null)
this._primaryIndicator.icon_name = icon; this._primaryIndicator.icon_name = icon;
@ -407,7 +424,7 @@ class Indicator extends PanelMenu.SystemIndicator {
this._inputIndicator.visible = this._volumeMenu.getInputVisible(); this._inputIndicator.visible = this._volumeMenu.getInputVisible();
}); });
this._volumeMenu.connect('input-icon-changed', () => { this._volumeMenu.connect('input-icon-changed', () => {
let icon = this._volumeMenu.getInputIcon(); let icon = this._volumeMenu.getIcon(VolumeType.INPUT);
if (icon !== null) if (icon !== null)
this._inputIndicator.icon_name = icon; this._inputIndicator.icon_name = icon;
@ -416,14 +433,14 @@ class Indicator extends PanelMenu.SystemIndicator {
this.menu.addMenuItem(this._volumeMenu); this.menu.addMenuItem(this._volumeMenu);
} }
vfunc_scroll_event() { _handleScrollEvent(type, event) {
let result = this._volumeMenu.scroll(Clutter.get_current_event()); const result = this._volumeMenu.scroll(type, event);
if (result == Clutter.EVENT_PROPAGATE || this.menu.actor.mapped) if (result == Clutter.EVENT_PROPAGATE || this.menu.actor.mapped)
return result; return result;
let gicon = new Gio.ThemedIcon({ name: this._volumeMenu.getOutputIcon() }); const gicon = new Gio.ThemedIcon({ name: this._volumeMenu.getIcon(type) });
let level = this._volumeMenu.getLevel(); const level = this._volumeMenu.getLevel(type);
let maxLevel = this._volumeMenu.getMaxLevel(); const maxLevel = this._volumeMenu.getMaxLevel(type);
Main.osdWindowManager.show(-1, gicon, null, level, maxLevel); Main.osdWindowManager.show(-1, gicon, null, level, maxLevel);
return result; return result;
} }