From: lx-s Date: Wed, 28 Oct 2020 10:34:02 +0000 (+0100) Subject: Quiet hours enhancement. Added notifications. X-Git-Tag: 1.6.0~12 X-Git-Url: https://repos.lx-s.de/gitweb/?a=commitdiff_plain;h=ef139fb2595fd8bb83d91b20722f0f90fd5e3778;p=winmute.git Quiet hours enhancement. Added notifications. Quiet Hours now respect if the workstation was already muted. An option has been added to force an unmute regardless whether the workstation was muted before. Also added system notifications when quiet hours start or end. --- diff --git a/WinMute/QuietHoursDlg.cpp b/WinMute/QuietHoursDlg.cpp index 8d51e19..7b3bad9 100644 --- a/WinMute/QuietHoursDlg.cpp +++ b/WinMute/QuietHoursDlg.cpp @@ -55,6 +55,7 @@ static bool IsValidTimeRange( static bool SaveQuietHours( Settings *settings, const int enabled, + const int forceUnmute, const LPSYSTEMTIME start, const LPSYSTEMTIME end) { @@ -78,6 +79,7 @@ static bool SaveQuietHours( int setEnd = end->wHour * 3600 + end->wMinute * 60 + end->wSecond; if (!settings->SetValue(SettingsKey::QUIETHOURS_ENABLE, enabled) || + !settings->SetValue(SettingsKey::QUIETHOURS_FORCEUNMUTE, forceUnmute) || !settings->SetValue(SettingsKey::QUIETHOURS_START, setStart) || !settings->SetValue(SettingsKey::QUIETHOURS_END, setEnd)) { TaskDialog( @@ -91,7 +93,7 @@ static bool SaveQuietHours( nullptr); return false; } - + return true; } @@ -101,6 +103,7 @@ INT_PTR CALLBACK QuietHoursDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lP switch (msg) { case WM_INITDIALOG: { HWND hEnable = GetDlgItem(hDlg, IDC_ENABLEQUIETHOURS); + HWND hForce = GetDlgItem(hDlg, IDC_FORCEUNMUTE); HWND hStart = GetDlgItem(hDlg, IDC_QUIETHOURS_START); HWND hEnd = GetDlgItem(hDlg, IDC_QUIETHOURS_END); Settings *settings = reinterpret_cast(lParam); @@ -109,6 +112,11 @@ INT_PTR CALLBACK QuietHoursDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lP DWORD qhEnabled = !!settings->QueryValue(SettingsKey::QUIETHOURS_ENABLE, FALSE); Button_SetCheck(hEnable, qhEnabled ? BST_CHECKED : BST_UNCHECKED); + + DWORD qhForceUnmute = !!settings->QueryValue(SettingsKey::QUIETHOURS_FORCEUNMUTE, FALSE); + Button_SetCheck(hForce, qhForceUnmute ? BST_CHECKED : BST_UNCHECKED); + + EnableWindow(hForce, qhEnabled); EnableWindow(hStart, qhEnabled); EnableWindow(hEnd, qhEnabled); @@ -137,6 +145,7 @@ INT_PTR CALLBACK QuietHoursDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lP } case WM_COMMAND: { HWND hEnable = GetDlgItem(hDlg, IDC_ENABLEQUIETHOURS); + HWND hForce = GetDlgItem(hDlg, IDC_FORCEUNMUTE); HWND hStart = GetDlgItem(hDlg, IDC_QUIETHOURS_START); HWND hEnd = GetDlgItem(hDlg, IDC_QUIETHOURS_END); if (LOWORD(wParam) == IDOK) { @@ -144,10 +153,11 @@ INT_PTR CALLBACK QuietHoursDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lP SYSTEMTIME end; Settings *settings = reinterpret_cast(GetWindowLongPtr(hDlg, GWLP_USERDATA)); int qhEnabled = Button_GetCheck(hEnable) == BST_CHECKED; + int qhForceUnmute = Button_GetCheck(hForce) == BST_CHECKED; DateTime_GetSystemtime(hStart, &start); DateTime_GetSystemtime(hEnd, &end); settings->SetValue(SettingsKey::QUIETHOURS_ENABLE, qhEnabled); - if (SaveQuietHours(settings, qhEnabled, &start, &end)) { + if (SaveQuietHours(settings, qhEnabled, qhForceUnmute, &start, &end)) { SendMessage(GetParent(hDlg), WM_WINMUTE_QUIETHOURS_CHANGE, 0, 0); EndDialog(hDlg, 0); } diff --git a/WinMute/Settings.cpp b/WinMute/Settings.cpp index f0d18fb..aaf8a1f 100644 --- a/WinMute/Settings.cpp +++ b/WinMute/Settings.cpp @@ -62,6 +62,9 @@ static LPCWSTR KeyToStr(SettingsKey key) case SettingsKey::QUIETHOURS_ENABLE: keyStr = _T("QuietHoursEnabled"); break; + case SettingsKey::QUIETHOURS_FORCEUNMUTE: + keyStr = _T("QuietHoursForceUnmute"); + break; case SettingsKey::QUIETHOURS_START: keyStr = _T("QuietHoursStart"); break; diff --git a/WinMute/Settings.h b/WinMute/Settings.h index 2476a6d..56c213e 100644 --- a/WinMute/Settings.h +++ b/WinMute/Settings.h @@ -43,6 +43,7 @@ enum class SettingsKey { , MUTE_ON_SHUTDOWN , MUTE_ON_LOGOUT , QUIETHOURS_ENABLE + , QUIETHOURS_FORCEUNMUTE , QUIETHOURS_START , QUIETHOURS_END }; diff --git a/WinMute/StdAfx.h b/WinMute/StdAfx.h index b62e5f9..f25beca 100644 --- a/WinMute/StdAfx.h +++ b/WinMute/StdAfx.h @@ -46,7 +46,7 @@ POSSIBILITY OF SUCH DAMAGE. #endif #define STRICT -#define _WIN32_WINNT 0x0600 +#define _WIN32_WINNT 0x0601 #include #include diff --git a/WinMute/TrayIcon.cpp b/WinMute/TrayIcon.cpp index 699034b..d3ef06f 100644 --- a/WinMute/TrayIcon.cpp +++ b/WinMute/TrayIcon.cpp @@ -124,6 +124,24 @@ void TrayIcon::ChangeText(const std::wstring& tooltip) ChangeText(); } +void TrayIcon::ShowPopup( + const std::wstring &title, + const std::wstring &text) +{ + NOTIFYICONDATA tnid; + tnid.cbSize = sizeof(NOTIFYICONDATA); + tnid.hWnd = hWnd_; + tnid.uID = trayID_; + tnid.uFlags = NIF_INFO; + tnid.dwInfoFlags = NIIF_INFO | NIIF_NOSOUND | NIIF_LARGE_ICON + | NIIF_RESPECT_QUIET_TIME; + tnid.uTimeout = 10 * 1000; + wcscpy_s(tnid.szInfoTitle, sizeof(tnid.szInfoTitle)/sizeof(TCHAR), title.c_str()); + wcscpy_s(tnid.szInfo, sizeof(tnid.szInfo)/sizeof(TCHAR), text.c_str()); + + Shell_NotifyIcon(NIM_MODIFY, &tnid); +} + void TrayIcon::DestroyTrayIcon() { if (hIcon_) { @@ -178,3 +196,5 @@ bool TrayIcon::ChangeText() } return false; } + + diff --git a/WinMute/TrayIcon.h b/WinMute/TrayIcon.h index 78417dc..b563598 100644 --- a/WinMute/TrayIcon.h +++ b/WinMute/TrayIcon.h @@ -49,6 +49,7 @@ public: bool IsShown() const { return iconVisible_; } void ChangeIcon(HICON hNewIcon); void ChangeText(const std::wstring& tooltip); + void ShowPopup(const std::wstring& title, const std::wstring& text); private: void DestroyTrayIcon(); diff --git a/WinMute/WinMute.cpp b/WinMute/WinMute.cpp index 65ec3c5..f0c159d 100644 --- a/WinMute/WinMute.cpp +++ b/WinMute/WinMute.cpp @@ -70,6 +70,7 @@ WinMute::MuteConfig::MuteConfig() this->noRestore.onShutdown = false; this->quietHours.enabled = false; + this->quietHours.forceUnmute = false; this->quietHours.start = 0; this->quietHours.end = 0; } @@ -78,7 +79,8 @@ WinMute::WinMute() : hWnd_(nullptr), hTrayMenu_(nullptr), hAppIcon_(nullptr), - hTrayIcon_(nullptr) + hTrayIcon_(nullptr), + wsAlreadyMuted_(false) { } WinMute::~WinMute() @@ -219,6 +221,8 @@ bool WinMute::LoadDefaults() muteConfig_.quietHours.enabled = settings_.QueryValue(SettingsKey::QUIETHOURS_ENABLE, 0) != 0; + muteConfig_.quietHours.forceUnmute = + settings_.QueryValue(SettingsKey::QUIETHOURS_FORCEUNMUTE, 0) != 0; muteConfig_.quietHours.start = settings_.QueryValue(SettingsKey::QUIETHOURS_START, 0); muteConfig_.quietHours.end = @@ -346,14 +350,13 @@ LRESULT CALLBACK WinMute::WindowProc( return 0; } case WM_WTSSESSION_CHANGE: { - static bool wasAlreadyMuted = false; if (wParam == WTS_SESSION_LOCK) { - wasAlreadyMuted = audio_->IsMuted(); - if (!wasAlreadyMuted && muteConfig_.withRestore.onLock) { + wsAlreadyMuted_ = audio_->IsMuted(); + if (!wsAlreadyMuted_ && muteConfig_.withRestore.onLock) { audio_->Mute(); } } else if (wParam == WTS_SESSION_UNLOCK) { - if (!wasAlreadyMuted && + if (!wsAlreadyMuted_ && muteConfig_.restoreAudio && muteConfig_.withRestore.onLock) { audio_->UnMute(); @@ -379,6 +382,26 @@ LRESULT CALLBACK WinMute::WindowProc( } } break; + case WM_WINMUTE_QUIETHOURS_START: + wsAlreadyMuted_ = audio_->IsMuted(); + audio_->Mute(); + trayIcon_.ShowPopup( + _T("WinMute: Quiet hours started"), + _T("Your workstation audio is now muted")); + return 0; + case WM_WINMUTE_QUIETHOURS_END: + if (wsAlreadyMuted_ && muteConfig_.quietHours.forceUnmute || + !wsAlreadyMuted_) { + audio_->UnMute(); + trayIcon_.ShowPopup( + _T("WinMute: Quiet Hours ended"), + _T("Your workstation audio has been restored.")); + } else { + trayIcon_.ShowPopup( + _T("WinMute: Quiet Hours ended"), + _T("Quiet hours ended, your workstation remains muted.")); + } + return 0; case WM_WINMUTE_MUTE: { bool mute = !!static_cast(wParam); if (mute) { @@ -410,14 +433,13 @@ LRESULT CALLBACK WinMute::WindowProc( return 0; } case WM_SCRNSAVE_CHANGE: { - static bool wasAlreadyMuted = false; if (wParam == SCRNSAVE_START) { - wasAlreadyMuted = audio_->IsMuted(); - if (!wasAlreadyMuted && muteConfig_.withRestore.onScreensaver) { + wsAlreadyMuted_ = audio_->IsMuted(); + if (!wsAlreadyMuted_ && muteConfig_.withRestore.onScreensaver) { audio_->Mute(); } } else if (wParam == SCRNSAVE_STOP) { - if (!wasAlreadyMuted && + if (!wsAlreadyMuted_ && muteConfig_.restoreAudio && muteConfig_.withRestore.onScreensaver) { audio_->UnMute(); @@ -475,7 +497,7 @@ static int GetDiffMillseconds(const LPSYSTEMTIME t1, const LPSYSTEMTIME t2) res = ulT1.QuadPart - ulT2.QuadPart; - res /= (1000000000 / 100); // To seconds + res /= (1000000000 / 100); // To seconds if (res < 0) { // Add 24 Hours for Wrap Around res += 24 * 60 * 60; } @@ -489,11 +511,11 @@ VOID CALLBACK QuietHoursTimer(HWND hWnd, UINT msg, UINT_PTR id, DWORD msSinceSys UNREFERENCED_PARAMETER( msg ); UNREFERENCED_PARAMETER( msSinceSysStart ); if (id == QUIETHOURS_TIMER_START_ID) { - SendMessage(hWnd, WM_WINMUTE_MUTE, 1, 0); + SendMessage(hWnd, WM_WINMUTE_QUIETHOURS_START, 0, 0); SendMessage(hWnd, WM_WINMUTE_QUIETHOURS_CHANGE, 0, 0); KillTimer(hWnd, id); } else if (id == QUIETHOURS_TIMER_END_ID) { - SendMessage(hWnd, WM_WINMUTE_MUTE, 0, 0); + SendMessage(hWnd, WM_WINMUTE_QUIETHOURS_END, 0, 0); SendMessage(hWnd, WM_WINMUTE_QUIETHOURS_CHANGE, 0, 0); KillTimer(hWnd, id); } diff --git a/WinMute/WinMute.h b/WinMute/WinMute.h index 3619d09..e53d5a8 100644 --- a/WinMute/WinMute.h +++ b/WinMute/WinMute.h @@ -39,6 +39,8 @@ class WinAudio; static const int WM_WINMUTE_QUIETHOURS_CHANGE = WM_APP + 200; static const int WM_WINMUTE_MUTE = WM_APP + 201; +static const int WM_WINMUTE_QUIETHOURS_START = WM_APP + 202; +static const int WM_WINMUTE_QUIETHOURS_END = WM_APP + 203; static const int QUIETHOURS_TIMER_START_ID = 271020; static const int QUIETHOURS_TIMER_END_ID = 271021; @@ -71,12 +73,15 @@ private: bool onSuspend; } noRestore; struct { - int enabled; + bool enabled; + bool forceUnmute; time_t start; time_t end; } quietHours; } muteConfig_; + bool wsAlreadyMuted_; + TrayIcon trayIcon_; std::unique_ptr audio_; ScreensaverNotifier scrnSaverNoti_; diff --git a/WinMute/res.rc b/WinMute/res.rc index e9a4b44..6484b81 100644 --- a/WinMute/res.rc +++ b/WinMute/res.rc @@ -96,19 +96,21 @@ BEGIN "SysLink",WS_TABSTOP,119,35,36,13 END -IDD_QUIETHOURS DIALOGEX 0, 0, 201, 146 +IDD_QUIETHOURS DIALOGEX 0, 0, 201, 190 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Configure Quiet Hours" FONT 8, "MS Shell Dlg", 400, 0, 0x1 BEGIN - CONTROL "Enable Quiet Hours",IDC_ENABLEQUIETHOURS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,38,77,10 + CONTROL "Enable Quiet Hours",IDC_ENABLEQUIETHOURS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,42,77,10 CONTROL "",IDC_QUIETHOURS_START,"SysDateTimePick32",DTS_RIGHTALIGN | DTS_UPDOWN | WS_TABSTOP | 0x8,79,58,54,15 CONTROL "",IDC_QUIETHOURS_END,"SysDateTimePick32",DTS_RIGHTALIGN | DTS_UPDOWN | WS_TABSTOP | 0x8,79,80,54,15 - DEFPUSHBUTTON "Save",IDOK,63,120,50,14 - PUSHBUTTON "Cancel",IDCANCEL,123,120,50,14 - LTEXT "During Quiet Hours WinMute automatically mutes your PC volumes and unmutes it afterwards.",IDC_STATIC,15,9,174,24 + CONTROL "Force unmute",IDC_FORCEUNMUTE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,31,102,60,10 + DEFPUSHBUTTON "Save",IDOK,63,165,50,14 + PUSHBUTTON "Cancel",IDCANCEL,123,165,50,14 + LTEXT "If force unmute is enabled, WinMute will unmute your workstation when quiet hours end and not take into account if your workstation was already muted before quiet hours started.",IDC_STATIC,32,115,162,38 LTEXT "Start time:",IDC_STATIC,31,60,42,12 LTEXT "End time:",IDC_STATIC,31,82,43,12 + LTEXT "During Quiet Hours WinMute automatically mutes your PC volumes and unmutes it afterwards.",IDC_STATIC,14,15,180,24 END @@ -134,7 +136,7 @@ BEGIN LEFTMARGIN, 7 RIGHTMARGIN, 194 TOPMARGIN, 7 - BOTTOMMARGIN, 139 + BOTTOMMARGIN, 183 END END #endif // APSTUDIO_INVOKED diff --git a/WinMute/resource.h b/WinMute/resource.h index 4177439..cd00b1f 100644 --- a/WinMute/resource.h +++ b/WinMute/resource.h @@ -14,6 +14,7 @@ #define IDC_QUIETHOURS_START 1002 #define IDC_ENABLEQUIETHOURS 1003 #define IDC_QUIETHOURS_END 1004 +#define IDC_FORCEUNMUTE 1005 #define ID_TRAYMENU_INFO 40001 #define ID_TRAYMENU_EXIT 40002 #define ID_TRAYMENU_MUTEONLOCK 40003