summaryrefslogtreecommitdiff
path: root/src/ui/oss
diff options
context:
space:
mode:
authorCalvin Morrison <calvin@pobox.com>2026-05-18 00:00:17 -0400
committerCalvin Morrison <calvin@pobox.com>2026-05-18 00:00:17 -0400
commit65c7ea9fbf4886fa3d6127c5fa699520f30f386c (patch)
treebca364e1c1f0244d477349345ec7dd531b8032f8 /src/ui/oss
parent3909a06fe6786027c83e3adaef89c343cde4fbe3 (diff)
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 <noreply@anthropic.com>
Diffstat (limited to 'src/ui/oss')
-rw-r--r--src/ui/oss/ossdevicewidget.cpp154
-rw-r--r--src/ui/oss/ossdevicewidget.h31
-rw-r--r--src/ui/oss/ossmixerwindow.cpp192
-rw-r--r--src/ui/oss/ossmixerwindow.h53
-rw-r--r--src/ui/oss/osspopup.cpp78
-rw-r--r--src/ui/oss/osspopup.h30
-rw-r--r--src/ui/oss/osstray.cpp129
-rw-r--r--src/ui/oss/osstray.h34
8 files changed, 701 insertions, 0 deletions
diff --git a/src/ui/oss/ossdevicewidget.cpp b/src/ui/oss/ossdevicewidget.cpp
new file mode 100644
index 0000000..03fd91b
--- /dev/null
+++ b/src/ui/oss/ossdevicewidget.cpp
@@ -0,0 +1,154 @@
+#include "ossdevicewidget.h"
+#include "../../model/ossdevice.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>
+
+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;
+};
+
+static TQPixmap ossPic( const char *name )
+{
+ TQString path = TDEGlobal::dirs()->findResource("data",
+ TQString("tmix/pics/") + name);
+ return path.isEmpty() ? TQPixmap() : TQPixmap(path);
+}
+
+static TQPixmap iconForDevice( OssDevice *dev )
+{
+ TQString n = dev->name().lower();
+ if ( n == "vol" || n.contains("master") )
+ return ossPic("crystal/audio-volume-medium.png");
+ if ( n.contains("headphone") || n.contains("headset") )
+ return ossPic("mix_headphone.png");
+ if ( n.contains("mic") )
+ return ossPic("mix_microphone.png");
+ if ( n.contains("line") )
+ return ossPic("mix_ext.png");
+ if ( n.contains("cd") )
+ return ossPic("mix_cd.png");
+ if ( n.contains("dig") || n.contains("spdif") || n.contains("iec") )
+ return ossPic("mix_digital.png");
+ if ( n.contains("pcm") || n.contains("wave") )
+ return ossPic("mix_audio.png");
+ if ( dev->category() == OssDevice::Input )
+ return ossPic("mix_microphone.png");
+ return ossPic("crystal/audio-volume-medium.png");
+}
+
+OssDeviceWidget::OssDeviceWidget( OssDevice *dev, TQWidget *parent )
+ : TQWidget(parent), m_dev(dev), m_balance(0)
+{
+ TQHBoxLayout *outer = new TQHBoxLayout(this, 4, 0);
+ outer->addStretch(1);
+
+ TQVBoxLayout *col = new TQVBoxLayout(0, 0, 2);
+
+ 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);
+
+ 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);
+
+ 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);
+ 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 OssDeviceWidget::onVolumeChanged( int v )
+{
+ m_slider->blockSignals(true);
+ m_slider->setValue(100 - v);
+ m_slider->blockSignals(false);
+ m_volLabel->setText(TQString("%1%").arg(v));
+}
+
+void OssDeviceWidget::onMuteChanged( bool m )
+{
+ m_muteBtn->blockSignals(true);
+ m_muteBtn->setState(m ? KLed::Off : KLed::On);
+ m_muteBtn->blockSignals(false);
+}
+
+void OssDeviceWidget::onPanChanged( int p )
+{
+ if ( m_balance ) {
+ m_balance->blockSignals(true);
+ m_balance->setValue(p);
+ m_balance->blockSignals(false);
+ }
+}
+
+void OssDeviceWidget::onSliderMoved( int v ) { m_dev->setVolume(100 - v); }
+void OssDeviceWidget::onMuteToggled( bool on ) { m_dev->setMuted(!on); }
+void OssDeviceWidget::onPanMoved( int p ) { m_dev->setPan(p); }
+
+#include "ossdevicewidget.moc"
diff --git a/src/ui/oss/ossdevicewidget.h b/src/ui/oss/ossdevicewidget.h
new file mode 100644
index 0000000..8a136cf
--- /dev/null
+++ b/src/ui/oss/ossdevicewidget.h
@@ -0,0 +1,31 @@
+#pragma once
+
+#include <tqwidget.h>
+
+class OssDevice;
+class TQSlider;
+class TQLabel;
+class KLedButton;
+class BalanceKnob;
+
+class OssDeviceWidget : public TQWidget
+{
+ TQ_OBJECT
+public:
+ OssDeviceWidget( OssDevice *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:
+ OssDevice *m_dev;
+ TQSlider *m_slider;
+ TQLabel *m_volLabel;
+ KLedButton *m_muteBtn;
+ BalanceKnob *m_balance;
+};
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 <tqlayout.h>
+#include <tqcombobox.h>
+#include <tqtabwidget.h>
+#include <tqlabel.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>
+
+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<OssCard> cards = model->cards();
+ for ( TQValueListConstIterator<OssCard> 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<OssDevice> devs = m_model->devicesForCard(cardIdx);
+ bool hasOutput = false, hasInput = false;
+ for ( TQPtrListIterator<OssDevice> 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<OssCard> cards = m_model->cards();
+ if ( idx < 0 || idx >= (int)cards.count() ) return;
+ TQValueListConstIterator<OssCard> it = cards.begin();
+ for ( int i = 0; i < idx; ++i ) ++it;
+ rebuildTabs((*it).index);
+}
+
+void OssMixerWindow::onDeviceAdded( OssDevice * )
+{
+ m_cardCombo->clear();
+ TQValueList<OssCard> cards = m_model->cards();
+ for ( TQValueListConstIterator<OssCard> 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"
diff --git a/src/ui/oss/ossmixerwindow.h b/src/ui/oss/ossmixerwindow.h
new file mode 100644
index 0000000..220c0cd
--- /dev/null
+++ b/src/ui/oss/ossmixerwindow.h
@@ -0,0 +1,53 @@
+#pragma once
+
+#include <tdemainwindow.h>
+#include <tqptrlist.h>
+#include "ossdevicewidget.h"
+
+class OssModel;
+class OssDevice;
+class OssTray;
+class TQComboBox;
+class TQTabWidget;
+class TQHBoxLayout;
+class TQWidget;
+
+class OssMixerWindow : public TDEMainWindow
+{
+ TQ_OBJECT
+public:
+ explicit OssMixerWindow( OssModel *model, TQWidget *parent = 0 );
+
+ void setTray( OssTray *tray ) { m_tray = tray; }
+
+signals:
+ void settingsChanged();
+
+public slots:
+ void bringToFront();
+ void quit();
+ void showPreferences();
+ void showAbout();
+
+protected:
+ bool queryClose();
+ void showEvent( TQShowEvent *e );
+
+private slots:
+ void onCardChanged( int idx );
+ void onDeviceAdded( OssDevice *dev );
+
+private:
+ void rebuildTabs( int cardIdx );
+
+ OssModel *m_model;
+ OssTray *m_tray;
+ bool m_posRestored;
+ TQComboBox *m_cardCombo;
+ TQTabWidget *m_tabs;
+ TQWidget *m_outputPage;
+ TQWidget *m_inputPage;
+ TQHBoxLayout *m_outputLayout;
+ TQHBoxLayout *m_inputLayout;
+ TQPtrList<OssDeviceWidget> m_widgets;
+};
diff --git a/src/ui/oss/osspopup.cpp b/src/ui/oss/osspopup.cpp
new file mode 100644
index 0000000..39279b5
--- /dev/null
+++ b/src/ui/oss/osspopup.cpp
@@ -0,0 +1,78 @@
+#include "osspopup.h"
+#include "ossdevicewidget.h"
+#include "../../model/ossmodel.h"
+#include "../../model/ossdevice.h"
+
+#include <tqlayout.h>
+#include <tqlabel.h>
+#include <tqapplication.h>
+#include <tqdesktopwidget.h>
+#include <twin.h>
+#include <tdelocale.h>
+
+OssPopup::OssPopup( OssModel *model, TQWidget *parent )
+ : TQWidget( parent, "OssPopup",
+ 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(OssDevice*)), this, TQ_SLOT(rebuild()));
+ connect(model, TQ_SIGNAL(preferredOutputChanged(OssDevice*)), this, TQ_SLOT(rebuild()));
+
+ rebuild();
+}
+
+void OssPopup::rebuild()
+{
+ delete m_container->layout();
+ if ( m_widget ) { delete m_widget; m_widget = 0; }
+
+ TQVBoxLayout *vbox = new TQVBoxLayout(m_container, 4, 0);
+ OssDevice *dev = m_model->preferredOutput();
+ if ( dev ) {
+ m_widget = new OssDeviceWidget(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 OssPopup::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 OssPopup::justHidden() const
+{
+ return m_hideTime.isValid() && m_hideTime.elapsed() < 100;
+}
+
+void OssPopup::hideEvent( TQHideEvent *e )
+{
+ TQWidget::hideEvent(e);
+ m_hideTime.start();
+}
+
+#include "osspopup.moc"
diff --git a/src/ui/oss/osspopup.h b/src/ui/oss/osspopup.h
new file mode 100644
index 0000000..1a2c80e
--- /dev/null
+++ b/src/ui/oss/osspopup.h
@@ -0,0 +1,30 @@
+#pragma once
+
+#include <tqwidget.h>
+#include <tqdatetime.h>
+
+class OssModel;
+class OssDevice;
+class OssDeviceWidget;
+
+class OssPopup : public TQWidget
+{
+ TQ_OBJECT
+public:
+ explicit OssPopup( OssModel *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:
+ OssModel *m_model;
+ TQWidget *m_container;
+ OssDeviceWidget *m_widget;
+ TQTime m_hideTime;
+};
diff --git a/src/ui/oss/osstray.cpp b/src/ui/oss/osstray.cpp
new file mode 100644
index 0000000..dfa63d0
--- /dev/null
+++ b/src/ui/oss/osstray.cpp
@@ -0,0 +1,129 @@
+#include "osstray.h"
+#include "osspopup.h"
+#include "ossmixerwindow.h"
+#include "../../model/ossmodel.h"
+#include "../../model/ossdevice.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>
+
+OssTray::OssTray( OssModel *model, OssMixerWindow *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(OssDevice*)), this, TQ_SLOT(updateIcon()));
+ connect(model, TQ_SIGNAL(preferredOutputChanged(OssDevice*)), this, TQ_SLOT(onPreferredChanged(OssDevice*)));
+
+ 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 OssTray::onPreferredChanged( OssDevice *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 OssTray::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 OssTray::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 OssPopup(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 OssTray::middleClickMute()
+{
+ if ( !m_output ) return;
+ TDEConfig *cfg = TDEGlobal::config();
+ cfg->setGroup("Tray");
+ if ( cfg->readBoolEntry("MiddleClickMute", false) )
+ m_output->setMuted( !m_output->muted() );
+}
+
+void OssTray::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 OssTray::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 "osstray.moc"
diff --git a/src/ui/oss/osstray.h b/src/ui/oss/osstray.h
new file mode 100644
index 0000000..dda1c76
--- /dev/null
+++ b/src/ui/oss/osstray.h
@@ -0,0 +1,34 @@
+#pragma once
+
+#include <ksystemtray.h>
+
+class OssModel;
+class OssDevice;
+class OssMixerWindow;
+class OssPopup;
+
+class OssTray : public KSystemTray
+{
+ TQ_OBJECT
+public:
+ OssTray( OssModel *model, OssMixerWindow *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( OssDevice *dev );
+
+private:
+ void middleClickMute();
+
+ OssModel *m_model;
+ OssMixerWindow *m_win;
+ OssDevice *m_output;
+ OssPopup *m_popup;
+};