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/alsa | |
| 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/alsa')
| -rw-r--r-- | src/ui/alsa/alsamixerwindow.cpp | 52 | ||||
| -rw-r--r-- | src/ui/alsa/alsamixerwindow.h | 10 |
2 files changed, 59 insertions, 3 deletions
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 <tdeconfig.h> #include <tdeglobal.h> #include <twin.h> +#include <tdeglobalaccel.h> +#include <kkeydialog.h> 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; |
