diff options
| author | Calvin Morrison <calvin@pobox.com> | 2026-05-17 23:38:18 -0400 |
|---|---|---|
| committer | Calvin Morrison <calvin@pobox.com> | 2026-05-17 23:38:18 -0400 |
| commit | 3909a06fe6786027c83e3adaef89c343cde4fbe3 (patch) | |
| tree | f5ea87c98b50764c8ad87e598f274319df0e74db /src/ui/alsa/alsatray.cpp | |
| parent | 311b69c14203860ab6d98bd11633eea287c8f04e (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/alsatray.cpp')
| -rw-r--r-- | src/ui/alsa/alsatray.cpp | 131 |
1 files changed, 131 insertions, 0 deletions
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" |
