From f929977083c64263c54de43554a6cb64814caa9c Mon Sep 17 00:00:00 2001 From: Calvin Morrison Date: Fri, 29 May 2026 23:00:50 -0400 Subject: add global hotkeys for volume and mute across all backends MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implements TDE Global hotkeys (volume up, volume down, mute, and mic mute for PulseAudio) like KMIX had Keys are unbound by default and configurable via Settings → Configure Global Shortcuts. OSS/ALSA target the user-configured preferred output device. Pusle is based on the current default device for mute/mic mute. Signed-off-by: Calvin Morrison --- src/ui/mixerwindow.cpp | 62 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) (limited to 'src/ui/mixerwindow.cpp') diff --git a/src/ui/mixerwindow.cpp b/src/ui/mixerwindow.cpp index a85ee34..2bc5b4c 100644 --- a/src/ui/mixerwindow.cpp +++ b/src/ui/mixerwindow.cpp @@ -17,6 +17,8 @@ #include #include #include +#include +#include #include #include #include @@ -54,8 +56,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), + : TDEMainWindow(parent), m_model(model), m_defaultDevice(0), m_globalAccel(0), + m_prefsDlg(0), m_devicesBtn(0), m_devicesPage(0), m_devicesInTabs(false), m_quitting(false), m_totalDevCount(0), m_waitLabel(0) { setPlainCaption( i18n("Volume Control") ); @@ -68,6 +70,8 @@ MixerWindow::MixerWindow( PulseModel *model, TQWidget *parent ) TDEPopupMenu *settingsMenu = new TDEPopupMenu( this ); settingsMenu->insertItem( SmallIcon("configure"), i18n("&Configure TMix..."), this, TQ_SLOT(showPreferences()) ); + settingsMenu->insertItem( SmallIcon("configure"), i18n("Configure &Global Shortcuts..."), + this, TQ_SLOT(slotConfigureGlobalShortcuts()) ); TDEPopupMenu *helpMenu = new TDEPopupMenu( this ); helpMenu->insertItem( SmallIcon("help"), i18n("&About TMix"), this, TQ_SLOT(showAbout()) ); @@ -88,6 +92,19 @@ MixerWindow::MixerWindow( PulseModel *model, TQWidget *parent ) if ( cfg->readBoolEntry("DockInTray", true) ) m_tray->show(); + // ---- global hotkeys ----------------------------------------------------- + m_globalAccel = new TDEGlobalAccel( this, "TMix" ); + m_globalAccel->insert( "Increase volume", i18n("Increase Volume"), TQString(), + TDEShortcut(), TDEShortcut(), this, TQ_SLOT(slotVolumeUp()) ); + m_globalAccel->insert( "Decrease volume", i18n("Decrease Volume"), TQString(), + TDEShortcut(), TDEShortcut(), this, TQ_SLOT(slotVolumeDown()) ); + m_globalAccel->insert( "Toggle mute", i18n("Toggle Mute"), TQString(), + TDEShortcut(), TDEShortcut(), this, TQ_SLOT(slotToggleMute()) ); + m_globalAccel->insert( "Toggle input mute", i18n("Toggle Mute of Microphone"), TQString(), + TDEShortcut(), TDEShortcut(), this, TQ_SLOT(slotToggleInputMute()) ); + m_globalAccel->readSettings(); + m_globalAccel->updateConnections(); + // ---- central widget ----------------------------------------------------- TQWidget *central = new TQWidget( this ); setCentralWidget( central ); @@ -314,9 +331,50 @@ void MixerWindow::onDeviceAdded( AudioDevice *dev ) void MixerWindow::onDefaultOutputChanged( AudioDevice *dev ) { + m_defaultDevice = dev; m_tray->setDevice( dev ); } +void MixerWindow::slotVolumeUp() +{ + if ( !m_defaultDevice ) return; + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("Tray"); + int step = cfg->readNumEntry("ScrollStep", 5); + int v = m_defaultDevice->volume() + step; + m_defaultDevice->setVolume( v > 100 ? 100 : v ); +} + +void MixerWindow::slotVolumeDown() +{ + if ( !m_defaultDevice ) return; + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("Tray"); + int step = cfg->readNumEntry("ScrollStep", 5); + int v = m_defaultDevice->volume() - step; + m_defaultDevice->setVolume( v < 0 ? 0 : v ); +} + +void MixerWindow::slotToggleMute() +{ + if ( !m_defaultDevice ) return; + m_defaultDevice->setMuted( !m_defaultDevice->muted() ); +} + +void MixerWindow::slotToggleInputMute() +{ + AudioDevice *dev = m_model->defaultInput(); + if ( !dev ) return; + dev->setMuted( !dev->muted() ); +} + +void MixerWindow::slotConfigureGlobalShortcuts() +{ + KKeyDialog::configure( m_globalAccel, 0, false ); + m_globalAccel->writeSettings(); + m_globalAccel->updateConnections(); +} + void MixerWindow::onDeviceRemoved( AudioDevice *dev ) { TQWidget *w = m_widgets[dev]; -- cgit v1.2.3