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

Commit

Permalink
Merge pull request #36 from MarkWhybird/master
Browse files Browse the repository at this point in the history
Spurrious mouse movement events squashed
  • Loading branch information
cwc authored Nov 17, 2017
2 parents b31a44c + 19230ae commit 00ec93b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion PreferencesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ private T LoadPrefByScreen<T>(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))
{
Expand Down
16 changes: 13 additions & 3 deletions ScreensaverForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 00ec93b

Please sign in to comment.