summaryrefslogtreecommitdiff
path: root/src/ui/oss/osstray.cpp
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/osstray.cpp
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/osstray.cpp')
-rw-r--r--src/ui/oss/osstray.cpp129
1 files changed, 129 insertions, 0 deletions
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"