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 +++++-- src/ui/mixerwindow.cpp | 62 +++++++++++++++++++++++++++++++++++++++-- src/ui/mixerwindow.h | 8 ++++++ src/ui/oss/ossmixerwindow.cpp | 52 +++++++++++++++++++++++++++++++++- src/ui/oss/ossmixerwindow.h | 12 ++++++-- 6 files changed, 188 insertions(+), 8 deletions(-) (limited to 'src/ui') 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; 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]; diff --git a/src/ui/mixerwindow.h b/src/ui/mixerwindow.h index 112fc47..170c4e8 100644 --- a/src/ui/mixerwindow.h +++ b/src/ui/mixerwindow.h @@ -13,6 +13,7 @@ class TQToolButton; class DevicesPage; class TQResizeEvent; class TQLabel; +class TDEGlobalAccel; class MixerWindow : public TDEMainWindow { @@ -52,6 +53,11 @@ private slots: void quit(); void onAppAboutToQuit(); void toggleDevices(); + void slotVolumeUp(); + void slotVolumeDown(); + void slotToggleMute(); + void slotToggleInputMute(); + void slotConfigureGlobalShortcuts(); private: Tab &tabForCategory( AudioDevice::Category cat ); @@ -60,6 +66,8 @@ private: void repositionDevicesBtn(); PulseModel *m_model; + AudioDevice *m_defaultDevice; + TDEGlobalAccel *m_globalAccel; KTabWidget *m_tabs; class PreferencesDlg *m_prefsDlg; TQWidgetStack *m_outerStack; diff --git a/src/ui/oss/ossmixerwindow.cpp b/src/ui/oss/ossmixerwindow.cpp index f8d8a74..e06b310 100644 --- a/src/ui/oss/ossmixerwindow.cpp +++ b/src/ui/oss/ossmixerwindow.cpp @@ -20,10 +20,12 @@ #include #include #include +#include +#include OssMixerWindow::OssMixerWindow( OssModel *model, TQWidget *parent ) : TDEMainWindow(parent, "OssMixerWindow"), - m_model(model), m_tray(0), m_posRestored(false), + m_model(model), m_tray(0), m_globalAccel(0), m_posRestored(false), m_outerStack(0), m_errorLabel(0), m_cardCombo(0), m_tabs(0), m_outputPage(0), m_inputPage(0), m_outputLayout(0), m_inputLayout(0) @@ -101,6 +103,8 @@ OssMixerWindow::OssMixerWindow( OssModel *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"), @@ -109,6 +113,16 @@ OssMixerWindow::OssMixerWindow( OssModel *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 OssMixerWindow::rebuildTabs( int cardIdx ) @@ -215,4 +229,40 @@ void OssMixerWindow::showAbout() dlg.exec(); } +void OssMixerWindow::slotVolumeUp() +{ + OssDevice *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 OssMixerWindow::slotVolumeDown() +{ + OssDevice *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 OssMixerWindow::slotToggleMute() +{ + OssDevice *dev = m_model->preferredOutput(); + if ( !dev ) return; + dev->setMuted( !dev->muted() ); +} + +void OssMixerWindow::slotConfigureGlobalShortcuts() +{ + KKeyDialog::configure( m_globalAccel, 0, false ); + m_globalAccel->writeSettings(); + m_globalAccel->updateConnections(); +} + #include "ossmixerwindow.moc" diff --git a/src/ui/oss/ossmixerwindow.h b/src/ui/oss/ossmixerwindow.h index 0b9f087..fec2bab 100644 --- a/src/ui/oss/ossmixerwindow.h +++ b/src/ui/oss/ossmixerwindow.h @@ -13,6 +13,7 @@ class TQHBoxLayout; class TQLabel; class TQWidgetStack; class TQWidget; +class TDEGlobalAccel; class OssMixerWindow : public TDEMainWindow { @@ -31,6 +32,12 @@ public slots: void showPreferences(); void showAbout(); +private slots: + void slotVolumeUp(); + void slotVolumeDown(); + void slotToggleMute(); + void slotConfigureGlobalShortcuts(); + protected: bool queryClose(); void showEvent( TQShowEvent *e ); @@ -42,8 +49,9 @@ private slots: private: void rebuildTabs( int cardIdx ); - OssModel *m_model; - OssTray *m_tray; + OssModel *m_model; + OssTray *m_tray; + TDEGlobalAccel *m_globalAccel; bool m_posRestored; TQWidgetStack *m_outerStack; TQLabel *m_errorLabel; -- cgit v1.2.3