]> repos.lx-s.de Git - winmute.git/commitdiff
Fixed muting behaviour with Windows' erratic screenshot behaviour
authorlx-s <lx-s@users.noreply.github.com>
Thu, 17 Jul 2014 11:50:46 +0000 (13:50 +0200)
committerlx-s <lx-s@users.noreply.github.com>
Thu, 17 Jul 2014 11:50:46 +0000 (13:50 +0200)
Build/WinMute.nuspec
Build/bin/changelog.txt
Build/bin/liesmich.html
Build/bin/readme.html
WinMute/ScreensaverNotifier.cpp
WinMute/ScreensaverNotifier.h
WinMute/res.rc

index 4dffc8d46920a26adcb1b3b664a03d637e1a8320..08154c392e49a6c99d02ceb7996510cb04987020 100644 (file)
@@ -4,7 +4,7 @@
   <metadata>
     <id>winmute</id>
     <title>WinMute</title>
-    <version>1.4.0.20140710</version>
+    <version>1.4.1.20140717</version>
     <authors>Alexander Steinhöfer</authors>
     <owners>Alexander Steinhöfer</owners>
     <summary>Automatic sound muter</summary>
index 9a27f75725a2861d9b8a2523d0fad8772d476cd0..fb6c57d194798d630089e88e09f1d205b2fa9c4f 100644 (file)
@@ -1,3 +1,8 @@
+Version 1.4.1 (2014-07-17)
+
+ * Fixed screenshot muting: It sometimes happened that WinMute 
+   muted Windows Audio for no apparent reason and "forgot" to
+   unmute. This is now fixed.
 
 Version 1.4 (2014-07-10)
 
index 6232b39ae371af0016ff7a8549c9045aec080198..9b96bb423f0e9a51af0dadb94413ea2d10e3a8d1 100644 (file)
@@ -2,7 +2,7 @@
 <html lang="de">
 <head>
    <meta charset="utf-8">
-   <title>WinMute 1.4 - Readme</title>
+   <title>WinMute 1.4.1 - Readme</title>
 
    <style type="text/css">
    <!--
index 7cb5b0cca2c0e38873806b9264ae66f5306369b8..9e1acbe1035005985c9dc6fbcf57eeb8a806fe05 100644 (file)
@@ -2,7 +2,7 @@
 <html lang="en">
 <head>
    <meta charset="utf-8">
-   <title>WinMute 1.4 - Readme</title>
+   <title>WinMute 1.4.1 - Readme</title>
 
    <style type="text/css">
    <!--
index 0adee9c9876daacdf0d9e45a548b673df35b54ec..5bfa77d84e04d1feb2a8478e27fe28b882775641 100644 (file)
@@ -76,6 +76,7 @@ ScreensaverNotifier::ScreensaverNotifier() :
    hookDll_(nullptr),
    regHook_(nullptr),
    unregHook_(nullptr),
+   alreadyNotified_(false),
    hookWndMsg_(0)
 { }
 
@@ -204,6 +205,23 @@ void ScreensaverNotifier::StartScreensaverPollTimer(bool start)
    }
 }
 
+/* ========================================================================== */
+/*    Other                                                                   */
+/* ========================================================================== */
+
+bool ScreensaverNotifier::IsScreensaverRunning()
+{
+   BOOL isRunning = FALSE;
+   if (SystemParametersInfo(SPI_GETSCREENSAVERRUNNING,
+                            0,
+                            &isRunning,
+                            FALSE) == NULL) {
+      PrintWindowsError(_T("SystemParametersInfo"));
+      return false;
+   }
+   return isRunning != 0;
+}
+
 /* ========================================================================== */
 /*    Window Proc                                                             */
 /* ========================================================================== */
@@ -220,25 +238,32 @@ LRESULT CALLBACK ScreensaverNotifier::WindowProc(HWND hWnd,
    }
    case WM_TIMER: {
       if (wParam == SCRSV_TIMER_ID) {
-         BOOL isRunning = FALSE;
-         if (SystemParametersInfo(SPI_GETSCREENSAVERRUNNING,
-                                  0,
-                                  &isRunning,
-                                  FALSE) == NULL) {
-            PrintWindowsError(_T("SystemParametersInfo"));
-         } else {
-            if (!isRunning) {
-               StartScreensaverPollTimer(false);
-               SendMessage(hNotifyWnd_, WM_SCRNSAVE_CHANGE, SCRNSAVE_STOP, 0);
-            }
+         if (!IsScreensaverRunning()) {
+            StartScreensaverPollTimer(false);
+            SendMessage(hNotifyWnd_, WM_SCRNSAVE_CHANGE, SCRNSAVE_STOP, 0);
+            alreadyNotified_ = false;
          }
       }
       return 0;
    }
    default:
       if (hookWndMsg_ != 0 && msg == hookWndMsg_) {
-         SendMessage(hNotifyWnd_, WM_SCRNSAVE_CHANGE, SCRNSAVE_START, 0);
-         StartScreensaverPollTimer();
+         /* Windows sends SC_SCREENSAVE when it tries to start a screensaver.
+            If screensaver is set to "none" or if another application cancels
+            this event, we would falsely mute windows.
+            To prevent that, we wait for a few milliseconds to and then check
+            if the screensaver has actually started. If yes, then send the
+            notification.
+         */
+         Sleep(500);
+         if (IsScreensaverRunning()) {
+            /* SC_SCREENSAVE might be fired multiple times */
+            if (!alreadyNotified_) {
+               alreadyNotified_ = true;
+               SendMessage(hNotifyWnd_, WM_SCRNSAVE_CHANGE, SCRNSAVE_START, 0);
+               StartScreensaverPollTimer();
+            }
+         }
       }
       break;
    }
