From a2b0c6b97bbe2448ca99318449c342c3322a0cdb Mon Sep 17 00:00:00 2001 From: lx-s Date: Tue, 18 Aug 2026 08:47:37 +0200 Subject: [PATCH] Added hotkey setting --- Translations/lang-de.json | 1 + Translations/lang-en.json | 1 + WinMute/AboutDlg.cpp | 8 +++++++- WinMute/Settings_GeneralDlg.cpp | 28 ++++++++++++++++++++++++++++ WinMute/WMSettings.cpp | 6 ++++++ WinMute/WMSettings.h | 4 +++- WinMute/WinMute.rc | 2 +- 7 files changed, 47 insertions(+), 3 deletions(-) diff --git a/Translations/lang-de.json b/Translations/lang-de.json index b57257d..d29ee0d 100644 --- a/Translations/lang-de.json +++ b/Translations/lang-de.json @@ -67,6 +67,7 @@ "settings.bluetooth.add-edit.edit-title": "Bluetooth-Gerät bearbeiten", "settings.bluetooth.add-edit.device-name-label": "Bluetooth Gerätename:", "settings.general.run-on-startup": "WinMute mit Windows starten", + "settings.general.enable-global-mute-hotkey": "Globalen Hotkey zur Stummschaltung aktivieren", "settings.general.enable-logging": "Protokoll in Datei speichern", "settings.general.btn-open-log-file": "Protokolldatei öffnen...", "settings.general.btn-open-log-window": "Protokoll anzeigen...", diff --git a/Translations/lang-en.json b/Translations/lang-en.json index 4299fc0..65ff4a4 100644 --- a/Translations/lang-en.json +++ b/Translations/lang-en.json @@ -76,6 +76,7 @@ "settings.general.check-for-updates-on-start": "Check for new updates on startup", "settings.general.check-for-beta-updates-on-start": "Also check for new beta versions", "settings.general.updates-handled-externally": "Options disabled: Updates are handled externally", + "settings.general.enable-global-mute-hotkey": "Enable global hotkey to mute workstation", "settings.general.enable-logging": "Save log to file", "settings.general.btn-open-log-file": "Open log file...", "settings.general.btn-open-log-window": "Show log...", diff --git a/WinMute/AboutDlg.cpp b/WinMute/AboutDlg.cpp index 9e2e0ca..69c4a92 100644 --- a/WinMute/AboutDlg.cpp +++ b/WinMute/AboutDlg.cpp @@ -36,7 +36,7 @@ POSSIBILITY OF SUCH DAMAGE. static const std::wstring kLicenseText = L"\ WinMute\r\n\ -Copyright(c) 2026, Alexander Steinhoefer\r\n\ +Copyright(c) 2011-2026, Alexander Steinhoefer\r\n\ \r\n\ -----------------------------------------------------------------------------\r\n\ Redistribution and use in source and binary forms, with or without\r\n\ @@ -65,10 +65,14 @@ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r\n\ LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY\r\n\ WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r\n\ POSSIBILITY OF SUCH DAMAGE.\r\n\ +\r\n\ +\r\n\ "; static const std::wstring kAttributionsText = L"\ +nlohmann/json / https://github.com/nlohmann/json\r\n\ +================================================\r\n\ MIT License\r\n\ \r\n\ Copyright (c) 2013-2026 Niels Lohmann\r\n\ @@ -90,6 +94,8 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n\ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n\ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\n\ SOFTWARE.\r\n\ +\r\n\ +\r\n\ "; enum AboutTabsIDs { diff --git a/WinMute/Settings_GeneralDlg.cpp b/WinMute/Settings_GeneralDlg.cpp index cef2f64..3b51df6 100644 --- a/WinMute/Settings_GeneralDlg.cpp +++ b/WinMute/Settings_GeneralDlg.cpp @@ -73,6 +73,8 @@ static void LoadSettingsGeneralDlgTranslation(HWND hDlg) i18n.SetItemText(hDlg, IDC_RUNONSTARTUP, "settings.general.run-on-startup"); i18n.SetItemText(hDlg, IDC_CHECK_FOR_UPDATES_ON_STARTUP, "settings.general.check-for-updates-on-start"); i18n.SetItemText(hDlg, IDC_CHECK_FOR_BETA_UPDATES, "settings.general.check-for-beta-updates-on-start"); + i18n.SetItemText(hDlg, IDC_ENABLE_GLOBAL_MUTE_HOTKEY, + "settings.general.enable-global-mute-hotkey"); i18n.SetItemText(hDlg, IDC_ENABLELOGGING, "settings.general.enable-logging"); i18n.SetItemText(hDlg, IDC_OPENLOG, "settings.general.btn-open-log-file"); i18n.SetItemText(hDlg, IDC_UPDATE_OPTIONS_DISABLED, "settings.general.updates-handled-externally"); @@ -89,6 +91,8 @@ INT_PTR CALLBACK Settings_GeneralDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPA HWND hLogging = GetDlgItem(hDlg, IDC_ENABLELOGGING); HWND hOpenLog = GetDlgItem(hDlg, IDC_OPENLOG); HWND hUpdatesDisabledNotice = GetDlgItem(hDlg, IDC_UPDATE_OPTIONS_DISABLED); + HWND hEnableGlobalMuteHotkey = GetDlgItem(hDlg, IDC_ENABLE_GLOBAL_MUTE_HOTKEY); + HWND hGlobalMuteHotkey = GetDlgItem(hDlg, IDC_GLOBAL_MUTE_HOTKEY); if (IsAppThemed()) { EnableThemeDialogTexture(hDlg, ETDT_ENABLETAB); @@ -114,6 +118,16 @@ INT_PTR CALLBACK Settings_GeneralDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPA enabled = !!dlgData->settings->QueryValue(SettingsKey::CHECK_FOR_BETA_UPDATE); Button_SetCheck(hBetaUpdateCheck, enabled ? BST_CHECKED : BST_UNCHECKED); + // Hotkey + const auto hotkey = + dlgData->settings->QueryValue(SettingsKey::GLOBAL_MUTE_HOTKEY); + SendMessage(hGlobalMuteHotkey, HKM_SETHOTKEY, hotkey, 0); + enabled = + !!dlgData->settings->QueryValue(SettingsKey::ENABLE_GLOBAL_MUTE_HOTKEY); + Button_SetCheck(hEnableGlobalMuteHotkey, + enabled ? BST_CHECKED : BST_UNCHECKED); + EnableWindow(hGlobalMuteHotkey, enabled); + // If the disable-update file is present, then also hide all options UpdateChecker updateChecker; if (updateChecker.IsUpdateCheckDisabledViaFile()) { @@ -179,6 +193,10 @@ INT_PTR CALLBACK Settings_GeneralDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPA SendMessageW(GetDlgItem(hDlg, IDC_LOGFILEPATH), WM_SETTEXT, 0, reinterpret_cast(L"")); } + } else if (LOWORD(wParam) == IDC_ENABLE_GLOBAL_MUTE_HOTKEY) { + const auto checked = + Button_GetCheck(GetDlgItem(hDlg, IDC_ENABLE_GLOBAL_MUTE_HOTKEY)); + EnableWindow(GetDlgItem(hDlg, IDC_GLOBAL_MUTE_HOTKEY), checked); } else if (LOWORD(wParam) == IDC_OPENLOGDLG) { auto hLogDlg = CreateDialogW( hglobInstance, @@ -204,6 +222,9 @@ INT_PTR CALLBACK Settings_GeneralDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPA HWND hLogging = GetDlgItem(hDlg, IDC_ENABLELOGGING); HWND hUpdateCheck = GetDlgItem(hDlg, IDC_CHECK_FOR_UPDATES_ON_STARTUP); HWND hBetaUpdateCheck = GetDlgItem(hDlg, IDC_CHECK_FOR_BETA_UPDATES); + HWND hEnableGlobalMuteHotkey = + GetDlgItem(hDlg, IDC_ENABLE_GLOBAL_MUTE_HOTKEY); + HWND hGlobalMuteHotkey = GetDlgItem(hDlg, IDC_GLOBAL_MUTE_HOTKEY); const int enableLog = Button_GetCheck(hLogging) == BST_CHECKED; dlgData->settings->SetValue(SettingsKey::LOGGING_ENABLED, enableLog); @@ -242,6 +263,13 @@ INT_PTR CALLBACK Settings_GeneralDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPA dlgData->settings->EnableAutostart(false); } + const int enableGlobalMuteHotkey = + Button_GetCheck(hEnableGlobalMuteHotkey) == BST_CHECKED; + dlgData->settings->SetValue(SettingsKey::ENABLE_GLOBAL_MUTE_HOTKEY, + enableGlobalMuteHotkey); + const auto hotkey = SendMessage(hGlobalMuteHotkey, HKM_GETHOTKEY, 0, 0); + dlgData->settings->SetValue(SettingsKey::GLOBAL_MUTE_HOTKEY, static_cast(hotkey)); + return 0; } default: diff --git a/WinMute/WMSettings.cpp b/WinMute/WMSettings.cpp index c4db1a4..b2cde98 100644 --- a/WinMute/WMSettings.cpp +++ b/WinMute/WMSettings.cpp @@ -137,6 +137,12 @@ static const wchar_t* KeyToStr(SettingsKey key) case SettingsKey::CHECK_FOR_BETA_UPDATE: keyStr = L"CheckForBetaUpdate"; break; + case SettingsKey::ENABLE_GLOBAL_MUTE_HOTKEY: + keyStr = L"EnableGlobalMuteHotkey"; + break; + case SettingsKey::GLOBAL_MUTE_HOTKEY: + keyStr = L"GlobalMuteHotkey"; + break; } return keyStr; } diff --git a/WinMute/WMSettings.h b/WinMute/WMSettings.h index 7b1a99d..efadee2 100644 --- a/WinMute/WMSettings.h +++ b/WinMute/WMSettings.h @@ -69,7 +69,9 @@ enum class SettingsKey { LOGGING_ENABLED, APP_LANGUAGE, CHECK_FOR_UPDATE, - CHECK_FOR_BETA_UPDATE + CHECK_FOR_BETA_UPDATE, + ENABLE_GLOBAL_MUTE_HOTKEY, + GLOBAL_MUTE_HOTKEY }; class WMSettings { diff --git a/WinMute/WinMute.rc b/WinMute/WinMute.rc index 26d6a96..d1541b7 100644 --- a/WinMute/WinMute.rc +++ b/WinMute/WinMute.rc @@ -126,13 +126,13 @@ IDD_ABOUT_WINMUTE DIALOGEX 0, 0, 298, 176 STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD FONT 8, "MS Shell Dlg", 400, 0, 0x1 BEGIN - EDITTEXT IDC_ABOUTTEXT,7,14,182,144,ES_MULTILINE | ES_AUTOVSCROLL | ES_NOHIDESEL | ES_READONLY | NOT WS_BORDER CONTROL "Author Site: www.lx-s.de",IDC_LINK_HOMEPAGE, "SysLink",WS_TABSTOP,197,14,94,14 CONTROL "Project Site && Code",IDC_LINK_PROJECT, "SysLink",WS_TABSTOP,197,32,94,14 CONTROL "Support",IDC_LINK_TICKETS, "SysLink",WS_TABSTOP,197,49,94,14 + EDITTEXT IDC_ABOUTTEXT,7,14,182,144,ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY | NOT WS_BORDER END IDD_SETTINGS_MUTE DIALOGEX 0, 0, 253, 274 -- 2.43.0