From 66f615e6b4b6a8f6d9d86a0e458d7c600401c606 Mon Sep 17 00:00:00 2001 From: JohnOberhauser <14130581+JohnOberhauser@users.noreply.github.com> Date: Fri, 11 Nov 2022 21:58:34 -0600 Subject: [PATCH] Adding input / output options (#1) --- extension.js | 3 +- features/inputOutput.js | 185 ++++++++++++++++++ prefPages/inputOutput.js | 47 +++++ prefs.js | 1 + ...tensions.quick-settings-tweaks.gschema.xml | 11 ++ stylesheet.css | 5 + 6 files changed, 251 insertions(+), 1 deletion(-) create mode 100644 features/inputOutput.js create mode 100644 prefPages/inputOutput.js diff --git a/extension.js b/extension.js index df4274a..ba2dcef 100644 --- a/extension.js +++ b/extension.js @@ -19,7 +19,8 @@ function enable() { new Features.notifications.notificationsFeature(settings), new Features.volumeMixer.volumeMixerFeature(settings), new Features.dateMenu.dateMenuFeature(settings), - new Features.buttonRemover.buttonRemoverFeature(settings) + new Features.buttonRemover.buttonRemoverFeature(settings), + new Features.inputOutput.inputOutputFeature(settings) ] // Add timeout for waitting other extensions such as GSConnect diff --git a/features/inputOutput.js b/features/inputOutput.js new file mode 100644 index 0000000..a3102f9 --- /dev/null +++ b/features/inputOutput.js @@ -0,0 +1,185 @@ +const ExtensionUtils = imports.misc.extensionUtils +const Me = ExtensionUtils.getCurrentExtension() + +const featureReloader = Me.imports.libs.featureReloader +const { addChildWithIndex } = Me.imports.libs.utility +const { QuickSettingsGrid } = Me.imports.libs.gnome +const { Label } = imports.gi.St +const Volume = imports.ui.status.volume +const PopupMenu = imports.ui.popupMenu; + +var inputOutputFeature = class { + constructor(settings) { + this.settings = settings + } + + load() { + // setup reloader + featureReloader.enableWithSettingKeys(this,[ + "output-show-selected", + "input-show-selected", + "input-always-show" + ]) + + this._setupOutputChangedListener() + this._setupInputChangedListener() + this._setupInputVisibilityObserver() + } + + unload() { + // disable feature reloader + featureReloader.disable(this) + + this._detachOutputLabel() + Volume.getMixerControl().disconnect(this._outputListener) + this._outputListener = null + + this._detachInputLabel() + Volume.getMixerControl().disconnect(this._inputListener) + this._inputListener = null + + this._getInputStreamSlider().disconnect(this._inputVisibilityListener) + this._inputVisibilityListener = null + this._getInputStreamSlider().visible = this._getInputStreamSlider()._shouldBeVisible() + } + + // =========================================== Ouput =========================================== + _setupOutputChangedListener() { + this._attachOutputLabel() + this._outputListener = Volume.getMixerControl().connect('active-output-update', (c, id) => this._onOutputDeviceChanged(id)) + } + + _onOutputDeviceChanged(deviceId) { + const device = Volume.getMixerControl().lookup_output_id(deviceId) + this.outputLabel.text = this._getDeviceName(device) + } + + _attachOutputLabel() { + this.outputLabel = new Label() + this.outputLabel.style_class = "QSTWEAKS-volume-mixer-label" + addChildWithIndex(QuickSettingsGrid, this.outputLabel, this._getOutputStreamSliderIndex() - 1); + this._spanTwoColumns(this.outputLabel) + this.outputLabel.visible = this.settings.get_boolean("output-show-selected") + this.outputLabel.text = this._findActiveDevice(this._getOutputStreamSlider()) + } + + _detachOutputLabel() { + if (this.outputLabel && this.outputLabel.get_parent()) { + this.outputLabel.get_parent().remove_child(this.outputLabel) + this.outputLabel = null + } + } + + // =========================================== Input =========================================== + _setupInputChangedListener() { + this._attachInputLabel() + this._outputListener = Volume.getMixerControl().connect('active-input-update', (c, id) => this._onInputDeviceChanged(id)) + } + + _attachInputLabel() { + this.inputLabel = new Label() + this.inputLabel.style_class = "QSTWEAKS-volume-mixer-label" + addChildWithIndex(QuickSettingsGrid, this.inputLabel, this._getInputStreamSliderIndex() - 1) + this._spanTwoColumns(this.inputLabel) + this._setInputLabelVisibility() + this.inputLabel.text = this._findActiveDevice(this._getInputStreamSlider()) + } + + _onInputDeviceChanged(deviceId) { + const device = Volume.getMixerControl().lookup_input_id(deviceId) + this.inputLabel.text = this._getDeviceName(device) + } + + _detachInputLabel() { + if (this.inputLabel && this.inputLabel.get_parent()) { + this.inputLabel.visible = true + this.inputLabel.get_parent().remove_child(this.inputLabel) + this.inputLabel = null + } + } + + // =========================================== Input Visbility =========================================== + _setupInputVisibilityObserver() { + this._inputVisibilityListener = this._getInputStreamSlider().connect("notify::visible", () => this._onInputStreamSliderSynced()) + this._onInputStreamSliderSynced() + } + + _onInputStreamSliderSynced() { + this._setInputStreamSliderVisibility() + this._setInputLabelVisibility() + } + + _setInputStreamSliderVisibility() { + this._getInputStreamSlider().visible = this._getInputStreamSlider()._shouldBeVisible() || this.settings.get_boolean("input-always-show") + } + + _setInputLabelVisibility() { + this.inputLabel.visible = this._getInputStreamSlider().visible && this.settings.get_boolean("input-show-selected") + } + + + // =========================================== Utils =========================================== + _getInputStreamSlider() { + return this._getUiObject("InputStreamSlider") + } + + _getInputStreamSliderIndex() { + return this._getUiObjectIndex("InputStreamSlider") + } + + _getOutputStreamSlider() { + return this._getUiObject("OutputStreamSlider") + } + + _getOutputStreamSliderIndex() { + return this._getUiObjectIndex("OutputStreamSlider") + } + + _getUiObject(constructorName) { + let gridChildren = QuickSettingsGrid.get_children() + let index = this._getUiObjectIndex(constructorName) + if (index) { + return gridChildren[index] + } + return null + } + + _getUiObjectIndex(constructorName) { + let gridChildren = QuickSettingsGrid.get_children() + let outputSliderIndex + for (let index = 0; index 'block' + + + + false + + + false + + + false + diff --git a/stylesheet.css b/stylesheet.css index 6689524..4b22aa9 100644 --- a/stylesheet.css +++ b/stylesheet.css @@ -214,3 +214,8 @@ .quick-settings .QSTWEAKS-media.QSTWEAKS-remove-shadow .message { box-shadow: none; } + +/* input output labels */ + .QSTWEAWKS-input-output-label { + width: auto; + } \ No newline at end of file