diff options
| author | Calvin Morrison <calvin@pobox.com> | 2026-05-29 23:00:50 -0400 |
|---|---|---|
| committer | Calvin Morrison <calvin@pobox.com> | 2026-05-29 23:01:37 -0400 |
| commit | f929977083c64263c54de43554a6cb64814caa9c (patch) | |
| tree | 55c49d946ab05f7f60880076b89966b94d122de5 /src/ui/mixerwindow.cpp | |
| parent | 4c9dd31005405aa0a32e36e4b500d773da9a1264 (diff) | |
add global hotkeys for volume and mute across all backends
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 <calvin@pobox.com>
Diffstat (limited to 'src/ui/mixerwindow.cpp')
| -rw-r--r-- | src/ui/mixerwindow.cpp | 62 |
1 files changed, 60 insertions, 2 deletions
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 <tdestandarddirs.h> #include <tdeaction.h> #include <tdeactioncollection.h> +#include <tdeglobalaccel.h> +#include <kkeydialog.h> #include <tdemenubar.h> #include <tdepopupmenu.h> #include <tdeaboutapplication.h> @@ -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]; |
