From 3909a06fe6786027c83e3adaef89c343cde4fbe3 Mon Sep 17 00:00:00 2001 From: Calvin Morrison Date: Sun, 17 May 2026 23:38:18 -0400 Subject: ALSA backend, backend switcher, UX fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ALSA backend: AlsaModel, AlsaDevice, AlsaMixerWindow, AlsaTray, AlsaPopup - BackendController: live pulse↔alsa switching, preserves window position/visibility - PA shutdown fix: stop mainloop thread before disconnect/free to prevent crash - Exit crash fix: BackendController deleted explicitly before TQApplication exits - Waiting-for-PulseAudio placeholder when PA not connected - Preferences: live backend stack (Pulse/ALSA), Startup/Exit card with autostart, Recording card, no-tabs greying, remove stale "requires restart" label - Recording tray: track source outputs directly; fix LED init in popup; level meter forwarding for monitor-source recordings via m_monitorSourceToSink - TmixTray: fix config group General→Tray for scroll/mute/popup settings; RecordingTray suppresses right-click menu - audiodevice.h: add recordingActive() virtual accessor Co-Authored-By: Claude Sonnet 4.6 --- src/ui/alsa/alsadevicespage.cpp | 161 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 src/ui/alsa/alsadevicespage.cpp (limited to 'src/ui/alsa/alsadevicespage.cpp') diff --git a/src/ui/alsa/alsadevicespage.cpp b/src/ui/alsa/alsadevicespage.cpp new file mode 100644 index 0000000..2b7ede0 --- /dev/null +++ b/src/ui/alsa/alsadevicespage.cpp @@ -0,0 +1,161 @@ +#include "alsadevicespage.h" +#include "../../model/alsamodel.h" +#include "../../model/alsadevice.h" +#include "../kledbutton.h" + +#include +#include +#include +#include +#include +#include + +// ── AlsaSwitchRow ───────────────────────────────────────────────────────── + +AlsaSwitchRow::AlsaSwitchRow( AlsaDevice *dev, TQWidget *parent ) + : TQWidget(parent), m_dev(dev) +{ + TQColor ledColor = ( dev->category() == AlsaDevice::Input ) ? TQt::red : TQt::yellow; + m_led = new KLedButton( ledColor, + dev->muted() ? KLed::Off : KLed::On, + KLed::Sunken, KLed::Circular, this ); + m_led->setFixedSize(14, 14); + + TQHBoxLayout *hbox = new TQHBoxLayout(this, 2, 4); + hbox->addWidget(m_led); + hbox->addWidget( new TQLabel(dev->name(), this) ); + hbox->addStretch(1); + + connect(dev, TQ_SIGNAL(muteChanged(bool)), this, TQ_SLOT(onMuteChanged(bool))); + connect(m_led, TQ_SIGNAL(stateChanged(bool)), this, TQ_SLOT(onLedToggled(bool))); +} + +void AlsaSwitchRow::onMuteChanged( bool m ) +{ + m_led->blockSignals(true); + m_led->setState( m ? KLed::Off : KLed::On ); + m_led->blockSignals(false); +} + +void AlsaSwitchRow::onLedToggled( bool on ) +{ + m_dev->setMuted( !on ); +} + +// ── AlsaEnumRow ────────────────────────────────────────────────────────────── + +AlsaEnumRow::AlsaEnumRow( AlsaDevice *dev, TQWidget *parent ) + : TQWidget(parent), m_dev(dev) +{ + m_combo = new TQComboBox(false, this); + TQStringList vals = dev->enumValues(); + for ( TQStringList::ConstIterator it = vals.begin(); it != vals.end(); ++it ) + m_combo->insertItem(*it); + m_combo->setCurrentItem( dev->enumId() ); + + TQHBoxLayout *hbox = new TQHBoxLayout(this, 2, 6); + hbox->addWidget( new TQLabel(dev->name() + ":", this) ); + hbox->addWidget(m_combo, 1); + + connect(dev, TQ_SIGNAL(enumChanged(int)), this, TQ_SLOT(onEnumChanged(int))); + connect(m_combo, TQ_SIGNAL(activated(int)), this, TQ_SLOT(onComboActivated(int))); +} + +void AlsaEnumRow::onEnumChanged( int id ) +{ + m_combo->blockSignals(true); + m_combo->setCurrentItem(id); + m_combo->blockSignals(false); +} + +void AlsaEnumRow::onComboActivated( int idx ) +{ + m_dev->setEnumId(idx); +} + +// ── AlsaDevicesPage ────────────────────────────────────────────────────────── + +AlsaDevicesPage::AlsaDevicesPage( AlsaModel *model, TQWidget *parent ) + : TQWidget(parent), m_model(model), m_cardIndex(-1), m_content(0) +{ + TQVBoxLayout *outer = new TQVBoxLayout(this, 8, 4); + + m_scroll = new TQScrollView(this); + m_scroll->setResizePolicy( TQScrollView::AutoOneFit ); + m_scroll->setFrameStyle( TQFrame::NoFrame ); + outer->addWidget(m_scroll, 1); + + m_content = new TQWidget( m_scroll->viewport() ); + m_scroll->addChild(m_content); + + connect(model, TQ_SIGNAL(deviceAdded(AlsaDevice*)), this, TQ_SLOT(onDeviceAdded(AlsaDevice*))); +} + +void AlsaDevicesPage::setCard( int cardIndex ) +{ + m_cardIndex = cardIndex; + rebuild(); +} + +void AlsaDevicesPage::rebuild() +{ + delete m_content; + m_content = new TQWidget( m_scroll->viewport() ); + m_scroll->addChild(m_content); + + TQVBoxLayout *vbox = new TQVBoxLayout(m_content, 6, 4); + + if ( m_cardIndex < 0 ) { + vbox->addWidget( new TQLabel( i18n("No card selected."), m_content ) ); + vbox->addStretch(1); + m_content->show(); + return; + } + + TQPtrList devs = m_model->devicesForCard(m_cardIndex); + bool hasSwitches = false, hasEnums = false; + + for ( TQPtrListIterator it(devs); *it; ++it ) { + if ( (*it)->type() == AlsaDevice::Switch ) hasSwitches = true; + if ( (*it)->type() == AlsaDevice::Enum ) hasEnums = true; + } + + if ( hasSwitches ) { + TQLabel *hdr = new TQLabel( TQString("%1").arg(i18n("Switches")), m_content ); + vbox->addWidget(hdr); + for ( TQPtrListIterator it(devs); *it; ++it ) { + if ( (*it)->type() == AlsaDevice::Switch ) { + AlsaSwitchRow *row = new AlsaSwitchRow( *it, m_content ); + vbox->addWidget(row); + } + } + if ( hasEnums ) + vbox->addSpacing(8); + } + + if ( hasEnums ) { + TQLabel *hdr = new TQLabel( TQString("%1").arg(i18n("Routing")), m_content ); + vbox->addWidget(hdr); + for ( TQPtrListIterator it(devs); *it; ++it ) { + if ( (*it)->type() == AlsaDevice::Enum ) { + AlsaEnumRow *row = new AlsaEnumRow( *it, m_content ); + vbox->addWidget(row); + } + } + } + + if ( !hasSwitches && !hasEnums ) { + vbox->addWidget( new TQLabel( i18n("No device settings available for this card."), m_content ) ); + } + + vbox->addStretch(1); + m_content->show(); + m_content->adjustSize(); +} + +void AlsaDevicesPage::onDeviceAdded( AlsaDevice * ) +{ + rebuild(); +} + +#include "alsadevicespage.moc" -- cgit v1.2.3