2011-09-28 13:16:26 +00:00
|
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2019-01-31 14:07:06 +00:00
|
|
|
|
/* exported Indicator */
|
2010-07-23 00:39:44 +00:00
|
|
|
|
|
2022-07-29 23:37:07 +00:00
|
|
|
|
const {Clutter, Gio, GLib, GObject, Gvc} = imports.gi;
|
2010-07-23 00:39:44 +00:00
|
|
|
|
|
2017-06-09 14:06:39 +00:00
|
|
|
|
const Main = imports.ui.main;
|
2010-07-23 00:39:44 +00:00
|
|
|
|
const PopupMenu = imports.ui.popupMenu;
|
2022-07-29 23:37:07 +00:00
|
|
|
|
|
|
|
|
|
const {QuickSlider, SystemIndicator} = imports.ui.quickSettings;
|
2010-07-23 00:39:44 +00:00
|
|
|
|
|
2018-07-31 06:02:04 +00:00
|
|
|
|
const ALLOW_AMPLIFIED_VOLUME_KEY = 'allow-volume-above-100-percent';
|
|
|
|
|
|
2012-08-26 14:05:46 +00:00
|
|
|
|
// Each Gvc.MixerControl is a connection to PulseAudio,
|
|
|
|
|
// so it's better to make it a singleton
|
|
|
|
|
let _mixerControl;
|
2022-07-15 12:23:23 +00:00
|
|
|
|
/**
|
|
|
|
|
* @returns {Gvc.MixerControl} - the mixer control singleton
|
|
|
|
|
*/
|
2012-08-26 14:05:46 +00:00
|
|
|
|
function getMixerControl() {
|
|
|
|
|
if (_mixerControl)
|
|
|
|
|
return _mixerControl;
|
2010-07-23 00:39:44 +00:00
|
|
|
|
|
2012-08-26 14:05:46 +00:00
|
|
|
|
_mixerControl = new Gvc.MixerControl({ name: 'GNOME Shell Volume Control' });
|
|
|
|
|
_mixerControl.open();
|
|
|
|
|
|
|
|
|
|
return _mixerControl;
|
|
|
|
|
}
|
2010-07-23 00:39:44 +00:00
|
|
|
|
|
2022-07-29 23:37:07 +00:00
|
|
|
|
const StreamSlider = GObject.registerClass({
|
|
|
|
|
Signals: {
|
|
|
|
|
'stream-updated': {},
|
|
|
|
|
},
|
|
|
|
|
}, class StreamSlider extends QuickSlider {
|
|
|
|
|
_init(control) {
|
|
|
|
|
super._init();
|
2022-07-04 22:30:44 +00:00
|
|
|
|
|
2012-12-20 02:57:26 +00:00
|
|
|
|
this._control = control;
|
2012-08-26 14:05:46 +00:00
|
|
|
|
|
2018-02-23 22:58:22 +00:00
|
|
|
|
this._inDrag = false;
|
|
|
|
|
this._notifyVolumeChangeId = 0;
|
|
|
|
|
|
2022-07-15 12:20:28 +00:00
|
|
|
|
this._soundSettings = new Gio.Settings({
|
|
|
|
|
schema_id: 'org.gnome.desktop.sound',
|
|
|
|
|
});
|
|
|
|
|
this._soundSettings.connect(`changed::${ALLOW_AMPLIFIED_VOLUME_KEY}`,
|
|
|
|
|
() => this._amplifySettingsChanged());
|
2018-07-31 06:02:04 +00:00
|
|
|
|
this._amplifySettingsChanged();
|
|
|
|
|
|
2022-07-29 23:37:07 +00:00
|
|
|
|
this._sliderChangedId = this.slider.connect('notify::value',
|
2022-07-15 12:20:28 +00:00
|
|
|
|
() => this._sliderChanged());
|
2022-07-29 23:37:07 +00:00
|
|
|
|
this.slider.connect('drag-begin', () => (this._inDrag = true));
|
|
|
|
|
this.slider.connect('drag-end', () => {
|
2018-02-23 22:58:22 +00:00
|
|
|
|
this._inDrag = false;
|
|
|
|
|
this._notifyVolumeChange();
|
|
|
|
|
});
|
2010-07-23 00:39:44 +00:00
|
|
|
|
|
2022-07-15 12:35:35 +00:00
|
|
|
|
this._deviceItems = new Map();
|
|
|
|
|
|
|
|
|
|
this._deviceSection = new PopupMenu.PopupMenuSection();
|
|
|
|
|
this.menu.addMenuItem(this._deviceSection);
|
|
|
|
|
|
2022-07-29 23:37:07 +00:00
|
|
|
|
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
2022-07-15 12:35:35 +00:00
|
|
|
|
this.menu.addSettingsAction(_('Sound Settings'),
|
|
|
|
|
'gnome-sound-panel.desktop');
|
|
|
|
|
|
2012-12-20 02:57:26 +00:00
|
|
|
|
this._stream = null;
|
2018-12-13 19:33:45 +00:00
|
|
|
|
this._volumeCancellable = null;
|
2020-06-21 00:51:01 +00:00
|
|
|
|
this._icons = [];
|
2022-07-15 12:35:35 +00:00
|
|
|
|
|
|
|
|
|
this._sync();
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2010-07-23 00:39:44 +00:00
|
|
|
|
|
2012-12-20 02:57:26 +00:00
|
|
|
|
get stream() {
|
|
|
|
|
return this._stream;
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2012-09-04 15:55:26 +00:00
|
|
|
|
|
2012-12-20 02:57:26 +00:00
|
|
|
|
set stream(stream) {
|
2022-07-15 12:30:49 +00:00
|
|
|
|
this._stream?.disconnectObject(this);
|
2012-12-20 02:57:26 +00:00
|
|
|
|
|
|
|
|
|
this._stream = stream;
|
|
|
|
|
|
|
|
|
|
if (this._stream) {
|
|
|
|
|
this._connectStream(this._stream);
|
|
|
|
|
this._updateVolume();
|
|
|
|
|
} else {
|
|
|
|
|
this.emit('stream-updated');
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-15 12:35:35 +00:00
|
|
|
|
this._sync();
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2012-12-20 02:57:26 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_connectStream(stream) {
|
2021-08-15 22:36:59 +00:00
|
|
|
|
stream.connectObject(
|
|
|
|
|
'notify::is-muted', this._updateVolume.bind(this),
|
|
|
|
|
'notify::volume', this._updateVolume.bind(this), this);
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2012-12-20 02:57:26 +00:00
|
|
|
|
|
2022-07-15 12:35:35 +00:00
|
|
|
|
_lookupDevice(_id) {
|
|
|
|
|
throw new GObject.NotImplementedError(
|
|
|
|
|
`_lookupDevice in ${this.constructor.name}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_activateDevice(_device) {
|
|
|
|
|
throw new GObject.NotImplementedError(
|
|
|
|
|
`_activateDevice in ${this.constructor.name}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_addDevice(id) {
|
|
|
|
|
if (this._deviceItems.has(id))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const device = this._lookupDevice(id);
|
|
|
|
|
if (!device)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-10-03 16:30:13 +00:00
|
|
|
|
const {description, origin} = device;
|
|
|
|
|
const name = origin
|
|
|
|
|
? `${description} – ${origin}`
|
|
|
|
|
: description;
|
|
|
|
|
const item = new PopupMenu.PopupImageMenuItem(name, device.get_gicon());
|
2022-07-15 12:35:35 +00:00
|
|
|
|
item.connect('activate', () => this._activateDevice(device));
|
|
|
|
|
|
|
|
|
|
this._deviceSection.addMenuItem(item);
|
|
|
|
|
this._deviceItems.set(id, item);
|
|
|
|
|
|
|
|
|
|
this._sync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_removeDevice(id) {
|
|
|
|
|
this._deviceItems.get(id)?.destroy();
|
|
|
|
|
if (this._deviceItems.delete(id))
|
|
|
|
|
this._sync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_setActiveDevice(activeId) {
|
|
|
|
|
for (const [id, item] of this._deviceItems) {
|
|
|
|
|
item.setOrnament(id === activeId
|
|
|
|
|
? PopupMenu.Ornament.CHECK
|
|
|
|
|
: PopupMenu.Ornament.NONE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_shouldBeVisible() {
|
2012-12-20 02:57:26 +00:00
|
|
|
|
return this._stream != null;
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2012-12-20 02:57:26 +00:00
|
|
|
|
|
2022-07-15 12:35:35 +00:00
|
|
|
|
_sync() {
|
2022-07-29 23:37:07 +00:00
|
|
|
|
this.visible = this._shouldBeVisible();
|
|
|
|
|
this.menuEnabled = this._deviceItems.size > 1;
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2010-10-20 19:53:23 +00:00
|
|
|
|
|
2019-07-25 16:53:00 +00:00
|
|
|
|
_sliderChanged() {
|
2012-12-20 02:57:26 +00:00
|
|
|
|
if (!this._stream)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-07-29 23:37:07 +00:00
|
|
|
|
let value = this.slider.value;
|
2012-12-20 02:57:26 +00:00
|
|
|
|
let volume = value * this._control.get_vol_max_norm();
|
|
|
|
|
let prevMuted = this._stream.is_muted;
|
2018-02-23 22:58:22 +00:00
|
|
|
|
let prevVolume = this._stream.volume;
|
2012-12-20 02:57:26 +00:00
|
|
|
|
if (volume < 1) {
|
|
|
|
|
this._stream.volume = 0;
|
|
|
|
|
if (!prevMuted)
|
|
|
|
|
this._stream.change_is_muted(true);
|
2011-03-28 14:10:11 +00:00
|
|
|
|
} else {
|
2012-12-20 02:57:26 +00:00
|
|
|
|
this._stream.volume = volume;
|
|
|
|
|
if (prevMuted)
|
|
|
|
|
this._stream.change_is_muted(false);
|
|
|
|
|
}
|
|
|
|
|
this._stream.push_volume();
|
2018-02-23 22:58:22 +00:00
|
|
|
|
|
2018-02-23 22:58:22 +00:00
|
|
|
|
let volumeChanged = this._stream.volume !== prevVolume;
|
|
|
|
|
if (volumeChanged && !this._notifyVolumeChangeId && !this._inDrag) {
|
2018-02-23 22:58:22 +00:00
|
|
|
|
this._notifyVolumeChangeId = GLib.timeout_add(GLib.PRIORITY_DEFAULT, 30, () => {
|
|
|
|
|
this._notifyVolumeChange();
|
|
|
|
|
this._notifyVolumeChangeId = 0;
|
|
|
|
|
return GLib.SOURCE_REMOVE;
|
|
|
|
|
});
|
|
|
|
|
GLib.Source.set_name_by_id(this._notifyVolumeChangeId,
|
|
|
|
|
'[gnome-shell] this._notifyVolumeChangeId');
|
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2012-12-20 02:57:26 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_notifyVolumeChange() {
|
2018-12-13 19:33:45 +00:00
|
|
|
|
if (this._volumeCancellable)
|
|
|
|
|
this._volumeCancellable.cancel();
|
2020-03-28 02:37:50 +00:00
|
|
|
|
this._volumeCancellable = null;
|
|
|
|
|
|
|
|
|
|
if (this._stream.state === Gvc.MixerStreamState.RUNNING)
|
|
|
|
|
return; // feedback not necessary while playing
|
2018-12-13 19:33:45 +00:00
|
|
|
|
|
|
|
|
|
this._volumeCancellable = new Gio.Cancellable();
|
|
|
|
|
let player = global.display.get_sound_player();
|
|
|
|
|
player.play_from_theme('audio-volume-change',
|
2022-07-15 12:20:28 +00:00
|
|
|
|
_('Volume changed'), this._volumeCancellable);
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2012-12-21 18:28:40 +00:00
|
|
|
|
|
2019-09-05 09:45:37 +00:00
|
|
|
|
_changeSlider(value) {
|
2022-07-29 23:37:07 +00:00
|
|
|
|
this.slider.block_signal_handler(this._sliderChangedId);
|
|
|
|
|
this.slider.value = value;
|
|
|
|
|
this.slider.unblock_signal_handler(this._sliderChangedId);
|
2019-09-05 09:45:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_updateVolume() {
|
2012-12-20 02:57:26 +00:00
|
|
|
|
let muted = this._stream.is_muted;
|
2019-09-05 09:45:37 +00:00
|
|
|
|
this._changeSlider(muted
|
2019-08-19 19:38:51 +00:00
|
|
|
|
? 0 : this._stream.volume / this._control.get_vol_max_norm());
|
2012-12-20 02:57:26 +00:00
|
|
|
|
this.emit('stream-updated');
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2012-12-20 02:57:26 +00:00
|
|
|
|
|
2018-07-31 06:02:04 +00:00
|
|
|
|
_amplifySettingsChanged() {
|
|
|
|
|
this._allowAmplified = this._soundSettings.get_boolean(ALLOW_AMPLIFIED_VOLUME_KEY);
|
|
|
|
|
|
2022-07-29 23:37:07 +00:00
|
|
|
|
this.slider.maximum_value = this._allowAmplified
|
2019-02-02 16:50:04 +00:00
|
|
|
|
? this.getMaxLevel() : 1;
|
2018-07-31 06:02:04 +00:00
|
|
|
|
|
|
|
|
|
if (this._stream)
|
|
|
|
|
this._updateVolume();
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2018-07-31 06:02:04 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
getIcon() {
|
2012-12-20 02:57:26 +00:00
|
|
|
|
if (!this._stream)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
let volume = this._stream.volume;
|
2018-02-09 14:10:16 +00:00
|
|
|
|
let n;
|
2012-12-20 02:57:26 +00:00
|
|
|
|
if (this._stream.is_muted || volume <= 0) {
|
2018-02-09 14:10:16 +00:00
|
|
|
|
n = 0;
|
2012-12-20 02:57:26 +00:00
|
|
|
|
} else {
|
2018-02-09 14:10:16 +00:00
|
|
|
|
n = Math.ceil(3 * volume / this._control.get_vol_max_norm());
|
2020-06-21 00:51:01 +00:00
|
|
|
|
n = Math.clamp(n, 1, this._icons.length - 1);
|
2011-03-28 14:10:11 +00:00
|
|
|
|
}
|
2020-06-21 00:51:01 +00:00
|
|
|
|
return this._icons[n];
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2017-06-09 14:06:39 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
getLevel() {
|
2017-06-09 14:06:39 +00:00
|
|
|
|
if (!this._stream)
|
|
|
|
|
return null;
|
|
|
|
|
|
2019-02-02 16:50:04 +00:00
|
|
|
|
return this._stream.volume / this._control.get_vol_max_norm();
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2018-07-31 06:02:04 +00:00
|
|
|
|
|
|
|
|
|
getMaxLevel() {
|
|
|
|
|
let maxVolume = this._control.get_vol_max_norm();
|
|
|
|
|
if (this._allowAmplified)
|
|
|
|
|
maxVolume = this._control.get_vol_max_amplified();
|
|
|
|
|
|
2019-02-02 16:50:04 +00:00
|
|
|
|
return maxVolume / this._control.get_vol_max_norm();
|
2012-12-20 02:57:26 +00:00
|
|
|
|
}
|
2022-07-29 23:37:07 +00:00
|
|
|
|
});
|
2012-12-20 02:57:26 +00:00
|
|
|
|
|
2022-07-29 23:37:07 +00:00
|
|
|
|
const OutputStreamSlider = GObject.registerClass(
|
|
|
|
|
class OutputStreamSlider extends StreamSlider {
|
|
|
|
|
_init(control) {
|
|
|
|
|
super._init(control);
|
2022-07-15 12:35:35 +00:00
|
|
|
|
|
2022-07-29 23:37:07 +00:00
|
|
|
|
this.slider.accessible_name = _('Volume');
|
2022-07-15 12:35:35 +00:00
|
|
|
|
|
|
|
|
|
this._control.connectObject(
|
|
|
|
|
'output-added', (c, id) => this._addDevice(id),
|
|
|
|
|
'output-removed', (c, id) => this._removeDevice(id),
|
|
|
|
|
'active-output-update', (c, id) => this._setActiveDevice(id),
|
|
|
|
|
this);
|
|
|
|
|
|
2020-06-21 00:51:01 +00:00
|
|
|
|
this._icons = [
|
|
|
|
|
'audio-volume-muted-symbolic',
|
|
|
|
|
'audio-volume-low-symbolic',
|
|
|
|
|
'audio-volume-medium-symbolic',
|
|
|
|
|
'audio-volume-high-symbolic',
|
|
|
|
|
'audio-volume-overamplified-symbolic',
|
|
|
|
|
];
|
2022-07-29 23:37:07 +00:00
|
|
|
|
|
|
|
|
|
this.menu.setHeader('audio-headphones-symbolic', _('Sound Output'));
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2013-08-21 16:24:30 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_connectStream(stream) {
|
2017-10-31 01:19:44 +00:00
|
|
|
|
super._connectStream(stream);
|
2021-08-15 22:36:59 +00:00
|
|
|
|
stream.connectObject('notify::port',
|
|
|
|
|
this._portChanged.bind(this), this);
|
2012-12-20 02:57:26 +00:00
|
|
|
|
this._portChanged();
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2010-07-23 00:39:44 +00:00
|
|
|
|
|
2022-07-15 12:35:35 +00:00
|
|
|
|
_lookupDevice(id) {
|
|
|
|
|
return this._control.lookup_output_id(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_activateDevice(device) {
|
|
|
|
|
this._control.change_output(device);
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_findHeadphones(sink) {
|
2012-10-18 17:42:17 +00:00
|
|
|
|
// This only works for external headphones (e.g. bluetooth)
|
|
|
|
|
if (sink.get_form_factor() == 'headset' ||
|
|
|
|
|
sink.get_form_factor() == 'headphone')
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
// a bit hackish, but ALSA/PulseAudio have a number
|
|
|
|
|
// of different identifiers for headphones, and I could
|
|
|
|
|
// not find the complete list
|
2013-02-01 19:19:02 +00:00
|
|
|
|
if (sink.get_ports().length > 0)
|
2018-07-14 20:56:22 +00:00
|
|
|
|
return sink.get_port().port.includes('headphone');
|
2012-10-18 17:42:17 +00:00
|
|
|
|
|
|
|
|
|
return false;
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2012-10-18 17:42:17 +00:00
|
|
|
|
|
2022-07-15 16:15:13 +00:00
|
|
|
|
_portChanged() {
|
|
|
|
|
const hasHeadphones = this._findHeadphones(this._stream);
|
|
|
|
|
if (hasHeadphones === this._hasHeadphones)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
this._hasHeadphones = hasHeadphones;
|
2022-07-29 23:37:07 +00:00
|
|
|
|
this.iconName = this._hasHeadphones
|
2019-08-19 19:33:15 +00:00
|
|
|
|
? 'audio-headphones-symbolic'
|
2019-08-19 19:38:51 +00:00
|
|
|
|
: 'audio-speakers-symbolic';
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2022-07-29 23:37:07 +00:00
|
|
|
|
});
|
2012-12-20 02:57:26 +00:00
|
|
|
|
|
2022-07-29 23:37:07 +00:00
|
|
|
|
const InputStreamSlider = GObject.registerClass(
|
|
|
|
|
class InputStreamSlider extends StreamSlider {
|
|
|
|
|
_init(control) {
|
|
|
|
|
super._init(control);
|
2022-07-15 12:35:35 +00:00
|
|
|
|
|
2022-07-29 23:37:07 +00:00
|
|
|
|
this.slider.accessible_name = _('Microphone');
|
2022-07-15 12:30:49 +00:00
|
|
|
|
|
|
|
|
|
this._control.connectObject(
|
2022-07-15 12:35:35 +00:00
|
|
|
|
'input-added', (c, id) => this._addDevice(id),
|
|
|
|
|
'input-removed', (c, id) => this._removeDevice(id),
|
|
|
|
|
'active-input-update', (c, id) => this._setActiveDevice(id),
|
2022-07-15 12:30:49 +00:00
|
|
|
|
'stream-added', () => this._maybeShowInput(),
|
|
|
|
|
'stream-removed', () => this._maybeShowInput(),
|
|
|
|
|
this);
|
|
|
|
|
|
2022-07-29 23:37:07 +00:00
|
|
|
|
this.iconName = 'audio-input-microphone-symbolic';
|
2020-06-21 00:51:01 +00:00
|
|
|
|
this._icons = [
|
|
|
|
|
'microphone-sensitivity-muted-symbolic',
|
|
|
|
|
'microphone-sensitivity-low-symbolic',
|
|
|
|
|
'microphone-sensitivity-medium-symbolic',
|
|
|
|
|
'microphone-sensitivity-high-symbolic',
|
|
|
|
|
];
|
2022-07-29 23:37:07 +00:00
|
|
|
|
|
|
|
|
|
this.menu.setHeader('audio-input-microphone-symbolic', _('Sound Input'));
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2010-07-23 00:39:44 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_connectStream(stream) {
|
2017-10-31 01:19:44 +00:00
|
|
|
|
super._connectStream(stream);
|
2012-12-20 02:57:26 +00:00
|
|
|
|
this._maybeShowInput();
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2010-07-23 00:39:44 +00:00
|
|
|
|
|
2022-07-15 12:35:35 +00:00
|
|
|
|
_lookupDevice(id) {
|
|
|
|
|
return this._control.lookup_input_id(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_activateDevice(device) {
|
|
|
|
|
this._control.change_input(device);
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_maybeShowInput() {
|
2010-07-23 00:39:44 +00:00
|
|
|
|
// only show input widgets if any application is recording audio
|
|
|
|
|
let showInput = false;
|
2019-09-14 12:33:09 +00:00
|
|
|
|
if (this._stream) {
|
|
|
|
|
// skip gnome-volume-control and pavucontrol which appear
|
|
|
|
|
// as recording because they show the input level
|
|
|
|
|
let skippedApps = [
|
|
|
|
|
'org.gnome.VolumeControl',
|
2019-08-20 21:43:54 +00:00
|
|
|
|
'org.PulseAudio.pavucontrol',
|
2019-09-14 12:33:09 +00:00
|
|
|
|
];
|
|
|
|
|
|
2022-07-15 12:20:28 +00:00
|
|
|
|
showInput = this._control.get_source_outputs().some(
|
|
|
|
|
output => !skippedApps.includes(output.get_application_id()));
|
2010-07-23 00:39:44 +00:00
|
|
|
|
}
|
2012-03-16 22:53:14 +00:00
|
|
|
|
|
2012-12-20 02:57:26 +00:00
|
|
|
|
this._showInput = showInput;
|
2022-07-15 12:35:35 +00:00
|
|
|
|
this._sync();
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2010-07-23 00:39:44 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_shouldBeVisible() {
|
2017-10-31 01:19:44 +00:00
|
|
|
|
return super._shouldBeVisible() && this._showInput;
|
2012-12-20 02:57:26 +00:00
|
|
|
|
}
|
2022-07-29 23:37:07 +00:00
|
|
|
|
});
|
2012-12-20 02:57:26 +00:00
|
|
|
|
|
2022-07-30 11:58:35 +00:00
|
|
|
|
var Indicator = GObject.registerClass(
|
2022-07-29 23:37:07 +00:00
|
|
|
|
class Indicator extends SystemIndicator {
|
2022-07-30 11:58:35 +00:00
|
|
|
|
_init() {
|
|
|
|
|
super._init();
|
2012-12-20 02:57:26 +00:00
|
|
|
|
|
2022-07-30 11:58:35 +00:00
|
|
|
|
this._primaryIndicator = this._addIndicator();
|
|
|
|
|
this._inputIndicator = this._addIndicator();
|
2012-12-20 02:57:26 +00:00
|
|
|
|
|
2022-07-30 11:58:35 +00:00
|
|
|
|
this._primaryIndicator.reactive = true;
|
|
|
|
|
this._inputIndicator.reactive = true;
|
|
|
|
|
|
|
|
|
|
this._primaryIndicator.connect('scroll-event',
|
|
|
|
|
(actor, event) => this._handleScrollEvent(this._output, event));
|
|
|
|
|
this._inputIndicator.connect('scroll-event',
|
|
|
|
|
(actor, event) => this._handleScrollEvent(this._input, event));
|
|
|
|
|
|
|
|
|
|
this._control = getMixerControl();
|
2022-07-15 12:30:49 +00:00
|
|
|
|
this._control.connectObject(
|
|
|
|
|
'state-changed', () => this._onControlStateChanged(),
|
|
|
|
|
'default-sink-changed', () => this._readOutput(),
|
|
|
|
|
'default-source-changed', () => this._readInput(),
|
|
|
|
|
this);
|
2012-12-20 02:57:26 +00:00
|
|
|
|
|
2013-04-23 20:57:43 +00:00
|
|
|
|
this._output = new OutputStreamSlider(this._control);
|
2022-07-30 11:58:35 +00:00
|
|
|
|
this._output.connect('stream-updated', () => {
|
|
|
|
|
const icon = this._output.getIcon();
|
|
|
|
|
|
|
|
|
|
if (icon)
|
|
|
|
|
this._primaryIndicator.icon_name = icon;
|
|
|
|
|
this._primaryIndicator.visible = icon !== null;
|
|
|
|
|
});
|
2012-12-20 02:57:26 +00:00
|
|
|
|
|
2013-04-23 20:57:43 +00:00
|
|
|
|
this._input = new InputStreamSlider(this._control);
|
2022-07-30 11:58:35 +00:00
|
|
|
|
this._input.connect('stream-updated', () => {
|
|
|
|
|
const icon = this._input.getIcon();
|
|
|
|
|
|
|
|
|
|
if (icon)
|
|
|
|
|
this._inputIndicator.icon_name = icon;
|
|
|
|
|
});
|
2012-12-20 02:57:26 +00:00
|
|
|
|
|
2022-07-29 23:37:07 +00:00
|
|
|
|
this._input.bind_property('visible',
|
2022-07-30 11:58:35 +00:00
|
|
|
|
this._inputIndicator, 'visible',
|
|
|
|
|
GObject.BindingFlags.SYNC_CREATE);
|
2012-12-20 02:57:26 +00:00
|
|
|
|
|
2022-07-29 23:37:07 +00:00
|
|
|
|
this.quickSettingsItems.push(this._output);
|
|
|
|
|
this.quickSettingsItems.push(this._input);
|
2010-07-23 00:39:44 +00:00
|
|
|
|
|
2022-07-30 11:58:35 +00:00
|
|
|
|
this._onControlStateChanged();
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2012-12-20 03:02:04 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_onControlStateChanged() {
|
2022-07-30 11:58:35 +00:00
|
|
|
|
if (this._control.get_state() === Gvc.MixerControlState.READY) {
|
2012-12-20 02:57:26 +00:00
|
|
|
|
this._readInput();
|
|
|
|
|
this._readOutput();
|
2012-12-20 03:02:04 +00:00
|
|
|
|
} else {
|
2022-07-30 11:58:35 +00:00
|
|
|
|
this._primaryIndicator.hide();
|
2012-12-20 03:02:04 +00:00
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2012-12-20 03:02:04 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_readOutput() {
|
2012-12-20 02:57:26 +00:00
|
|
|
|
this._output.stream = this._control.get_default_sink();
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2012-12-20 02:57:26 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_readInput() {
|
2012-12-20 02:57:26 +00:00
|
|
|
|
this._input.stream = this._control.get_default_source();
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2012-12-20 02:57:26 +00:00
|
|
|
|
|
2022-07-30 11:58:35 +00:00
|
|
|
|
_handleScrollEvent(item, event) {
|
2022-07-29 23:37:07 +00:00
|
|
|
|
const result = item.slider.scroll(event);
|
|
|
|
|
if (result === Clutter.EVENT_PROPAGATE || item.mapped)
|
2017-06-09 14:06:39 +00:00
|
|
|
|
return result;
|
|
|
|
|
|
2022-07-30 11:58:35 +00:00
|
|
|
|
const gicon = new Gio.ThemedIcon({name: item.getIcon()});
|
|
|
|
|
const level = item.getLevel();
|
|
|
|
|
const maxLevel = item.getMaxLevel();
|
2018-07-31 06:02:04 +00:00
|
|
|
|
Main.osdWindowManager.show(-1, gicon, null, level, maxLevel);
|
2017-06-09 14:06:39 +00:00
|
|
|
|
return result;
|
2010-07-23 00:39:44 +00:00
|
|
|
|
}
|
2019-07-16 09:24:13 +00:00
|
|
|
|
});
|