diff --git a/PreferencesManager.cs b/PreferencesManager.cs index c65b5fa..56a2c79 100644 --- a/PreferencesManager.cs +++ b/PreferencesManager.cs @@ -315,7 +315,7 @@ private T LoadPrefByScreen(int screenNum, string prefBaseName, string primary // look for the non-screen-specific pref setting, and if found, move it from there. // This is a one-off preferences upgrade. - if (Screen.AllScreens.Length == 1 || Screen.AllScreens.Length >= screenNum && Screen.AllScreens[screenNum].Primary) + if (Screen.AllScreens.Length == 1 || (screenNum < Screen.AllScreens.Length && Screen.AllScreens[screenNum].Primary)) { if (reg.GetValueNames().Contains(prefBaseName)) { diff --git a/ScreensaverForm.cs b/ScreensaverForm.cs index 302520c..4f63bed 100644 --- a/ScreensaverForm.cs +++ b/ScreensaverForm.cs @@ -163,14 +163,24 @@ public class GlobalUserEventHandler : IMessageFilter private const int WM_KEYDOWN = 0x100; private const int WM_KEYUP = 0x101; + // screensavers and especially multi-window apps can get spurrious WM_MOUSEMOVE events + // that don't actually involve any movement (cursor chnages and some mouse driver software + // can generate them, for example) - so we record the actual mouse position and compare against it for actual movement. + private Point? lastMousePos; + public event UserEvent Event; public bool PreFilterMessage(ref Message m) { - if ((m.Msg >= WM_MOUSEMOVE && m.Msg <= WM_MBUTTONDBLCLK) - || m.Msg == WM_KEYDOWN - || m.Msg == WM_KEYUP) + if ((m.Msg == WM_MOUSEMOVE) && (this.lastMousePos == null)) { + this.lastMousePos = Cursor.Position; + } + + if (((m.Msg == WM_MOUSEMOVE) && (Cursor.Position != this.lastMousePos)) + || (m.Msg > WM_MOUSEMOVE && m.Msg <= WM_MBUTTONDBLCLK) || m.Msg == WM_KEYDOWN || m.Msg == WM_KEYUP) + { + if (Event != null) { Event();