From b599def75b6ce9d1d1557cea46798fe964750137 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexander=20Steinh=C3=B6fer?= Date: Tue, 1 Mar 2022 13:27:49 +0100 Subject: [PATCH] Start of major WinMute rework. --- Dist/bin/changelog.txt | 2 + WinMute/BaseTypes.h | 43 +++++ WinMute/Log.cpp | 39 +++-- WinMute/Log.h | 31 +++- WinMute/MuteControl.cpp | 274 ++++++++++++++++++++++++++++++++ WinMute/MuteControl.h | 93 +++++++++++ WinMute/QuietHours.cpp | 34 ++++ WinMute/QuietHours.h | 26 +++ WinMute/QuietHoursDlg.cpp | 8 +- WinMute/ScreensaverNotifier.cpp | 28 ++-- WinMute/Settings.cpp | 3 + WinMute/Settings.h | 3 +- WinMute/VistaAudio.cpp | 19 +-- WinMute/WinAudio.h | 6 +- WinMute/WinMute.cpp | 263 ++++++++++++------------------ WinMute/WinMute.h | 18 +-- WinMute/WinMute.rc | 15 +- WinMute/WinMute.vcxproj | 13 +- WinMute/WinMute.vcxproj.filters | 126 +++++++++------ WinMute/WinMute.vcxproj.user | 17 +- WinMute/common.h | 33 ++-- WinMute/icons/tray_bright.ico | Bin 7406 -> 7406 bytes WinMute/icons/tray_dark.ico | Bin 7406 -> 7406 bytes WinMute/resource.h | 4 +- 24 files changed, 795 insertions(+), 303 deletions(-) create mode 100644 WinMute/BaseTypes.h create mode 100644 WinMute/MuteControl.cpp create mode 100644 WinMute/MuteControl.h create mode 100644 WinMute/QuietHours.cpp create mode 100644 WinMute/QuietHours.h diff --git a/Dist/bin/changelog.txt b/Dist/bin/changelog.txt index 7909c23..91b93c9 100644 --- a/Dist/bin/changelog.txt +++ b/Dist/bin/changelog.txt @@ -1,6 +1,8 @@ Version 1.7.0-beta (2022-*-*) * Added Hi-DPI Awareness to manifest * Added Tray-Icon for bright system theme + * Added detection for display standby + Version 1.6.0 (2020-12-18) * Added "Quiet Hours": A time frame where WinMute automatically diff --git a/WinMute/BaseTypes.h b/WinMute/BaseTypes.h new file mode 100644 index 0000000..4d9f4aa --- /dev/null +++ b/WinMute/BaseTypes.h @@ -0,0 +1,43 @@ +/* + WinMute + Copyright (c) 2022, Alexander Steinhoefer + +----------------------------------------------------------------------------- +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of the author nor the names of its contributors may + be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. +----------------------------------------------------------------------------- +*/ + +#pragma once + +#include +#include + +#include + +using tstring = std::basic_string, std::allocator>; +using tstring_view = std::basic_string_view; + diff --git a/WinMute/Log.cpp b/WinMute/Log.cpp index ae44416..99694ac 100644 --- a/WinMute/Log.cpp +++ b/WinMute/Log.cpp @@ -33,10 +33,14 @@ POSSIBILITY OF SUCH DAMAGE. #include "common.h" +#ifdef UNICODE +static bool OpenLogFile(std::wofstream& logFile) +#else static bool OpenLogFile(std::ofstream& logFile) +#endif { auto path = std::filesystem::temp_directory_path(); - path /= "WinMute.log"; + path /= L"WinMute.log"; logFile.open(path.string(), std::ios::out | std::ios::app | std::ios::binary); return logFile.is_open(); } @@ -62,21 +66,34 @@ Log::~Log() } } -void Log::Write(std::string msg) +void Log::SetEnabled(bool enable) { - if (!initialized_) { - return; - } + enabled_ = enable; +} + +void Log::WriteMessage(const tstring& msg) +{ + struct tm tm; auto now = std::chrono::system_clock::now(); auto in_time_t = std::chrono::system_clock::to_time_t(now); - struct tm tm; +#ifdef UNICODE + std::wstringstream ss; +#else std::stringstream ss; +#endif localtime_s(&tm, &in_time_t); - ss << "[" << std::put_time(&tm, "%Y-%m-%d %X") << "] "; - ss << msg; - ss << "\n"; - - logFile_.write(ss.str().c_str(), ss.str().length()); + ss << _T("[") << std::put_time(&tm, _T("%Y-%m-%d %X")) << _T("] ") + << msg << _T("\n"); + const auto& logStr = ss.str(); + logFile_.write(logStr.c_str(), logStr.length()); logFile_.flush(); } + +void Log::Write(const tstring& msg) +{ + if (!initialized_ || !enabled_) { + return; + } + WriteMessage(msg); +} diff --git a/WinMute/Log.h b/WinMute/Log.h index 406d737..0ea0f41 100644 --- a/WinMute/Log.h +++ b/WinMute/Log.h @@ -38,13 +38,42 @@ POSSIBILITY OF SUCH DAMAGE. class Log { public: static Log& GetInstance(); - void Write(std::string msg); + + void Write(const tstring& wmsg); + + template + void Write( + [[maybe_unused]] const tstring_view& fmt, + [[maybe_unused]] Args&&... args) + { + if (!initialized_ || !enabled_) { + return; + } +#ifdef UNICODE + const std::wstring str = std::vformat( + fmt, std::make_wformat_args(args...)); +#else + const std::wstring str = std::vformat( + fmt, std::make_format_args(args...)); +#endif + WriteMessage(str); + } + + void SetEnabled(bool enable); + private: Log(); ~Log(); Log(const Log&) = delete; Log& operator=(const Log&) = delete; + void WriteMessage(const tstring& msg); + bool initialized_; + bool enabled_; +#ifdef UNICODE + std::wofstream logFile_; +#else std::ofstream logFile_; +#endif }; diff --git a/WinMute/MuteControl.cpp b/WinMute/MuteControl.cpp new file mode 100644 index 0000000..7610c5b --- /dev/null +++ b/WinMute/MuteControl.cpp @@ -0,0 +1,274 @@ +/* + WinMute + Copyright (c) 2022, Alexander Steinhoefer + +----------------------------------------------------------------------------- +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of the author nor the names of its contributors may + be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. +----------------------------------------------------------------------------- +*/ + +#include "common.h" + +enum MuteType { + // With restore + MuteTypeWorkstationLock = 0, + MuteTypeScreensaverActive, + MuteTypeRemoteSession, + MuteTypeDisplayStandby, + + // Without restore + MuteTypeLogout, + MuteTypeSuspend, + MuteTypeShutdown, + MuteTypeCount // Meta +}; + +MuteControl::MuteControl() : + wasAlreadyMuted_(false) +{ + MuteConfig initMuteConf; + initMuteConf.active = false; + initMuteConf.shouldMute = false; + for (int i = 0; i < MuteTypeCount; ++i) { + muteConfig_.push_back(initMuteConf); + } +} + +MuteControl::~MuteControl() +{ +} + +bool MuteControl::Init(HWND hParent) +{ + winAudio_ = std::make_unique(); + if (!winAudio_->Init(hParent)) { + return false; + } + return true; +} + +void MuteControl::SetMute(bool mute) +{ + Log::GetInstance().Write(_T("Manual muting: {}"), mute ? _T("on") : _T("off")); + winAudio_->SetMute(mute); +} + +void MuteControl::ConfigureWasAlreadyMuted() +{ + bool muteAlreadyActive = false; + for (const auto& conf : muteConfig_) { + if (conf.shouldMute && conf.active) { + muteAlreadyActive = true; + break; + } + } + if (!muteAlreadyActive && winAudio_->IsMuted()) { + wasAlreadyMuted_ = true; + } +} + +void MuteControl::RestoreVolume() +{ + if (!restoreVolume_) { + Log::GetInstance().Write(_T("Restore is FALSE")); + return; + } + bool restore = true; + int i = 0; + for (const auto& conf : muteConfig_) { + if (conf.shouldMute && conf.active) { + Log::GetInstance().Write(_T("Entry {} found with ShouldMute: Yes and Active: Yes"), i); + restore = false; + //break; + } + ++i; + } + if (restore) { + if (winAudio_->IsMuted() && !wasAlreadyMuted_) { + Log::GetInstance().Write(_T("Mute: Off")); + winAudio_->SetMute(false); + } else { + Log::GetInstance().Write( + _T("Skipping unmute since workstation was already muted.")); + } + } +} + +void MuteControl::SetRestoreVolume(bool enable) +{ + restoreVolume_ = enable; +} + +void MuteControl::SetMuteOnWorkstationLock(bool enable) +{ + muteConfig_[MuteTypeWorkstationLock].shouldMute = enable; +} + +void MuteControl::SetMuteOnScreensaverActivation(bool enable) +{ + muteConfig_[MuteTypeScreensaverActive].shouldMute = enable; +} + +void MuteControl::SetMuteOnLogout(bool enable) +{ + muteConfig_[MuteTypeLogout].shouldMute = enable; +} + +void MuteControl::SetMuteOnSuspend(bool enable) +{ + muteConfig_[MuteTypeSuspend].shouldMute = enable; +} + +void MuteControl::SetMuteOnShutdown(bool enable) +{ + muteConfig_[MuteTypeShutdown].shouldMute = enable; +} + +void MuteControl::SetMuteOnRemoteSession(bool enable) +{ + muteConfig_[MuteTypeRemoteSession].shouldMute = enable; +} + + +void MuteControl::SetMuteOnDisplayStandby(bool enable) +{ + muteConfig_[MuteTypeDisplayStandby].shouldMute = enable; +} + +bool MuteControl::GetRestoreVolume() +{ + return restoreVolume_; +} + +bool MuteControl::GetMuteOnWorkstationLock() +{ + return muteConfig_[MuteTypeWorkstationLock].shouldMute; +} + +bool MuteControl::GetMuteOnScreensaverActivation() +{ + return muteConfig_[MuteTypeScreensaverActive].shouldMute; +} + +bool MuteControl::GetMuteOnRemoteSession() +{ + return muteConfig_[MuteTypeRemoteSession].shouldMute; +} + +bool MuteControl::GetMuteOnDisplayStandby() +{ + return muteConfig_[MuteTypeDisplayStandby].shouldMute; +} + +bool MuteControl::GetMuteOnLogout() +{ + return muteConfig_[MuteTypeLogout].shouldMute; +} + +bool MuteControl::GetMuteOnSuspend() +{ + return muteConfig_[MuteTypeSuspend].shouldMute; +} + +bool MuteControl::GetMuteOnShutdown() +{ + return muteConfig_[MuteTypeShutdown].shouldMute; +} + +void MuteControl::NotifyRestoreCondition(int type, bool active) +{ + if (active) { + ConfigureWasAlreadyMuted(); + muteConfig_[type].active = active; + Log::GetInstance().Write(_T("Condition {}: ACTIVE"), type); + if (muteConfig_[type].shouldMute && + !winAudio_->IsMuted()) { + Log::GetInstance().Write(_T("Mute: On")); + winAudio_->SetMute(true); + } + } else { + Log::GetInstance().Write(_T("Condition {}: INACTIVE"), type); + muteConfig_[type].active = active; + RestoreVolume(); + } +} + +void MuteControl::NotifyWorkstationLock(bool active) +{ + NotifyRestoreCondition(MuteTypeWorkstationLock, active); +} + +void MuteControl::NotifyScreensaver(bool active) +{ + NotifyRestoreCondition(MuteTypeScreensaverActive, active); +} + +void MuteControl::NotifyRemoteSession(bool active) +{ + NotifyRestoreCondition(MuteTypeRemoteSession, active); +} + +void MuteControl::NotifyDisplayStandby(bool active) +{ + NotifyRestoreCondition(MuteTypeDisplayStandby, active); +} + +void MuteControl::NotifyLogout() +{ + if (muteConfig_[MuteTypeLogout].shouldMute) { + winAudio_->SetMute(true); + } +} + +void MuteControl::NotifySuspend(bool /*active*/) +{ + Log::GetInstance().Write(_T("Suspend: START")); + if (muteConfig_[MuteTypeSuspend].shouldMute) { + winAudio_->SetMute(true); + } +} + +void MuteControl::NotifyShutdown() +{ + if (muteConfig_[MuteTypeShutdown].shouldMute) { + winAudio_->SetMute(true); + } +} + +void MuteControl::NotifyQuietHours(bool active) +{ + if (active) { + ConfigureWasAlreadyMuted(); + Log::GetInstance().Write(L"Quiet Hours startet"); + if (!winAudio_->IsMuted()) { + winAudio_->SetMute(true); + } + } else { + Log::GetInstance().Write(L"Quiet Hours ended"); + RestoreVolume(); + } +} diff --git a/WinMute/MuteControl.h b/WinMute/MuteControl.h new file mode 100644 index 0000000..6f059fc --- /dev/null +++ b/WinMute/MuteControl.h @@ -0,0 +1,93 @@ +/* + WinMute + Copyright (c) 2022, Alexander Steinhoefer + +----------------------------------------------------------------------------- +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of the author nor the names of its contributors may + be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. +----------------------------------------------------------------------------- +*/ + +#pragma once + +#include "common.h" + +class MuteControl { + struct MuteConfig { + bool shouldMute; + bool active; + }; + std::vector muteConfig_; + bool wasAlreadyMuted_; + bool restoreVolume_; + std::unique_ptr winAudio_; + + void NotifyRestoreCondition(int type, bool active); + void ConfigureWasAlreadyMuted(); + void RestoreVolume(); +public: + MuteControl(); + ~MuteControl(); + MuteControl(const MuteControl&) = delete; + MuteControl& operator=(const MuteControl&) = delete; + + bool Init(HWND hParent); + + void SetMute(bool mute); + + void SetRestoreVolume(bool enable); + + void SetMuteOnWorkstationLock(bool enable); + void SetMuteOnScreensaverActivation(bool enable); + void SetMuteOnRemoteSession(bool enable); + void SetMuteOnDisplayStandby(bool enable); + + void SetMuteOnLogout(bool enable); + void SetMuteOnSuspend(bool enable); + void SetMuteOnShutdown(bool enable); + + bool GetRestoreVolume(); + + bool GetMuteOnWorkstationLock(); + bool GetMuteOnScreensaverActivation(); + bool GetMuteOnRemoteSession(); + bool GetMuteOnDisplayStandby(); + + bool GetMuteOnLogout(); + bool GetMuteOnSuspend(); + bool GetMuteOnShutdown(); + + void NotifyScreensaver(bool active); + void NotifyWorkstationLock(bool active); + void NotifyRemoteSession(bool active); + void NotifyDisplayStandby(bool enable); + + void NotifyLogout(); + void NotifySuspend(bool active); + void NotifyShutdown(); + + void NotifyQuietHours(bool active); +}; diff --git a/WinMute/QuietHours.cpp b/WinMute/QuietHours.cpp new file mode 100644 index 0000000..076ae68 --- /dev/null +++ b/WinMute/QuietHours.cpp @@ -0,0 +1,34 @@ +/* + WinMute + Copyright (c) 2022, Alexander Steinhoefer + +----------------------------------------------------------------------------- +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of the author nor the names of its contributors may + be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. +----------------------------------------------------------------------------- +*/ + +#include "common.h" diff --git a/WinMute/QuietHours.h b/WinMute/QuietHours.h new file mode 100644 index 0000000..fcedf09 --- /dev/null +++ b/WinMute/QuietHours.h @@ -0,0 +1,26 @@ +#pragma once + +#include "common.h" + +class QuietHours { + HWND hTimer; +public: + QuietHours(); + ~QuietHours(); + QuietHours(const QuietHours&) = delete; + QuietHours& operator=(const QuietHours&) = delete; + + bool IsQuietTime(); + + void HandleTimerProc(HWND hWnd, UINT msg, UINT_PTR id, DWORD msSinceSysStart); + + bool SetStartTime(); + bool SetEndTime(); + bool ShowNotifications(bool show); + bool ForceUnmute(bool force); + bool Enable(); + +private: + SYSTEMTIME start; + SYSTEMTIME end; +}; diff --git a/WinMute/QuietHoursDlg.cpp b/WinMute/QuietHoursDlg.cpp index 7e0149f..3626d3b 100644 --- a/WinMute/QuietHoursDlg.cpp +++ b/WinMute/QuietHoursDlg.cpp @@ -74,10 +74,10 @@ 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_NOTIFICATIONS, showNotifications) || - !settings->SetValue(SettingsKey::QUIETHOURS_START, setStart) || - !settings->SetValue(SettingsKey::QUIETHOURS_END, setEnd)) { + !settings->SetValue(SettingsKey::QUIETHOURS_FORCEUNMUTE, forceUnmute) || + !settings->SetValue(SettingsKey::QUIETHOURS_NOTIFICATIONS, showNotifications) || + !settings->SetValue(SettingsKey::QUIETHOURS_START, setStart) || + !settings->SetValue(SettingsKey::QUIETHOURS_END, setEnd)) { TaskDialog( nullptr, nullptr, diff --git a/WinMute/ScreensaverNotifier.cpp b/WinMute/ScreensaverNotifier.cpp index 090e9ae..50526ea 100644 --- a/WinMute/ScreensaverNotifier.cpp +++ b/WinMute/ScreensaverNotifier.cpp @@ -101,10 +101,10 @@ bool ScreensaverNotifier::Init() return true; } return RegisterWindowClass() && - InitWindow() && - InitWindowMessage() && - InitHookDll() && - InitHook32(); + InitWindow() && + InitWindowMessage() && + InitHookDll() && + InitHook32(); } bool ScreensaverNotifier::InitWindow() @@ -168,16 +168,16 @@ bool ScreensaverNotifier::InitHook32() PrintWindowsError(_T("SetInformationJobObject"), GetLastError()); CloseHandle(hJob_); } else if (CreateProcess( - _T(".\\ScreensaverProxy32.exe"), - commandLine, - NULL, - NULL, - FALSE, - NORMAL_PRIORITY_CLASS, - NULL, - NULL, - &startupInfo, - &procInfo) == FALSE) { + _T(".\\ScreensaverProxy32.exe"), + commandLine, + NULL, + NULL, + FALSE, + NORMAL_PRIORITY_CLASS, + NULL, + NULL, + &startupInfo, + &procInfo) == FALSE) { PrintWindowsError(_T("CreateProcess")); CloseHandle(hJob_); hJob_ = nullptr; diff --git a/WinMute/Settings.cpp b/WinMute/Settings.cpp index 19544b0..9aaf5df 100644 --- a/WinMute/Settings.cpp +++ b/WinMute/Settings.cpp @@ -47,6 +47,9 @@ static LPCWSTR KeyToStr(SettingsKey key) case SettingsKey::MUTE_ON_SCREENSAVER: keyStr = _T("MuteOnScreensaver"); break; + case SettingsKey::MUTE_ON_DISPLAYSTANDBY: + keyStr = _T("MuteOnDisplayStandby"); + break; case SettingsKey::RESTORE_AUDIO: keyStr = _T("RestoreAudio"); break; diff --git a/WinMute/Settings.h b/WinMute/Settings.h index 360c80d..5db7ae8 100644 --- a/WinMute/Settings.h +++ b/WinMute/Settings.h @@ -36,8 +36,9 @@ POSSIBILITY OF SUCH DAMAGE. #include "common.h" enum class SettingsKey { - MUTE_ON_LOCK + MUTE_ON_LOCK , MUTE_ON_SCREENSAVER + , MUTE_ON_DISPLAYSTANDBY , RESTORE_AUDIO , MUTE_ON_SUSPEND , MUTE_ON_SHUTDOWN diff --git a/WinMute/VistaAudio.cpp b/WinMute/VistaAudio.cpp index c5beb06..33368e8 100644 --- a/WinMute/VistaAudio.cpp +++ b/WinMute/VistaAudio.cpp @@ -193,24 +193,13 @@ bool VistaAudio::IsMuted() return false; } -void VistaAudio::Mute() +void VistaAudio::SetMute(bool mute) { if (CheckForReInit() && endpointVolume_ != nullptr) { - BOOL isMuted = FALSE; - endpointVolume_->GetMute(&isMuted); - if (!isMuted) { - endpointVolume_->SetMute(TRUE, nullptr); - } - } -} - -void VistaAudio::UnMute() -{ - if (CheckForReInit() && endpointVolume_ != nullptr) { - BOOL isMuted = TRUE; + BOOL isMuted = !mute; endpointVolume_->GetMute(&isMuted); - if (isMuted) { - endpointVolume_->SetMute(FALSE, nullptr); + if (!!isMuted != mute) { + endpointVolume_->SetMute(mute, nullptr); } } } diff --git a/WinMute/WinAudio.h b/WinMute/WinAudio.h index a965b56..d6b527d 100644 --- a/WinMute/WinAudio.h +++ b/WinMute/WinAudio.h @@ -40,8 +40,7 @@ public: virtual bool Init(HWND hParent) = 0; virtual void ShouldReInit() = 0; virtual bool IsMuted() = 0; - virtual void Mute() = 0; - virtual void UnMute() = 0; + virtual void SetMute(bool mute) = 0; virtual ~WinAudio() noexcept {}; }; @@ -60,8 +59,7 @@ public: bool Init(HWND hParent) override; void ShouldReInit() override; bool IsMuted() override; - void Mute() override; - void UnMute() override; + void SetMute(bool mute) override; private: void Uninit(); bool CheckForReInit(); diff --git a/WinMute/WinMute.cpp b/WinMute/WinMute.cpp index 85a0fe8..0419946 100644 --- a/WinMute/WinMute.cpp +++ b/WinMute/WinMute.cpp @@ -95,14 +95,6 @@ static int IsDarkMode(bool& isDarkMode) WinMute::MuteConfig::MuteConfig() { - this->withRestore.onLock = true; - this->withRestore.onScreensaver = true; - this->restoreAudio = true; - - this->noRestore.onLogoff = false; - this->noRestore.onSuspend = false; - this->noRestore.onShutdown = false; - this->quietHours.enabled = false; this->quietHours.forceUnmute = false; this->quietHours.notifications = false; @@ -114,13 +106,8 @@ WinMute::WinMute() : hWnd_(nullptr), hTrayMenu_(nullptr), hAppIcon_(nullptr), - hTrayIcon_(nullptr), - wasAlreadyMuted_(false), - muteCounter_(0) + hTrayIcon_(nullptr) { - muteCfg_["locked"] = { false, false }; - muteCfg_["screensaver"] = { false, false }; - muteCfg_["remote_session"] = { false, false }; } WinMute::~WinMute() @@ -158,7 +145,7 @@ bool WinMute::InitWindow() bool WinMute::InitAudio() { if (IsWindowsVistaOrGreater()) { - audio_ = std::unique_ptr(new VistaAudio); + // Nothing to do } else if (IsWindowsXPOrGreater()) { TaskDialog(nullptr, nullptr, PROGRAM_NAME, _T("Only Windows Vista and newer is supported"), @@ -168,9 +155,10 @@ bool WinMute::InitAudio() return false; } - if (!audio_->Init(hWnd_)) { + if (!muteCtrl_.Init(hWnd_)) { return false; } + Log::GetInstance().SetEnabled(true); return true; } @@ -185,12 +173,12 @@ bool WinMute::InitTrayMenu() PrintWindowsError(_T("LoadMenu")); return false; } else if ( - !CHECK_MENU_ITEM(MUTEONLOCK, muteConfig_.withRestore.onLock) || - !CHECK_MENU_ITEM(MUTEONSCREENSAVER, muteConfig_.withRestore.onScreensaver) || - !CHECK_MENU_ITEM(RESTOREAUDIO, muteConfig_.restoreAudio) || - !CHECK_MENU_ITEM(MUTEONSUSPEND, muteConfig_.noRestore.onSuspend) || - !CHECK_MENU_ITEM(MUTEONSHUTDOWN, muteConfig_.noRestore.onShutdown) || - !CHECK_MENU_ITEM(MUTEONLOGOUT, muteConfig_.noRestore.onLogoff) || + !CHECK_MENU_ITEM(MUTEONLOCK, muteCtrl_.GetMuteOnWorkstationLock()) || + !CHECK_MENU_ITEM(MUTEONSCREENSAVER, muteCtrl_.GetMuteOnScreensaverActivation()) || + !CHECK_MENU_ITEM(RESTOREAUDIO, muteCtrl_.GetRestoreVolume()) || + !CHECK_MENU_ITEM(MUTEONSUSPEND, muteCtrl_.GetMuteOnSuspend()) || + !CHECK_MENU_ITEM(MUTEONSHUTDOWN, muteCtrl_.GetMuteOnShutdown()) || + !CHECK_MENU_ITEM(MUTEONLOGOUT, muteCtrl_.GetMuteOnLogout()) || !CHECK_MENU_ITEM(CONFIGUREQUIETHOURS, muteConfig_.quietHours.enabled)) { return false; } @@ -203,13 +191,17 @@ bool WinMute::Init() hAppIcon_ = LoadIcon(hglobInstance, MAKEINTRESOURCE(IDI_APP)); if (!settings_.Init() || - !LoadDefaults()) { + !LoadDefaults()) { return false; } if (!RegisterWindowClass() || - !InitWindow() || - !InitTrayMenu()) { + !InitWindow() || + !InitTrayMenu()) { + return false; + } + + if (!InitAudio()) { return false; } @@ -217,7 +209,7 @@ bool WinMute::Init() return false; } - if (muteConfig_.withRestore.onScreensaver) { + if (muteCtrl_.GetMuteOnScreensaverActivation()) { if (!scrnSaverNoti_.ActivateNotifications(hWnd_)) { return false; } @@ -228,16 +220,12 @@ bool WinMute::Init() return false; } - if (!InitAudio()) { - return false; - } - bool isDarkMode = true; IsDarkMode(isDarkMode); hTrayIcon_ = LoadIcon( hglobInstance, isDarkMode ? MAKEINTRESOURCE(IDI_TRAY_DARK) - : MAKEINTRESOURCE(IDI_TRAY_BRIGHT)); + : MAKEINTRESOURCE(IDI_TRAY_BRIGHT)); if (hTrayIcon_ == NULL) { PrintWindowsError(_T("LoadIcon")); return false; @@ -251,19 +239,13 @@ bool WinMute::Init() bool WinMute::LoadDefaults() { - muteConfig_.withRestore.onLock = - settings_.QueryValue(SettingsKey::MUTE_ON_LOCK, 1) != 0; - muteConfig_.withRestore.onScreensaver = - settings_.QueryValue(SettingsKey::MUTE_ON_SCREENSAVER, 1) != 0; - muteConfig_.restoreAudio = - settings_.QueryValue(SettingsKey::RESTORE_AUDIO, 1) != 0; - - muteConfig_.noRestore.onLogoff = - settings_.QueryValue(SettingsKey::MUTE_ON_LOGOUT, 0) != 0; - muteConfig_.noRestore.onSuspend = - settings_.QueryValue(SettingsKey::MUTE_ON_SUSPEND, 0) != 0; - muteConfig_.noRestore.onShutdown = - settings_.QueryValue(SettingsKey::MUTE_ON_SHUTDOWN, 0) != 0; + muteCtrl_.SetRestoreVolume(!!settings_.QueryValue(SettingsKey::RESTORE_AUDIO, 1)); + muteCtrl_.SetMuteOnWorkstationLock(!!settings_.QueryValue(SettingsKey::MUTE_ON_LOCK, 1)); + muteCtrl_.SetMuteOnScreensaverActivation(!!settings_.QueryValue(SettingsKey::MUTE_ON_SCREENSAVER, 1)); + muteCtrl_.SetMuteOnDisplayStandby(!!settings_.QueryValue(SettingsKey::MUTE_ON_DISPLAYSTANDBY, 1)); + muteCtrl_.SetMuteOnLogout(!!settings_.QueryValue(SettingsKey::MUTE_ON_LOGOUT, 0)); + muteCtrl_.SetMuteOnSuspend(!!settings_.QueryValue(SettingsKey::MUTE_ON_SUSPEND, 0)); + muteCtrl_.SetMuteOnShutdown(!!settings_.QueryValue(SettingsKey::MUTE_ON_SHUTDOWN, 0)); muteConfig_.quietHours.enabled = settings_.QueryValue(SettingsKey::QUIETHOURS_ENABLE, 0) != 0; @@ -326,54 +308,57 @@ LRESULT CALLBACK WinMute::WindowProc( case ID_TRAYMENU_MUTE: { bool state = false; ToggleMenuCheck(ID_TRAYMENU_MUTE, &state); - if (!state) { - Log::GetInstance().Write("Mute: Off | Manual per Menu"); - audio_->UnMute(); - } else { - Log::GetInstance().Write("Mute: On | Manual per Menu"); - audio_->Mute(); - } + muteCtrl_.SetMute(state); break; } - case ID_TRAYMENU_MUTEONLOCK: - ToggleMenuCheck(ID_TRAYMENU_MUTEONLOCK, - &muteConfig_.withRestore.onLock); - settings_.SetValue(SettingsKey::MUTE_ON_LOCK, - muteConfig_.withRestore.onLock); + case ID_TRAYMENU_MUTEONLOCK: { + bool checked = false; + ToggleMenuCheck(ID_TRAYMENU_MUTEONLOCK, &checked); + muteCtrl_.SetMuteOnWorkstationLock(checked); + settings_.SetValue(SettingsKey::MUTE_ON_LOCK, checked); break; - case ID_TRAYMENU_RESTOREAUDIO: - ToggleMenuCheck(ID_TRAYMENU_RESTOREAUDIO, &muteConfig_.restoreAudio); - settings_.SetValue(SettingsKey::RESTORE_AUDIO, - muteConfig_.restoreAudio); + } + case ID_TRAYMENU_RESTOREAUDIO:{ + bool checked = false; + ToggleMenuCheck(ID_TRAYMENU_RESTOREAUDIO, &checked); + muteCtrl_.SetRestoreVolume(checked); + settings_.SetValue(SettingsKey::RESTORE_AUDIO, checked); break; - case ID_TRAYMENU_MUTEONSCREENSAVER: - ToggleMenuCheck(ID_TRAYMENU_MUTEONSCREENSAVER, - &muteConfig_.withRestore.onScreensaver); - settings_.SetValue(SettingsKey::MUTE_ON_SCREENSAVER, - muteConfig_.withRestore.onScreensaver); - if (muteConfig_.withRestore.onScreensaver) { + } + case ID_TRAYMENU_MUTEONSCREENSAVER: { + bool checked = false; + ToggleMenuCheck(ID_TRAYMENU_MUTEONSCREENSAVER, &checked); + muteCtrl_.SetMuteOnScreensaverActivation(checked); + settings_.SetValue(SettingsKey::MUTE_ON_SCREENSAVER, checked); + if (checked) { scrnSaverNoti_.ActivateNotifications(hWnd_); } else { scrnSaverNoti_.ClearNotifications(); } break; - case ID_TRAYMENU_MUTEONSHUTDOWN: - ToggleMenuCheck(ID_TRAYMENU_MUTEONSHUTDOWN, - &muteConfig_.noRestore.onShutdown); - settings_.SetValue(SettingsKey::MUTE_ON_SHUTDOWN, - muteConfig_.noRestore.onShutdown); + } + case ID_TRAYMENU_MUTEONSHUTDOWN: { + bool checked = false; + ToggleMenuCheck(ID_TRAYMENU_MUTEONSHUTDOWN, &checked); + muteCtrl_.SetMuteOnShutdown(checked); + settings_.SetValue(SettingsKey::MUTE_ON_SHUTDOWN, checked); + break; + } + case ID_TRAYMENU_MUTEONSUSPEND: { + bool checked = false; + ToggleMenuCheck(ID_TRAYMENU_MUTEONSUSPEND, &checked); + muteCtrl_.SetMuteOnSuspend(checked); + settings_.SetValue(SettingsKey::MUTE_ON_SUSPEND, checked); break; - case ID_TRAYMENU_MUTEONSUSPEND: - ToggleMenuCheck(ID_TRAYMENU_MUTEONSUSPEND, - &muteConfig_.noRestore.onSuspend); - settings_.SetValue(SettingsKey::MUTE_ON_SUSPEND, - muteConfig_.noRestore.onSuspend); + } + case ID_TRAYMENU_MUTEONLOGOUT: { + bool checked = false; + ToggleMenuCheck(ID_TRAYMENU_MUTEONLOGOUT, &checked); + muteCtrl_.SetMuteOnLogout(checked); + settings_.SetValue(SettingsKey::MUTE_ON_LOGOUT, checked); break; - case ID_TRAYMENU_MUTEONLOGOUT: - ToggleMenuCheck(ID_TRAYMENU_MUTEONLOGOUT, - &muteConfig_.noRestore.onLogoff); - settings_.SetValue(SettingsKey::MUTE_ON_LOGOUT, - muteConfig_.noRestore.onLogoff); + } + default: break; } return 0; @@ -402,92 +387,55 @@ LRESULT CALLBACK WinMute::WindowProc( } case WM_WTSSESSION_CHANGE: { if (wParam == WTS_SESSION_LOCK) { - if (muteCounter_ == 0 && audio_->IsMuted()) { - muteCounter_ = 1; - } - if (muteConfig_.withRestore.onLock) { - if (muteCounter_ == 0) { - Log::GetInstance().Write("Mute: Off | Workstation Lock"); - audio_->Mute(); - } - muteCounter_ += 1; - } + muteCtrl_.NotifyWorkstationLock(true); } else if (wParam == WTS_SESSION_UNLOCK) { - if (muteConfig_.restoreAudio && - muteConfig_.withRestore.onLock) { - if (--muteCounter_ == 0) { - Log::GetInstance().Write("Mute: Off | Workstation Unlock"); - audio_->UnMute(); - } - } + muteCtrl_.NotifyWorkstationLock(false); } return 0; } case WM_POWERBROADCAST: if (wParam == PBT_APMSUSPEND) { - if (muteConfig_.noRestore.onSuspend) { - Log::GetInstance().Write("Mute: On | Suspend/Hibernate"); - audio_->Mute(); + muteCtrl_.NotifySuspend(true); + } else if (wParam == PBT_POWERSETTINGCHANGE) { + const PPOWERBROADCAST_SETTING bs = + reinterpret_cast(lParam); + if (IsEqualGUID(bs->PowerSetting, GUID_CONSOLE_DISPLAY_STATE)) { + const DWORD state = reinterpret_cast(bs->Data); + if (state == 0x0) { // Display off + muteCtrl_.NotifyDisplayStandby(true); + } else if (state == 0x1) { // Display on + muteCtrl_.NotifyDisplayStandby(false); + } else if (state == 0x2) { // Display dimmed + } } } break; case WM_QUERYENDSESSION: if (lParam == 0) { // Shutdown - if (muteConfig_.noRestore.onShutdown) { - Log::GetInstance().Write("Mute: On | Shutdown"); - audio_->Mute(); - } + muteCtrl_.NotifyShutdown(); } else if ((lParam & ENDSESSION_LOGOFF)) { - if (muteConfig_.noRestore.onLogoff) { - Log::GetInstance().Write("Mute: On | Logoff"); - audio_->Mute(); - } + muteCtrl_.NotifyLogout(); } break; case WM_WINMUTE_QUIETHOURS_START: - muteCounter_ = !!audio_->IsMuted(); - Log::GetInstance().Write("Mute: On | Quiet Hours started"); - audio_->Mute(); - muteCounter_ += 1; + muteCtrl_.NotifyQuietHours(true); if (muteConfig_.quietHours.notifications) { trayIcon_.ShowPopup( _T("WinMute: Quiet hours started"), - _T("Your workstation audio is now muted")); + _T("Your workstation audio will now be muted.")); } SetQuietHoursEnd(); return 0; case WM_WINMUTE_QUIETHOURS_END: - muteCounter_ -= 1; - if (muteCounter_ > 0 && muteConfig_.quietHours.forceUnmute || - muteCounter_ == 0) { - Log::GetInstance().Write("Mute: Off | Quiet Hours ended"); - audio_->UnMute(); - if (muteConfig_.quietHours.notifications) { - trayIcon_.ShowPopup( - _T("WinMute: Quiet Hours ended"), - _T("Your workstation audio has been restored.")); - } - } else { - if (muteConfig_.quietHours.notifications) { - trayIcon_.ShowPopup( - _T("WinMute: Quiet Hours ended"), - _T("Quiet hours ended, since your your audio was already muted ") - _T("and force unmute is off, your workstation will remain muted.")); - } + muteCtrl_.NotifyQuietHours(false); + trayIcon_.ShowPopup( + _T("WinMute: Quiet Hours ended"), + _T("Your workstation audio has been restored.")); + if (muteConfig_.quietHours.forceUnmute) { + muteCtrl_.SetMute(false); } SetQuietHoursStart(); return 0; - case WM_WINMUTE_MUTE: { - bool mute = !!static_cast(wParam); - if (mute) { - Log::GetInstance().Write("Mute: On | Per Windows-Message"); - audio_->Mute(); - } else { - Log::GetInstance().Write("Mute: Off | Per Windows-Message"); - audio_->UnMute(); - } - return 0; - } case WM_WINMUTE_QUIETHOURS_CHANGE: { muteConfig_.quietHours.enabled = settings_.QueryValue( SettingsKey::QUIETHOURS_ENABLE, @@ -517,27 +465,14 @@ LRESULT CALLBACK WinMute::WindowProc( } case WM_SCRNSAVE_CHANGE: { if (wParam == SCRNSAVE_START) { - muteCounter_ = !!audio_->IsMuted(); - if (muteConfig_.withRestore.onScreensaver) { - if (muteCounter_ == 0) { - Log::GetInstance().Write("Mute: On | Screensaver start"); - audio_->Mute(); - } - muteCounter_ += 1; - } + muteCtrl_.NotifyScreensaver(true); } else if (wParam == SCRNSAVE_STOP) { - if (muteConfig_.restoreAudio && - muteConfig_.withRestore.onScreensaver) { - if (--muteCounter_ == 0) { - Log::GetInstance().Write("Mute: Off | Screensaver start"); - audio_->UnMute(); - } - } + muteCtrl_.NotifyScreensaver(false); } return 0; } case WM_SETTINGCHANGE: { - if (lstrcmp(LPCTSTR(lParam), L"ImmersiveColorSet") == 0) { + if (lstrcmp(LPCTSTR(lParam), _T("ImmersiveColorSet")) == 0) { bool isDarkMode = true; IsDarkMode(isDarkMode); hTrayIcon_ = LoadIcon( @@ -650,15 +585,15 @@ void WinMute::ResetQuietHours() if (QuietHoursShouldAlreadyHaveStarted(&now, &start, &end)) { int timerQhEnd = GetDiffMillseconds(&end, &now); - Log::GetInstance().Write("Mute: On | Quiet hours have already started"); - audio_->Mute(); + Log::GetInstance().Write(L"Mute: On | Quiet hours have already started"); + muteCtrl_.NotifyQuietHours(true); if (SetTimer(hWnd_, QUIETHOURS_TIMER_END_ID, timerQhEnd, QuietHoursTimer) == 0) { - MessageBox(hWnd_, _T("Failed to create Timer"), PROGRAM_NAME, MB_OK); + MessageBox(hWnd_, L"Failed to create Timer", PROGRAM_NAME, MB_OK); } } else { int timerQhStart = GetDiffMillseconds(&start, &now); if (SetTimer(hWnd_, QUIETHOURS_TIMER_START_ID, timerQhStart, QuietHoursTimer) == 0) { - MessageBox(hWnd_, _T("Failed to create Timer"), PROGRAM_NAME, MB_OK); + MessageBox(hWnd_, L"Failed to create Timer", PROGRAM_NAME, MB_OK); } } } @@ -678,7 +613,7 @@ void WinMute::SetQuietHoursStart() int timerQhStart = GetDiffMillseconds(&start, &now); if (SetTimer(hWnd_, QUIETHOURS_TIMER_START_ID, timerQhStart, QuietHoursTimer) == 0) { - MessageBox(hWnd_, _T("Failed to create Timer"), PROGRAM_NAME, MB_OK); + MessageBox(hWnd_, L"Failed to create Timer", PROGRAM_NAME, MB_OK); } } @@ -698,7 +633,7 @@ void WinMute::SetQuietHoursEnd() if (timerQhEnd <= 0) { SendMessage(hWnd_, WM_WINMUTE_QUIETHOURS_END, 0, 0); } else if (SetTimer(hWnd_, QUIETHOURS_TIMER_END_ID, timerQhEnd, QuietHoursTimer) == 0) { - MessageBox(hWnd_, _T("Failed to create Timer"), PROGRAM_NAME, MB_OK); + MessageBox(hWnd_, L"Failed to create Timer", PROGRAM_NAME, MB_OK); } } diff --git a/WinMute/WinMute.h b/WinMute/WinMute.h index d40a31f..ff8a8c5 100644 --- a/WinMute/WinMute.h +++ b/WinMute/WinMute.h @@ -38,7 +38,6 @@ POSSIBILITY OF SUCH DAMAGE. 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; @@ -55,13 +54,6 @@ public: // for internal use LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); private: - struct MuteConfigItem { - bool shouldMute; - bool isActive; - }; - - std::unordered_map muteCfg_; - HWND hWnd_; HMENU hTrayMenu_; HICON hAppIcon_; @@ -69,7 +61,7 @@ private: struct MuteConfig { MuteConfig(); - struct { + /*struct { bool onLock; bool onScreensaver; } withRestore; @@ -78,7 +70,7 @@ private: bool onLogoff; bool onShutdown; bool onSuspend; - } noRestore; + } noRestore;*/ struct { bool enabled; bool forceUnmute; @@ -88,18 +80,16 @@ private: } quietHours; } muteConfig_; - bool wasAlreadyMuted_; - int muteCounter_; - TrayIcon trayIcon_; - std::unique_ptr audio_; ScreensaverNotifier scrnSaverNoti_; Settings settings_; + MuteControl muteCtrl_; bool RegisterWindowClass(); bool InitWindow(); bool InitAudio(); bool InitTrayMenu(); + void InitMuteSettings(); bool LoadDefaults(); void ResetQuietHours(); diff --git a/WinMute/WinMute.rc b/WinMute/WinMute.rc index 88c8086..d597c19 100644 --- a/WinMute/WinMute.rc +++ b/WinMute/WinMute.rc @@ -83,15 +83,14 @@ BEGIN LTEXT "End time:",IDC_STATIC,28,76,32,16 END -IDD_SETTINGS DIALOGEX 0, 0, 403, 238 +IDD_SETTINGS DIALOGEX 0, 0, 272, 199 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Settings" FONT 8, "MS Shell Dlg", 400, 0, 0x1 BEGIN - DEFPUSHBUTTON "OK",IDOK,294,217,50,14 - PUSHBUTTON "Cancel",IDCANCEL,346,217,50,14 - CONTROL "",IDC_TREE1,"SysTreeView32",WS_BORDER | WS_HSCROLL | WS_TABSTOP,7,7,99,167 - CONTROL "",IDC_TAB1,"SysTabControl32",0x0,111,7,285,167 + DEFPUSHBUTTON "OK",IDOK,158,178,50,14 + PUSHBUTTON "Cancel",IDCANCEL,213,178,50,14 + CONTROL "",IDC_TAB1,"SysTabControl32",0x0,7,7,258,167 END IDD_SETTINGS_GENERAL DIALOGEX 0, 0, 297, 171 @@ -99,6 +98,8 @@ STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_SYSMENU FONT 8, "MS Shell Dlg", 400, 0, 0x1 BEGIN CONTROL "Start WinMute on system startup",IDC_CHECK1,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,15,132,26 + CONTROL "Enable Logging",IDC_ENABLELOGGING,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,61,101,21 + CONTROL "Show notifications",IDC_SHOWNOTIFICATIONS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,40,86,21 END IDD_SETTINGS_QUIETHOURS DIALOGEX 0, 0, 310, 177 @@ -136,9 +137,9 @@ BEGIN IDD_SETTINGS, DIALOG BEGIN LEFTMARGIN, 7 - RIGHTMARGIN, 396 + RIGHTMARGIN, 265 TOPMARGIN, 7 - BOTTOMMARGIN, 231 + BOTTOMMARGIN, 192 END IDD_SETTINGS_GENERAL, DIALOG diff --git a/WinMute/WinMute.vcxproj b/WinMute/WinMute.vcxproj index 0481912..adc1bda 100644 --- a/WinMute/WinMute.vcxproj +++ b/WinMute/WinMute.vcxproj @@ -101,7 +101,7 @@ true WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) true - stdcpp20 + stdcpplatest true Caret Use @@ -124,7 +124,7 @@ true WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) true - stdcpp20 + stdcpplatest true Caret true @@ -148,7 +148,7 @@ true _DEBUG;_WINDOWS;%(PreprocessorDefinitions) true - stdcpp20 + stdcpplatest true Caret Use @@ -171,7 +171,7 @@ true NDEBUG;_WINDOWS;%(PreprocessorDefinitions) true - stdcpp20 + stdcpplatest true Caret true @@ -190,9 +190,12 @@ + + + @@ -220,6 +223,8 @@ + + diff --git a/WinMute/WinMute.vcxproj.filters b/WinMute/WinMute.vcxproj.filters index f464b6e..3d631a0 100644 --- a/WinMute/WinMute.vcxproj.filters +++ b/WinMute/WinMute.vcxproj.filters @@ -9,58 +9,88 @@ {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - {6fe7a132-28a9-4b7b-aa69-1380069e7ee3} + + {8054b676-f98f-4a0b-bf41-266bac229306} - - {50123732-775b-41e8-9f2b-fc5925475924} + + {8ace85b5-3ff6-415f-91e0-f14665e8392d} - - {5f81f4a6-31a5-4c91-8563-6b63f79478fc} + + {006ee102-2667-484e-91ac-7ace0b94711a} - - {b90f43eb-497c-4b84-b7d9-df7a809e9cab} + + {10644ce7-c96f-4c74-9d5b-a2d66957235b} - - {8054b676-f98f-4a0b-bf41-266bac229306} + + {8d380999-372a-406c-b3d1-602d609c150c} - + {0cfb448e-c954-4181-96c8-c89e8d1728aa} + + {b90f43eb-497c-4b84-b7d9-df7a809e9cab} + + + {5f81f4a6-31a5-4c91-8563-6b63f79478fc} + + + {6fe7a132-28a9-4b7b-aa69-1380069e7ee3} + + + {50123732-775b-41e8-9f2b-fc5925475924} + + + {a30e53a3-8e2a-4955-b138-f2cbc8e92f9f} + + + {4879e951-6a56-461d-adcb-b4fca14928a6} + + + {21b7f94e-74d0-4737-bd72-da855556df2d} + - Source Files\Audio - - - Source Files + Source Files\Controllers\Muting\Audio - Source Files\Audio\VistaAudio + Source Files\Controllers\Muting\Audio\VistaAudio - Source Files\Audio\VistaAudio + Source Files\Controllers\Muting\Audio\VistaAudio - Source Files\Helper + Source Files\Base\Helper - Source Files\Log + Source Files\Base\Log + + + Source Files\Base\Settings + + + Source Files\Base\Helper + + + Source Files\Main + + + Source Files Source Files - Source Files\UI + Source Files\UI\TrayIcon - - Source Files + + Source Files\Controllers\QuietHours - - Source Files\Settings + + Source Files\Controllers\Muting - - Source Files\Helper + + Source Files @@ -80,44 +110,50 @@ - - Source Files - - Source Files\Audio + Source Files\Controllers\Muting\Audio - Source Files\Audio\VistaAudio + Source Files\Controllers\Muting\Audio\VistaAudio - Source Files\Audio\VistaAudio + Source Files\Controllers\Muting\Audio\VistaAudio - Source Files\Helper + Source Files\Base\Helper - Source Files\Helper + Source Files\Base\Helper - Source Files\Log + Source Files\Base\Log + + + Source Files\Base\Settings + + + Source Files\Main + + + Source Files\Main + + + Source Files - Source Files\UI + Source Files\UI\Dialogs - Source Files\UI + Source Files\UI\Dialogs - Source Files\UI + Source Files\UI\TrayIcon - - Source Files - - - Source Files + + Source Files\Controllers\QuietHours - - Source Files\Settings + + Source Files\Controllers\Muting \ No newline at end of file diff --git a/WinMute/WinMute.vcxproj.user b/WinMute/WinMute.vcxproj.user index 88a5509..779e244 100644 --- a/WinMute/WinMute.vcxproj.user +++ b/WinMute/WinMute.vcxproj.user @@ -1,4 +1,19 @@  - + + $(TargetDir) + WindowsLocalDebugger + + + $(TargetDir) + WindowsLocalDebugger + + + $(TargetDir) + WindowsLocalDebugger + + + $(TargetDir) + WindowsLocalDebugger + \ No newline at end of file diff --git a/WinMute/common.h b/WinMute/common.h index 0968c58..47bd3f4 100644 --- a/WinMute/common.h +++ b/WinMute/common.h @@ -49,16 +49,18 @@ POSSIBILITY OF SUCH DAMAGE. #define _WIN32_WINNT 0x0601 #include +#include #include #include -#include -#include -#include -#include -#include -#include #include +#include +#include +#include +#include +#include +#include #include +#include #include #include @@ -70,13 +72,21 @@ POSSIBILITY OF SUCH DAMAGE. #include "resource.h" +#include "BaseTypes.h" #include "ScreensaverNotifier.h" #include "Settings.h" #include "Log.h" #include "TrayIcon.h" +#include "WinAudio.h" +#include "MuteControl.h" #include "WinMute.h" #include "VersionHelper.h" +// Utility +void PrintWindowsError(LPCWSTR lpszFunction, DWORD lastError = -1); + +static const LPCTSTR PROGRAM_NAME = _T("WinMute"); + template inline void SafeRelease(Interface** ppInterfaceToRelease) { @@ -85,14 +95,3 @@ inline void SafeRelease(Interface** ppInterfaceToRelease) (*ppInterfaceToRelease) = nullptr; } } - -#ifdef UNICODE -typedef std::basic_string tstring; -#else -typedef std::basic_string tstring; -#endif - -// Utility -void PrintWindowsError(LPCWSTR lpszFunction, DWORD lastError = -1); - -static const LPCTSTR PROGRAM_NAME = _T("WinMute"); diff --git a/WinMute/icons/tray_bright.ico b/WinMute/icons/tray_bright.ico index fb4361ffe6909ca895eddeca847a91f634a65ca7..bbb5355d0795e9ef6095c1490b080257d27c5000 100644 GIT binary patch literal 7406 zcmeI$L1-LR7{Ku_G-8C%B$wi$vZ1}0dMP{*7DiTj@RnmB$6(;$#gb!#hfOIYAcauq z9iBYG(IAOzY=3$cX4!xapOMRem>b1=|d0%69C^ZEZ~(jElGg9j@!o8S97Z)e{7 z_M7eSW<^HiluSnR%1q<=I^|?tLRY;;`O`YZ)+V+t+1S{q)+S%~ zdh*N9PoA$!s`HwrsX$YK|3w9wb&81I$6F%hU6J3v5IO!-WTz+c<1KV}2JDJ_&oSTO z8$7{RxYZH4Pqh22Jt8jP`F-{kcAjl^kFD;r%0$&4joKf(Di0n!5X}bi?XSPdu6FGZ z`RR=h<-&zesu4y29=cL_kSI?TWv$HZc zHzx}V3*x<(rKKfVSy_?m*RRXXn>QucGw0@}+`fHVwzjsaxnqp7ySpooA3v6Uzb^*| z2a;u(93LN(qlzO7kAMiv&pMe_JOUyVcAx`OOF)FePImAh1&L7DfDRr3q#_EN#K9vV zqFz!vrglu@7}9aN<4`6h8IOPng(c_U5fGuUgdIErA{6!^96SOd6!yU!JOUyVOu)>( zdIj1Dg%!ZTBOpRyMR5p-P*{;1JOUyVRyYTbfCz;Z)4?MkLcu`fVp)Xh6=@Y#bO(=s z2!&k;2akXVgU|w(9rt=wzi#i>aqX~<6L}TO iR#C;GQ!d+hB;U43^1&j>KeCweIc#35v*q!u?tcL9xwCBm literal 7406 zcmeI$L17{Ku_Bw~c%wwK_cvZ1}$dMOMD3o9!*c+0WSV=ypyvGmyBVN(hXNFW4q z842`YL=V9pghG31A(l`Wj9@@4q8pzz2MbLIDf`U2pZ{;(+imOFOZDyM_r9HZvoqg* zZ?nv<$cT)})Rb@=moLXf-r>=S6Gi*OS44iM@BI1l{Ocm`<1Ly~cn>2yFWtt9kd7l9 z4Y%p(X}NguqRf3TCzn3DB=c9U$o1>jWo2bWJ`F+EKU^*>7ac z-j%G`?aeh0`e&M%jyAXST60@BMK!x>`xM*COkucBDfcCG6?>F_>{D!SV*8S{wY9W2 z`EGk#e*f*!a9@(1R~@PfR2BG7RN#eu%F&B2=_s{_okwC1i%xq`{0&a0bAz)-<*32n za?qfeCVFnFqCGsDCbp>tbEmavJl9TxhwXCkuw9-Vw9A>x@NAy)yxtYjcSZWQMgIC) zZ%0$&bhuW8yg#P z>(;Hbc8pPWc6Q|9!-vx8bmZ~l$I|U~<@orR990}ycmzaPe%8sd;t>#`uz?ONEddb< zd$NNEDM*CECUo!!AQe&AA`Tt_5yh6;v9x0u$CQqzJBG3_$#?`rC@eV#kAMh;CG6l4 z5TURa;ouPvp|BU`;1Lj^U;$S4=^i*nD69Yu9sv;wD~dxvgu;sC;1Lj^u);Zb1VkvT zm<}ER5eg;1Vkv9fL!QDK!k!x$%TFdL?~E@TZ2 z?&aOK#qE4Q&37Z;CHAD1Z>HEjUbM)9wIcTGMeMbT*liba-|}Ew%7@4gcd5Nt###~k zZx*rFC}MZMi2Lbv^>nw4n`K-qW37n&dJ!jDMSP>3qVAV<+1)PMn|noEJS<`@PqAO8 d4whGox)4deVUgs6MUsDDF)Lrkb9GM7`y0Yl>AwH~ diff --git a/WinMute/icons/tray_dark.ico b/WinMute/icons/tray_dark.ico index 73d5cc968c34c5a268135ee31d1f885e9ba640a7..92ed62e79dc167cb34a74b7f0d0d21cc534a5a76 100644 GIT binary patch delta 734 zcmaE7`Ob1f5+@HY5}2IFse&pn4_)9Kr|e__Hg;51|2QSZ*};Gh1dvSRovgwlp8`#*eX=G%>DP@RTs$N)h@&{H< zYz7K)%S`qa;Xn7e delta 438 zcmXZXK}!Nb7zW@aW_Fxi-K}+lv``U`L0%=&Ur_i5@(|r5>J&tX-nRioDB5h4*%HKm8?<x@$5K6^qabT{s`jW EAMzuz0RR91 diff --git a/WinMute/resource.h b/WinMute/resource.h index 36de0f8..1191b59 100644 --- a/WinMute/resource.h +++ b/WinMute/resource.h @@ -21,6 +21,8 @@ #define IDC_TREE1 1008 #define IDC_TAB1 1010 #define IDC_CHECK1 1011 +#define IDC_ENABLELOGGING 1012 +#define IDC_CHECK3 1013 #define ID_TRAYMENU_INFO 40001 #define ID_TRAYMENU_ 40002 #define ID_TRAYMENU_MUTEON 40003 @@ -52,7 +54,7 @@ #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 118 #define _APS_NEXT_COMMAND_VALUE 40025 -#define _APS_NEXT_CONTROL_VALUE 1012 +#define _APS_NEXT_CONTROL_VALUE 1014 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif -- 2.43.0