summaryrefslogtreecommitdiff
path: root/src/ui/alsa
diff options
context:
space:
mode:
authorCalvin Morrison <calvin@pobox.com>2026-05-17 23:38:18 -0400
committerCalvin Morrison <calvin@pobox.com>2026-05-17 23:38:18 -0400
commit3909a06fe6786027c83e3adaef89c343cde4fbe3 (patch)
treef5ea87c98b50764c8ad87e598f274319df0e74db /src/ui/alsa
parent311b69c14203860ab6d98bd11633eea287c8f04e (diff)
ALSA backend, backend switcher, UX fixesalsa-wip
- 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 <noreply@anthropic.com>
Diffstat (limited to 'src/ui/alsa')
-rw-r--r--src/ui/alsa/alsadevicespage.cpp161
-rw-r--r--src/ui/alsa/alsadevicespage.h66
-rw-r--r--src/ui/alsa/alsadevicewidget.cpp175
-rw-r--r--src/ui/alsa/alsadevicewidget.h31
-rw-r--r--src/ui/alsa/alsamixerwindow.cpp206
-rw-r--r--src/ui/alsa/alsamixerwindow.h55
-rw-r--r--src/ui/alsa/alsapopup.cpp79
-rw-r--r--src/ui/alsa/alsapopup.h30
-rw-r--r--src/ui/alsa/alsatray.cpp131
-rw-r--r--src/ui/alsa/alsatray.h35
10 files changed, 969 insertions, 0 deletions
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 <tqlayout.h>
+#include <tqlabel.h>
+#include <tqcombobox.h>
+#include <tqscrollview.h>
+#include <tqframe.h>
+#include <tdelocale.h>
+
+// ── 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<AlsaDevice> devs = m_model->devicesForCard(m_cardIndex);
+ bool hasSwitches = false, hasEnums = false;
+
+ for ( TQPtrListIterator<AlsaDevice> 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("<b>%1</b>").arg(i18n("Switches")), m_content );
+ vbox->addWidget(hdr);
+ for ( TQPtrListIterator<AlsaDevice> 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("<b>%1</b>").arg(i18n("Routing")), m_content );
+ vbox->addWidget(hdr);
+ for ( TQPtrListIterator<AlsaDevice> 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"
diff --git a/src/ui/alsa/alsadevicespage.h b/src/ui/alsa/alsadevicespage.h
new file mode 100644
index 0000000..4883f85
--- /dev/null
+++ b/src/ui/alsa/alsadevicespage.h
@@ -0,0 +1,66 @@
+#pragma once
+
+#include <tqwidget.h>
+#include <tqstring.h>
+
+class AlsaModel;
+class AlsaDevice;
+class TQScrollView;
+class TQComboBox;
+class KLedButton;
+
+// ── One row per Switch element ──────────────────────────────────────────────
+
+class AlsaSwitchRow : public TQWidget
+{
+ TQ_OBJECT
+public:
+ AlsaSwitchRow( AlsaDevice *dev, TQWidget *parent = 0 );
+
+private slots:
+ void onMuteChanged( bool m );
+ void onLedToggled( bool on );
+
+private:
+ AlsaDevice *m_dev;
+ KLedButton *m_led;
+};
+
+// ── One row per Enum element ────────────────────────────────────────────────
+
+class AlsaEnumRow : public TQWidget
+{
+ TQ_OBJECT
+public:
+ AlsaEnumRow( AlsaDevice *dev, TQWidget *parent = 0 );
+
+private slots:
+ void onEnumChanged( int id );
+ void onComboActivated( int idx );
+
+private:
+ AlsaDevice *m_dev;
+ TQComboBox *m_combo;
+};
+
+// ── Device Settings page ────────────────────────────────────────────────────
+
+class AlsaDevicesPage : public TQWidget
+{
+ TQ_OBJECT
+public:
+ explicit AlsaDevicesPage( AlsaModel *model, TQWidget *parent = 0 );
+
+ void setCard( int cardIndex );
+
+private slots:
+ void onDeviceAdded( AlsaDevice * );
+
+private:
+ void rebuild();
+
+ AlsaModel *m_model;
+ int m_cardIndex;
+ TQScrollView *m_scroll;
+ TQWidget *m_content;
+};
diff --git a/src/ui/alsa/alsadevicewidget.cpp b/src/ui/alsa/alsadevicewidget.cpp
new file mode 100644
index 0000000..214d931
--- /dev/null
+++ b/src/ui/alsa/alsadevicewidget.cpp
@@ -0,0 +1,175 @@
+#include "alsadevicewidget.h"
+#include "../../model/alsadevice.h"
+#include "../balanceknob.h"
+#include "../kledbutton.h"
+
+#include <tqlayout.h>
+#include <tqslider.h>
+#include <tqlabel.h>
+#include <tqpixmap.h>
+#include <tqpainter.h>
+#include <tdeglobal.h>
+#include <kstandarddirs.h>
+
+// ---- rotated label (same as PA widget) --------------------------------------
+
+class VerticalLabel : public TQWidget
+{
+public:
+ VerticalLabel( const TQString &text, TQWidget *parent )
+ : TQWidget(parent), m_text(text)
+ {
+ setMinimumSize( 20, 10 );
+ }
+ TQSize sizeHint() const { return TQSize( 20, 100 ); }
+ TQSizePolicy sizePolicy() const {
+ return TQSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Expanding );
+ }
+protected:
+ void paintEvent( TQPaintEvent * ) {
+ TQPainter p( this );
+ TQFontMetrics fm = p.fontMetrics();
+ int available = height() - 6;
+ TQString text = m_text;
+ if ( fm.width(text) > available ) {
+ while ( text.length() > 1 && fm.width(text) + fm.width("...") > available )
+ text.truncate( text.length() - 1 );
+ text += "...";
+ }
+ p.rotate( 270 );
+ p.translate( 0, -4 );
+ p.drawText( -height() + 2, width(), text );
+ }
+private:
+ TQString m_text;
+};
+
+// ---- widget -----------------------------------------------------------------
+
+static TQPixmap alsaPic( const char *name )
+{
+ TQString path = TDEGlobal::dirs()->findResource("data",
+ TQString("tmix/pics/") + name);
+ return path.isEmpty() ? TQPixmap() : TQPixmap(path);
+}
+
+static TQPixmap iconForDevice( AlsaDevice *dev )
+{
+ TQString n = dev->name().lower();
+
+ if ( n.contains("headphone") || n.contains("headset") )
+ return alsaPic("mix_headphone.png");
+ if ( n.contains("mic") )
+ return alsaPic("mix_microphone.png");
+ if ( n.contains("line") || n.contains("panel") )
+ return alsaPic("mix_ext.png");
+ if ( n.contains("capture") || n.contains("record") )
+ return alsaPic("mix_record.png");
+ if ( n.contains("surround") )
+ return alsaPic("mix_surround.png");
+ if ( n.contains("bass") || n.contains("lfe") )
+ return alsaPic("mix_bass.png");
+ if ( n.contains("cd") )
+ return alsaPic("mix_cd.png");
+ if ( n.contains("digital") || n.contains("iec") || n.contains("spdif") )
+ return alsaPic("mix_digital.png");
+ if ( n.contains("video") )
+ return alsaPic("mix_video.png");
+ if ( n.contains("midi") )
+ return alsaPic("mix_midi.png");
+ if ( n.contains("pcm") || n.contains("wave") )
+ return alsaPic("mix_audio.png");
+ if ( dev->category() == AlsaDevice::Input )
+ return alsaPic("mix_microphone.png");
+ return alsaPic("crystal/audio-volume-medium.png");
+}
+
+AlsaDeviceWidget::AlsaDeviceWidget( AlsaDevice *dev, TQWidget *parent )
+ : TQWidget(parent), m_dev(dev), m_balance(0)
+{
+ // outer centers everything horizontally
+ TQHBoxLayout *outer = new TQHBoxLayout(this, 4, 0);
+ outer->addStretch(1);
+
+ TQVBoxLayout *col = new TQVBoxLayout(0, 0, 2);
+
+ // top: icon + vol%
+ TQHBoxLayout *topRow = new TQHBoxLayout(0, 0, 2);
+ TQLabel *icon = new TQLabel(this);
+ TQPixmap px = iconForDevice(dev);
+ if ( !px.isNull() ) icon->setPixmap(px);
+ topRow->addWidget(icon, 0, TQt::AlignVCenter);
+ m_volLabel = new TQLabel(TQString("%1%").arg(dev->volume()), this);
+ topRow->addWidget(m_volLabel, 0, TQt::AlignVCenter);
+ col->addLayout(topRow);
+
+ // slider row: rotated label beside slider, so label bottom == slider bottom
+ TQHBoxLayout *sliderRow = new TQHBoxLayout(0, 0, 2);
+ VerticalLabel *vlabel = new VerticalLabel(dev->name(), this);
+ sliderRow->addWidget(vlabel);
+ m_slider = new TQSlider(0, 100, 5, 100 - dev->volume(), TQt::Vertical, this);
+ m_slider->setTickmarks( TQSlider::Right );
+ m_slider->setTickInterval( 5 );
+ m_slider->setMinimumHeight(80);
+ sliderRow->addWidget(m_slider, 1);
+ col->addLayout(sliderRow, 1);
+
+ // fixed bottom row: balance + mute
+ TQWidget *bottom = new TQWidget(this);
+ bottom->setFixedHeight(30);
+ TQHBoxLayout *bottomRow = new TQHBoxLayout(bottom, 0, 2);
+ bottomRow->addStretch(1);
+ if ( dev->stereo() ) {
+ m_balance = new BalanceKnob(-50, 50, dev->pan(), bottom);
+ bottomRow->addWidget(m_balance, 0, TQt::AlignVCenter);
+ bottomRow->addStretch(1);
+ connect(m_balance, TQ_SIGNAL(valueChanged(int)), this, TQ_SLOT(onPanMoved(int)));
+ }
+ m_muteBtn = new KLedButton(TQt::green,
+ dev->muted() ? KLed::Off : KLed::On,
+ KLed::Raised, KLed::Circular, bottom);
+ m_muteBtn->setFixedSize(16, 16);
+ m_muteBtn->setEnabled(dev->hasMute());
+ bottomRow->addWidget(m_muteBtn, 0, TQt::AlignVCenter);
+ bottomRow->addStretch(1);
+ col->addWidget(bottom, 0);
+
+ outer->addLayout(col);
+ outer->addStretch(1);
+
+ connect(dev, TQ_SIGNAL(volumeChanged(int)), this, TQ_SLOT(onVolumeChanged(int)));
+ connect(dev, TQ_SIGNAL(muteChanged(bool)), this, TQ_SLOT(onMuteChanged(bool)));
+ connect(dev, TQ_SIGNAL(panChanged(int)), this, TQ_SLOT(onPanChanged(int)));
+ connect(m_slider, TQ_SIGNAL(valueChanged(int)), this, TQ_SLOT(onSliderMoved(int)));
+ connect(m_muteBtn, TQ_SIGNAL(stateChanged(bool)), this, TQ_SLOT(onMuteToggled(bool)));
+}
+
+void AlsaDeviceWidget::onVolumeChanged( int v )
+{
+ m_slider->blockSignals(true);
+ m_slider->setValue(100 - v);
+ m_slider->blockSignals(false);
+ m_volLabel->setText(TQString("%1%").arg(v));
+}
+
+void AlsaDeviceWidget::onMuteChanged( bool m )
+{
+ m_muteBtn->blockSignals(true);
+ m_muteBtn->setState(m ? KLed::Off : KLed::On);
+ m_muteBtn->blockSignals(false);
+}
+
+void AlsaDeviceWidget::onPanChanged( int p )
+{
+ if ( m_balance ) {
+ m_balance->blockSignals(true);
+ m_balance->setValue(p);
+ m_balance->blockSignals(false);
+ }
+}
+
+void AlsaDeviceWidget::onSliderMoved( int v ) { m_dev->setVolume(100 - v); }
+void AlsaDeviceWidget::onMuteToggled( bool on ) { m_dev->setMuted(!on); }
+void AlsaDeviceWidget::onPanMoved( int p ) { m_dev->setPan(p); }
+
+#include "alsadevicewidget.moc"
diff --git a/src/ui/alsa/alsadevicewidget.h b/src/ui/alsa/alsadevicewidget.h
new file mode 100644
index 0000000..aa4d63e
--- /dev/null
+++ b/src/ui/alsa/alsadevicewidget.h
@@ -0,0 +1,31 @@
+#pragma once
+
+#include <tqwidget.h>
+
+class AlsaDevice;
+class TQSlider;
+class TQLabel;
+class KLedButton;
+class BalanceKnob;
+
+class AlsaDeviceWidget : public TQWidget
+{
+ TQ_OBJECT
+public:
+ AlsaDeviceWidget( AlsaDevice *dev, TQWidget *parent = 0 );
+
+private slots:
+ void onVolumeChanged( int v );
+ void onMuteChanged( bool m );
+ void onPanChanged( int p );
+ void onSliderMoved( int v );
+ void onMuteToggled( bool on );
+ void onPanMoved( int p );
+
+private:
+ AlsaDevice *m_dev;
+ TQSlider *m_slider;
+ TQLabel *m_volLabel;
+ KLedButton *m_muteBtn;
+ BalanceKnob *m_balance;
+};
diff --git a/src/ui/alsa/alsamixerwindow.cpp b/src/ui/alsa/alsamixerwindow.cpp
new file mode 100644
index 0000000..6c14ce4
--- /dev/null
+++ b/src/ui/alsa/alsamixerwindow.cpp
@@ -0,0 +1,206 @@
+#include "alsamixerwindow.h"
+#include "alsadevicewidget.h"
+#include "alsadevicespage.h"
+#include "alsatray.h"
+#include "../preferencesdlg.h"
+#include "../../model/alsamodel.h"
+#include "../../model/alsadevice.h"
+
+#include <tqlayout.h>
+#include <tqcombobox.h>
+#include <tqtabwidget.h>
+#include <tqlabel.h>
+#include <tqhbox.h>
+#include <tdeapplication.h>
+#include <tdelocale.h>
+#include <tdemenubar.h>
+#include <tdepopupmenu.h>
+#include <tdeaboutapplication.h>
+#include <tdeaboutdata.h>
+#include <kiconloader.h>
+#include <tdeconfig.h>
+#include <tdeglobal.h>
+#include <twin.h>
+
+AlsaMixerWindow::AlsaMixerWindow( AlsaModel *model, TQWidget *parent )
+ : TDEMainWindow(parent, "AlsaMixerWindow"),
+ m_model(model), m_tray(0), m_posRestored(false), m_devicesPage(0)
+{
+ m_widgets.setAutoDelete(true);
+ setCaption( i18n("Volume Control") );
+
+ TQWidget *central = new TQWidget(this);
+ setCentralWidget(central);
+ TQVBoxLayout *vbox = new TQVBoxLayout(central, 8, 6);
+
+ // card selector row — right aligned
+ TQHBoxLayout *topRow = new TQHBoxLayout(0, 0, 6);
+ topRow->addStretch();
+ topRow->addWidget( new TQLabel(i18n("Card:"), central) );
+ m_cardCombo = new TQComboBox(false, central);
+ TQValueList<AlsaCard> cards = model->cards();
+ for ( TQValueListConstIterator<AlsaCard> it = cards.begin(); it != cards.end(); ++it )
+ m_cardCombo->insertItem( (*it).name );
+ topRow->addWidget(m_cardCombo);
+ vbox->addLayout(topRow);
+
+ // tabs
+ m_tabs = new TQTabWidget(central);
+
+ m_outputPage = new TQWidget(m_tabs);
+ m_outputLayout = new TQHBoxLayout(m_outputPage, 8, 6);
+ m_tabs->addTab(m_outputPage, i18n("Output"));
+
+ m_inputPage = new TQWidget(m_tabs);
+ m_inputLayout = new TQHBoxLayout(m_inputPage, 8, 6);
+ m_tabs->addTab(m_inputPage, i18n("Input"));
+
+ m_devicesPage = new AlsaDevicesPage(model, m_tabs);
+ m_tabs->addTab(m_devicesPage, i18n("Device Settings"));
+
+ vbox->addWidget(m_tabs, 1);
+
+ if ( !cards.isEmpty() )
+ rebuildTabs( cards.front().index );
+
+ setMinimumSize( 400, 250 );
+
+ TDEConfig *gcfg = TDEGlobal::config();
+ gcfg->setGroup("AlsaMainWindow");
+ if ( gcfg->hasKey("Width") )
+ applyMainWindowSettings( gcfg, "AlsaMainWindow" );
+ else
+ resize( 650, 380 );
+
+ connect(m_cardCombo, TQ_SIGNAL(activated(int)), this, TQ_SLOT(onCardChanged(int)));
+ connect(model, TQ_SIGNAL(deviceAdded(AlsaDevice*)), this, TQ_SLOT(onDeviceAdded(AlsaDevice*)));
+
+ TDEPopupMenu *fileMenu = new TDEPopupMenu(this);
+ fileMenu->insertItem( SmallIcon("application-exit"), i18n("&Quit"),
+ this, TQ_SLOT(quit()) );
+
+ TDEPopupMenu *settingsMenu = new TDEPopupMenu(this);
+ settingsMenu->insertItem( SmallIcon("configure"), i18n("&Configure..."),
+ this, TQ_SLOT(showPreferences()) );
+
+ TDEPopupMenu *helpMenu = new TDEPopupMenu(this);
+ helpMenu->insertItem( SmallIcon("help"), i18n("&About TMix"),
+ this, TQ_SLOT(showAbout()) );
+
+ menuBar()->insertItem( i18n("&File"), fileMenu );
+ menuBar()->insertItem( i18n("&Settings"), settingsMenu );
+ menuBar()->insertItem( i18n("&Help"), helpMenu );
+}
+
+void AlsaMixerWindow::rebuildTabs( int cardIndex )
+{
+ m_widgets.clear();
+
+ delete m_outputPage->layout();
+ m_outputLayout = new TQHBoxLayout(m_outputPage, 8, 6);
+
+ delete m_inputPage->layout();
+ m_inputLayout = new TQHBoxLayout(m_inputPage, 8, 6);
+
+ TQPtrList<AlsaDevice> devs = m_model->devicesForCard(cardIndex);
+ bool hasOutput = false, hasInput = false;
+ for ( TQPtrListIterator<AlsaDevice> it(devs); *it; ++it ) {
+ AlsaDevice *dev = *it;
+ if ( dev->type() != AlsaDevice::Slider ) continue;
+
+ AlsaDeviceWidget *w = new AlsaDeviceWidget(dev,
+ dev->category() == AlsaDevice::Output ? m_outputPage : m_inputPage);
+ if ( dev->category() == AlsaDevice::Output ) {
+ m_outputLayout->addWidget(w);
+ hasOutput = true;
+ } else {
+ m_inputLayout->addWidget(w);
+ hasInput = true;
+ }
+ w->show();
+ m_widgets.append(w);
+ }
+
+ if ( !hasOutput ) m_outputLayout->addWidget( new TQLabel(i18n("No output controls."), m_outputPage) );
+ if ( !hasInput ) m_inputLayout->addWidget( new TQLabel(i18n("No input controls."), m_inputPage) );
+
+ m_outputLayout->addStretch();
+ m_inputLayout->addStretch();
+
+ if ( m_devicesPage )
+ m_devicesPage->setCard(cardIndex);
+}
+
+void AlsaMixerWindow::onCardChanged( int idx )
+{
+ TQValueList<AlsaCard> cards = m_model->cards();
+ if ( idx < 0 || idx >= (int)cards.count() ) return;
+ TQValueListConstIterator<AlsaCard> it = cards.begin();
+ for ( int i = 0; i < idx; ++i ) ++it;
+ rebuildTabs( (*it).index );
+}
+
+void AlsaMixerWindow::onDeviceAdded( AlsaDevice * )
+{
+ m_cardCombo->clear();
+ TQValueList<AlsaCard> cards = m_model->cards();
+ for ( TQValueListConstIterator<AlsaCard> it = cards.begin(); it != cards.end(); ++it )
+ m_cardCombo->insertItem( (*it).name );
+ onCardChanged( m_cardCombo->currentItem() );
+}
+
+void AlsaMixerWindow::bringToFront()
+{
+ show();
+ KWin::forceActiveWindow( winId() );
+}
+
+void AlsaMixerWindow::showEvent( TQShowEvent *e )
+{
+ TDEMainWindow::showEvent(e);
+ if ( !m_posRestored ) {
+ m_posRestored = true;
+ TDEConfig *cfg = TDEGlobal::config();
+ cfg->setGroup("AlsaMainWindow");
+ int xp = cfg->readNumEntry("XPos", -1);
+ int yp = cfg->readNumEntry("YPos", -1);
+ if ( xp >= 0 && yp >= 0 )
+ move( xp, yp );
+ }
+}
+
+bool AlsaMixerWindow::queryClose()
+{
+ saveMainWindowSettings( TDEGlobal::config(), "AlsaMainWindow" );
+ TDEConfig *cfg = TDEGlobal::config();
+ cfg->setGroup("AlsaMainWindow");
+ cfg->writeEntry("XPos", x());
+ cfg->writeEntry("YPos", y());
+ cfg->sync();
+
+ if ( m_tray ) { hide(); return false; }
+ // Not in systray — closing the window means quit.
+ quit();
+ return false;
+}
+
+void AlsaMixerWindow::quit()
+{
+ m_tray = 0;
+ kapp->quit();
+}
+
+void AlsaMixerWindow::showPreferences()
+{
+ PreferencesDlg dlg( m_model, this );
+ dlg.exec();
+ emit settingsChanged();
+}
+
+void AlsaMixerWindow::showAbout()
+{
+ TDEAboutApplication dlg(this);
+ dlg.exec();
+}
+
+#include "alsamixerwindow.moc"
diff --git a/src/ui/alsa/alsamixerwindow.h b/src/ui/alsa/alsamixerwindow.h
new file mode 100644
index 0000000..8d8ef4f
--- /dev/null
+++ b/src/ui/alsa/alsamixerwindow.h
@@ -0,0 +1,55 @@
+#pragma once
+
+#include <tdemainwindow.h>
+#include <tqptrlist.h>
+
+class AlsaModel;
+class AlsaDevice;
+class AlsaDevicesPage;
+#include "alsadevicewidget.h"
+class AlsaTray;
+class TQComboBox;
+class TQTabWidget;
+class TQHBoxLayout;
+class TQWidget;
+
+class AlsaMixerWindow : public TDEMainWindow
+{
+ TQ_OBJECT
+public:
+ explicit AlsaMixerWindow( AlsaModel *model, TQWidget *parent = 0 );
+
+ void setTray( AlsaTray *tray ) { m_tray = tray; }
+
+signals:
+ void settingsChanged();
+
+public slots:
+ void bringToFront();
+ void quit();
+
+protected:
+ bool queryClose();
+ void showEvent( TQShowEvent *e );
+
+private slots:
+ void onCardChanged( int idx );
+ void onDeviceAdded( AlsaDevice *dev );
+ void showPreferences();
+ void showAbout();
+
+private:
+ void rebuildTabs( int cardIndex );
+
+ AlsaModel *m_model;
+ AlsaTray *m_tray;
+ bool m_posRestored;
+ TQComboBox *m_cardCombo;
+ TQTabWidget *m_tabs;
+ TQWidget *m_outputPage;
+ TQWidget *m_inputPage;
+ TQHBoxLayout *m_outputLayout;
+ TQHBoxLayout *m_inputLayout;
+ TQPtrList<AlsaDeviceWidget> m_widgets;
+ AlsaDevicesPage *m_devicesPage;
+};
diff --git a/src/ui/alsa/alsapopup.cpp b/src/ui/alsa/alsapopup.cpp
new file mode 100644
index 0000000..0a6269d
--- /dev/null
+++ b/src/ui/alsa/alsapopup.cpp
@@ -0,0 +1,79 @@
+#include "alsapopup.h"
+#include "alsadevicewidget.h"
+#include "../../model/alsamodel.h"
+#include "../../model/alsadevice.h"
+
+#include <tqlayout.h>
+#include <tqlabel.h>
+#include <tqapplication.h>
+#include <tqdesktopwidget.h>
+#include <twin.h>
+#include <tdelocale.h>
+
+AlsaPopup::AlsaPopup( AlsaModel *model, TQWidget *parent )
+ : TQWidget( parent, "AlsaPopup",
+ WStyle_Customize | WType_Popup | WStyle_DialogBorder ),
+ m_model(model), m_container(0), m_widget(0)
+{
+ TQVBoxLayout *outer = new TQVBoxLayout( this, 4, 0 );
+ m_container = new TQWidget( this );
+ outer->addWidget( m_container );
+
+ connect( model, TQ_SIGNAL(deviceAdded(AlsaDevice*)), this, TQ_SLOT(rebuild()) );
+ connect( model, TQ_SIGNAL(preferredOutputChanged(AlsaDevice*)), this, TQ_SLOT(rebuild()) );
+
+ rebuild();
+}
+
+void AlsaPopup::rebuild()
+{
+ delete m_container->layout();
+ if ( m_widget ) { delete m_widget; m_widget = 0; }
+
+ TQVBoxLayout *vbox = new TQVBoxLayout( m_container, 4, 0 );
+ AlsaDevice *dev = m_model->preferredOutput();
+ if ( dev ) {
+ m_widget = new AlsaDeviceWidget( dev, m_container );
+ vbox->addWidget( m_widget );
+ m_widget->show();
+ } else {
+ vbox->addWidget( new TQLabel( i18n("No output device."), m_container ) );
+ }
+
+ if ( isVisible() )
+ adjustSize();
+}
+
+void AlsaPopup::toggleAt( const TQPoint &trayPos, const TQSize &traySize )
+{
+ if ( isVisible() ) { hide(); return; }
+
+ rebuild();
+ adjustSize();
+
+ TQRect screen = TQApplication::desktop()->screenGeometry( trayPos );
+ int x = trayPos.x() + traySize.width() / 2 - width() / 2;
+ int y = trayPos.y() - height();
+ if ( y < screen.top() ) y = trayPos.y() + traySize.height();
+ if ( x + width() > screen.right() ) x = screen.right() - width();
+ if ( x < screen.left() ) x = screen.left();
+
+ move( x, y );
+ show();
+
+ KWin::setState( winId(), NET::KeepAbove | NET::SkipTaskbar | NET::SkipPager );
+ KWin::setOnAllDesktops( winId(), true );
+}
+
+bool AlsaPopup::justHidden() const
+{
+ return m_hideTime.isValid() && m_hideTime.elapsed() < 100;
+}
+
+void AlsaPopup::hideEvent( TQHideEvent *e )
+{
+ TQWidget::hideEvent( e );
+ m_hideTime.start();
+}
+
+#include "alsapopup.moc"
diff --git a/src/ui/alsa/alsapopup.h b/src/ui/alsa/alsapopup.h
new file mode 100644
index 0000000..94b1800
--- /dev/null
+++ b/src/ui/alsa/alsapopup.h
@@ -0,0 +1,30 @@
+#pragma once
+
+#include <tqwidget.h>
+#include <tqdatetime.h>
+
+class AlsaModel;
+class AlsaDevice;
+class AlsaDeviceWidget;
+
+class AlsaPopup : public TQWidget
+{
+ TQ_OBJECT
+public:
+ explicit AlsaPopup( AlsaModel *model, TQWidget *parent = 0 );
+
+ void toggleAt( const TQPoint &trayPos, const TQSize &traySize );
+ bool justHidden() const;
+
+protected:
+ void hideEvent( TQHideEvent *e );
+
+private slots:
+ void rebuild();
+
+private:
+ AlsaModel *m_model;
+ TQWidget *m_container;
+ AlsaDeviceWidget *m_widget;
+ TQTime m_hideTime;
+};
diff --git a/src/ui/alsa/alsatray.cpp b/src/ui/alsa/alsatray.cpp
new file mode 100644
index 0000000..46ff59f
--- /dev/null
+++ b/src/ui/alsa/alsatray.cpp
@@ -0,0 +1,131 @@
+#include "alsatray.h"
+#include "alsapopup.h"
+#include "alsamixerwindow.h"
+#include "../../model/alsamodel.h"
+#include "../../model/alsadevice.h"
+
+#include <tqevent.h>
+#include <tdeglobal.h>
+#include <kiconloader.h>
+#include <kstandarddirs.h>
+#include <tdelocale.h>
+#include <tdeconfig.h>
+#include <tdepopupmenu.h>
+#include <twin.h>
+
+AlsaTray::AlsaTray( AlsaModel *model, AlsaMixerWindow *win, TQWidget *parent )
+ : KSystemTray(parent), m_model(model), m_win(win),
+ m_output(model->preferredOutput()), m_popup(0)
+{
+ setCaption( i18n("Volume Control") );
+
+ connect(model, TQ_SIGNAL(deviceAdded(AlsaDevice*)), this, TQ_SLOT(updateIcon()));
+ connect(model, TQ_SIGNAL(preferredOutputChanged(AlsaDevice*)), this, TQ_SLOT(onPreferredChanged(AlsaDevice*)));
+
+ if ( m_output ) {
+ connect(m_output, TQ_SIGNAL(volumeChanged(int)), this, TQ_SLOT(updateIcon()));
+ connect(m_output, TQ_SIGNAL(muteChanged(bool)), this, TQ_SLOT(updateIcon()));
+ }
+
+ updateIcon();
+}
+
+void AlsaTray::onPreferredChanged( AlsaDevice *dev )
+{
+ if ( m_output ) {
+ disconnect(m_output, TQ_SIGNAL(volumeChanged(int)), this, TQ_SLOT(updateIcon()));
+ disconnect(m_output, TQ_SIGNAL(muteChanged(bool)), this, TQ_SLOT(updateIcon()));
+ }
+ m_output = dev;
+ if ( m_output ) {
+ connect(m_output, TQ_SIGNAL(volumeChanged(int)), this, TQ_SLOT(updateIcon()));
+ connect(m_output, TQ_SIGNAL(muteChanged(bool)), this, TQ_SLOT(updateIcon()));
+ }
+ updateIcon();
+}
+
+void AlsaTray::updateIcon()
+{
+ if ( !m_output )
+ m_output = m_model->preferredOutput();
+
+ int vol = m_output ? m_output->volume() : 0;
+ bool mute = m_output ? m_output->muted() : true;
+
+ const char *pic;
+ if ( mute || vol == 0 ) pic = "audio-volume-muted.png";
+ else if ( vol < 34 ) pic = "audio-volume-low.png";
+ else if ( vol < 67 ) pic = "audio-volume-medium.png";
+ else pic = "audio-volume-high.png";
+
+ TQString path = TDEGlobal::dirs()->findResource("data",
+ TQString("tmix/pics/crystal/") + pic);
+ if ( !path.isEmpty() )
+ setPixmap( TQPixmap(path) );
+}
+
+void AlsaTray::mousePressEvent( TQMouseEvent *e )
+{
+ if ( e->button() == TQt::LeftButton ) {
+ TDEConfig *cfg = TDEGlobal::config();
+ cfg->setGroup("Tray");
+ int mode = cfg->readNumEntry("PopupMode", 1);
+ if ( mode == 1 ) {
+ if ( !m_popup )
+ m_popup = new AlsaPopup( m_model, this );
+ if ( m_popup->justHidden() ) return;
+ m_popup->toggleAt( mapToGlobal( TQPoint(0,0) ), size() );
+ } else {
+ m_win->bringToFront();
+ }
+ e->accept();
+ return;
+ }
+ if ( e->button() == TQt::MidButton ) {
+ middleClickMute();
+ e->accept();
+ return;
+ }
+ KSystemTray::mousePressEvent(e);
+}
+
+void AlsaTray::middleClickMute()
+{
+ if ( !m_output ) return;
+ TDEConfig *cfg = TDEGlobal::config();
+ cfg->setGroup("Tray");
+ if ( cfg->readBoolEntry("MiddleClickMute", false) )
+ m_output->setMuted( !m_output->muted() );
+}
+
+void AlsaTray::wheelEvent( TQWheelEvent *e )
+{
+ if ( !m_output ) return;
+ TDEConfig *cfg = TDEGlobal::config();
+ cfg->setGroup("Tray");
+ int step = cfg->readNumEntry("ScrollStep", 5);
+ int delta = e->delta() > 0 ? step : -step;
+ int vol = m_output->volume() + delta;
+ if ( vol < 0 ) vol = 0;
+ if ( vol > 100 ) vol = 100;
+ m_output->setVolume(vol);
+}
+
+void AlsaTray::contextMenuAboutToShow( TDEPopupMenu *menu )
+{
+ while ( menu->count() > 1 )
+ menu->removeItemAt(1);
+
+ menu->insertItem( SmallIcon("tmix"), i18n("&Open Mixer"),
+ m_win, TQ_SLOT(bringToFront()) );
+ menu->insertSeparator();
+ menu->insertItem( SmallIcon("configure"), i18n("&Configure TMix..."),
+ m_win, TQ_SLOT(showPreferences()) );
+ menu->insertItem( SmallIcon("help"), i18n("&About TMix"),
+ m_win, TQ_SLOT(showAbout()) );
+ menu->insertSeparator();
+ menu->insertItem( SmallIcon("application-exit"), i18n("&Quit"),
+ m_win, TQ_SLOT(quit()) );
+}
+
+#include "alsatray.moc"
diff --git a/src/ui/alsa/alsatray.h b/src/ui/alsa/alsatray.h
new file mode 100644
index 0000000..8f518fa
--- /dev/null
+++ b/src/ui/alsa/alsatray.h
@@ -0,0 +1,35 @@
+#pragma once
+
+#include <ksystemtray.h>
+
+class AlsaModel;
+class AlsaDevice;
+class AlsaMixerWindow;
+class AlsaPopup;
+
+class AlsaTray : public KSystemTray
+{
+ TQ_OBJECT
+public:
+ AlsaTray( AlsaModel *model, AlsaMixerWindow *win, TQWidget *parent = 0 );
+
+public slots:
+ void updateIcon();
+
+protected:
+ void mousePressEvent( TQMouseEvent *e );
+ void wheelEvent( TQWheelEvent *e );
+ void contextMenuAboutToShow( TDEPopupMenu *menu );
+
+private slots:
+ void onPreferredChanged( AlsaDevice *dev );
+
+private:
+ void middleClickMute();
+
+private:
+ AlsaModel *m_model;
+ AlsaMixerWindow *m_win;
+ AlsaDevice *m_output;
+ AlsaPopup *m_popup;
+};