From 65c7ea9fbf4886fa3d6127c5fa699520f30f386c Mon Sep 17 00:00:00 2001 From: Calvin Morrison Date: Mon, 18 May 2026 00:00:17 -0400 Subject: OSS backend for FreeBSD support Adds a complete OSS audio backend alongside PulseAudio and ALSA: - OssDevice/OssModel: enumerate /dev/mixer*, poll for changes at 500ms - Full UI layer: mixer window, system tray, mini popup, per-channel widgets - Fake mute (saves/restores volume since OSS has no mute bit) - BackendController and PreferencesDlg updated; backend combo now uses m_backendIds list so any combination of compiled-in backends works Co-Authored-By: Claude Sonnet 4.6 --- src/ui/oss/ossmixerwindow.cpp | 192 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 192 insertions(+) create mode 100644 src/ui/oss/ossmixerwindow.cpp (limited to 'src/ui/oss/ossmixerwindow.cpp') diff --git a/src/ui/oss/ossmixerwindow.cpp b/src/ui/oss/ossmixerwindow.cpp new file mode 100644 index 0000000..04c2fc6 --- /dev/null +++ b/src/ui/oss/ossmixerwindow.cpp @@ -0,0 +1,192 @@ +#include "ossmixerwindow.h" +#include "ossdevicewidget.h" +#include "osstray.h" +#include "../preferencesdlg.h" +#include "../../model/ossmodel.h" +#include "../../model/ossdevice.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +OssMixerWindow::OssMixerWindow( OssModel *model, TQWidget *parent ) + : TDEMainWindow(parent, "OssMixerWindow"), + m_model(model), m_tray(0), m_posRestored(false) +{ + m_widgets.setAutoDelete(true); + setCaption(i18n("Volume Control")); + + TQWidget *central = new TQWidget(this); + setCentralWidget(central); + TQVBoxLayout *vbox = new TQVBoxLayout(central, 8, 6); + + TQHBoxLayout *topRow = new TQHBoxLayout(0, 0, 6); + topRow->addStretch(); + topRow->addWidget(new TQLabel(i18n("Card:"), central)); + m_cardCombo = new TQComboBox(false, central); + TQValueList cards = model->cards(); + for ( TQValueListConstIterator it = cards.begin(); it != cards.end(); ++it ) + m_cardCombo->insertItem((*it).name); + topRow->addWidget(m_cardCombo); + vbox->addLayout(topRow); + + 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")); + + vbox->addWidget(m_tabs, 1); + + if ( !cards.isEmpty() ) + rebuildTabs(cards.front().index); + + setMinimumSize(400, 250); + + TDEConfig *gcfg = TDEGlobal::config(); + gcfg->setGroup("OssMainWindow"); + if ( gcfg->hasKey("Width") ) + applyMainWindowSettings(gcfg, "OssMainWindow"); + else + resize(550, 320); + + connect(m_cardCombo, TQ_SIGNAL(activated(int)), this, TQ_SLOT(onCardChanged(int))); + connect(model, TQ_SIGNAL(deviceAdded(OssDevice*)), this, TQ_SLOT(onDeviceAdded(OssDevice*))); + + 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 OssMixerWindow::rebuildTabs( int cardIdx ) +{ + 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 devs = m_model->devicesForCard(cardIdx); + bool hasOutput = false, hasInput = false; + for ( TQPtrListIterator it(devs); *it; ++it ) { + OssDevice *dev = *it; + OssDeviceWidget *w = new OssDeviceWidget(dev, + dev->category() == OssDevice::Output ? m_outputPage : m_inputPage); + if ( dev->category() == OssDevice::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(); +} + +void OssMixerWindow::onCardChanged( int idx ) +{ + TQValueList cards = m_model->cards(); + if ( idx < 0 || idx >= (int)cards.count() ) return; + TQValueListConstIterator it = cards.begin(); + for ( int i = 0; i < idx; ++i ) ++it; + rebuildTabs((*it).index); +} + +void OssMixerWindow::onDeviceAdded( OssDevice * ) +{ + m_cardCombo->clear(); + TQValueList cards = m_model->cards(); + for ( TQValueListConstIterator it = cards.begin(); it != cards.end(); ++it ) + m_cardCombo->insertItem((*it).name); + onCardChanged(m_cardCombo->currentItem()); +} + +void OssMixerWindow::bringToFront() +{ + show(); + KWin::forceActiveWindow(winId()); +} + +void OssMixerWindow::showEvent( TQShowEvent *e ) +{ + TDEMainWindow::showEvent(e); + if ( !m_posRestored ) { + m_posRestored = true; + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("OssMainWindow"); + int xp = cfg->readNumEntry("XPos", -1); + int yp = cfg->readNumEntry("YPos", -1); + if ( xp >= 0 && yp >= 0 ) move(xp, yp); + } +} + +bool OssMixerWindow::queryClose() +{ + saveMainWindowSettings(TDEGlobal::config(), "OssMainWindow"); + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("OssMainWindow"); + cfg->writeEntry("XPos", x()); + cfg->writeEntry("YPos", y()); + cfg->sync(); + + if ( m_tray ) { hide(); return false; } + quit(); + return false; +} + +void OssMixerWindow::quit() +{ + m_tray = 0; + kapp->quit(); +} + +void OssMixerWindow::showPreferences() +{ + PreferencesDlg dlg(m_model, this); + dlg.exec(); + emit settingsChanged(); +} + +void OssMixerWindow::showAbout() +{ + TDEAboutApplication dlg(this); + dlg.exec(); +} + +#include "ossmixerwindow.moc" -- cgit v1.2.3