From 3909a06fe6786027c83e3adaef89c343cde4fbe3 Mon Sep 17 00:00:00 2001 From: Calvin Morrison Date: Sun, 17 May 2026 23:38:18 -0400 Subject: ALSA backend, backend switcher, UX fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- src/CMakeLists.txt | 82 ++++++--- src/main.cpp | 26 +-- src/model/alsadevice.cpp | 187 +++++++++++++++++++ src/model/alsadevice.h | 67 +++++++ src/model/alsamodel.cpp | 150 ++++++++++++++++ src/model/alsamodel.h | 54 ++++++ src/model/audiodevice.h | 1 + src/model/pulsedevice.h | 7 +- src/model/pulsemodel.cpp | 54 ++++-- src/model/pulsemodel.h | 1 + src/ui/alsa/alsadevicespage.cpp | 161 +++++++++++++++++ src/ui/alsa/alsadevicespage.h | 66 +++++++ src/ui/alsa/alsadevicewidget.cpp | 175 ++++++++++++++++++ src/ui/alsa/alsadevicewidget.h | 31 ++++ src/ui/alsa/alsamixerwindow.cpp | 206 +++++++++++++++++++++ src/ui/alsa/alsamixerwindow.h | 55 ++++++ src/ui/alsa/alsapopup.cpp | 79 +++++++++ src/ui/alsa/alsapopup.h | 30 ++++ src/ui/alsa/alsatray.cpp | 131 ++++++++++++++ src/ui/alsa/alsatray.h | 35 ++++ src/ui/backendcontroller.cpp | 162 +++++++++++++++++ src/ui/backendcontroller.h | 39 ++++ src/ui/devicewidget.cpp | 5 +- src/ui/mixerwindow.cpp | 46 ++++- src/ui/mixerwindow.h | 8 +- src/ui/preferencesdlg.cpp | 375 +++++++++++++++++++++++++++++++-------- src/ui/preferencesdlg.h | 45 ++++- src/ui/tmixapp.cpp | 2 +- src/ui/tmixapp.h | 9 +- src/ui/tmixpopup.cpp | 2 +- src/ui/tmixtray.cpp | 61 ++++--- src/ui/tmixtray.h | 1 + 32 files changed, 2177 insertions(+), 176 deletions(-) create mode 100644 src/model/alsadevice.cpp create mode 100644 src/model/alsadevice.h create mode 100644 src/model/alsamodel.cpp create mode 100644 src/model/alsamodel.h create mode 100644 src/ui/alsa/alsadevicespage.cpp create mode 100644 src/ui/alsa/alsadevicespage.h create mode 100644 src/ui/alsa/alsadevicewidget.cpp create mode 100644 src/ui/alsa/alsadevicewidget.h create mode 100644 src/ui/alsa/alsamixerwindow.cpp create mode 100644 src/ui/alsa/alsamixerwindow.h create mode 100644 src/ui/alsa/alsapopup.cpp create mode 100644 src/ui/alsa/alsapopup.h create mode 100644 src/ui/alsa/alsatray.cpp create mode 100644 src/ui/alsa/alsatray.h create mode 100644 src/ui/backendcontroller.cpp create mode 100644 src/ui/backendcontroller.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c10da7f..5e9ee2d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,41 +1,77 @@ include( FindPkgConfig ) -pkg_check_modules( PULSE REQUIRED libpulse ) -include_directories( +pkg_check_modules( PULSE libpulse ) +pkg_check_modules( ALSA alsa ) + +if( NOT PULSE_FOUND AND NOT ALSA_FOUND ) + message( FATAL_ERROR "Neither libpulse nor libasound found — cannot build tmix" ) +endif() + +set( TMIX_SOURCES + main.cpp + model/audiodevice.cpp + ui/backendcontroller.cpp + ui/balanceknob.cpp + ui/kledbutton.cpp + ui/preferencesdlg.cpp + ui/tmixapp.cpp +) + +set( TMIX_LIBS + tqt-mt + tdecore + tdeui + DCOP +) + +set( TMIX_INCLUDES ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${TDE_INCLUDE_DIR} ${TQT_INCLUDE_DIRS} - ${PULSE_INCLUDE_DIRS} ) -link_directories( - ${TQT_LIBRARY_DIRS} - ${TDE_LIB_DIR} -) - -tde_add_executable( tmix AUTOMOC - SOURCES - main.cpp - model/audiodevice.cpp +if( PULSE_FOUND ) + add_definitions( -DWITH_PULSE ) + list( APPEND TMIX_INCLUDES ${PULSE_INCLUDE_DIRS} ) + list( APPEND TMIX_LIBS ${PULSE_LIBRARIES} ) + list( APPEND TMIX_SOURCES model/pulsedevice.cpp model/pulsemodel.cpp - ui/balanceknob.cpp - ui/devicewidget.cpp - ui/preferencesdlg.cpp - ui/kledbutton.cpp ui/levelmeter.cpp + ui/devicewidget.cpp ui/devicespage.cpp ui/tmixpopup.cpp ui/tmixtray.cpp - ui/tmixapp.cpp ui/mixerwindow.cpp - LINK - tqt-mt - tdecore - tdeui - DCOP - ${PULSE_LIBRARIES} + ) +endif() + +if( ALSA_FOUND ) + add_definitions( -DWITH_ALSA ) + list( APPEND TMIX_INCLUDES ${ALSA_INCLUDE_DIRS} ) + list( APPEND TMIX_LIBS ${ALSA_LIBRARIES} ) + list( APPEND TMIX_SOURCES + model/alsadevice.cpp + model/alsamodel.cpp + ui/alsa/alsadevicewidget.cpp + ui/alsa/alsadevicespage.cpp + ui/alsa/alsamixerwindow.cpp + ui/alsa/alsapopup.cpp + ui/alsa/alsatray.cpp + ) +endif() + +include_directories( ${TMIX_INCLUDES} ) + +link_directories( + ${TQT_LIBRARY_DIRS} + ${TDE_LIB_DIR} +) + +tde_add_executable( tmix AUTOMOC + SOURCES ${TMIX_SOURCES} + LINK ${TMIX_LIBS} DESTINATION ${BIN_INSTALL_DIR} ) diff --git a/src/main.cpp b/src/main.cpp index e8e7d36..02da9e1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,12 +2,9 @@ #include #include #include -#include -#include -#include "model/pulsemodel.h" -#include "ui/mixerwindow.h" #include "ui/tmixapp.h" +#include "ui/backendcontroller.h" static TDECmdLineOptions options[] = { TDECmdLineLastOption }; @@ -31,19 +28,12 @@ int main( int argc, char **argv ) TmixApp app; app.disableSessionManagement(); - PulseModel *model = new PulseModel; - if ( !model->open() ) { - delete model; - return 1; - } + // No parent — we delete ctrl explicitly before app exits so that + // TmixTray's X11 teardown happens while the display is still open. + BackendController *ctrl = new BackendController; + ctrl->start(); - MixerWindow *win = new MixerWindow( model ); - app.setMainWindow( win ); - - TDEConfig *cfg = TDEGlobal::config(); - cfg->setGroup("General"); - if ( !cfg->readBoolEntry("DockInTray", true) ) - win->show(); - - return app.exec(); + int ret = app.exec(); + delete ctrl; + return ret; } diff --git a/src/model/alsadevice.cpp b/src/model/alsadevice.cpp new file mode 100644 index 0000000..4a03e7f --- /dev/null +++ b/src/model/alsadevice.cpp @@ -0,0 +1,187 @@ +#include "alsadevice.h" +#include +#include + +AlsaDevice::AlsaDevice( Category cat, int cardIndex, snd_mixer_elem_t *elem, + const TQString &cardName, TQObject *parent ) + : TQObject(parent), m_category(cat), m_type(Slider), m_cardIndex(cardIndex), + m_elem(elem), m_cardName(cardName), + m_stereo(false), m_hasMute(false), m_volMin(0), m_volMax(0), + m_volume(0), m_muted(false), m_pan(0), m_enumId(0) +{ + m_name = TQString::fromUtf8( snd_mixer_selem_get_name(elem) ); + + if ( snd_mixer_selem_is_enumerated(elem) ) { + m_type = Enum; + int n = snd_mixer_selem_get_enum_items(elem); + for ( int i = 0; i < n; ++i ) { + char buf[128]; + if ( snd_mixer_selem_get_enum_item_name(elem, i, sizeof(buf), buf) >= 0 ) + m_enumValues.append( TQString::fromUtf8(buf) ); + } + } else if ( snd_mixer_selem_has_playback_volume(elem) || + snd_mixer_selem_has_capture_volume(elem) ) { + m_type = Slider; + if ( cat == Output ) { + m_stereo = snd_mixer_selem_has_playback_channel(elem, SND_MIXER_SCHN_FRONT_RIGHT); + m_hasMute = snd_mixer_selem_has_playback_switch(elem); + snd_mixer_selem_get_playback_volume_range(elem, &m_volMin, &m_volMax); + } else { + m_stereo = snd_mixer_selem_has_capture_channel(elem, SND_MIXER_SCHN_FRONT_RIGHT); + m_hasMute = snd_mixer_selem_has_capture_switch(elem); + snd_mixer_selem_get_capture_volume_range(elem, &m_volMin, &m_volMax); + } + } else { + m_type = Switch; + m_hasMute = true; + } + + snd_mixer_elem_set_callback(elem, elemCallback); + snd_mixer_elem_set_callback_private(elem, this); + + syncFromAlsa(); +} + +int AlsaDevice::elemCallback( snd_mixer_elem_t *elem, unsigned int /*mask*/ ) +{ + AlsaDevice *self = static_cast( snd_mixer_elem_get_callback_private(elem) ); + if ( self ) self->syncFromAlsa(); + return 0; +} + +void AlsaDevice::syncFromAlsa() +{ + if ( m_type == Enum ) { + unsigned int idx = 0; + snd_mixer_selem_get_enum_item(m_elem, SND_MIXER_SCHN_FRONT_LEFT, &idx); + int newId = (int)idx; + if ( newId != m_enumId ) { m_enumId = newId; emit enumChanged(m_enumId); } + return; + } + + if ( m_type == Switch ) { + int sw = 1; + if ( m_category == Output && snd_mixer_selem_has_playback_switch(m_elem) ) + snd_mixer_selem_get_playback_switch(m_elem, SND_MIXER_SCHN_FRONT_LEFT, &sw); + else if ( m_category == Input && snd_mixer_selem_has_capture_switch(m_elem) ) + snd_mixer_selem_get_capture_switch(m_elem, SND_MIXER_SCHN_FRONT_LEFT, &sw); + else if ( snd_mixer_selem_has_playback_switch(m_elem) ) + snd_mixer_selem_get_playback_switch(m_elem, SND_MIXER_SCHN_FRONT_LEFT, &sw); + bool newMute = (sw == 0); + if ( newMute != m_muted ) { m_muted = newMute; emit muteChanged(m_muted); } + return; + } + + // Slider + long range = m_volMax - m_volMin; + if ( range <= 0 ) return; + + long l = m_volMin, r = m_volMin; + int sw = 1; + + if ( m_category == Output ) { + snd_mixer_selem_get_playback_volume(m_elem, SND_MIXER_SCHN_FRONT_LEFT, &l); + if ( m_stereo ) + snd_mixer_selem_get_playback_volume(m_elem, SND_MIXER_SCHN_FRONT_RIGHT, &r); + else + r = l; + if ( m_hasMute ) + snd_mixer_selem_get_playback_switch(m_elem, SND_MIXER_SCHN_FRONT_LEFT, &sw); + } else { + snd_mixer_selem_get_capture_volume(m_elem, SND_MIXER_SCHN_FRONT_LEFT, &l); + if ( m_stereo ) + snd_mixer_selem_get_capture_volume(m_elem, SND_MIXER_SCHN_FRONT_RIGHT, &r); + else + r = l; + if ( m_hasMute ) + snd_mixer_selem_get_capture_switch(m_elem, SND_MIXER_SCHN_FRONT_LEFT, &sw); + } + + long lv = l - m_volMin, rv = r - m_volMin; + long mx = std::max(lv, rv); + + int newVol = (int)std::lround( (double)mx / range * 100.0 ); + bool newMute = (sw == 0); + int newPan = 0; + if ( m_stereo && mx > 0 ) { + if ( lv >= rv ) + newPan = (int)std::lround( -50.0 * (1.0 - (double)rv / lv) ); + else + newPan = (int)std::lround( 50.0 * (1.0 - (double)lv / rv) ); + } + + if ( newVol != m_volume ) { m_volume = newVol; emit volumeChanged(m_volume); } + if ( newMute != m_muted ) { m_muted = newMute; emit muteChanged(m_muted); } + if ( newPan != m_pan ) { m_pan = newPan; emit panChanged(m_pan); } +} + +long AlsaDevice::toAlsaVol( int pct ) const +{ + if ( pct <= 0 ) return m_volMin; + if ( pct >= 100 ) return m_volMax; + return m_volMin + (long)std::lround( (double)pct / 100.0 * (m_volMax - m_volMin) ); +} + +void AlsaDevice::pushVolume() +{ + long vol = toAlsaVol( m_volume ); + double lf = m_pan >= 0 ? (50.0 - m_pan) / 50.0 : 1.0; + double rf = m_pan <= 0 ? (50.0 + m_pan) / 50.0 : 1.0; + long lv = (long)(vol * lf + 0.5); + long rv = (long)(vol * rf + 0.5); + + if ( m_category == Output ) { + snd_mixer_selem_set_playback_volume(m_elem, SND_MIXER_SCHN_FRONT_LEFT, lv); + if ( m_stereo ) + snd_mixer_selem_set_playback_volume(m_elem, SND_MIXER_SCHN_FRONT_RIGHT, rv); + } else { + snd_mixer_selem_set_capture_volume(m_elem, SND_MIXER_SCHN_FRONT_LEFT, lv); + if ( m_stereo ) + snd_mixer_selem_set_capture_volume(m_elem, SND_MIXER_SCHN_FRONT_RIGHT, rv); + } +} + +void AlsaDevice::setVolume( int v ) +{ + v = v < 0 ? 0 : v > 100 ? 100 : v; + m_volume = v; + emit volumeChanged(v); + pushVolume(); +} + +void AlsaDevice::setPan( int p ) +{ + p = p < -50 ? -50 : p > 50 ? 50 : p; + m_pan = p; + emit panChanged(p); + pushVolume(); +} + +void AlsaDevice::setMuted( bool m ) +{ + m_muted = m; + int sw = m ? 0 : 1; + if ( m_type == Switch || m_type == Slider ) { + if ( snd_mixer_selem_has_playback_switch(m_elem) ) + snd_mixer_selem_set_playback_switch_all(m_elem, sw); + if ( snd_mixer_selem_has_capture_switch(m_elem) ) + snd_mixer_selem_set_capture_switch_all(m_elem, sw); + } + emit muteChanged(m); +} + +void AlsaDevice::setEnumId( int id ) +{ + if ( m_type != Enum ) return; + if ( id < 0 || id >= (int)m_enumValues.count() ) return; + m_enumId = id; + emit enumChanged(id); + for ( int ch = 0; ch <= SND_MIXER_SCHN_LAST; ++ch ) { + snd_mixer_selem_channel_id_t chId = (snd_mixer_selem_channel_id_t)ch; + if ( snd_mixer_selem_has_playback_channel(m_elem, chId) || + snd_mixer_selem_has_capture_channel(m_elem, chId) ) + snd_mixer_selem_set_enum_item(m_elem, chId, (unsigned int)id); + } +} + +#include "alsadevice.moc" diff --git a/src/model/alsadevice.h b/src/model/alsadevice.h new file mode 100644 index 0000000..cc26801 --- /dev/null +++ b/src/model/alsadevice.h @@ -0,0 +1,67 @@ +#pragma once + +#include +#include +#include +#include + +class AlsaDevice : public TQObject +{ + TQ_OBJECT +public: + enum Category { Output, Input, Neutral }; + enum Type { Slider, Switch, Enum }; + + AlsaDevice( Category cat, int cardIndex, snd_mixer_elem_t *elem, + const TQString &cardName, TQObject *parent = 0 ); + + TQString name() const { return m_name; } + TQString cardName() const { return m_cardName; } + int cardIndex() const { return m_cardIndex; } + Category category() const { return m_category; } + Type type() const { return m_type; } + + // Slider + int volume() const { return m_volume; } + bool muted() const { return m_muted; } + int pan() const { return m_pan; } + bool stereo() const { return m_stereo; } + bool hasMute() const { return m_hasMute; } + void setVolume( int v ); + void setMuted( bool m ); + void setPan( int p ); + + // Enum + TQStringList enumValues() const { return m_enumValues; } + int enumId() const { return m_enumId; } + void setEnumId( int id ); + + void syncFromAlsa(); + static int elemCallback( snd_mixer_elem_t *elem, unsigned int mask ); + +signals: + void volumeChanged( int v ); + void muteChanged( bool m ); + void panChanged( int p ); + void enumChanged( int id ); + +private: + long toAlsaVol( int pct ) const; + void pushVolume(); + + Category m_category; + Type m_type; + int m_cardIndex; + snd_mixer_elem_t *m_elem; + TQString m_name; + TQString m_cardName; + bool m_stereo; + bool m_hasMute; + long m_volMin; + long m_volMax; + int m_volume; + bool m_muted; + int m_pan; + TQStringList m_enumValues; + int m_enumId; +}; diff --git a/src/model/alsamodel.cpp b/src/model/alsamodel.cpp new file mode 100644 index 0000000..ce3caec --- /dev/null +++ b/src/model/alsamodel.cpp @@ -0,0 +1,150 @@ +#include "alsamodel.h" +#include +#include +#include +#include +#include + +AlsaModel::AlsaModel( TQObject *parent ) + : TQObject(parent) +{ + m_devices.setAutoDelete(true); + m_notifiers.setAutoDelete(true); +} + +AlsaModel::~AlsaModel() +{ + close(); +} + +bool AlsaModel::open() +{ + int card = -1; + while ( snd_card_next(&card) == 0 && card >= 0 ) + openCard(card); + emit ready(); + return !m_devices.isEmpty(); +} + +void AlsaModel::openCard( int card ) +{ + char hwname[32]; + snprintf(hwname, sizeof(hwname), "hw:%d", card); + + snd_mixer_t *mixer = 0; + if ( snd_mixer_open(&mixer, 0) < 0 ) return; + if ( snd_mixer_attach(mixer, hwname) < 0 ) { snd_mixer_close(mixer); return; } + if ( snd_mixer_selem_register(mixer, 0, 0) < 0 ) { snd_mixer_close(mixer); return; } + if ( snd_mixer_load(mixer) < 0 ) { snd_mixer_close(mixer); return; } + + char *cardName = 0; + snd_card_get_name(card, &cardName); + TQString qName = cardName ? TQString::fromUtf8(cardName) : TQString("Card %1").arg(card); + free(cardName); + + AlsaCard ac; + ac.index = card; + ac.name = qName; + m_cards.append(ac); + + for ( snd_mixer_elem_t *elem = snd_mixer_first_elem(mixer); + elem; elem = snd_mixer_elem_next(elem) ) { + if ( !snd_mixer_selem_is_active(elem) ) continue; + if ( snd_mixer_selem_is_enumerated(elem) ) + addElement(card, qName, elem, AlsaDevice::Neutral); + else if ( snd_mixer_selem_has_capture_volume(elem) ) + addElement(card, qName, elem, AlsaDevice::Input); + else if ( snd_mixer_selem_has_playback_volume(elem) ) + addElement(card, qName, elem, AlsaDevice::Output); + else if ( snd_mixer_selem_has_playback_switch(elem) ) + addElement(card, qName, elem, AlsaDevice::Output); + else if ( snd_mixer_selem_has_capture_switch(elem) ) + addElement(card, qName, elem, AlsaDevice::Input); + else if ( snd_mixer_selem_has_common_switch(elem) ) + addElement(card, qName, elem, AlsaDevice::Neutral); + } + + int count = snd_mixer_poll_descriptors_count(mixer); + if ( count > 0 ) { + struct pollfd *fds = new struct pollfd[count]; + snd_mixer_poll_descriptors(mixer, fds, count); + for ( int i = 0; i < count; i++ ) { + m_fdToMixer[fds[i].fd] = mixer; + TQSocketNotifier *sn = new TQSocketNotifier(fds[i].fd, TQSocketNotifier::Read, this); + connect(sn, TQ_SIGNAL(activated(int)), this, TQ_SLOT(onMixerFd(int))); + m_notifiers.append(sn); + } + delete[] fds; + } + + m_mixers.append(mixer); +} + +void AlsaModel::addElement( int card, const TQString &cardName, + snd_mixer_elem_t *elem, AlsaDevice::Category cat ) +{ + AlsaDevice *dev = new AlsaDevice(cat, card, elem, cardName, this); + m_devices.append(dev); + emit deviceAdded(dev); +} + +void AlsaModel::onMixerFd( int fd ) +{ + snd_mixer_t *mixer = m_fdToMixer[fd]; + if ( mixer ) snd_mixer_handle_events(mixer); +} + +TQPtrList AlsaModel::devicesForCard( int cardIndex ) const +{ + TQPtrList result; + for ( TQPtrListIterator it(m_devices); *it; ++it ) + if ( (*it)->cardIndex() == cardIndex ) + result.append(*it); + return result; +} + +AlsaDevice *AlsaModel::defaultOutput() const +{ + for ( TQPtrListIterator it(m_devices); *it; ++it ) + if ( (*it)->category() == AlsaDevice::Output ) + return *it; + return 0; +} + +AlsaDevice *AlsaModel::preferredOutput() const +{ + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("Tray"); + int card = cfg->readNumEntry("TrayCard", -1); + TQString name = cfg->readEntry("TrayDevice", ""); + if ( card >= 0 && !name.isEmpty() ) { + for ( TQPtrListIterator it(m_devices); *it; ++it ) + if ( (*it)->cardIndex() == card && (*it)->name() == name && + (*it)->category() == AlsaDevice::Output ) + return *it; + } + return defaultOutput(); +} + +void AlsaModel::setPreferredOutput( int cardIndex, const TQString &name ) +{ + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("Tray"); + cfg->writeEntry("TrayCard", cardIndex); + cfg->writeEntry("TrayDevice", name); + cfg->sync(); + emit preferredOutputChanged( preferredOutput() ); +} + +void AlsaModel::close() +{ + m_notifiers.clear(); + m_devices.clear(); + m_fdToMixer.clear(); + for ( TQValueListIterator it = m_mixers.begin(); it != m_mixers.end(); ++it ) + snd_mixer_close(*it); + m_mixers.clear(); + m_cards.clear(); +} + +#include "alsamodel.moc" diff --git a/src/model/alsamodel.h b/src/model/alsamodel.h new file mode 100644 index 0000000..fc8a0f0 --- /dev/null +++ b/src/model/alsamodel.h @@ -0,0 +1,54 @@ +#pragma once + +#include +#include +#include +#include +#include +#include + +#include "alsadevice.h" + +class TQSocketNotifier; + +struct AlsaCard { + int index; + TQString name; +}; + +class AlsaModel : public TQObject +{ + TQ_OBJECT +public: + explicit AlsaModel( TQObject *parent = 0 ); + ~AlsaModel(); + + bool open(); + void close(); + + TQValueList cards() const { return m_cards; } + TQPtrList devices() const { return m_devices; } + TQPtrList devicesForCard( int cardIndex ) const; + AlsaDevice *defaultOutput() const; + AlsaDevice *preferredOutput() const; + void setPreferredOutput( int cardIndex, const TQString &name ); + +signals: + void deviceAdded( AlsaDevice *dev ); + void preferredOutputChanged( AlsaDevice *dev ); + void ready(); + +private slots: + void onMixerFd( int fd ); + +private: + void openCard( int card ); + void addElement( int card, const TQString &cardName, + snd_mixer_elem_t *elem, AlsaDevice::Category cat ); + + TQValueList m_cards; + TQPtrList m_devices; + TQPtrList m_notifiers; + TQValueList m_mixers; + TQMap m_fdToMixer; +}; diff --git a/src/model/audiodevice.h b/src/model/audiodevice.h index 854ba35..051ae4a 100644 --- a/src/model/audiodevice.h +++ b/src/model/audiodevice.h @@ -27,6 +27,7 @@ public: virtual int volume() const = 0; // 0-100 virtual bool muted() const = 0; virtual int pan() const = 0; // -50 (left) .. 0 .. +50 (right) + virtual bool recordingActive() const = 0; // true when ≥1 stream is capturing from this input virtual void setVolume( int v ) = 0; virtual void setMuted( bool m ) = 0; diff --git a/src/model/pulsedevice.h b/src/model/pulsedevice.h index 289f2ed..92e2ac9 100644 --- a/src/model/pulsedevice.h +++ b/src/model/pulsedevice.h @@ -16,9 +16,10 @@ public: TQString name() const { return m_name; } TQString iconName() const { return m_iconName; } Category category() const { return m_category; } - int volume() const { return m_volume; } - bool muted() const { return m_muted; } - int pan() const { return m_pan; } + int volume() const { return m_volume; } + bool muted() const { return m_muted; } + int pan() const { return m_pan; } + bool recordingActive() const { return m_recordingCount > 0; } uint32_t paIndex() const { return m_paIndex; } uint32_t sinkIndex() const { return m_sinkIndex; } TQString monitorName() const { return m_monitorName; } diff --git a/src/model/pulsemodel.cpp b/src/model/pulsemodel.cpp index de91831..24c1af8 100644 --- a/src/model/pulsemodel.cpp +++ b/src/model/pulsemodel.cpp @@ -32,7 +32,8 @@ struct PAEvent : public TQCustomEvent { TQString monitorName; TQString iconName; TQString paName; // raw PA name (sinks/sources only, for default tracking) - uint32_t parentIndex; // for Playback: parent sink PA index + uint32_t parentIndex; // for Playback: parent sink; for Recording: parent source + uint32_t monitorSourceIdx; // for Output: PA index of the monitor source uint32_t cardIdx; // for Output/Input: owning card PA index TQString activePortName; TQValueList devPorts; @@ -45,7 +46,7 @@ struct PAEvent : public TQCustomEvent { : TQCustomEvent(PA_EVENT), kind(k), cat(c), paIndex(idx), name(n), volume(vol), muted(m), channels(ch), pan(p), monitorName(mon), iconName(icon), paName(pname), parentIndex(parent), - cardIdx(PA_INVALID_INDEX) {} + monitorSourceIdx(PA_INVALID_INDEX), cardIdx(PA_INVALID_INDEX) {} }; struct PACardEvent : public TQCustomEvent { @@ -216,26 +217,22 @@ bool PulseModel::open() void PulseModel::close() { - bool alreadyDead = false; - if ( m_context ) { - pa_context_state_t state = pa_context_get_state( m_context ); - alreadyDead = ( state == PA_CONTEXT_FAILED || - state == PA_CONTEXT_TERMINATED ); + // Stop the PA thread first. After this returns the thread is dead and + // no callbacks can fire, so we can touch PA objects without locking. + if ( m_mainloop ) { + pa_threaded_mainloop_stop( m_mainloop ); } - forEachDevice( [alreadyDead](PulseDevice *dev) { dev->detach( alreadyDead ); } ); + // With the thread stopped, detach devices without locking. + forEachDevice( [](PulseDevice *dev) { dev->detach( true ); } ); if ( m_context ) { - if ( !alreadyDead ) { - pa_threaded_mainloop_lock( m_mainloop ); - pa_context_disconnect( m_context ); - pa_threaded_mainloop_unlock( m_mainloop ); - } + pa_context_set_state_callback( m_context, 0, 0 ); + pa_context_disconnect( m_context ); pa_context_unref( m_context ); m_context = 0; } if ( m_mainloop ) { - pa_threaded_mainloop_stop( m_mainloop ); pa_threaded_mainloop_free( m_mainloop ); m_mainloop = 0; } @@ -324,7 +321,8 @@ void PulseModel::sinkInfoCb( pa_context *, const pa_sink_info *info, int eol, vo TQString::fromUtf8( pa_proplist_gets( info->proplist, PA_PROP_DEVICE_ICON_NAME ) ? : "" ), PA_INVALID_INDEX, TQString::fromUtf8( info->name ) ); - ev->cardIdx = info->card; + ev->cardIdx = info->card; + ev->monitorSourceIdx = info->monitor_source; ev->activePortName = info->active_port ? TQString::fromUtf8( info->active_port->name ) : TQString(); for ( uint32_t i = 0; i < info->n_ports; ++i ) { @@ -515,6 +513,7 @@ void PulseModel::customEvent( TQCustomEvent *e ) m_sinksByName.clear(); m_sourcesByName.clear(); m_sourceOutputToSource.clear(); + m_monitorSourceToSink.clear(); m_cards.clear(); close(); TQTimer::singleShot( 2000, this, TQ_SLOT(reconnect()) ); @@ -586,6 +585,12 @@ void PulseModel::customEvent( TQCustomEvent *e ) m_sinkCard.remove( ev->paIndex ); m_sinkActivePort.remove( ev->paIndex ); m_sinkPorts.remove( ev->paIndex ); + // Remove monitor→sink mapping for this sink. + TQMap::Iterator mi = m_monitorSourceToSink.begin(); + while ( mi != m_monitorSourceToSink.end() ) { + if ( mi.data() == ev->paIndex ) { m_monitorSourceToSink.remove(mi); break; } + ++mi; + } } else if ( ev->cat == AudioDevice::Input ) { m_sourceCard.remove( ev->paIndex ); m_sourceActivePort.remove( ev->paIndex ); @@ -619,6 +624,8 @@ void PulseModel::customEvent( TQCustomEvent *e ) if ( ev->cat == AudioDevice::Output ) { m_sinkCard[ev->paIndex] = ev->cardIdx; m_sinkPorts[ev->paIndex] = ev->devPorts; + if ( ev->monitorSourceIdx != PA_INVALID_INDEX ) + m_monitorSourceToSink[ev->monitorSourceIdx] = ev->paIndex; TQString oldPort = m_sinkActivePort.contains(ev->paIndex) ? m_sinkActivePort[ev->paIndex] : TQString(); m_sinkActivePort[ev->paIndex] = ev->activePortName; @@ -661,14 +668,25 @@ void PulseModel::customEvent( TQCustomEvent *e ) emit defaultOutputChanged( dev ); if ( ev->cat == AudioDevice::Input && ev->paName == m_defaultSourceName ) emit defaultInputChanged( dev ); - // Track which source a new recording stream is attached to. + // Forward Recording device level from its parent source (best-effort). if ( ev->cat == AudioDevice::Recording && ev->parentIndex != PA_INVALID_INDEX ) { m_sourceOutputToSource.insert( ev->paIndex, ev->parentIndex ); PulseDevice *src = findDevice( m_sources, ev->parentIndex ); if ( src ) { + // Parent is a real hardware input (microphone). src->adjustRecordingCount( +1 ); - connect( src, TQ_SIGNAL(levelChanged(float)), - dev, TQ_SIGNAL(levelChanged(float)) ); + connect( src, TQ_SIGNAL(levelChanged(float)), + dev, TQ_SIGNAL(levelChanged(float)) ); + } else { + // Parent may be a monitor source — forward the parent sink's level. + TQMap::ConstIterator si = + m_monitorSourceToSink.find( ev->parentIndex ); + if ( si != m_monitorSourceToSink.end() ) { + PulseDevice *sink = findDevice( m_sinks, si.data() ); + if ( sink ) + connect( sink, TQ_SIGNAL(levelChanged(float)), + dev, TQ_SIGNAL(levelChanged(float)) ); + } } } } diff --git a/src/model/pulsemodel.h b/src/model/pulsemodel.h index 2adfee7..befdd52 100644 --- a/src/model/pulsemodel.h +++ b/src/model/pulsemodel.h @@ -140,6 +140,7 @@ private: TQString m_defaultSinkName; TQString m_defaultSourceName; TQMap m_sourceOutputToSource; // soIdx → sourceIdx + TQMap m_monitorSourceToSink; // monitorSourceIdx → sinkIdx TQValueList m_cards; 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 +#include +#include +#include +#include +#include + +// ── 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 devs = m_model->devicesForCard(m_cardIndex); + bool hasSwitches = false, hasEnums = false; + + for ( TQPtrListIterator 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("%1").arg(i18n("Switches")), m_content ); + vbox->addWidget(hdr); + for ( TQPtrListIterator 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("%1").arg(i18n("Routing")), m_content ); + vbox->addWidget(hdr); + for ( TQPtrListIterator 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 +#include + +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 +#include +#include +#include +#include +#include +#include + +// ---- 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 + +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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +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 cards = model->cards(); + for ( TQValueListConstIterator 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 devs = m_model->devicesForCard(cardIndex); + bool hasOutput = false, hasInput = false; + for ( TQPtrListIterator 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 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 AlsaMixerWindow::onDeviceAdded( AlsaDevice * ) +{ + 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 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 +#include + +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 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 +#include +#include +#include +#include +#include + +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 +#include + +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 +#include +#include +#include +#include +#include +#include +#include + +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 + +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; +}; diff --git a/src/ui/backendcontroller.cpp b/src/ui/backendcontroller.cpp new file mode 100644 index 0000000..3a41b8d --- /dev/null +++ b/src/ui/backendcontroller.cpp @@ -0,0 +1,162 @@ +#include "backendcontroller.h" +#include "tmixapp.h" + +#include +#include +#include +#include + +#ifdef WITH_PULSE +#include "../model/pulsemodel.h" +#include "mixerwindow.h" +#endif + +#ifdef WITH_ALSA +#include "../model/alsamodel.h" +#include "alsa/alsamixerwindow.h" +#include "alsa/alsatray.h" +#endif + +BackendController::BackendController( TQObject *parent ) + : TQObject(parent) +#ifdef WITH_PULSE + , m_pulseModel(0), m_pulseWin(0) +#endif +#ifdef WITH_ALSA + , m_alsaModel(0), m_alsaWin(0), m_alsaTray(0) +#endif +{} + +BackendController::~BackendController() +{ + stop(); +} + +void BackendController::start() +{ + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("General"); + m_currentBackend = cfg->readEntry("Backend", "pulse"); + +#ifdef WITH_ALSA + if ( m_currentBackend == "alsa" ) { startAlsa(); return; } +#endif +#ifdef WITH_PULSE + startPulse(); +#endif +} + +void BackendController::stop() +{ +#ifdef WITH_ALSA + if ( m_alsaTray ) { delete m_alsaTray; m_alsaTray = 0; } + if ( m_alsaWin ) { delete m_alsaWin; m_alsaWin = 0; } + if ( m_alsaModel ) { delete m_alsaModel; m_alsaModel = 0; } +#endif +#ifdef WITH_PULSE + // Model first: stops the PA mainloop thread before any widget is destroyed. + if ( m_pulseModel ) { delete m_pulseModel; m_pulseModel = 0; } + if ( m_pulseWin ) { delete m_pulseWin; m_pulseWin = 0; } +#endif +} + +#ifdef WITH_PULSE +void BackendController::startPulse( bool showWindow ) +{ + m_pulseModel = new PulseModel( this ); + if ( !m_pulseModel->open() ) { + delete m_pulseModel; + m_pulseModel = 0; + return; + } + m_pulseWin = new MixerWindow( m_pulseModel ); + connect( m_pulseWin, TQ_SIGNAL(settingsChanged()), + this, TQ_SLOT(onSettingsChanged()) ); + static_cast(kapp)->setMainWindow( m_pulseWin ); + + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("Tray"); + bool dockInTray = cfg->readBoolEntry("DockInTray", true); + if ( !dockInTray || showWindow ) + m_pulseWin->show(); +} +#endif + +#ifdef WITH_ALSA +void BackendController::startAlsa( bool showWindow ) +{ + m_alsaModel = new AlsaModel( this ); + if ( !m_alsaModel->open() ) { + delete m_alsaModel; + m_alsaModel = 0; + return; + } + m_alsaWin = new AlsaMixerWindow( m_alsaModel ); + connect( m_alsaWin, TQ_SIGNAL(settingsChanged()), + this, TQ_SLOT(onSettingsChanged()) ); + static_cast(kapp)->setMainWindow( m_alsaWin ); + + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("Tray"); + bool dockInTray = cfg->readBoolEntry("DockInTray", true); + if ( dockInTray ) { + m_alsaTray = new AlsaTray( m_alsaModel, m_alsaWin, m_alsaWin ); + m_alsaWin->setTray( m_alsaTray ); + m_alsaTray->show(); + } + if ( !dockInTray || showWindow ) + m_alsaWin->show(); +} +#endif + +void BackendController::onSettingsChanged() +{ + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("General"); + TQString newBackend = cfg->readEntry("Backend", "pulse"); + if ( newBackend != m_currentBackend ) + TQTimer::singleShot( 0, this, TQ_SLOT(doSwitch()) ); +} + +void BackendController::doSwitch() +{ + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("General"); + m_currentBackend = cfg->readEntry("Backend", "pulse"); + + // Remember whether the mixer window was open so we can reopen it after the switch. + bool wasVisible = false; +#ifdef WITH_PULSE + if ( m_pulseWin ) { + wasVisible = m_pulseWin->isVisible(); + if ( wasVisible ) { + cfg->setGroup("MainWindow"); + cfg->writeEntry("XPos", m_pulseWin->x()); + cfg->writeEntry("YPos", m_pulseWin->y()); + cfg->sync(); + } + } +#endif +#ifdef WITH_ALSA + if ( m_alsaWin ) { + wasVisible = wasVisible || m_alsaWin->isVisible(); + if ( m_alsaWin->isVisible() ) { + cfg->setGroup("MainWindow"); + cfg->writeEntry("XPos", m_alsaWin->x()); + cfg->writeEntry("YPos", m_alsaWin->y()); + cfg->sync(); + } + } +#endif + + stop(); + +#ifdef WITH_ALSA + if ( m_currentBackend == "alsa" ) { startAlsa( wasVisible ); return; } +#endif +#ifdef WITH_PULSE + startPulse( wasVisible ); +#endif +} + +#include "backendcontroller.moc" diff --git a/src/ui/backendcontroller.h b/src/ui/backendcontroller.h new file mode 100644 index 0000000..a6cfe6c --- /dev/null +++ b/src/ui/backendcontroller.h @@ -0,0 +1,39 @@ +#pragma once + +#include +#include + +class TmixApp; + +class BackendController : public TQObject +{ + TQ_OBJECT +public: + explicit BackendController( TQObject *parent = 0 ); + ~BackendController(); + + void start(); + +public slots: + void onSettingsChanged(); + +private slots: + void doSwitch(); + +private: + void stop(); + void startPulse( bool showWindow = false ); + void startAlsa( bool showWindow = false ); + + TQString m_currentBackend; + +#ifdef WITH_PULSE + class PulseModel *m_pulseModel; + class MixerWindow *m_pulseWin; +#endif +#ifdef WITH_ALSA + class AlsaModel *m_alsaModel; + class AlsaMixerWindow *m_alsaWin; + class AlsaTray *m_alsaTray; +#endif +}; diff --git a/src/ui/devicewidget.cpp b/src/ui/devicewidget.cpp index f7ac79a..645ffaa 100644 --- a/src/ui/devicewidget.cpp +++ b/src/ui/devicewidget.cpp @@ -178,7 +178,8 @@ DeviceWidget::DeviceWidget( AudioDevice *device, PulseModel *model, TQWidget *pa // Red recording-active LED — Input only, shows when a stream is capturing if ( device->category() == AudioDevice::Input ) { - m_recordingLed = new KLed( TQt::red, KLed::Off, KLed::Raised, KLed::Circular, bottomWidget ); + KLed::State initState = device->recordingActive() ? KLed::On : KLed::Off; + m_recordingLed = new KLed( TQt::red, initState, KLed::Raised, KLed::Circular, bottomWidget ); m_recordingLed->setFixedSize( 16, 16 ); TQToolTip::add( m_recordingLed, i18n("Microphone in use") ); connect( device, TQ_SIGNAL(recordingActiveChanged(bool)), @@ -291,7 +292,7 @@ void DeviceWidget::onDeviceName( const TQString &name ) void DeviceWidget::wheelEvent( TQWheelEvent *e ) { TDEConfig *cfg = TDEGlobal::config(); - cfg->setGroup("General"); + cfg->setGroup("Tray"); int step = cfg->readNumEntry("ScrollStep", 5); int delta = e->delta() > 0 ? step : -step; int vol = TQMAX( 0, TQMIN( 100, m_device->volume() + delta ) ); diff --git a/src/ui/mixerwindow.cpp b/src/ui/mixerwindow.cpp index d8463f1..12a6666 100644 --- a/src/ui/mixerwindow.cpp +++ b/src/ui/mixerwindow.cpp @@ -4,6 +4,7 @@ #include "../model/pulsemodel.h" #include +#include #include #include #include @@ -54,7 +55,8 @@ static MixerWindow::Tab makeTab( KTabWidget *tabs, const TQString &label ) MixerWindow::MixerWindow( PulseModel *model, TQWidget *parent ) : TDEMainWindow(parent), m_model(model), m_prefsDlg(0), - m_devicesBtn(0), m_devicesPage(0), m_devicesInTabs(false), m_quitting(false) + m_devicesBtn(0), m_devicesPage(0), m_devicesInTabs(false), + m_quitting(false), m_totalDevCount(0), m_waitLabel(0) { setPlainCaption( i18n("Volume Control") ); setIcon( TDEGlobal::iconLoader()->loadIcon( "kmix", TDEIcon::Desktop, 48 ) ); @@ -82,7 +84,7 @@ MixerWindow::MixerWindow( PulseModel *model, TQWidget *parent ) onDefaultOutputChanged( model->defaultOutput() ); TDEConfig *cfg = TDEGlobal::config(); - cfg->setGroup("General"); + cfg->setGroup("Tray"); if ( cfg->readBoolEntry("DockInTray", true) ) m_tray->show(); @@ -93,14 +95,23 @@ MixerWindow::MixerWindow( PulseModel *model, TQWidget *parent ) TQVBoxLayout *top = new TQVBoxLayout( central, 0, 0 ); - // Outer stack: page 0 = mixer content, page 1 = devices (no-tab mode only) + // Outer stack: page 0 = mixer, page 1 = devices (no-tab mode), page 2 = waiting m_outerStack = new TQWidgetStack( central ); top->addWidget( m_outerStack, 1 ); TQWidget *mixerPage = new TQWidget( m_outerStack ); TQVBoxLayout *mixerLayout = new TQVBoxLayout( mixerPage, 0, 0 ); m_outerStack->addWidget( mixerPage, 0 ); - m_outerStack->raiseWidget( 0 ); + + // Page 2: shown when PA is not yet connected / no devices present + TQWidget *waitPage = new TQWidget( m_outerStack ); + TQVBoxLayout *waitLayout = new TQVBoxLayout( waitPage, 0, 0 ); + m_waitLabel = new TQLabel( i18n("Waiting for PulseAudio to start..."), waitPage ); + m_waitLabel->setAlignment( Qt::AlignCenter ); + waitLayout->addWidget( m_waitLabel ); + m_outerStack->addWidget( waitPage, 2 ); + + m_outerStack->raiseWidget( 2 ); // start on waiting page; switch to 0 on first device m_stack = new TQWidgetStack( mixerPage ); mixerLayout->addWidget( m_stack ); @@ -189,7 +200,7 @@ bool MixerWindow::queryClose() if ( m_quitting || tdeApp->sessionSaving() ) return true; TDEConfig *cfg = TDEGlobal::config(); - cfg->setGroup("General"); + cfg->setGroup("Tray"); if ( cfg->readBoolEntry("DockInTray", true) ) { saveMainWindowSettings( TDEGlobal::config(), "MainWindow" ); TDEConfig *c = TDEGlobal::config(); @@ -200,6 +211,21 @@ bool MixerWindow::queryClose() hide(); return false; } + // Not in systray — show confirm if needed, then let TDE close the window + // normally (returning true). TDE quits the app when the last main window closes. + TDEConfig *gcfg = TDEGlobal::config(); + gcfg->setGroup("General"); + if ( gcfg->readBoolEntry("ConfirmQuit", false) ) { + int r = KMessageBox::questionYesNo( + this, + i18n("Are you sure you want to quit TMix?"), + i18n("Quit TMix"), + KStdGuiItem::quit(), + KStdGuiItem::cancel() ); + if ( r != KMessageBox::Yes ) + return false; + } + m_quitting = true; return true; } @@ -249,6 +275,10 @@ static void updateSeparators( TQHBoxLayout *layout ) void MixerWindow::onDeviceAdded( AudioDevice *dev ) { + if ( m_totalDevCount == 0 ) + m_outerStack->raiseWidget( 0 ); + m_totalDevCount++; + if ( m_stack->id( m_stack->visibleWidget() ) == 1 ) { TQWidget *w = dev->createWidget( m_allStrip ); m_allLayout->insertWidget( m_allCount, w ); @@ -291,6 +321,9 @@ void MixerWindow::onDeviceRemoved( AudioDevice *dev ) delete w; updateSeparators( t.layout ); } + m_totalDevCount--; + if ( m_totalDevCount == 0 ) + m_outerStack->raiseWidget( 2 ); } @@ -381,7 +414,7 @@ void MixerWindow::applySettings() { TDEConfig *cfg = TDEGlobal::config(); - cfg->setGroup("General"); + cfg->setGroup("Tray"); if ( cfg->readBoolEntry("DockInTray", true) ) m_tray->show(); else @@ -398,6 +431,7 @@ void MixerWindow::applySettings() m_tabs->setTabEnabled( m_playback.scroll, cfg->readBoolEntry("ShowPlayback", true) ); m_tabs->setTabEnabled( m_recording.scroll, cfg->readBoolEntry("ShowRecording", true) ); } + emit settingsChanged(); } void MixerWindow::toggleDevices() diff --git a/src/ui/mixerwindow.h b/src/ui/mixerwindow.h index 8dc740d..893f903 100644 --- a/src/ui/mixerwindow.h +++ b/src/ui/mixerwindow.h @@ -12,6 +12,7 @@ class TQWidgetStack; class TQToolButton; class DevicesPage; class TQResizeEvent; +class TQLabel; class MixerWindow : public TDEMainWindow { @@ -34,6 +35,9 @@ protected: void showEvent( TQShowEvent *e ); void hideEvent( TQHideEvent *e ); +signals: + void settingsChanged(); + public slots: void bringToFront(); @@ -66,8 +70,10 @@ private: class TmixTray *m_tray; TQToolButton *m_devicesBtn; DevicesPage *m_devicesPage; - bool m_devicesInTabs; // true = DevicesPage is a tab in m_tabs + bool m_devicesInTabs; bool m_quitting; + int m_totalDevCount; + TQLabel *m_waitLabel; Tab m_output; Tab m_input; diff --git a/src/ui/preferencesdlg.cpp b/src/ui/preferencesdlg.cpp index b263850..fa69bd3 100644 --- a/src/ui/preferencesdlg.cpp +++ b/src/ui/preferencesdlg.cpp @@ -7,112 +7,298 @@ #include #include #include +#include +#include +#include +#include +#include #include #include #include +static TQString autostartPath() +{ + TQString tdehome = TQString::fromLocal8Bit( ::getenv("TDEHOME") ); + if ( tdehome.isEmpty() ) + tdehome = TQDir::homeDirPath() + "/.trinity"; + return tdehome + "/Autostart/tmix.desktop"; +} + +#ifdef WITH_ALSA +#include "../model/alsamodel.h" +#include "../model/alsadevice.h" +#endif + +// ── Pulse constructor ───────────────────────────────────────────────────────── + PreferencesDlg::PreferencesDlg( TQWidget *parent ) : KDialogBase( Tabbed, i18n("Configure TMix"), - Ok | Apply | Cancel, Ok, parent, 0, false ) + Ok | Apply | Cancel, Ok, parent, 0, false ), + m_backend(0), m_dockInTray(0), m_popupMode(0), + m_scrollStep(0), m_confirmQuit(0), m_middleClickMute(0), + m_startOnLogin(0), + m_backendStack(0), + m_popupShowOutput(0), m_popupShowMic(0), m_popupShowApps(0), + m_showRecTray(0), + m_noTabs(0), m_showTabsLabel(0), m_showOutput(0), m_showInput(0), + m_showPlayback(0), m_showRecording(0) +#ifdef WITH_ALSA + , m_alsaModel(0), m_trayDevice(0) +#endif +{ + buildGeneralPage(); + buildBackendPage(); + load(); +} + +#ifdef WITH_ALSA + +// ── ALSA constructor ────────────────────────────────────────────────────────── + +PreferencesDlg::PreferencesDlg( AlsaModel *model, TQWidget *parent ) + : KDialogBase( Tabbed, i18n("Configure TMix"), + Ok | Apply | Cancel, Ok, parent, 0, false ), + m_backend(0), m_dockInTray(0), m_popupMode(0), + m_scrollStep(0), m_confirmQuit(0), m_middleClickMute(0), + m_startOnLogin(0), + m_backendStack(0), + m_popupShowOutput(0), m_popupShowMic(0), m_popupShowApps(0), + m_showRecTray(0), + m_noTabs(0), m_showTabsLabel(0), m_showOutput(0), m_showInput(0), + m_showPlayback(0), m_showRecording(0), + m_alsaModel(model), m_trayDevice(0) +{ + buildGeneralPage(); + buildBackendPage(); + load(); +} + +#endif + +// ── General page ────────────────────────────────────────────────────────────── + +void PreferencesDlg::buildGeneralPage() { - // ---- General ------------------------------------------------------------- TQFrame *gen = addPage( i18n("General") ); TQVBoxLayout *gl = new TQVBoxLayout( gen, marginHint(), spacingHint() ); - m_dockInTray = new TQCheckBox( i18n("Dock in system tray"), gen ); - gl->addWidget( m_dockInTray ); + TQHBoxLayout *backendRow = new TQHBoxLayout( 0, 0, spacingHint() ); + backendRow->addWidget( new TQLabel( i18n("Audio backend:"), gen ) ); + m_backend = new TQComboBox( false, gen ); + m_backend->insertItem( i18n("PulseAudio") ); +#ifdef WITH_ALSA + m_backend->insertItem( i18n("ALSA") ); +#endif + backendRow->addWidget( m_backend ); + backendRow->addStretch(); + gl->addLayout( backendRow ); - gl->addSpacing( 4 ); + gl->addSpacing( 8 ); + + TQGroupBox *trayCard = new TQGroupBox( i18n("System Tray"), gen ); + trayCard->setColumnLayout( 0, Qt::Vertical ); + trayCard->layout()->setSpacing( spacingHint() ); + trayCard->layout()->setMargin( marginHint() ); + TQVBoxLayout *tl = new TQVBoxLayout( trayCard->layout() ); + + m_dockInTray = new TQCheckBox( i18n("Dock in system tray"), trayCard ); + tl->addWidget( m_dockInTray ); TQHBoxLayout *popupRow = new TQHBoxLayout( 0, 0, spacingHint() ); - popupRow->addWidget( new TQLabel( i18n("Tray left-click:"), gen ) ); - m_popupMode = new TQComboBox( false, gen ); + popupRow->addWidget( new TQLabel( i18n("Left-click:"), trayCard ) ); + m_popupMode = new TQComboBox( false, trayCard ); m_popupMode->insertItem( i18n("Show mixer window") ); m_popupMode->insertItem( i18n("Show mini popup") ); popupRow->addWidget( m_popupMode ); popupRow->addStretch(); - gl->addLayout( popupRow ); - - TQGroupBox *popupContent = new TQGroupBox( i18n("Mini popup shows:"), gen ); - popupContent->setColumnLayout( 0, Qt::Vertical ); - popupContent->layout()->setSpacing( spacingHint() ); - popupContent->layout()->setMargin( marginHint() ); - TQVBoxLayout *pcl = new TQVBoxLayout( popupContent->layout() ); - m_popupShowOutput = new TQCheckBox( i18n("Default output (speakers/headphones)"), popupContent ); - m_popupShowMic = new TQCheckBox( i18n("Microphone inputs"), popupContent ); - m_popupShowApps = new TQCheckBox( i18n("Active app streams"), popupContent ); - pcl->addWidget( m_popupShowOutput ); - pcl->addWidget( m_popupShowMic ); - pcl->addWidget( m_popupShowApps ); - gl->addWidget( popupContent ); + tl->addLayout( popupRow ); connect( m_popupMode, TQ_SIGNAL(activated(int)), this, TQ_SLOT(onPopupModeChanged(int)) ); - gl->addSpacing( 4 ); - - m_showRecTray = new TQCheckBox( i18n("Show microphone-in-use icon in tray"), gen ); - gl->addWidget( m_showRecTray ); - - m_confirmQuit = new TQCheckBox( i18n("Ask for confirmation before quitting"), gen ); - gl->addWidget( m_confirmQuit ); - - gl->addSpacing( 8 ); + m_middleClickMute = new TQCheckBox( i18n("Middle-click mutes/unmutes"), trayCard ); + tl->addWidget( m_middleClickMute ); TQHBoxLayout *stepRow = new TQHBoxLayout( 0, 0, spacingHint() ); - stepRow->addWidget( new TQLabel( i18n("Scroll wheel volume step:"), gen ) ); - m_scrollStep = new TQSpinBox( 1, 20, 1, gen ); + stepRow->addWidget( new TQLabel( i18n("Scroll wheel step:"), trayCard ) ); + m_scrollStep = new TQSpinBox( 1, 20, 1, trayCard ); m_scrollStep->setSuffix( i18n(" %") ); stepRow->addWidget( m_scrollStep ); stepRow->addStretch(); - gl->addLayout( stepRow ); + tl->addLayout( stepRow ); + + gl->addWidget( trayCard ); + + gl->addSpacing( 4 ); + + TQGroupBox *startupCard = new TQGroupBox( i18n("Startup / Exit"), gen ); + startupCard->setColumnLayout( 0, Qt::Vertical ); + startupCard->layout()->setSpacing( spacingHint() ); + startupCard->layout()->setMargin( marginHint() ); + TQVBoxLayout *sl = new TQVBoxLayout( startupCard->layout() ); + m_startOnLogin = new TQCheckBox( i18n("Start TMix when Trinity starts"), startupCard ); + sl->addWidget( m_startOnLogin ); + m_confirmQuit = new TQCheckBox( i18n("Ask for confirmation before quitting"), startupCard ); + sl->addWidget( m_confirmQuit ); + gl->addWidget( startupCard ); gl->addStretch(); +} - // ---- View ---------------------------------------------------------------- - TQFrame *view = addPage( i18n("View") ); - TQVBoxLayout *vl = new TQVBoxLayout( view, marginHint(), spacingHint() ); - - m_noTabs = new TQCheckBox( i18n("Show all devices in one view (no tabs)"), view ); - vl->addWidget( m_noTabs ); - - vl->addSpacing( 8 ); - vl->addWidget( new TQLabel( i18n("Show tabs:"), view ) ); - m_showOutput = new TQCheckBox( i18n("Output"), view ); - m_showInput = new TQCheckBox( i18n("Input"), view ); - m_showPlayback = new TQCheckBox( i18n("Playback"), view ); - m_showRecording = new TQCheckBox( i18n("Recording"), view ); - vl->addWidget( m_showOutput ); - vl->addWidget( m_showInput ); - vl->addWidget( m_showPlayback ); - vl->addWidget( m_showRecording ); - vl->addStretch(); +// ── Backend settings page (stacked Pulse / ALSA) ────────────────────────────── - load(); +void PreferencesDlg::buildBackendPage() +{ + TQFrame *page = addPage( i18n("Audio Settings") ); + TQVBoxLayout *vl = new TQVBoxLayout( page, marginHint(), spacingHint() ); + + m_backendStack = new TQWidgetStack( page ); + vl->addWidget( m_backendStack ); + + // ── Pulse page (stack index 0) ──────────────────────────────────────────── + TQWidget *pulseWidget = new TQWidget( m_backendStack ); + TQVBoxLayout *pl = new TQVBoxLayout( pulseWidget, 0, spacingHint() ); + + TQGroupBox *popupBox = new TQGroupBox( i18n("Mini popup shows:"), pulseWidget ); + popupBox->setColumnLayout( 0, Qt::Vertical ); + popupBox->layout()->setSpacing( spacingHint() ); + popupBox->layout()->setMargin( marginHint() ); + TQVBoxLayout *pcl = new TQVBoxLayout( popupBox->layout() ); + m_popupShowOutput = new TQCheckBox( i18n("Default output (speakers/headphones)"), popupBox ); + m_popupShowMic = new TQCheckBox( i18n("Microphone inputs"), popupBox ); + m_popupShowApps = new TQCheckBox( i18n("Active app streams"), popupBox ); + pcl->addWidget( m_popupShowOutput ); + pcl->addWidget( m_popupShowMic ); + pcl->addWidget( m_popupShowApps ); + pl->addWidget( popupBox ); + + TQGroupBox *recBox = new TQGroupBox( i18n("Recording"), pulseWidget ); + recBox->setColumnLayout( 0, Qt::Vertical ); + recBox->layout()->setSpacing( spacingHint() ); + recBox->layout()->setMargin( marginHint() ); + TQVBoxLayout *rcl = new TQVBoxLayout( recBox->layout() ); + m_showRecTray = new TQCheckBox( i18n("Show microphone-in-use icon in tray"), recBox ); + rcl->addWidget( m_showRecTray ); + pl->addWidget( recBox ); + + pl->addSpacing( 8 ); + + TQGroupBox *viewBox = new TQGroupBox( i18n("View"), pulseWidget ); + viewBox->setColumnLayout( 0, Qt::Vertical ); + viewBox->layout()->setSpacing( spacingHint() ); + viewBox->layout()->setMargin( marginHint() ); + TQVBoxLayout *vbl = new TQVBoxLayout( viewBox->layout() ); + m_noTabs = new TQCheckBox( i18n("Show all devices in one view (no tabs)"), viewBox ); + connect( m_noTabs, TQ_SIGNAL(toggled(bool)), this, TQ_SLOT(onNoTabsToggled(bool)) ); + vbl->addWidget( m_noTabs ); + vbl->addSpacing( 4 ); + m_showTabsLabel = new TQLabel( i18n("Show tabs:"), viewBox ); + vbl->addWidget( m_showTabsLabel ); + m_showOutput = new TQCheckBox( i18n("Output"), viewBox ); + m_showInput = new TQCheckBox( i18n("Input"), viewBox ); + m_showPlayback = new TQCheckBox( i18n("Playback"), viewBox ); + m_showRecording = new TQCheckBox( i18n("Recording"), viewBox ); + vbl->addWidget( m_showOutput ); + vbl->addWidget( m_showInput ); + vbl->addWidget( m_showPlayback ); + vbl->addWidget( m_showRecording ); + pl->addWidget( viewBox ); + pl->addStretch(); + + m_backendStack->addWidget( pulseWidget, 0 ); + +#ifdef WITH_ALSA + // ── ALSA page (stack index 1) ───────────────────────────────────────────── + TQWidget *alsaWidget = new TQWidget( m_backendStack ); + TQVBoxLayout *al = new TQVBoxLayout( alsaWidget, 0, spacingHint() ); + + TQHBoxLayout *trayRow = new TQHBoxLayout( 0, 0, spacingHint() ); + trayRow->addWidget( new TQLabel( i18n("Tray device:"), alsaWidget ) ); + m_trayDevice = new TQComboBox( false, alsaWidget ); + + if ( m_alsaModel ) { + TQPtrList devs = m_alsaModel->devices(); + for ( TQPtrListIterator it(devs); *it; ++it ) { + AlsaDevice *dev = *it; + if ( dev->category() == AlsaDevice::Output && + dev->type() == AlsaDevice::Slider ) { + m_trayDevice->insertItem( + TQString("%1 - %2").arg(dev->cardName()).arg(dev->name()) ); + m_trayCardIndices.append( dev->cardIndex() ); + m_trayDeviceNames.append( dev->name() ); + } + } + } else { + m_trayDevice->setEnabled( false ); + } + + trayRow->addWidget( m_trayDevice, 1 ); + al->addLayout( trayRow ); + al->addStretch(); + + m_backendStack->addWidget( alsaWidget, 1 ); +#endif + + // Show the page matching the current backend + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("General"); + TQString backend = cfg->readEntry("Backend", "pulse"); + m_backendStack->raiseWidget( backend == "alsa" ? 1 : 0 ); + + connect( m_backend, TQ_SIGNAL(activated(int)), + this, TQ_SLOT(onBackendComboChanged(int)) ); } +// ── Slot: backend combo changed ─────────────────────────────────────────────── + +void PreferencesDlg::onBackendComboChanged( int idx ) +{ + m_backendStack->raiseWidget( idx ); +} + +void PreferencesDlg::onNoTabsToggled( bool checked ) +{ + bool tabsEnabled = !checked; + m_showTabsLabel->setEnabled( tabsEnabled ); + m_showOutput->setEnabled( tabsEnabled ); + m_showInput->setEnabled( tabsEnabled ); + m_showPlayback->setEnabled( tabsEnabled ); + m_showRecording->setEnabled( tabsEnabled ); +} + +// ── onPopupModeChanged ──────────────────────────────────────────────────────── + void PreferencesDlg::onPopupModeChanged( int idx ) { bool popupEnabled = ( idx == 1 ); - m_popupShowOutput->setEnabled( popupEnabled ); - m_popupShowMic->setEnabled( popupEnabled ); - m_popupShowApps->setEnabled( popupEnabled ); + if ( m_popupShowOutput ) m_popupShowOutput->setEnabled( popupEnabled ); + if ( m_popupShowMic ) m_popupShowMic->setEnabled( popupEnabled ); + if ( m_popupShowApps ) m_popupShowApps->setEnabled( popupEnabled ); } +// ── load / save ─────────────────────────────────────────────────────────────── + void PreferencesDlg::load() { TDEConfig *cfg = TDEGlobal::config(); - cfg->setGroup("General"); - m_dockInTray->setChecked( cfg->readBoolEntry("DockInTray", true) ); + + TQString backend = cfg->readEntry("Backend", "pulse"); + m_backend->setCurrentItem( backend == "alsa" ? 1 : 0 ); + m_confirmQuit->setChecked( cfg->readBoolEntry("ConfirmQuit", false) ); + m_startOnLogin->setChecked( TQFile::exists( autostartPath() ) ); + + cfg->setGroup("Tray"); + m_dockInTray->setChecked( cfg->readBoolEntry("DockInTray", true) ); int mode = cfg->readNumEntry("PopupMode", 1); m_popupMode->setCurrentItem( mode ); + onPopupModeChanged( mode ); + m_middleClickMute->setChecked( cfg->readBoolEntry("MiddleClickMute", false) ); + m_scrollStep->setValue( cfg->readNumEntry( "ScrollStep", 5 ) ); + m_popupShowOutput->setChecked( cfg->readBoolEntry("PopupShowOutput", true) ); m_popupShowMic->setChecked( cfg->readBoolEntry("PopupShowMic", false) ); m_popupShowApps->setChecked( cfg->readBoolEntry("PopupShowApps", true) ); - onPopupModeChanged( mode ); - m_showRecTray->setChecked( cfg->readBoolEntry("ShowRecordingTray", true) ); - m_confirmQuit->setChecked( cfg->readBoolEntry("ConfirmQuit", false) ); - m_scrollStep->setValue( cfg->readNumEntry( "ScrollStep", 5) ); + m_showRecTray->setChecked( cfg->readBoolEntry("ShowRecordingTray", true) ); cfg->setGroup("View"); m_noTabs->setChecked( cfg->readBoolEntry("NoTabs", false) ); @@ -120,21 +306,58 @@ void PreferencesDlg::load() m_showInput->setChecked( cfg->readBoolEntry("ShowInput", true) ); m_showPlayback->setChecked( cfg->readBoolEntry("ShowPlayback", true) ); m_showRecording->setChecked( cfg->readBoolEntry("ShowRecording", true) ); + +#ifdef WITH_ALSA + if ( m_trayDevice && !m_trayCardIndices.isEmpty() ) { + cfg->setGroup("Tray"); + int preferredCard = cfg->readNumEntry("TrayCard", -1); + TQString preferredName = cfg->readEntry( "TrayDevice", ""); + TQValueListConstIterator ci = m_trayCardIndices.begin(); + TQValueListConstIterator ni = m_trayDeviceNames.begin(); + for ( int i = 0; ci != m_trayCardIndices.end(); ++ci, ++ni, ++i ) { + if ( *ci == preferredCard && *ni == preferredName ) { + m_trayDevice->setCurrentItem(i); + break; + } + } + } +#endif } void PreferencesDlg::save() { TDEConfig *cfg = TDEGlobal::config(); - cfg->setGroup("General"); - cfg->writeEntry( "DockInTray", m_dockInTray->isChecked() ); - cfg->writeEntry( "PopupMode", m_popupMode->currentItem() ); - cfg->writeEntry( "PopupShowOutput", m_popupShowOutput->isChecked() ); - cfg->writeEntry( "PopupShowMic", m_popupShowMic->isChecked() ); - cfg->writeEntry( "PopupShowApps", m_popupShowApps->isChecked() ); - cfg->writeEntry( "ShowRecordingTray", m_showRecTray->isChecked() ); - cfg->writeEntry( "ConfirmQuit", m_confirmQuit->isChecked() ); - cfg->writeEntry( "ScrollStep", m_scrollStep->value() ); + cfg->writeEntry( "Backend", m_backend->currentItem() == 1 ? "alsa" : "pulse" ); + cfg->writeEntry( "ConfirmQuit", m_confirmQuit->isChecked() ); + + // Autostart: create or remove ~/.trinity/Autostart/tmix.desktop + TQString apath = autostartPath(); + if ( m_startOnLogin->isChecked() ) { + if ( !TQFile::exists( apath ) ) { + TQFile f( apath ); + if ( f.open( IO_WriteOnly ) ) { + TQTextStream ts( &f ); + ts << "[Desktop Entry]\n" + << "Type=Application\n" + << "Name=TMix\n" + << "Exec=tmix\n" + << "X-TDE-StartupNotify=false\n"; + } + } + } else { + TQFile::remove( apath ); + } + + cfg->setGroup("Tray"); + cfg->writeEntry( "DockInTray", m_dockInTray->isChecked() ); + cfg->writeEntry( "PopupMode", m_popupMode->currentItem() ); + cfg->writeEntry( "MiddleClickMute", m_middleClickMute->isChecked() ); + cfg->writeEntry( "ScrollStep", m_scrollStep->value() ); + cfg->writeEntry( "PopupShowOutput", m_popupShowOutput->isChecked() ); + cfg->writeEntry( "PopupShowMic", m_popupShowMic->isChecked() ); + cfg->writeEntry( "PopupShowApps", m_popupShowApps->isChecked() ); + cfg->writeEntry( "ShowRecordingTray", m_showRecTray->isChecked() ); cfg->setGroup("View"); cfg->writeEntry( "NoTabs", m_noTabs->isChecked() ); @@ -143,6 +366,18 @@ void PreferencesDlg::save() cfg->writeEntry( "ShowPlayback", m_showPlayback->isChecked() ); cfg->writeEntry( "ShowRecording", m_showRecording->isChecked() ); +#ifdef WITH_ALSA + if ( m_trayDevice && m_alsaModel ) { + int ti = m_trayDevice->currentItem(); + if ( ti >= 0 && ti < (int)m_trayCardIndices.count() ) { + TQValueListConstIterator ci = m_trayCardIndices.begin(); + TQValueListConstIterator ni = m_trayDeviceNames.begin(); + for ( int i = 0; i < ti; ++i ) { ++ci; ++ni; } + m_alsaModel->setPreferredOutput( *ci, *ni ); + } + } +#endif + cfg->sync(); emit settingsChanged(); } diff --git a/src/ui/preferencesdlg.h b/src/ui/preferencesdlg.h index 09d740f..93ac377 100644 --- a/src/ui/preferencesdlg.h +++ b/src/ui/preferencesdlg.h @@ -1,17 +1,30 @@ #pragma once #include +#include +#include class TQCheckBox; class TQComboBox; +class TQLabel; class TQSpinBox; +class TQWidgetStack; + +#ifdef WITH_ALSA +class AlsaModel; +#endif class PreferencesDlg : public KDialogBase { TQ_OBJECT public: - PreferencesDlg( TQWidget *parent = 0 ); + explicit PreferencesDlg( TQWidget *parent = 0 ); + +#ifdef WITH_ALSA + PreferencesDlg( AlsaModel *model, TQWidget *parent = 0 ); +#endif + void load(); signals: @@ -23,22 +36,42 @@ protected slots: private slots: void onPopupModeChanged( int idx ); + void onBackendComboChanged( int idx ); + void onNoTabsToggled( bool checked ); private: + void buildGeneralPage(); + void buildBackendPage(); void save(); - TQCheckBox *m_dockInTray; - TQComboBox *m_popupMode; + // General — shared + TQComboBox *m_backend; + TQCheckBox *m_dockInTray; + TQComboBox *m_popupMode; + TQSpinBox *m_scrollStep; + TQCheckBox *m_confirmQuit; + TQCheckBox *m_middleClickMute; + TQCheckBox *m_startOnLogin; + + // Backend settings stack + TQWidgetStack *m_backendStack; + + // Pulse widgets — always built, may be on the inactive stack page TQCheckBox *m_popupShowOutput; TQCheckBox *m_popupShowMic; TQCheckBox *m_popupShowApps; TQCheckBox *m_showRecTray; - TQCheckBox *m_confirmQuit; - TQSpinBox *m_scrollStep; - TQCheckBox *m_noTabs; + TQLabel *m_showTabsLabel; TQCheckBox *m_showOutput; TQCheckBox *m_showInput; TQCheckBox *m_showPlayback; TQCheckBox *m_showRecording; + +#ifdef WITH_ALSA + AlsaModel *m_alsaModel; + TQComboBox *m_trayDevice; + TQValueList m_trayCardIndices; + TQValueList m_trayDeviceNames; +#endif }; diff --git a/src/ui/tmixapp.cpp b/src/ui/tmixapp.cpp index 20c509e..2bed54a 100644 --- a/src/ui/tmixapp.cpp +++ b/src/ui/tmixapp.cpp @@ -1,5 +1,5 @@ #include "tmixapp.h" -#include "mixerwindow.h" +#include #include TmixApp::TmixApp() : KUniqueApplication(), m_win(0), m_firstInstance(true) {} diff --git a/src/ui/tmixapp.h b/src/ui/tmixapp.h index 8f41245..78b2687 100644 --- a/src/ui/tmixapp.h +++ b/src/ui/tmixapp.h @@ -1,8 +1,7 @@ #pragma once #include - -class MixerWindow; +#include class TmixApp : public KUniqueApplication { @@ -10,8 +9,8 @@ class TmixApp : public KUniqueApplication public: TmixApp(); int newInstance(); - void setMainWindow( MixerWindow *w ) { m_win = w; } + void setMainWindow( TQWidget *w ) { m_win = w; } private: - MixerWindow *m_win; - bool m_firstInstance; + TQWidget *m_win; + bool m_firstInstance; }; diff --git a/src/ui/tmixpopup.cpp b/src/ui/tmixpopup.cpp index 2cdd16a..29911fa 100644 --- a/src/ui/tmixpopup.cpp +++ b/src/ui/tmixpopup.cpp @@ -191,7 +191,7 @@ void TmixPopup::wheelEvent( TQWheelEvent *e ) AudioDevice *dev = m_model->defaultOutput(); if ( !dev ) return; TDEConfig *cfg = TDEGlobal::config(); - cfg->setGroup("General"); + cfg->setGroup("Tray"); int step = cfg->readNumEntry("ScrollStep", 5); int delta = e->delta() > 0 ? step : -step; int vol = TQMAX( 0, TQMIN( 100, dev->volume() + delta ) ); diff --git a/src/ui/tmixtray.cpp b/src/ui/tmixtray.cpp index f54961f..7603f37 100644 --- a/src/ui/tmixtray.cpp +++ b/src/ui/tmixtray.cpp @@ -14,7 +14,7 @@ protected: m_owner->toggleRecordingPopup(); e->accept(); } else { - KSystemTray::mousePressEvent( e ); + e->accept(); } } private: @@ -68,13 +68,15 @@ void TmixTray::setDevice( AudioDevice *dev ) void TmixTray::setModel( PulseModel *model ) { m_model = model; - TQPtrList inputs = model->devices( AudioDevice::Input ); - for ( TQPtrListIterator it(inputs); *it; ++it ) { - connect( *it, TQ_SIGNAL(recordingActiveChanged(bool)), - this, TQ_SLOT(onRecordingActive(bool)) ); - } connect( model, TQ_SIGNAL(deviceAdded(AudioDevice*)), this, TQ_SLOT(onDeviceAdded(AudioDevice*)) ); + connect( model, TQ_SIGNAL(deviceRemoved(AudioDevice*)), + this, TQ_SLOT(onDeviceRemoved(AudioDevice*)) ); + // Count any Recording devices already present (e.g. after reconnect). + TQPtrList recs = model->devices( AudioDevice::Recording ); + for ( TQPtrListIterator it(recs); *it; ++it ) + m_recordingCount++; + updateRecordingTray(); } void TmixTray::mousePressEvent( TQMouseEvent *e ) @@ -85,6 +87,15 @@ void TmixTray::mousePressEvent( TQMouseEvent *e ) e->accept(); return; } + if ( e->button() == TQt::MidButton && m_device ) { + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("Tray"); + if ( cfg->readBoolEntry("MiddleClickMute", false) ) { + m_device->setMuted( !m_device->muted() ); + e->accept(); + return; + } + } KSystemTray::mousePressEvent( e ); } @@ -92,7 +103,7 @@ void TmixTray::mousePressEvent( TQMouseEvent *e ) void TmixTray::executeSingleClick() { TDEConfig *cfg = TDEGlobal::config(); - cfg->setGroup("General"); + cfg->setGroup("Tray"); int mode = cfg->readNumEntry( "PopupMode", 1 ); bool showOutput = cfg->readBoolEntry("PopupShowOutput", true ); bool showMic = cfg->readBoolEntry("PopupShowMic", false ); @@ -141,24 +152,33 @@ void TmixTray::updateIcon() setPixmap( TQPixmap(path) ); } -void TmixTray::onRecordingActive( bool active ) +void TmixTray::onRecordingActive( bool /*active*/ ) { - m_recordingCount += active ? 1 : -1; - if ( m_recordingCount < 0 ) m_recordingCount = 0; - updateRecordingTray(); + // Kept for any future per-source signal use; recording count is now + // driven by onDeviceAdded/onDeviceRemoved for Recording devices. } void TmixTray::onDeviceAdded( AudioDevice *dev ) { - if ( dev->category() == AudioDevice::Input ) - connect( dev, TQ_SIGNAL(recordingActiveChanged(bool)), - this, TQ_SLOT(onRecordingActive(bool)) ); + if ( dev->category() == AudioDevice::Recording ) { + m_recordingCount++; + updateRecordingTray(); + } +} + +void TmixTray::onDeviceRemoved( AudioDevice *dev ) +{ + if ( dev->category() == AudioDevice::Recording ) { + if ( m_recordingCount > 0 ) + m_recordingCount--; + updateRecordingTray(); + } } void TmixTray::updateRecordingTray() { TDEConfig *cfg = TDEGlobal::config(); - cfg->setGroup("General"); + cfg->setGroup("Tray"); bool showRec = cfg->readBoolEntry("ShowRecordingTray", true); if ( m_recordingCount > 0 && showRec ) { @@ -213,7 +233,7 @@ void TmixTray::wheelEvent( TQWheelEvent *e ) { if ( !m_device ) return; TDEConfig *cfg = TDEGlobal::config(); - cfg->setGroup("General"); + cfg->setGroup("Tray"); int step = cfg->readNumEntry("ScrollStep", 5); int delta = e->delta() > 0 ? step : -step; int newVol = m_device->volume() + delta; @@ -229,12 +249,9 @@ void TmixTray::contextMenuAboutToShow( TDEPopupMenu *menu ) MixerWindow *win = static_cast( parentWidget() ); - TDEConfig *cfg = TDEGlobal::config(); - cfg->setGroup("General"); - if ( cfg->readNumEntry("PopupMode", 1) >= 1 ) - menu->insertItem( SmallIcon("tmix"), i18n("&Open Mixer"), - win, TQ_SLOT(bringToFront()) ); - + menu->insertItem( SmallIcon("tmix"), i18n("&Open Mixer"), + win, TQ_SLOT(bringToFront()) ); + menu->insertSeparator(); menu->insertItem( SmallIcon("configure"), i18n("&Configure TMix..."), win, TQ_SLOT(showPreferences()) ); menu->insertItem( SmallIcon("help"), i18n("&About TMix"), diff --git a/src/ui/tmixtray.h b/src/ui/tmixtray.h index f04450c..8e0f0a3 100644 --- a/src/ui/tmixtray.h +++ b/src/ui/tmixtray.h @@ -19,6 +19,7 @@ public slots: void updateIcon(); void onRecordingActive( bool active ); void onDeviceAdded( AudioDevice *dev ); + void onDeviceRemoved( AudioDevice *dev ); protected: void mousePressEvent( TQMouseEvent *e ); -- cgit v1.2.3 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/CMakeLists.txt | 18 +++- src/model/ossdevice.cpp | 89 +++++++++++++++++++ src/model/ossdevice.h | 51 +++++++++++ src/model/ossmodel.cpp | 140 ++++++++++++++++++++++++++++++ src/model/ossmodel.h | 50 +++++++++++ src/ui/backendcontroller.cpp | 58 +++++++++++++ src/ui/backendcontroller.h | 8 +- src/ui/oss/ossdevicewidget.cpp | 154 +++++++++++++++++++++++++++++++++ src/ui/oss/ossdevicewidget.h | 31 +++++++ src/ui/oss/ossmixerwindow.cpp | 192 +++++++++++++++++++++++++++++++++++++++++ src/ui/oss/ossmixerwindow.h | 53 ++++++++++++ src/ui/oss/osspopup.cpp | 78 +++++++++++++++++ src/ui/oss/osspopup.h | 30 +++++++ src/ui/oss/osstray.cpp | 129 +++++++++++++++++++++++++++ src/ui/oss/osstray.h | 34 ++++++++ src/ui/preferencesdlg.cpp | 142 +++++++++++++++++++++++++----- src/ui/preferencesdlg.h | 19 ++++ 17 files changed, 1251 insertions(+), 25 deletions(-) create mode 100644 src/model/ossdevice.cpp create mode 100644 src/model/ossdevice.h create mode 100644 src/model/ossmodel.cpp create mode 100644 src/model/ossmodel.h create mode 100644 src/ui/oss/ossdevicewidget.cpp create mode 100644 src/ui/oss/ossdevicewidget.h create mode 100644 src/ui/oss/ossmixerwindow.cpp create mode 100644 src/ui/oss/ossmixerwindow.h create mode 100644 src/ui/oss/osspopup.cpp create mode 100644 src/ui/oss/osspopup.h create mode 100644 src/ui/oss/osstray.cpp create mode 100644 src/ui/oss/osstray.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5e9ee2d..7a8fd38 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,10 +1,12 @@ include( FindPkgConfig ) +include( CheckIncludeFile ) pkg_check_modules( PULSE libpulse ) pkg_check_modules( ALSA alsa ) +check_include_file( "sys/soundcard.h" HAVE_OSS_HEADER ) -if( NOT PULSE_FOUND AND NOT ALSA_FOUND ) - message( FATAL_ERROR "Neither libpulse nor libasound found — cannot build tmix" ) +if( NOT PULSE_FOUND AND NOT ALSA_FOUND AND NOT HAVE_OSS_HEADER ) + message( FATAL_ERROR "No audio backend found (need libpulse, libasound, or sys/soundcard.h)" ) endif() set( TMIX_SOURCES @@ -63,6 +65,18 @@ if( ALSA_FOUND ) ) endif() +if( HAVE_OSS_HEADER ) + add_definitions( -DWITH_OSS ) + list( APPEND TMIX_SOURCES + model/ossdevice.cpp + model/ossmodel.cpp + ui/oss/ossdevicewidget.cpp + ui/oss/ossmixerwindow.cpp + ui/oss/osspopup.cpp + ui/oss/osstray.cpp + ) +endif() + include_directories( ${TMIX_INCLUDES} ) link_directories( diff --git a/src/model/ossdevice.cpp b/src/model/ossdevice.cpp new file mode 100644 index 0000000..6a3b70a --- /dev/null +++ b/src/model/ossdevice.cpp @@ -0,0 +1,89 @@ +#include "ossdevice.h" +#include +#include +#include +#include + +OssDevice::OssDevice( Category cat, int cardIdx, const TQString &cardPath, + int fd, int channelIdx, const TQString &name, bool stereo, + TQObject *parent ) + : TQObject(parent), m_fd(fd), m_cardIdx(cardIdx), m_cardPath(cardPath), + m_channelIdx(channelIdx), m_name(name), m_category(cat), + m_stereo(stereo), m_volume(0), m_savedVol(50), m_muted(false), m_pan(0) +{ + syncFromOss(); +} + +void OssDevice::syncFromOss() +{ + if ( m_fd < 0 ) return; + int val = 0; + if ( ::ioctl(m_fd, MIXER_READ(m_channelIdx), &val) < 0 ) return; + + int left = val & 0xff; + int right = (val >> 8) & 0xff; + int mx = std::max(left, right); + + if ( m_muted ) return; // don't overwrite display while muted + + int newVol = mx; + int newPan = 0; + if ( m_stereo && mx > 0 ) { + if ( left >= right ) + newPan = (int)std::lround( -50.0 * (1.0 - (double)right / left) ); + else + newPan = (int)std::lround( 50.0 * (1.0 - (double)left / right) ); + } + + if ( newVol != m_volume ) { m_volume = newVol; emit volumeChanged(m_volume); } + if ( newPan != m_pan ) { m_pan = newPan; emit panChanged(m_pan); } +} + +void OssDevice::pushVolume() +{ + if ( m_fd < 0 ) return; + int vol = m_muted ? 0 : m_volume; + double lf = m_pan >= 0 ? (50.0 - m_pan) / 50.0 : 1.0; + double rf = m_pan <= 0 ? (50.0 + m_pan) / 50.0 : 1.0; + int lv = (int)(vol * lf + 0.5); + int rv = (int)(vol * rf + 0.5); + if ( lv > 100 ) lv = 100; + if ( rv > 100 ) rv = 100; + int val = lv | (rv << 8); + ::ioctl(m_fd, MIXER_WRITE(m_channelIdx), &val); +} + +void OssDevice::setVolume( int v ) +{ + v = v < 0 ? 0 : v > 100 ? 100 : v; + m_volume = v; + if ( !m_muted ) m_savedVol = v; + emit volumeChanged(v); + pushVolume(); +} + +void OssDevice::setMuted( bool m ) +{ + if ( m == m_muted ) return; + if ( m ) { + if ( m_volume > 0 ) m_savedVol = m_volume; + m_muted = true; + pushVolume(); + } else { + m_muted = false; + m_volume = m_savedVol; + pushVolume(); + emit volumeChanged(m_volume); + } + emit muteChanged(m_muted); +} + +void OssDevice::setPan( int p ) +{ + p = p < -50 ? -50 : p > 50 ? 50 : p; + m_pan = p; + emit panChanged(p); + pushVolume(); +} + +#include "ossdevice.moc" diff --git a/src/model/ossdevice.h b/src/model/ossdevice.h new file mode 100644 index 0000000..66a0d1b --- /dev/null +++ b/src/model/ossdevice.h @@ -0,0 +1,51 @@ +#pragma once + +#include +#include + +class OssDevice : public TQObject +{ + TQ_OBJECT +public: + enum Category { Output, Input }; + + OssDevice( Category cat, int cardIdx, const TQString &cardPath, + int fd, int channelIdx, const TQString &name, bool stereo, + TQObject *parent = 0 ); + + TQString name() const { return m_name; } + TQString cardPath() const { return m_cardPath; } + int cardIndex() const { return m_cardIdx; } + Category category() const { return m_category; } + int volume() const { return m_volume; } + bool muted() const { return m_muted; } + int pan() const { return m_pan; } + bool stereo() const { return m_stereo; } + bool hasMute() const { return true; } + + void setVolume( int v ); + void setMuted( bool m ); + void setPan( int p ); + + void syncFromOss(); + +signals: + void volumeChanged( int v ); + void muteChanged( bool m ); + void panChanged( int p ); + +private: + void pushVolume(); + + int m_fd; // borrowed from OssModel — do not close + int m_cardIdx; + TQString m_cardPath; + int m_channelIdx; + TQString m_name; + Category m_category; + bool m_stereo; + int m_volume; + int m_savedVol; // pre-mute volume for fake-mute + bool m_muted; + int m_pan; +}; diff --git a/src/model/ossmodel.cpp b/src/model/ossmodel.cpp new file mode 100644 index 0000000..35aa842 --- /dev/null +++ b/src/model/ossmodel.cpp @@ -0,0 +1,140 @@ +#include "ossmodel.h" +#include +#include +#include +#include +#include +#include +#include +#include + +static const char *ossChannelNames[] = SOUND_DEVICE_NAMES; + +OssModel::OssModel( TQObject *parent ) + : TQObject(parent), m_timer(0) +{ + m_devices.setAutoDelete(true); + m_timer = new TQTimer(this); + connect(m_timer, TQ_SIGNAL(timeout()), this, TQ_SLOT(onPollTimer())); +} + +OssModel::~OssModel() +{ + close(); +} + +bool OssModel::open() +{ + openCard(0, "/dev/mixer"); + for ( int i = 1; i < 16; ++i ) { + char path[32]; + snprintf(path, sizeof(path), "/dev/mixer%d", i); + int probe = ::open(path, O_RDONLY); + if ( probe < 0 ) break; + ::close(probe); + openCard(i, TQString::fromLocal8Bit(path)); + } + if ( m_devices.isEmpty() ) return false; + m_timer->start(500); + emit ready(); + return true; +} + +void OssModel::openCard( int cardIdx, const TQString &path ) +{ + int fd = ::open(path.local8Bit().data(), O_RDWR); + if ( fd < 0 ) return; + + mixer_info info; + TQString cardName; + if ( ::ioctl(fd, SOUND_MIXER_INFO, &info) == 0 ) + cardName = TQString::fromLocal8Bit(info.name); + else + cardName = path; + + int devmask = 0, stmask = 0, recmask = 0; + ::ioctl(fd, SOUND_MIXER_READ_DEVMASK, &devmask); + ::ioctl(fd, SOUND_MIXER_READ_STEREODEVS, &stmask); + ::ioctl(fd, SOUND_MIXER_READ_RECMASK, &recmask); + + OssCard card; + card.index = cardIdx; + card.path = path; + card.name = cardName; + m_cards.append(card); + m_fds.append(fd); + + for ( int i = 0; i < SOUND_MIXER_NRDEVICES; ++i ) { + if ( !(devmask & (1 << i)) ) continue; + OssDevice::Category cat = (recmask & (1 << i)) + ? OssDevice::Input : OssDevice::Output; + bool stereo = (stmask & (1 << i)) != 0; + TQString name = TQString::fromLocal8Bit(ossChannelNames[i]); + OssDevice *dev = new OssDevice(cat, cardIdx, path, fd, i, name, stereo, this); + m_devices.append(dev); + emit deviceAdded(dev); + } +} + +void OssModel::onPollTimer() +{ + for ( TQPtrListIterator it(m_devices); *it; ++it ) + (*it)->syncFromOss(); +} + +void OssModel::close() +{ + if ( m_timer ) m_timer->stop(); + m_devices.clear(); + m_cards.clear(); + for ( TQValueListIterator it = m_fds.begin(); it != m_fds.end(); ++it ) + ::close(*it); + m_fds.clear(); +} + +TQPtrList OssModel::devicesForCard( int cardIdx ) const +{ + TQPtrList result; + for ( TQPtrListIterator it(m_devices); *it; ++it ) + if ( (*it)->cardIndex() == cardIdx ) + result.append(*it); + return result; +} + +OssDevice *OssModel::defaultOutput() const +{ + for ( TQPtrListIterator it(m_devices); *it; ++it ) + if ( (*it)->category() == OssDevice::Output && (*it)->name() == "vol" ) + return *it; + for ( TQPtrListIterator it(m_devices); *it; ++it ) + if ( (*it)->category() == OssDevice::Output ) + return *it; + return 0; +} + +OssDevice *OssModel::preferredOutput() const +{ + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("OssTray"); + int card = cfg->readNumEntry("TrayCard", -1); + TQString name = cfg->readEntry("TrayDevice", ""); + if ( card >= 0 && !name.isEmpty() ) { + for ( TQPtrListIterator it(m_devices); *it; ++it ) + if ( (*it)->cardIndex() == card && (*it)->name() == name && + (*it)->category() == OssDevice::Output ) + return *it; + } + return defaultOutput(); +} + +void OssModel::setPreferredOutput( int cardIdx, const TQString &name ) +{ + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("OssTray"); + cfg->writeEntry("TrayCard", cardIdx); + cfg->writeEntry("TrayDevice", name); + cfg->sync(); + emit preferredOutputChanged( preferredOutput() ); +} + +#include "ossmodel.moc" diff --git a/src/model/ossmodel.h b/src/model/ossmodel.h new file mode 100644 index 0000000..8c3db8b --- /dev/null +++ b/src/model/ossmodel.h @@ -0,0 +1,50 @@ +#pragma once + +#include +#include +#include +#include + +#include "ossdevice.h" + +class TQTimer; + +struct OssCard { + int index; + TQString path; + TQString name; +}; + +class OssModel : public TQObject +{ + TQ_OBJECT +public: + explicit OssModel( TQObject *parent = 0 ); + ~OssModel(); + + bool open(); + void close(); + + TQValueList cards() const { return m_cards; } + TQPtrList devices() const { return m_devices; } + TQPtrList devicesForCard( int cardIdx ) const; + OssDevice *defaultOutput() const; + OssDevice *preferredOutput() const; + void setPreferredOutput( int cardIdx, const TQString &name ); + +signals: + void deviceAdded( OssDevice *dev ); + void preferredOutputChanged( OssDevice *dev ); + void ready(); + +private slots: + void onPollTimer(); + +private: + void openCard( int cardIdx, const TQString &path ); + + TQValueList m_cards; + TQPtrList m_devices; + TQValueList m_fds; // one open fd per card, owned here + TQTimer *m_timer; +}; diff --git a/src/ui/backendcontroller.cpp b/src/ui/backendcontroller.cpp index 3a41b8d..037c797 100644 --- a/src/ui/backendcontroller.cpp +++ b/src/ui/backendcontroller.cpp @@ -17,6 +17,12 @@ #include "alsa/alsatray.h" #endif +#ifdef WITH_OSS +#include "../model/ossmodel.h" +#include "oss/ossmixerwindow.h" +#include "oss/osstray.h" +#endif + BackendController::BackendController( TQObject *parent ) : TQObject(parent) #ifdef WITH_PULSE @@ -25,6 +31,9 @@ BackendController::BackendController( TQObject *parent ) #ifdef WITH_ALSA , m_alsaModel(0), m_alsaWin(0), m_alsaTray(0) #endif +#ifdef WITH_OSS + , m_ossModel(0), m_ossWin(0), m_ossTray(0) +#endif {} BackendController::~BackendController() @@ -41,6 +50,9 @@ void BackendController::start() #ifdef WITH_ALSA if ( m_currentBackend == "alsa" ) { startAlsa(); return; } #endif +#ifdef WITH_OSS + if ( m_currentBackend == "oss" ) { startOss(); return; } +#endif #ifdef WITH_PULSE startPulse(); #endif @@ -53,6 +65,11 @@ void BackendController::stop() if ( m_alsaWin ) { delete m_alsaWin; m_alsaWin = 0; } if ( m_alsaModel ) { delete m_alsaModel; m_alsaModel = 0; } #endif +#ifdef WITH_OSS + if ( m_ossTray ) { delete m_ossTray; m_ossTray = 0; } + if ( m_ossWin ) { delete m_ossWin; m_ossWin = 0; } + if ( m_ossModel ) { delete m_ossModel; m_ossModel = 0; } +#endif #ifdef WITH_PULSE // Model first: stops the PA mainloop thread before any widget is destroyed. if ( m_pulseModel ) { delete m_pulseModel; m_pulseModel = 0; } @@ -109,6 +126,33 @@ void BackendController::startAlsa( bool showWindow ) } #endif +#ifdef WITH_OSS +void BackendController::startOss( bool showWindow ) +{ + m_ossModel = new OssModel( this ); + if ( !m_ossModel->open() ) { + delete m_ossModel; + m_ossModel = 0; + return; + } + m_ossWin = new OssMixerWindow( m_ossModel ); + connect( m_ossWin, TQ_SIGNAL(settingsChanged()), + this, TQ_SLOT(onSettingsChanged()) ); + static_cast(kapp)->setMainWindow( m_ossWin ); + + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("Tray"); + bool dockInTray = cfg->readBoolEntry("DockInTray", true); + if ( dockInTray ) { + m_ossTray = new OssTray( m_ossModel, m_ossWin, m_ossWin ); + m_ossWin->setTray( m_ossTray ); + m_ossTray->show(); + } + if ( !dockInTray || showWindow ) + m_ossWin->show(); +} +#endif + void BackendController::onSettingsChanged() { TDEConfig *cfg = TDEGlobal::config(); @@ -148,12 +192,26 @@ void BackendController::doSwitch() } } #endif +#ifdef WITH_OSS + if ( m_ossWin ) { + wasVisible = wasVisible || m_ossWin->isVisible(); + if ( m_ossWin->isVisible() ) { + cfg->setGroup("MainWindow"); + cfg->writeEntry("XPos", m_ossWin->x()); + cfg->writeEntry("YPos", m_ossWin->y()); + cfg->sync(); + } + } +#endif stop(); #ifdef WITH_ALSA if ( m_currentBackend == "alsa" ) { startAlsa( wasVisible ); return; } #endif +#ifdef WITH_OSS + if ( m_currentBackend == "oss" ) { startOss( wasVisible ); return; } +#endif #ifdef WITH_PULSE startPulse( wasVisible ); #endif diff --git a/src/ui/backendcontroller.h b/src/ui/backendcontroller.h index a6cfe6c..5938fdd 100644 --- a/src/ui/backendcontroller.h +++ b/src/ui/backendcontroller.h @@ -23,7 +23,8 @@ private slots: private: void stop(); void startPulse( bool showWindow = false ); - void startAlsa( bool showWindow = false ); + void startAlsa( bool showWindow = false ); + void startOss( bool showWindow = false ); TQString m_currentBackend; @@ -36,4 +37,9 @@ private: class AlsaMixerWindow *m_alsaWin; class AlsaTray *m_alsaTray; #endif +#ifdef WITH_OSS + class OssModel *m_ossModel; + class OssMixerWindow *m_ossWin; + class OssTray *m_ossTray; +#endif }; 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 +#include +#include +#include +#include +#include +#include + +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 + +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 +#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" 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 +#include +#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 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 +#include +#include +#include +#include +#include + +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 +#include + +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 +#include +#include +#include +#include +#include +#include +#include + +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 + +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; +}; diff --git a/src/ui/preferencesdlg.cpp b/src/ui/preferencesdlg.cpp index fa69bd3..9797c93 100644 --- a/src/ui/preferencesdlg.cpp +++ b/src/ui/preferencesdlg.cpp @@ -29,22 +29,32 @@ static TQString autostartPath() #include "../model/alsadevice.h" #endif +#ifdef WITH_OSS +#include "../model/ossmodel.h" +#include "../model/ossdevice.h" +#endif + +#define PREFS_INIT_LIST \ + m_backend(0), m_dockInTray(0), m_popupMode(0), \ + m_scrollStep(0), m_confirmQuit(0), m_middleClickMute(0), \ + m_startOnLogin(0), m_backendStack(0), \ + m_popupShowOutput(0), m_popupShowMic(0), m_popupShowApps(0), \ + m_showRecTray(0), \ + m_noTabs(0), m_showTabsLabel(0), m_showOutput(0), m_showInput(0), \ + m_showPlayback(0), m_showRecording(0) + // ── Pulse constructor ───────────────────────────────────────────────────────── PreferencesDlg::PreferencesDlg( TQWidget *parent ) : KDialogBase( Tabbed, i18n("Configure TMix"), Ok | Apply | Cancel, Ok, parent, 0, false ), - m_backend(0), m_dockInTray(0), m_popupMode(0), - m_scrollStep(0), m_confirmQuit(0), m_middleClickMute(0), - m_startOnLogin(0), - m_backendStack(0), - m_popupShowOutput(0), m_popupShowMic(0), m_popupShowApps(0), - m_showRecTray(0), - m_noTabs(0), m_showTabsLabel(0), m_showOutput(0), m_showInput(0), - m_showPlayback(0), m_showRecording(0) + PREFS_INIT_LIST #ifdef WITH_ALSA , m_alsaModel(0), m_trayDevice(0) #endif +#ifdef WITH_OSS + , m_ossModel(0), m_ossTrayDevice(0) +#endif { buildGeneralPage(); buildBackendPage(); @@ -58,15 +68,31 @@ PreferencesDlg::PreferencesDlg( TQWidget *parent ) PreferencesDlg::PreferencesDlg( AlsaModel *model, TQWidget *parent ) : KDialogBase( Tabbed, i18n("Configure TMix"), Ok | Apply | Cancel, Ok, parent, 0, false ), - m_backend(0), m_dockInTray(0), m_popupMode(0), - m_scrollStep(0), m_confirmQuit(0), m_middleClickMute(0), - m_startOnLogin(0), - m_backendStack(0), - m_popupShowOutput(0), m_popupShowMic(0), m_popupShowApps(0), - m_showRecTray(0), - m_noTabs(0), m_showTabsLabel(0), m_showOutput(0), m_showInput(0), - m_showPlayback(0), m_showRecording(0), + PREFS_INIT_LIST, m_alsaModel(model), m_trayDevice(0) +#ifdef WITH_OSS + , m_ossModel(0), m_ossTrayDevice(0) +#endif +{ + buildGeneralPage(); + buildBackendPage(); + load(); +} + +#endif + +#ifdef WITH_OSS + +// ── OSS constructor ─────────────────────────────────────────────────────────── + +PreferencesDlg::PreferencesDlg( OssModel *model, TQWidget *parent ) + : KDialogBase( Tabbed, i18n("Configure TMix"), + Ok | Apply | Cancel, Ok, parent, 0, false ), + PREFS_INIT_LIST +#ifdef WITH_ALSA + , m_alsaModel(0), m_trayDevice(0) +#endif + , m_ossModel(model), m_ossTrayDevice(0) { buildGeneralPage(); buildBackendPage(); @@ -85,9 +111,17 @@ void PreferencesDlg::buildGeneralPage() TQHBoxLayout *backendRow = new TQHBoxLayout( 0, 0, spacingHint() ); backendRow->addWidget( new TQLabel( i18n("Audio backend:"), gen ) ); m_backend = new TQComboBox( false, gen ); +#ifdef WITH_PULSE m_backend->insertItem( i18n("PulseAudio") ); + m_backendIds << "pulse"; +#endif #ifdef WITH_ALSA m_backend->insertItem( i18n("ALSA") ); + m_backendIds << "alsa"; +#endif +#ifdef WITH_OSS + m_backend->insertItem( i18n("OSS") ); + m_backendIds << "oss"; #endif backendRow->addWidget( m_backend ); backendRow->addStretch(); @@ -204,10 +238,11 @@ void PreferencesDlg::buildBackendPage() pl->addWidget( viewBox ); pl->addStretch(); - m_backendStack->addWidget( pulseWidget, 0 ); + int nextPage = 0; + m_backendStack->addWidget( pulseWidget, nextPage++ ); #ifdef WITH_ALSA - // ── ALSA page (stack index 1) ───────────────────────────────────────────── + // ── ALSA page ──────────────────────────────────────────────────────────── TQWidget *alsaWidget = new TQWidget( m_backendStack ); TQVBoxLayout *al = new TQVBoxLayout( alsaWidget, 0, spacingHint() ); @@ -235,14 +270,46 @@ void PreferencesDlg::buildBackendPage() al->addLayout( trayRow ); al->addStretch(); - m_backendStack->addWidget( alsaWidget, 1 ); + m_backendStack->addWidget( alsaWidget, nextPage++ ); +#endif + +#ifdef WITH_OSS + // ── OSS page ───────────────────────────────────────────────────────────── + TQWidget *ossWidget = new TQWidget( m_backendStack ); + TQVBoxLayout *ol = new TQVBoxLayout( ossWidget, 0, spacingHint() ); + + TQHBoxLayout *ossTrayRow = new TQHBoxLayout( 0, 0, spacingHint() ); + ossTrayRow->addWidget( new TQLabel( i18n("Tray device:"), ossWidget ) ); + m_ossTrayDevice = new TQComboBox( false, ossWidget ); + + if ( m_ossModel ) { + TQPtrList devs = m_ossModel->devices(); + for ( TQPtrListIterator it(devs); *it; ++it ) { + OssDevice *dev = *it; + if ( dev->category() == OssDevice::Output ) { + m_ossTrayDevice->insertItem( + TQString("%1 - %2").arg(dev->cardPath()).arg(dev->name()) ); + m_ossTrayCardIndices.append( dev->cardIndex() ); + m_ossTrayDeviceNames.append( dev->name() ); + } + } + } else { + m_ossTrayDevice->setEnabled( false ); + } + + ossTrayRow->addWidget( m_ossTrayDevice, 1 ); + ol->addLayout( ossTrayRow ); + ol->addStretch(); + + m_backendStack->addWidget( ossWidget, nextPage++ ); #endif // Show the page matching the current backend TDEConfig *cfg = TDEGlobal::config(); cfg->setGroup("General"); TQString backend = cfg->readEntry("Backend", "pulse"); - m_backendStack->raiseWidget( backend == "alsa" ? 1 : 0 ); + int backendPage = m_backendIds.findIndex(backend); + m_backendStack->raiseWidget( backendPage >= 0 ? backendPage : 0 ); connect( m_backend, TQ_SIGNAL(activated(int)), this, TQ_SLOT(onBackendComboChanged(int)) ); @@ -283,7 +350,8 @@ void PreferencesDlg::load() cfg->setGroup("General"); TQString backend = cfg->readEntry("Backend", "pulse"); - m_backend->setCurrentItem( backend == "alsa" ? 1 : 0 ); + int backendIdx = m_backendIds.findIndex(backend); + m_backend->setCurrentItem( backendIdx >= 0 ? backendIdx : 0 ); m_confirmQuit->setChecked( cfg->readBoolEntry("ConfirmQuit", false) ); m_startOnLogin->setChecked( TQFile::exists( autostartPath() ) ); @@ -322,13 +390,31 @@ void PreferencesDlg::load() } } #endif + +#ifdef WITH_OSS + if ( m_ossTrayDevice && !m_ossTrayCardIndices.isEmpty() ) { + cfg->setGroup("OssTray"); + int preferredCard = cfg->readNumEntry("TrayCard", -1); + TQString preferredName = cfg->readEntry( "TrayDevice", ""); + TQValueListConstIterator ci = m_ossTrayCardIndices.begin(); + TQValueListConstIterator ni = m_ossTrayDeviceNames.begin(); + for ( int i = 0; ci != m_ossTrayCardIndices.end(); ++ci, ++ni, ++i ) { + if ( *ci == preferredCard && *ni == preferredName ) { + m_ossTrayDevice->setCurrentItem(i); + break; + } + } + } +#endif } void PreferencesDlg::save() { TDEConfig *cfg = TDEGlobal::config(); cfg->setGroup("General"); - cfg->writeEntry( "Backend", m_backend->currentItem() == 1 ? "alsa" : "pulse" ); + int bi = m_backend->currentItem(); + TQString backendKey = (bi >= 0 && bi < (int)m_backendIds.count()) ? m_backendIds[bi] : "pulse"; + cfg->writeEntry( "Backend", backendKey ); cfg->writeEntry( "ConfirmQuit", m_confirmQuit->isChecked() ); // Autostart: create or remove ~/.trinity/Autostart/tmix.desktop @@ -378,6 +464,18 @@ void PreferencesDlg::save() } #endif +#ifdef WITH_OSS + if ( m_ossTrayDevice && m_ossModel ) { + int ti = m_ossTrayDevice->currentItem(); + if ( ti >= 0 && ti < (int)m_ossTrayCardIndices.count() ) { + TQValueListConstIterator ci = m_ossTrayCardIndices.begin(); + TQValueListConstIterator ni = m_ossTrayDeviceNames.begin(); + for ( int i = 0; i < ti; ++i ) { ++ci; ++ni; } + m_ossModel->setPreferredOutput( *ci, *ni ); + } + } +#endif + cfg->sync(); emit settingsChanged(); } diff --git a/src/ui/preferencesdlg.h b/src/ui/preferencesdlg.h index 93ac377..85f59c3 100644 --- a/src/ui/preferencesdlg.h +++ b/src/ui/preferencesdlg.h @@ -3,6 +3,7 @@ #include #include #include +#include class TQCheckBox; class TQComboBox; @@ -14,6 +15,10 @@ class TQWidgetStack; class AlsaModel; #endif +#ifdef WITH_OSS +class OssModel; +#endif + class PreferencesDlg : public KDialogBase { TQ_OBJECT @@ -25,6 +30,10 @@ public: PreferencesDlg( AlsaModel *model, TQWidget *parent = 0 ); #endif +#ifdef WITH_OSS + PreferencesDlg( OssModel *model, TQWidget *parent = 0 ); +#endif + void load(); signals: @@ -44,6 +53,9 @@ private: void buildBackendPage(); void save(); + // Maps combo index → backend key ("pulse", "alsa", "oss") + TQStringList m_backendIds; + // General — shared TQComboBox *m_backend; TQCheckBox *m_dockInTray; @@ -74,4 +86,11 @@ private: TQValueList m_trayCardIndices; TQValueList m_trayDeviceNames; #endif + +#ifdef WITH_OSS + OssModel *m_ossModel; + TQComboBox *m_ossTrayDevice; + TQValueList m_ossTrayCardIndices; + TQValueList m_ossTrayDeviceNames; +#endif }; -- cgit v1.2.3 From 30ea77bff2c64b9c0e6262679199d0cb445c98fe Mon Sep 17 00:00:00 2001 From: Calvin Morrison Date: Thu, 21 May 2026 10:18:57 -0400 Subject: wall werr whatever --- CMakeLists.txt | 2 +- src/model/pulsemodel.cpp | 5 ++--- src/ui/mixerwindow.cpp | 3 +-- 3 files changed, 4 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/CMakeLists.txt b/CMakeLists.txt index 773b32f..80e5966 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ include( FindPkgConfig ) find_package( TQt ) find_package( TDE ) -set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TQT_CXX_FLAGS}" ) +set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TQT_CXX_FLAGS} -Wall -Wextra -Werror -Wno-nonnull-compare" ) ##### subdirectories ############################ diff --git a/src/model/pulsemodel.cpp b/src/model/pulsemodel.cpp index 24c1af8..4e73473 100644 --- a/src/model/pulsemodel.cpp +++ b/src/model/pulsemodel.cpp @@ -573,11 +573,10 @@ void PulseModel::customEvent( TQCustomEvent *e ) PulseDevice *dev = findDevice( *list, ev->paIndex ); if ( dev ) { // Remove from name maps if present. - TQMap::Iterator it; - for ( it = m_sinksByName.begin(); it != m_sinksByName.end(); ++it ) { + for ( TQMap::Iterator it = m_sinksByName.begin(); it != m_sinksByName.end(); ++it ) { if ( it.data() == dev ) { m_sinksByName.remove(it); break; } } - for ( it = m_sourcesByName.begin(); it != m_sourcesByName.end(); ++it ) { + for ( TQMap::Iterator it = m_sourcesByName.begin(); it != m_sourcesByName.end(); ++it ) { if ( it.data() == dev ) { m_sourcesByName.remove(it); break; } } // Clean up port tracking maps. diff --git a/src/ui/mixerwindow.cpp b/src/ui/mixerwindow.cpp index 12a6666..4e84005 100644 --- a/src/ui/mixerwindow.cpp +++ b/src/ui/mixerwindow.cpp @@ -365,8 +365,7 @@ void MixerWindow::showPreferences() void MixerWindow::rebuildView() { // Tear down all existing device widgets - TQMap::iterator it; - for ( it = m_widgets.begin(); it != m_widgets.end(); ++it ) + for ( TQMap::iterator it = m_widgets.begin(); it != m_widgets.end(); ++it ) delete it.data(); m_widgets.clear(); m_output.count = m_input.count = m_playback.count = m_recording.count = 0; -- cgit v1.2.3 From dd3f8434813e851d941df9d5e22d14d8f97aaeba Mon Sep 17 00:00:00 2001 From: Calvin Morrison Date: Thu, 21 May 2026 12:56:39 -0400 Subject: Qt->TQt --- src/ui/devicespage.cpp | 6 +++--- src/ui/mixerwindow.cpp | 2 +- src/ui/preferencesdlg.cpp | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/ui/devicespage.cpp b/src/ui/devicespage.cpp index 6ae12e6..fd61acb 100644 --- a/src/ui/devicespage.cpp +++ b/src/ui/devicespage.cpp @@ -38,8 +38,8 @@ static TQPixmap availDot( bool plugged, int size ) TQBitmap mask( size, size, true ); { TQPainter mp( &mask ); - mp.setBrush( Qt::color1 ); - mp.setPen( Qt::NoPen ); + mp.setBrush(TQt::color1 ); + mp.setPen(TQt::NoPen ); mp.drawEllipse( 1, 1, size-2, size-2 ); } pm.setMask( mask ); @@ -89,7 +89,7 @@ void DevicesPage::rebuild() PulseCardInfo &info = *it; TQGroupBox *grp = new TQGroupBox( info.description, m_container ); - grp->setColumnLayout( 0, Qt::Vertical ); + grp->setColumnLayout( 0, TQt::Vertical ); grp->layout()->setSpacing( 4 ); grp->layout()->setMargin( 8 ); vbox->addWidget( grp ); diff --git a/src/ui/mixerwindow.cpp b/src/ui/mixerwindow.cpp index 4e84005..57dfbfc 100644 --- a/src/ui/mixerwindow.cpp +++ b/src/ui/mixerwindow.cpp @@ -107,7 +107,7 @@ MixerWindow::MixerWindow( PulseModel *model, TQWidget *parent ) TQWidget *waitPage = new TQWidget( m_outerStack ); TQVBoxLayout *waitLayout = new TQVBoxLayout( waitPage, 0, 0 ); m_waitLabel = new TQLabel( i18n("Waiting for PulseAudio to start..."), waitPage ); - m_waitLabel->setAlignment( Qt::AlignCenter ); + m_waitLabel->setAlignment( TQt::AlignCenter ); waitLayout->addWidget( m_waitLabel ); m_outerStack->addWidget( waitPage, 2 ); diff --git a/src/ui/preferencesdlg.cpp b/src/ui/preferencesdlg.cpp index 9797c93..1167f97 100644 --- a/src/ui/preferencesdlg.cpp +++ b/src/ui/preferencesdlg.cpp @@ -130,7 +130,7 @@ void PreferencesDlg::buildGeneralPage() gl->addSpacing( 8 ); TQGroupBox *trayCard = new TQGroupBox( i18n("System Tray"), gen ); - trayCard->setColumnLayout( 0, Qt::Vertical ); + trayCard->setColumnLayout( 0, TQt::Vertical ); trayCard->layout()->setSpacing( spacingHint() ); trayCard->layout()->setMargin( marginHint() ); TQVBoxLayout *tl = new TQVBoxLayout( trayCard->layout() ); @@ -165,7 +165,7 @@ void PreferencesDlg::buildGeneralPage() gl->addSpacing( 4 ); TQGroupBox *startupCard = new TQGroupBox( i18n("Startup / Exit"), gen ); - startupCard->setColumnLayout( 0, Qt::Vertical ); + startupCard->setColumnLayout( 0, TQt::Vertical ); startupCard->layout()->setSpacing( spacingHint() ); startupCard->layout()->setMargin( marginHint() ); TQVBoxLayout *sl = new TQVBoxLayout( startupCard->layout() ); @@ -193,7 +193,7 @@ void PreferencesDlg::buildBackendPage() TQVBoxLayout *pl = new TQVBoxLayout( pulseWidget, 0, spacingHint() ); TQGroupBox *popupBox = new TQGroupBox( i18n("Mini popup shows:"), pulseWidget ); - popupBox->setColumnLayout( 0, Qt::Vertical ); + popupBox->setColumnLayout( 0, TQt::Vertical ); popupBox->layout()->setSpacing( spacingHint() ); popupBox->layout()->setMargin( marginHint() ); TQVBoxLayout *pcl = new TQVBoxLayout( popupBox->layout() ); @@ -206,7 +206,7 @@ void PreferencesDlg::buildBackendPage() pl->addWidget( popupBox ); TQGroupBox *recBox = new TQGroupBox( i18n("Recording"), pulseWidget ); - recBox->setColumnLayout( 0, Qt::Vertical ); + recBox->setColumnLayout( 0, TQt::Vertical ); recBox->layout()->setSpacing( spacingHint() ); recBox->layout()->setMargin( marginHint() ); TQVBoxLayout *rcl = new TQVBoxLayout( recBox->layout() ); @@ -217,7 +217,7 @@ void PreferencesDlg::buildBackendPage() pl->addSpacing( 8 ); TQGroupBox *viewBox = new TQGroupBox( i18n("View"), pulseWidget ); - viewBox->setColumnLayout( 0, Qt::Vertical ); + viewBox->setColumnLayout( 0, TQt::Vertical ); viewBox->layout()->setSpacing( spacingHint() ); viewBox->layout()->setMargin( marginHint() ); TQVBoxLayout *vbl = new TQVBoxLayout( viewBox->layout() ); -- cgit v1.2.3 From 4c5ab244331bef95f20f04d174ae70c6cffbc252 Mon Sep 17 00:00:00 2001 From: Calvin Morrison Date: Thu, 21 May 2026 13:12:05 -0400 Subject: add missingle recording flag --- src/ui/tmixtray.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/ui/tmixtray.cpp b/src/ui/tmixtray.cpp index 7603f37..db04de1 100644 --- a/src/ui/tmixtray.cpp +++ b/src/ui/tmixtray.cpp @@ -122,7 +122,7 @@ void TmixTray::executeSingleClick() m_popupShowOutput = showOutput; m_popupShowMic = showMic; m_popupShowApps = showApps; - m_popup = new TmixPopup( m_model, showOutput, showMic, showApps, this ); + m_popup = new TmixPopup( m_model, showOutput, showMic, showApps, false, this ); } if ( m_popup->justHidden() ) return; m_popup->toggleAt( mapToGlobal( TQPoint(0,0) ), size() ); -- cgit v1.2.3 From d9876849f0208291cc7010522e85593703ff52bd Mon Sep 17 00:00:00 2001 From: Calvin Morrison Date: Thu, 21 May 2026 13:47:54 -0400 Subject: add options for Cmake to which audio libraries to build --- src/CMakeLists.txt | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7a8fd38..563d408 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,9 +1,19 @@ include( FindPkgConfig ) include( CheckIncludeFile ) -pkg_check_modules( PULSE libpulse ) -pkg_check_modules( ALSA alsa ) -check_include_file( "sys/soundcard.h" HAVE_OSS_HEADER ) +option( TMIX_WITH_PULSE "Enable PulseAudio backend" ON ) +option( TMIX_WITH_ALSA "Enable ALSA backend" ON ) +option( TMIX_WITH_OSS "Enable OSS backend" ON ) + +if( TMIX_WITH_PULSE ) + pkg_check_modules( PULSE libpulse ) +endif() +if( TMIX_WITH_ALSA ) + pkg_check_modules( ALSA alsa ) +endif() +if( TMIX_WITH_OSS ) + check_include_file( "sys/soundcard.h" HAVE_OSS_HEADER ) +endif() if( NOT PULSE_FOUND AND NOT ALSA_FOUND AND NOT HAVE_OSS_HEADER ) message( FATAL_ERROR "No audio backend found (need libpulse, libasound, or sys/soundcard.h)" ) -- cgit v1.2.3