2020-02-10 11:39:25 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
* This program is free software: you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU General Public License as published by the Free Software
|
|
|
|
* Foundation, either version 3 of the License, or (at your option) any later
|
|
|
|
* version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* *****************************************************************************
|
|
|
|
* Original Author: Gopi Sankar Karmegam
|
|
|
|
******************************************************************************/
|
|
|
|
/* jshint moz:true */
|
|
|
|
|
|
|
|
const Main = imports.ui.main;
|
|
|
|
const PopupMenu = imports.ui.popupMenu;
|
|
|
|
const VolumeMenu = imports.ui.status.volume;
|
2021-01-20 02:42:26 +00:00
|
|
|
const { Atk, St, GObject, GLib } = imports.gi;
|
2020-02-10 11:39:25 +00:00
|
|
|
|
|
|
|
const Gvc = imports.gi.Gvc;
|
|
|
|
const ExtensionUtils = imports.misc.extensionUtils;
|
|
|
|
const Me = ExtensionUtils.getCurrentExtension();
|
|
|
|
const Lib = Me.imports.convenience;
|
2020-05-31 23:26:13 +00:00
|
|
|
const _d = Lib._log;
|
2020-02-10 11:39:25 +00:00
|
|
|
const Prefs = Me.imports.prefs;
|
|
|
|
const SignalManager = Lib.SignalManager;
|
|
|
|
|
2021-01-20 02:42:26 +00:00
|
|
|
let maxId = -1;
|
2020-02-10 11:39:25 +00:00
|
|
|
|
2021-01-20 02:42:26 +00:00
|
|
|
var SoundDeviceChooserBase = class SoundDeviceChooserBase {
|
2020-02-10 11:39:25 +00:00
|
|
|
|
|
|
|
constructor(deviceType) {
|
2020-04-02 17:13:28 +00:00
|
|
|
_d("SDC: init");
|
2021-01-20 02:42:26 +00:00
|
|
|
this.menuItem = new PopupMenu.PopupSubMenuMenuItem('Extension initialising...', true);
|
2020-02-10 11:39:25 +00:00
|
|
|
this.deviceType = deviceType;
|
|
|
|
this._devices = {};
|
2021-01-20 02:42:26 +00:00
|
|
|
this._cards = [];
|
2020-02-10 11:39:25 +00:00
|
|
|
this._availableDevicesIds = {};
|
|
|
|
this._control = VolumeMenu.getMixerControl();
|
|
|
|
this._settings = Lib.getSettings(Prefs.SETTINGS_SCHEMA);
|
2020-04-02 17:13:28 +00:00
|
|
|
_d("Constructor" + deviceType);
|
2020-02-10 11:39:25 +00:00
|
|
|
|
|
|
|
this._setLog();
|
|
|
|
this._signalManager = new SignalManager();
|
2021-01-20 02:42:26 +00:00
|
|
|
this._signalManager.addSignal(this._settings, "changed::" + Prefs.ENABLE_LOG, this._setLog.bind(this));
|
2020-02-10 11:39:25 +00:00
|
|
|
|
2021-01-20 02:42:26 +00:00
|
|
|
if (this._control.get_state() == Gvc.MixerControlState.READY) {
|
2020-02-10 11:39:25 +00:00
|
|
|
this._onControlStateChanged();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this._controlStateChangeSignal = this._signalManager.addSignal(this._control, "state-changed", this._onControlStateChanged.bind(this));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-20 02:42:26 +00:00
|
|
|
_setLog() { Lib.setLog(this._settings.get_boolean(Prefs.ENABLE_LOG)); }
|
2020-02-10 11:39:25 +00:00
|
|
|
|
|
|
|
_onControlStateChanged() {
|
2021-01-20 02:42:26 +00:00
|
|
|
if (this._control.get_state() == Gvc.MixerControlState.READY) {
|
|
|
|
if (!this._initialised) {
|
2020-02-10 11:39:25 +00:00
|
|
|
this._initialised = true;
|
|
|
|
|
|
|
|
this._signalManager.addSignal(this._control, this.deviceType + "-added", this._deviceAdded.bind(this));
|
|
|
|
this._signalManager.addSignal(this._control, this.deviceType + "-removed", this._deviceRemoved.bind(this));
|
|
|
|
this._signalManager.addSignal(this._control, "active-" + this.deviceType + "-update", this._deviceActivated.bind(this));
|
2021-01-20 02:42:26 +00:00
|
|
|
this._signalManager.addSignal(this._control, "card-removed", this._updateCards.bind(this));
|
|
|
|
this._signalManager.addSignal(this._control, "card-added", this._updateCards.bind(this));
|
2020-02-10 11:39:25 +00:00
|
|
|
|
2021-01-20 02:42:26 +00:00
|
|
|
this._signalManager.addSignal(this._settings, "changed::" + Prefs.HIDE_ON_SINGLE_DEVICE, this._setChooserVisibility.bind(this));
|
|
|
|
this._signalManager.addSignal(this._settings, "changed::" + Prefs.SHOW_PROFILES, this._setProfileVisibility.bind(this));
|
|
|
|
this._signalManager.addSignal(this._settings, "changed::" + Prefs.ICON_THEME, this._setIcons.bind(this));
|
|
|
|
this._signalManager.addSignal(this._settings, "changed::" + Prefs.HIDE_MENU_ICONS, this._setIcons.bind(this));
|
|
|
|
this._signalManager.addSignal(this._settings, "changed::" + Prefs.PORT_SETTINGS, this._resetDevices.bind(this));
|
2020-02-10 11:39:25 +00:00
|
|
|
|
2021-01-20 02:42:26 +00:00
|
|
|
this._show_device_signal = Prefs["SHOW_" + this.deviceType.toUpperCase() + "_DEVICES"];
|
2020-02-10 11:39:25 +00:00
|
|
|
|
2021-01-20 02:42:26 +00:00
|
|
|
this._signalManager.addSignal(this._settings, "changed::" + this._show_device_signal, this._setVisibility.bind(this));
|
2020-02-10 11:39:25 +00:00
|
|
|
|
2021-01-20 02:42:26 +00:00
|
|
|
//this._portsSettings = JSON.parse(this._settings.get_string(Prefs.PORT_SETTINGS));
|
|
|
|
this._portsSettings = Prefs.getPortsFromSettings(this._settings);
|
2020-02-10 11:39:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* There is no direct way to get all the UI devices from
|
|
|
|
* mixercontrol. When enabled after shell loads, the signals
|
|
|
|
* will not be emitted, a simple hack to look for ids, until any
|
|
|
|
* uidevice is not found. The UI devices are always serialed
|
|
|
|
* from from 1 to n
|
|
|
|
*/
|
|
|
|
|
|
|
|
let id = 0;
|
2021-01-20 02:42:26 +00:00
|
|
|
if (maxId < 0) {
|
|
|
|
let dummyDevice = new Gvc.MixerUIDevice();
|
|
|
|
maxId = dummyDevice.get_id();
|
|
|
|
}
|
2020-04-02 17:13:28 +00:00
|
|
|
_d("Max Id:" + maxId);
|
2021-03-14 02:42:28 +00:00
|
|
|
|
2020-02-10 11:39:25 +00:00
|
|
|
let defaultDevice = this.getDefaultDevice();
|
2021-01-20 02:42:26 +00:00
|
|
|
while (++id < maxId) {
|
2020-02-10 11:39:25 +00:00
|
|
|
let uidevice = this._deviceAdded(this._control, id);
|
2021-01-20 02:42:26 +00:00
|
|
|
if (uidevice) {
|
2020-02-10 11:39:25 +00:00
|
|
|
let stream = this._control.get_stream_from_device(uidevice);
|
2021-01-20 02:42:26 +00:00
|
|
|
if (stream) {
|
2020-02-10 11:39:25 +00:00
|
|
|
let stream_port = stream.get_port();
|
|
|
|
let uidevice_port = uidevice.get_port();
|
|
|
|
|
2021-01-20 02:42:26 +00:00
|
|
|
if (((!stream_port && !uidevice_port) ||
|
|
|
|
(stream_port && stream_port.port === uidevice_port)) &&
|
|
|
|
stream == defaultDevice) {
|
2020-02-10 11:39:25 +00:00
|
|
|
this._deviceActivated(this._control, id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-20 02:42:26 +00:00
|
|
|
//We dont have any way to understand that the profile has changed in the settings
|
|
|
|
//Just an useless workaround and potentially crashes shell
|
|
|
|
this.activeProfileTimeout = GLib.timeout_add(GLib.PRIORITY_DEFAULT, 2000,
|
|
|
|
this._setActiveProfile.bind(this));
|
2020-02-10 11:39:25 +00:00
|
|
|
|
2021-01-20 02:42:26 +00:00
|
|
|
if (this._controlStateChangeSignal) {
|
2020-02-10 11:39:25 +00:00
|
|
|
this._controlStateChangeSignal.disconnect();
|
|
|
|
delete this._controlStateChangeSignal;
|
|
|
|
}
|
|
|
|
this._setVisibility();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-20 02:42:26 +00:00
|
|
|
_updateCards(control, cardId) {
|
|
|
|
this._cards = [];
|
|
|
|
let cards = this._control.get_cards();
|
|
|
|
for (let card of cards) {
|
|
|
|
this._cards.push(card.index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-10 11:39:25 +00:00
|
|
|
_deviceAdded(control, id, dontcheck) {
|
|
|
|
let obj = this._devices[id];
|
|
|
|
let uidevice = null;
|
2021-03-14 02:42:28 +00:00
|
|
|
|
|
|
|
_d("Added - "+ id);
|
2020-02-10 11:39:25 +00:00
|
|
|
|
2021-01-20 02:42:26 +00:00
|
|
|
if (!obj) {
|
2020-02-10 11:39:25 +00:00
|
|
|
uidevice = this.lookupDeviceById(id);
|
2021-03-14 02:42:28 +00:00
|
|
|
if (!uidevice || uidevice.description.match(/Dummy\s+(Output|Input)/gi)) {
|
2020-02-10 11:39:25 +00:00
|
|
|
return null;
|
|
|
|
}
|
2021-01-20 02:42:26 +00:00
|
|
|
|
2020-02-10 11:39:25 +00:00
|
|
|
obj = new Object();
|
2021-01-20 02:42:26 +00:00
|
|
|
obj.id = id;
|
2020-02-10 11:39:25 +00:00
|
|
|
obj.uidevice = uidevice;
|
|
|
|
obj.text = uidevice.description;
|
2021-01-20 02:42:26 +00:00
|
|
|
if (uidevice.origin != "")
|
|
|
|
obj.text += " - " + uidevice.origin;
|
2020-02-10 11:39:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* obj.item = this.menu.addAction( obj.text, function() {
|
|
|
|
* this.changeDevice(uidevice); }.bind(this)); let icon =
|
|
|
|
* uidevice.get_icon_name(); if(icon == null || icon.trim() == "")
|
|
|
|
* icon = this.getDefaultIcon(); obj.item._icon = new St.Icon({
|
|
|
|
* style_class: 'popup-menu-icon', icon_name: this._getIcon(icon)});
|
|
|
|
* obj.item.actor.insert_child_at_index(obj.item._icon,1);
|
|
|
|
*/
|
|
|
|
|
|
|
|
let icon = uidevice.get_icon_name();
|
2021-01-20 02:42:26 +00:00
|
|
|
if (icon == null || icon.trim() == "")
|
2020-02-10 11:39:25 +00:00
|
|
|
icon = this.getDefaultIcon();
|
2020-05-31 23:26:13 +00:00
|
|
|
let icon_name = this._getIcon(icon);
|
2020-02-10 11:39:25 +00:00
|
|
|
|
2021-01-20 02:42:26 +00:00
|
|
|
obj.item = this.menuItem.menu.addAction(obj.text, function() {
|
|
|
|
_d("Device Change request");
|
2020-02-10 11:39:25 +00:00
|
|
|
this.changeDevice(uidevice);
|
|
|
|
}.bind(this), icon_name);
|
|
|
|
|
2021-01-20 02:42:26 +00:00
|
|
|
if (!obj.profiles) {
|
2020-02-10 11:39:25 +00:00
|
|
|
obj.profiles = Lib.getProfiles(control, uidevice);
|
|
|
|
}
|
|
|
|
|
2021-01-20 02:42:26 +00:00
|
|
|
if (!obj.profilesitems) {
|
2020-02-10 11:39:25 +00:00
|
|
|
obj.profilesitems = [];
|
|
|
|
}
|
|
|
|
this._devices[id] = obj;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
uidevice = obj.uidevice;
|
|
|
|
}
|
|
|
|
|
2020-04-02 17:13:28 +00:00
|
|
|
_d("Device Name:" + obj.text);
|
2020-02-10 11:39:25 +00:00
|
|
|
|
|
|
|
if (obj.profiles) {
|
|
|
|
for (let profile of obj.profiles) {
|
2020-04-02 17:13:28 +00:00
|
|
|
_d("Profile:" + profile.name);
|
2020-02-10 11:39:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-20 02:42:26 +00:00
|
|
|
if (obj.active) {
|
2020-02-10 11:39:25 +00:00
|
|
|
return uidevice;
|
|
|
|
}
|
|
|
|
|
2021-03-14 02:42:28 +00:00
|
|
|
_d("Added: " + id + ":" + uidevice.description + ":" + uidevice.port_name + ":" + uidevice.origin);
|
2021-01-20 02:42:26 +00:00
|
|
|
if (!this._availableDevicesIds[id]) {
|
2020-02-10 11:39:25 +00:00
|
|
|
this._availableDevicesIds[id] = 0;
|
|
|
|
}
|
2021-01-20 02:42:26 +00:00
|
|
|
this._availableDevicesIds[id]++;
|
2020-02-10 11:39:25 +00:00
|
|
|
|
|
|
|
obj.active = true;
|
2021-01-20 02:42:26 +00:00
|
|
|
let stream = this._control.get_stream_from_device(uidevice);
|
|
|
|
if (stream) {
|
|
|
|
obj.activeProfile = uidevice.get_active_profile();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
obj.activeProfile = "";
|
|
|
|
}
|
|
|
|
//let showProfiles = this._settings.get_boolean(Prefs.SHOW_PROFILES);
|
2020-02-10 11:39:25 +00:00
|
|
|
if (obj.profiles) {
|
|
|
|
for (let profile of obj.profiles) {
|
|
|
|
let profileItem = obj.profilesitems[profile.name];
|
2021-01-20 02:42:26 +00:00
|
|
|
if (!profileItem) {
|
2020-02-10 11:39:25 +00:00
|
|
|
let profileName = profile.name;
|
2021-01-20 02:42:26 +00:00
|
|
|
profileItem = this.menuItem.menu.addAction("Profile: " + profile.human_name, function() {
|
2020-04-02 17:13:28 +00:00
|
|
|
_d("i am setting profile, " + profile.human_name + ":" + uidevice.description + ":" + uidevice.port_name);
|
2021-01-20 02:42:26 +00:00
|
|
|
let stream = this._control.get_stream_from_device(uidevice);
|
|
|
|
//No Active stream probably inactive port
|
|
|
|
if (!stream) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (this._activeDevice && this._activeDevice.uidevice !== uidevice) {
|
2020-04-02 17:13:28 +00:00
|
|
|
_d("Changing active device to " + uidevice.description + ":" + uidevice.port_name);
|
2020-02-10 11:39:25 +00:00
|
|
|
this.changeDevice(uidevice);
|
|
|
|
}
|
|
|
|
this._control.change_profile_on_selected_device(uidevice, profileName);
|
|
|
|
this._setDeviceActiveProfile(obj);
|
|
|
|
}.bind(this));
|
|
|
|
|
|
|
|
obj.profilesitems[profileName] = profileItem;
|
|
|
|
profileItem.setProfileActive = function(active) {
|
2021-01-20 02:42:26 +00:00
|
|
|
if (active) {
|
2020-02-10 11:39:25 +00:00
|
|
|
// this._ornamentLabel.text = "\u2727";
|
2020-04-02 17:13:28 +00:00
|
|
|
this._ornamentLabel.text = "\u266A";
|
2021-01-20 02:42:26 +00:00
|
|
|
if (this.add_style_pseudo_class) {
|
2020-02-10 11:39:25 +00:00
|
|
|
this.add_style_pseudo_class('checked');
|
|
|
|
this.remove_style_pseudo_class('insensitive');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.actor.add_style_pseudo_class('checked');
|
|
|
|
this.actor.remove_style_pseudo_class('insensitive');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2020-04-02 17:13:28 +00:00
|
|
|
this._ornamentLabel.text = "";
|
2021-01-20 02:42:26 +00:00
|
|
|
if (this.add_style_pseudo_class) {
|
2020-02-10 11:39:25 +00:00
|
|
|
this.remove_style_pseudo_class('checked');
|
|
|
|
this.add_style_pseudo_class('insensitive');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.actor.remove_style_pseudo_class('checked');
|
|
|
|
this.actor.add_style_pseudo_class('insensitive');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
// profileItem._ornamentLabel.width = "500em";
|
2020-04-02 17:13:28 +00:00
|
|
|
profileItem._ornamentLabel.set_style("min-width: 3em;margin-left: 3em;");
|
2020-02-10 11:39:25 +00:00
|
|
|
}
|
|
|
|
profileItem.setProfileActive(obj.activeProfile == profile.name);
|
|
|
|
}
|
|
|
|
}
|
2021-01-20 02:42:26 +00:00
|
|
|
if (!dontcheck && !this._canShowDevice(uidevice, uidevice.port_available)) {
|
2020-02-10 11:39:25 +00:00
|
|
|
this._deviceRemoved(control, id, true);
|
|
|
|
}
|
|
|
|
this._setChooserVisibility();
|
|
|
|
this._setVisibility();
|
|
|
|
return uidevice;
|
|
|
|
}
|
|
|
|
|
|
|
|
_deviceRemoved(control, id, dontcheck) {
|
|
|
|
let obj = this._devices[id];
|
2021-01-20 02:42:26 +00:00
|
|
|
//delete this._devices[id];
|
|
|
|
if (obj && obj.active) {
|
|
|
|
_d("Removed: " + id + ":" + obj.uidevice.description + ":" + obj.uidevice.port_name + ":" + obj.uidevice.origin);
|
|
|
|
if (!dontcheck && this._canShowDevice(obj.uidevice, false)) {
|
2020-04-02 17:13:28 +00:00
|
|
|
_d('Device removed, but not hiding as its set to be shown always');
|
2020-02-10 11:39:25 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-01-20 02:42:26 +00:00
|
|
|
delete this._availableDevicesIds[id];
|
2020-02-10 11:39:25 +00:00
|
|
|
obj.item.actor.visible = false;
|
|
|
|
obj.active = false;
|
|
|
|
if (obj.profiles) {
|
|
|
|
for (let profile of obj.profiles) {
|
|
|
|
let profileItem = obj.profilesitems[profile.name];
|
2021-01-20 02:42:26 +00:00
|
|
|
if (profileItem) {
|
2020-02-10 11:39:25 +00:00
|
|
|
profileItem.actor.visible = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-20 02:42:26 +00:00
|
|
|
if (this.deviceRemovedTimout) {
|
2020-02-10 11:39:25 +00:00
|
|
|
GLib.source_remove(this.deviceRemovedTimout);
|
|
|
|
this.deviceRemovedTimout = null;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* If the active uidevice is removed, then need to activate the
|
|
|
|
* first available uidevice. However for some cases like Headphones,
|
|
|
|
* when the uidevice is removed, Speakers are automatically
|
|
|
|
* activated. So, lets wait for sometime before activating.
|
|
|
|
*/
|
2021-01-20 02:42:26 +00:00
|
|
|
this.deviceRemovedTimout = GLib.timeout_add(GLib.PRIORITY_DEFAULT, 1500, function() {
|
|
|
|
_d("Device Removed timeout");
|
2020-02-10 11:39:25 +00:00
|
|
|
if (obj === this._activeDevice) {
|
2021-01-20 02:42:26 +00:00
|
|
|
for (let id in this._devices) {
|
2020-02-10 11:39:25 +00:00
|
|
|
let device = this._devices[id];
|
2021-01-20 02:42:26 +00:00
|
|
|
if (device.active == true) {
|
2020-02-10 11:39:25 +00:00
|
|
|
this.changeDevice(device.uidevice);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.deviceRemovedTimout = null;
|
|
|
|
return false;
|
|
|
|
}.bind(this));
|
|
|
|
this._setChooserVisibility();
|
|
|
|
this._setVisibility();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_deviceActivated(control, id) {
|
2021-03-14 02:42:28 +00:00
|
|
|
_d("Activated:- " + id);
|
2020-02-10 11:39:25 +00:00
|
|
|
let obj = this._devices[id];
|
2021-01-20 02:42:26 +00:00
|
|
|
if (obj && obj !== this._activeDevice) {
|
|
|
|
_d("Activated: " + id + ":" + obj.uidevice.description + ":" + obj.uidevice.port_name + ":" + obj.uidevice.origin);
|
|
|
|
if (this._activeDevice) {
|
2020-02-10 11:39:25 +00:00
|
|
|
this._activeDevice.item.setOrnament(PopupMenu.Ornament.NONE);
|
2021-01-20 02:42:26 +00:00
|
|
|
if (this._activeDevice.item.remove_style_pseudo_class) {
|
2020-02-10 11:39:25 +00:00
|
|
|
this._activeDevice.item.remove_style_pseudo_class('checked');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this._activeDevice.item.actor.remove_style_pseudo_class('checked');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this._activeDevice = obj;
|
|
|
|
obj.item.setOrnament(PopupMenu.Ornament.CHECK);
|
2021-01-20 02:42:26 +00:00
|
|
|
if (obj.item.add_style_pseudo_class) {
|
2020-02-10 11:39:25 +00:00
|
|
|
obj.item.add_style_pseudo_class('checked');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
obj.item.actor.add_style_pseudo_class('checked');
|
|
|
|
}
|
|
|
|
|
|
|
|
obj.item._ornamentLabel.text = '\u266B';
|
|
|
|
this.menuItem.label.text = obj.text;
|
|
|
|
|
|
|
|
if (!this._settings.get_boolean(Prefs.HIDE_MENU_ICONS)) {
|
|
|
|
let icon = obj.uidevice.get_icon_name();
|
2021-01-20 02:42:26 +00:00
|
|
|
if (icon == null || icon.trim() == "")
|
2020-02-10 11:39:25 +00:00
|
|
|
icon = this.getDefaultIcon();
|
|
|
|
this.menuItem.icon.icon_name = this._getIcon(icon);
|
|
|
|
} else {
|
2020-05-31 23:26:13 +00:00
|
|
|
this.menuItem.icon.gicon = null;
|
2020-02-10 11:39:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_setActiveProfile() {
|
2021-01-20 02:42:26 +00:00
|
|
|
//_d("Setting Active Profile");
|
|
|
|
/*for (let id in this._devices) {
|
2020-02-10 11:39:25 +00:00
|
|
|
let device = this._devices[id];
|
2021-01-20 02:42:26 +00:00
|
|
|
if (device.active) {
|
2020-02-10 11:39:25 +00:00
|
|
|
this._setDeviceActiveProfile(device);
|
|
|
|
}
|
2021-01-20 02:42:26 +00:00
|
|
|
}*/
|
2021-03-14 02:42:28 +00:00
|
|
|
if(this._activeDevice){
|
|
|
|
this._setDeviceActiveProfile(this._activeDevice);
|
|
|
|
}
|
2020-02-10 11:39:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
_setDeviceActiveProfile(device) {
|
2021-01-20 02:42:26 +00:00
|
|
|
if (!device.uidevice.port_name || !this._availableDevicesIds[device.id]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let stream = this._control.get_stream_from_device(device.uidevice);
|
|
|
|
if (stream) {
|
2020-02-10 11:39:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
let activeProfile = device.uidevice.get_active_profile();
|
2021-01-20 02:42:26 +00:00
|
|
|
if (activeProfile && device.activeProfile != activeProfile) {
|
2020-02-10 11:39:25 +00:00
|
|
|
device.activeProfile = activeProfile;
|
|
|
|
for (let profile of device.profiles) {
|
|
|
|
device.profilesitems[profile.name].setProfileActive(profile.name == device.activeProfile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_getDeviceVisibility() {
|
|
|
|
let hideChooser = this._settings.get_boolean(Prefs.HIDE_ON_SINGLE_DEVICE);
|
|
|
|
if (hideChooser) {
|
|
|
|
return (Object.keys(this._availableDevicesIds).length > 1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_setChooserVisibility() {
|
|
|
|
let visibility = this._getDeviceVisibility();
|
|
|
|
for (let id in this._availableDevicesIds) {
|
|
|
|
this._devices[id].item.actor.visible = visibility;
|
|
|
|
}
|
|
|
|
this.menuItem._triangleBin.visible = visibility;
|
|
|
|
this._setProfileVisibility();
|
|
|
|
}
|
|
|
|
|
|
|
|
_setProfileVisibility() {
|
|
|
|
let visibility = this._settings.get_boolean(Prefs.SHOW_PROFILES);
|
|
|
|
for (let id in this._availableDevicesIds) {
|
|
|
|
let device = this._devices[id];
|
2021-01-20 02:42:26 +00:00
|
|
|
if (device.profiles) {
|
2020-02-10 11:39:25 +00:00
|
|
|
for (let profile of device.profiles) {
|
|
|
|
device.profilesitems[profile.name].actor.visible =
|
|
|
|
(visibility && device.item.actor.visible && Object.keys(device.profilesitems).length > 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_getIcon(name) {
|
|
|
|
let iconsType = this._settings.get_string(Prefs.ICON_THEME);
|
|
|
|
switch (iconsType) {
|
2021-01-20 02:42:26 +00:00
|
|
|
case Prefs.ICON_THEME_COLORED:
|
|
|
|
return name;
|
|
|
|
case Prefs.ICON_THEME_MONOCHROME:
|
|
|
|
return name + "-symbolic";
|
|
|
|
default:
|
|
|
|
return "none";
|
2020-02-10 11:39:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_setIcons() {
|
|
|
|
// Set the icons in the selection list
|
|
|
|
for (let id in this._devices) {
|
|
|
|
let device = this._devices[id];
|
|
|
|
let icon = device.uidevice.get_icon_name();
|
2021-01-20 02:42:26 +00:00
|
|
|
if (icon == null || icon.trim() == "")
|
2020-02-10 11:39:25 +00:00
|
|
|
icon = this.getDefaultIcon();
|
|
|
|
// device.item._icon.icon_name = this._getIcon(icon);
|
|
|
|
device.item.setIcon(this._getIcon(icon));
|
|
|
|
}
|
|
|
|
|
|
|
|
// These indicate the active device, which is displayed directly in the
|
|
|
|
// Gnome menu, not in the list.
|
|
|
|
if (!this._settings.get_boolean(Prefs.HIDE_MENU_ICONS)) {
|
|
|
|
let icon = this._activeDevice.uidevice.get_icon_name();
|
2021-01-20 02:42:26 +00:00
|
|
|
if (icon == null || icon.trim() == "")
|
2020-02-10 11:39:25 +00:00
|
|
|
icon = this.getDefaultIcon();
|
|
|
|
|
|
|
|
this.menuItem.icon.icon_name = this._getIcon(icon);
|
|
|
|
} else {
|
2020-05-31 23:26:13 +00:00
|
|
|
this.menuItem.icon.gicon = null;
|
2020-02-10 11:39:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_canShowDevice(uidevice, defaultValue) {
|
2021-01-20 02:42:26 +00:00
|
|
|
if (!uidevice || !this._portsSettings || uidevice.port_name == null || uidevice.description == null) {
|
2020-02-10 11:39:25 +00:00
|
|
|
return defaultValue;
|
|
|
|
}
|
2021-01-20 02:42:26 +00:00
|
|
|
let stream = this._control.get_stream_from_device(uidevice);
|
|
|
|
let cardName = null;
|
|
|
|
if (stream) {
|
|
|
|
let cardId = stream.get_card_index();
|
|
|
|
if (cardId != null) {
|
|
|
|
_d("Card Index" + cardId);
|
|
|
|
let _card = Lib.getCard(cardId);
|
|
|
|
if (_card) {
|
|
|
|
cardName = _card.name;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
//card id found, but not available in list
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
_d("Card Name" + cardName);
|
|
|
|
}
|
|
|
|
}
|
2020-02-10 11:39:25 +00:00
|
|
|
|
|
|
|
for (let port of this._portsSettings) {
|
2021-01-20 02:42:26 +00:00
|
|
|
//_d("P" + port.name + "==" + uidevice.port_name + "==" + port.human_name + "==" + uidevice.description + "==" + cardName + "==" + port.card_name)
|
|
|
|
if (port && port.name == uidevice.port_name && port.human_name == uidevice.description && (!cardName || cardName == port.card_name)) {
|
|
|
|
switch (port.display_option) {
|
|
|
|
case 1:
|
|
|
|
return true;
|
2020-02-10 11:39:25 +00:00
|
|
|
|
2021-01-20 02:42:26 +00:00
|
|
|
case 2:
|
|
|
|
return false;
|
2020-02-10 11:39:25 +00:00
|
|
|
|
2021-01-20 02:42:26 +00:00
|
|
|
default:
|
|
|
|
return defaultValue;
|
2020-02-10 11:39:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return defaultValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
_resetDevices() {
|
2021-01-20 02:42:26 +00:00
|
|
|
//this._portsSettings = JSON.parse(this._settings.get_string(Prefs.PORT_SETTINGS));
|
|
|
|
this._portsSettings = Prefs.getPortsFromSettings(this._settings);
|
2020-02-10 11:39:25 +00:00
|
|
|
for (let id in this._devices) {
|
|
|
|
let device = this._devices[id];
|
|
|
|
let uidevice = device.uidevice;
|
2021-01-20 02:42:26 +00:00
|
|
|
if (uidevice.port_name == null || uidevice.description == null) {
|
2021-03-14 02:42:28 +00:00
|
|
|
_d("Device port_name null or description null");
|
2020-02-10 11:39:25 +00:00
|
|
|
continue;
|
|
|
|
}
|
2021-01-20 02:42:26 +00:00
|
|
|
switch (this._canShowDevice(uidevice, uidevice.port_available)) {
|
|
|
|
case true:
|
|
|
|
this._deviceAdded(this._control, uidevice.get_id(), true);
|
|
|
|
break;
|
|
|
|
case false:
|
|
|
|
this._deviceRemoved(this._control, uidevice.get_id(), true);
|
|
|
|
break;
|
2020-02-10 11:39:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-20 02:42:26 +00:00
|
|
|
_setVisibility() {
|
2020-02-10 11:39:25 +00:00
|
|
|
if (!this._settings.get_boolean(this._show_device_signal))
|
|
|
|
this.menuItem.actor.visible = false;
|
|
|
|
else
|
|
|
|
// if setting says to show device, check for any device, otherwise
|
|
|
|
// hide the "actor"
|
|
|
|
this.menuItem.actor.visible = (Object.keys(this._availableDevicesIds).length > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
destroy() {
|
|
|
|
this._signalManager.disconnectAll();
|
2021-01-20 02:42:26 +00:00
|
|
|
if (this.deviceRemovedTimout) {
|
2020-02-10 11:39:25 +00:00
|
|
|
GLib.source_remove(this.deviceRemovedTimout);
|
|
|
|
this.deviceRemovedTimout = null;
|
|
|
|
}
|
2021-01-20 02:42:26 +00:00
|
|
|
if (this.activeProfileTimeout) {
|
2020-02-10 11:39:25 +00:00
|
|
|
GLib.source_remove(this.activeProfileTimeout);
|
|
|
|
this.activeProfileTimeout = null;
|
|
|
|
}
|
|
|
|
this.menuItem.destroy();
|
|
|
|
}
|
|
|
|
};
|