index ef8ffb95109d4564ef314c9b4cbb7c658ad41be6..0a37f96aeb1e92023b5521b4609475f5364bf2f7 100644 (file)
@@ -60,6 +60,8 @@ private:
    typedef int(*RegisterHook)(HWND, UINT);
    typedef void(*UnregisterHook)(void);
 
+   bool alreadyNotified_;
+
 
    HINSTANCE hookDll_;
    HWND hWnd_, hNotifyWnd_;
@@ -70,6 +72,8 @@ private:
 
    void StartScreensaverPollTimer(bool start = true);
 
+   bool IsScreensaverRunning();
+
    bool InitHookDll();
    bool RegisterWindowClass();
    bool InitWindow();
index d1d92aa4605d87b589d5e728571e9402563a5bf9..e7e73d703dc5b72514ea34703576fff73e5783e3 100644 (file)
@@ -80,7 +80,7 @@ CAPTION "About WinMute"
 FONT 8, "MS Shell Dlg", 400, 0, 0x1
 BEGIN
     DEFPUSHBUTTON   "OK",IDOK,194,7,50,14
-    LTEXT           "WinMute v1.4",IDC_STATIC,43,9,67,11
+    LTEXT           "WinMute v1.4.1",IDC_STATIC,43,9,67,11
     CONTROL         "<a href=""http://lx-s.de"">lx-systems - lx-s.de</a>",IDC_LINK_HOMEPAGE,
                     "SysLink",WS_TABSTOP,43,31,69,13
     LTEXT           "Copyright © 2014 Alexander Steinhöfer",IDC_STATIC,43,20,148,12
@@ -114,8 +114,8 @@ END
 //
 
 VS_VERSION_INFO VERSIONINFO
- FILEVERSION 1,4,0,0
- PRODUCTVERSION 1,4,0,0
+ FILEVERSION 1,4,1,0
+ PRODUCTVERSION 1,4,1,0
  FILEFLAGSMASK 0x17L
 #ifdef _DEBUG
  FILEFLAGS 0x1L
@@ -130,25 +130,25 @@ BEGIN
     BEGIN
         BLOCK "000004b0"
         BEGIN
-            VALUE "CompanyName", "lx-s"
+            VALUE "CompanyName", "lx-systems"
             VALUE "FileDescription", "Automatic sound muter."
-            VALUE "FileVersion", "1.4.0.0"
+            VALUE "FileVersion", "1.4.1.0"
             VALUE "InternalName", "WinMute"
-            VALUE "LegalCopyright", "Copyright (C) 2013 Alexander Steinhöfer"
+            VALUE "LegalCopyright", "Copyright (C) 2014, Alexander Steinhöfer"
             VALUE "OriginalFilename", "WinMute.exe"
             VALUE "ProductName", "WinMute"
-            VALUE "ProductVersion", "1.4.0.0"
+            VALUE "ProductVersion", "1.4.1.0"
         END
         BLOCK "040704b0"
         BEGIN
-            VALUE "CompanyName", "lx-s"
+            VALUE "CompanyName", "lx-systems"
             VALUE "FileDescription", "Automatisches Stummschalten bei PC Sperre."
-            VALUE "FileVersion", "1.4.0.0"
+            VALUE "FileVersion", "1.4.1.0"
             VALUE "InternalName", "WinMute"
-            VALUE "LegalCopyright", "Copyright (C) 2013 Alexander Steinhöfer"
+            VALUE "LegalCopyright", "Copyright (C) 2014, Alexander Steinhöfer"
             VALUE "OriginalFilename", "WinMute.exe"
             VALUE "ProductName", "WinMute"
-            VALUE "ProductVersion", "1.4.0.0"
+            VALUE "ProductVersion", "1.4.1.0"
         END
     END
     BLOCK "VarFileInfo"