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.
static bool SaveQuietHours(
Settings *settings,
const int enabled,
+ const int forceUnmute,
const LPSYSTEMTIME start,
const LPSYSTEMTIME end)
{
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(
nullptr);
return false;
}
-
+
return true;
}
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<Settings*>(lParam);
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);
}
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) {
SYSTEMTIME end;
Settings *settings = reinterpret_cast<Settings*>(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);
}
case SettingsKey::QUIETHOURS_ENABLE:
keyStr = _T("QuietHoursEnabled");
break;
+ case SettingsKey::QUIETHOURS_FORCEUNMUTE:
+ keyStr = _T("QuietHoursForceUnmute");
+ break;
case SettingsKey::QUIETHOURS_START:
keyStr = _T("QuietHoursStart");
break;
, MUTE_ON_SHUTDOWN
, MUTE_ON_LOGOUT
, QUIETHOURS_ENABLE
+ , QUIETHOURS_FORCEUNMUTE
, QUIETHOURS_START
, QUIETHOURS_END
};
#endif
#define STRICT
-#define _WIN32_WINNT 0x0600
+#define _WIN32_WINNT 0x0601
#include <sdkddkver.h>
#include <cassert>
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_) {
}
return false;
}
+
+
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();
this->noRestore.onShutdown = false;
this->quietHours.enabled = false;
+ this->quietHours.forceUnmute = false;
this->quietHours.start = 0;
this->quietHours.end = 0;
}
hWnd_(nullptr),
hTrayMenu_(nullptr),
hAppIcon_(nullptr),
- hTrayIcon_(nullptr)
+ hTrayIcon_(nullptr),
+ wsAlreadyMuted_(false)
{ }
WinMute::~WinMute()
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 =
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();
}
}
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<int>(wParam);
if (mute) {
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();
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;
}
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);
}
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;
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<WinAudio> audio_;
ScreensaverNotifier scrnSaverNoti_;
"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
LEFTMARGIN, 7
RIGHTMARGIN, 194
TOPMARGIN, 7
- BOTTOMMARGIN, 139
+ BOTTOMMARGIN, 183
END
END
#endif // APSTUDIO_INVOKED
#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