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/alsa/alsamixerwindow.cpp | 52 ++++++++++++++++++++++++++++++++++++++++- src/ui/alsa/alsamixerwindow.h | 10 ++++++-- 2 files changed, 59 insertions(+), 3 deletions(-) (limited to 'src/ui/alsa') diff --git a/src/ui/alsa/alsamixerwindow.cpp b/src/ui/alsa/alsamixerwindow.cpp index 42b0774..ccb1a67 100644 --- a/src/ui/alsa/alsamixerwindow.cpp +++ b/src/ui/alsa/alsamixerwindow.cpp @@ -21,10 +21,12 @@ #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_model(model), m_tray(0), m_globalAccel(0), m_posRestored(false), m_devicesPage(0) { m_widgets.setAutoDelete(true); setCaption( i18n("Volume Control") ); @@ -82,6 +84,8 @@ AlsaMixerWindow::AlsaMixerWindow( AlsaModel *model, TQWidget *parent ) TDEPopupMenu *settingsMenu = new TDEPopupMenu(this); settingsMenu->insertItem( SmallIcon("configure"), i18n("&Configure..."), 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"), @@ -90,6 +94,16 @@ AlsaMixerWindow::AlsaMixerWindow( AlsaModel *model, TQWidget *parent ) menuBar()->insertItem( i18n("&File"), fileMenu ); menuBar()->insertItem( i18n("&Settings"), settingsMenu ); menuBar()->insertItem( i18n("&Help"), helpMenu ); + + 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->readSettings(); + m_globalAccel->updateConnections(); } void AlsaMixerWindow::rebuildTabs( int cardIndex ) @@ -203,4 +217,40 @@ void AlsaMixerWindow::showAbout() dlg.exec(); } +void AlsaMixerWindow::slotVolumeUp() +{ + AlsaDevice *dev = m_model->preferredOutput(); + if ( !dev ) return; + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("Tray"); + int step = cfg->readNumEntry("ScrollStep", 5); + int v = dev->volume() + step; + dev->setVolume( v > 100 ? 100 : v ); +} + +void AlsaMixerWindow::slotVolumeDown() +{ + AlsaDevice *dev = m_model->preferredOutput(); + if ( !dev ) return; + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("Tray"); + int step = cfg->readNumEntry("ScrollStep", 5); + int v = dev->volume() - step; + dev->setVolume( v < 0 ? 0 : v ); +} + +void AlsaMixerWindow::slotToggleMute() +{ + AlsaDevice *dev = m_model->preferredOutput(); + if ( !dev ) return; + dev->setMuted( !dev->muted() ); +} + +void AlsaMixerWindow::slotConfigureGlobalShortcuts() +{ + KKeyDialog::configure( m_globalAccel, 0, false ); + m_globalAccel->writeSettings(); + m_globalAccel->updateConnections(); +} + #include "alsamixerwindow.moc" diff --git a/src/ui/alsa/alsamixerwindow.h b/src/ui/alsa/alsamixerwindow.h index 8d8ef4f..c11bec9 100644 --- a/src/ui/alsa/alsamixerwindow.h +++ b/src/ui/alsa/alsamixerwindow.h @@ -12,6 +12,7 @@ class TQComboBox; class TQTabWidget; class TQHBoxLayout; class TQWidget; +class TDEGlobalAccel; class AlsaMixerWindow : public TDEMainWindow { @@ -37,12 +38,17 @@ private slots: void onDeviceAdded( AlsaDevice *dev ); void showPreferences(); void showAbout(); + void slotVolumeUp(); + void slotVolumeDown(); + void slotToggleMute(); + void slotConfigureGlobalShortcuts(); private: void rebuildTabs( int cardIndex ); - AlsaModel *m_model; - AlsaTray *m_tray; + AlsaModel *m_model; + AlsaTray *m_tray; + TDEGlobalAccel *m_globalAccel; bool m_posRestored; TQComboBox *m_cardCombo; TQTabWidget *m_tabs; -- cgit v1.2.3