Skip to content
This repository was archived by the owner on Apr 17, 2019. It is now read-only.

Commit 00ec93b

Browse files
authored
Merge pull request #36 from MarkWhybird/master
Spurrious mouse movement events squashed
2 parents b31a44c + 19230ae commit 00ec93b

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

PreferencesManager.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ private T LoadPrefByScreen<T>(int screenNum, string prefBaseName, string primary
315315
// look for the non-screen-specific pref setting, and if found, move it from there.
316316
// This is a one-off preferences upgrade.
317317

318-
if (Screen.AllScreens.Length == 1 || Screen.AllScreens.Length >= screenNum && Screen.AllScreens[screenNum].Primary)
318+
if (Screen.AllScreens.Length == 1 || (screenNum < Screen.AllScreens.Length && Screen.AllScreens[screenNum].Primary))
319319
{
320320
if (reg.GetValueNames().Contains(prefBaseName))
321321
{

ScreensaverForm.cs

+13-3
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,24 @@ public class GlobalUserEventHandler : IMessageFilter
163163
private const int WM_KEYDOWN = 0x100;
164164
private const int WM_KEYUP = 0x101;
165165

166+
// screensavers and especially multi-window apps can get spurrious WM_MOUSEMOVE events
167+
// that don't actually involve any movement (cursor chnages and some mouse driver software
168+
// can generate them, for example) - so we record the actual mouse position and compare against it for actual movement.
169+
private Point? lastMousePos;
170+
166171
public event UserEvent Event;
167172

168173
public bool PreFilterMessage(ref Message m)
169174
{
170-
if ((m.Msg >= WM_MOUSEMOVE && m.Msg <= WM_MBUTTONDBLCLK)
171-
|| m.Msg == WM_KEYDOWN
172-
|| m.Msg == WM_KEYUP)
175+
if ((m.Msg == WM_MOUSEMOVE) && (this.lastMousePos == null))
173176
{
177+
this.lastMousePos = Cursor.Position;
178+
}
179+
180+
if (((m.Msg == WM_MOUSEMOVE) && (Cursor.Position != this.lastMousePos))
181+
|| (m.Msg > WM_MOUSEMOVE && m.Msg <= WM_MBUTTONDBLCLK) || m.Msg == WM_KEYDOWN || m.Msg == WM_KEYUP)
182+
{
183+
174184
if (Event != null)
175185
{
176186
Event();

0 commit comments

Comments
 (0)