[gnome-shell] status/volume: Merge VolumeMenu into indicator
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] status/volume: Merge VolumeMenu into indicator
- Date: Mon, 1 Aug 2022 12:38:13 +0000 (UTC)
commit 3bc9f00a15bb638ec6dced32649ea56a6c13e6c2
Author: Florian Müllner <fmuellner gnome org>
Date: Sat Jul 30 13:58:35 2022 +0200
status/volume: Merge VolumeMenu into indicator
Other than connecting stream when necessary, the volume menu
only forwards slider events to the indicator, and method calls
from the indicator to the appropriate slider.
Just cut our the middle-man and let the indicator handle the
slider items directly.
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2391>
js/ui/status/volume.js | 141 ++++++++++++++++---------------------------------
1 file changed, 45 insertions(+), 96 deletions(-)
---
diff --git a/js/ui/status/volume.js b/js/ui/status/volume.js
index 9668e5bde5..256240319d 100644
--- a/js/ui/status/volume.js
+++ b/js/ui/status/volume.js
@@ -11,11 +11,6 @@ const Slider = imports.ui.slider;
const ALLOW_AMPLIFIED_VOLUME_KEY = 'allow-volume-above-100-percent';
-const VolumeType = {
- OUTPUT: 0,
- INPUT: 1,
-};
-
// Each Gvc.MixerControl is a connection to PulseAudio,
// so it's better to make it a singleton
let _mixerControl;
@@ -417,13 +412,25 @@ var InputStreamSlider = class extends StreamSlider {
}
};
-var VolumeMenu = class extends PopupMenu.PopupMenuSection {
- constructor(control) {
- super();
+var Indicator = GObject.registerClass(
+class Indicator extends PanelMenu.SystemIndicator {
+ _init() {
+ super._init();
- this.hasHeadphones = false;
+ this._primaryIndicator = this._addIndicator();
+ this._inputIndicator = this._addIndicator();
- this._control = control;
+ 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));
+
+ const volumeMenu = new PopupMenu.PopupMenuSection();
+
+ this._control = getMixerControl();
this._control.connectObject(
'state-changed', () => this._onControlStateChanged(),
'default-sink-changed', () => this._readOutput(),
@@ -431,34 +438,39 @@ var VolumeMenu = class extends PopupMenu.PopupMenuSection {
this);
this._output = new OutputStreamSlider(this._control);
- this._output.connect('stream-updated',
- () => this.emit('output-icon-changed'));
- this.addMenuItem(this._output.item);
+ this._output.connect('stream-updated', () => {
+ const icon = this._output.getIcon();
+
+ if (icon)
+ this._primaryIndicator.icon_name = icon;
+ this._primaryIndicator.visible = icon !== null;
+ });
+ volumeMenu.addMenuItem(this._output.item);
this._input = new InputStreamSlider(this._control);
- this._input.item.connect('notify::visible',
- () => this.emit('input-visible-changed'));
- this._input.connect('stream-updated',
- () => this.emit('input-icon-changed'));
- this.addMenuItem(this._input.item);
+ this._input.connect('stream-updated', () => {
+ const icon = this._input.getIcon();
+
+ if (icon)
+ this._inputIndicator.icon_name = icon;
+ });
+ volumeMenu.addMenuItem(this._input.item);
- this.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
+ this._input.item.actor.bind_property('visible',
+ this._inputIndicator, 'visible',
+ GObject.BindingFlags.SYNC_CREATE);
- this._onControlStateChanged();
- }
+ this.menu.addMenuItem(volumeMenu);
- scroll(type, event) {
- return type === VolumeType.INPUT
- ? this._input.scroll(event)
- : this._output.scroll(event);
+ this._onControlStateChanged();
}
_onControlStateChanged() {
- if (this._control.get_state() == Gvc.MixerControlState.READY) {
+ if (this._control.get_state() === Gvc.MixerControlState.READY) {
this._readInput();
this._readOutput();
} else {
- this.emit('output-icon-changed');
+ this._primaryIndicator.hide();
}
}
@@ -470,77 +482,14 @@ var VolumeMenu = class extends PopupMenu.PopupMenuSection {
this._input.stream = this._control.get_default_source();
}
- getIcon(type) {
- return type === VolumeType.INPUT
- ? this._input.getIcon()
- : this._output.getIcon();
- }
-
- getLevel(type) {
- return type === VolumeType.INPUT
- ? this._input.getLevel()
- : this._output.getLevel();
- }
-
- getMaxLevel(type) {
- return type === VolumeType.INPUT
- ? this._input.getMaxLevel()
- : this._output.getMaxLevel();
- }
-
- getInputVisible() {
- return this._input.item.visible;
- }
-};
-
-var Indicator = GObject.registerClass(
-class Indicator extends PanelMenu.SystemIndicator {
- _init() {
- super._init();
-
- this._primaryIndicator = 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._volumeMenu = new VolumeMenu(this._control);
- this._volumeMenu.connect('output-icon-changed', () => {
- let icon = this._volumeMenu.getIcon(VolumeType.OUTPUT);
-
- if (icon != null)
- this._primaryIndicator.icon_name = icon;
- this._primaryIndicator.visible = icon !== null;
- });
-
- this._inputIndicator.visible = this._volumeMenu.getInputVisible();
- this._volumeMenu.connect('input-visible-changed', () => {
- this._inputIndicator.visible = this._volumeMenu.getInputVisible();
- });
- this._volumeMenu.connect('input-icon-changed', () => {
- let icon = this._volumeMenu.getIcon(VolumeType.INPUT);
-
- if (icon !== null)
- this._inputIndicator.icon_name = icon;
- });
-
- this.menu.addMenuItem(this._volumeMenu);
- }
-
- _handleScrollEvent(type, event) {
- const result = this._volumeMenu.scroll(type, event);
- if (result == Clutter.EVENT_PROPAGATE || this.menu.actor.mapped)
+ _handleScrollEvent(item, event) {
+ const result = item.scroll(event);
+ if (result === Clutter.EVENT_PROPAGATE || this.menu.actor.mapped)
return result;
- const gicon = new Gio.ThemedIcon({ name: this._volumeMenu.getIcon(type) });
- const level = this._volumeMenu.getLevel(type);
- const maxLevel = this._volumeMenu.getMaxLevel(type);
+ const gicon = new Gio.ThemedIcon({name: item.getIcon()});
+ const level = item.getLevel();
+ const maxLevel = item.getMaxLevel();
Main.osdWindowManager.show(-1, gicon, null, level, maxLevel);
return result;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]