mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-12 18:29:24 +08:00
Trying to dispose mouse hook earlier to potentialy fix the lagging mouse bug after selecting the color (#5530)
This commit is contained in:
parent
be36b4aac1
commit
04c80915e5
@ -2,6 +2,7 @@
|
|||||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
|
using ColorPicker.Helpers;
|
||||||
using System;
|
using System;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
@ -71,7 +72,7 @@ namespace ColorPicker.Mouse
|
|||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
int errorCode = Marshal.GetLastWin32Error();
|
int errorCode = Marshal.GetLastWin32Error();
|
||||||
throw new Win32Exception(errorCode);
|
Logger.LogError("Failed to unsubscribe mouse hook with the error code" + errorCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -90,7 +91,7 @@ namespace ColorPicker.Mouse
|
|||||||
if (_mouseHookHandle == IntPtr.Zero)
|
if (_mouseHookHandle == IntPtr.Zero)
|
||||||
{
|
{
|
||||||
int errorCode = Marshal.GetLastWin32Error();
|
int errorCode = Marshal.GetLastWin32Error();
|
||||||
throw new Win32Exception(errorCode);
|
Logger.LogError("Failed to subscribe mouse hook with the error code" + errorCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,15 +94,7 @@ namespace ColorPicker.Mouse
|
|||||||
|
|
||||||
private void AppStateMonitor_AppClosed(object sender, EventArgs e)
|
private void AppStateMonitor_AppClosed(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
_timer.Stop();
|
DisposeHook();
|
||||||
_previousMousePosition = new System.Windows.Point(-1, 1);
|
|
||||||
_mouseHook.OnMouseDown -= MouseHook_OnMouseDown;
|
|
||||||
_mouseHook.OnMouseWheel -= MouseHook_OnMouseWheel;
|
|
||||||
|
|
||||||
if (_userSettings.ChangeCursor.Value)
|
|
||||||
{
|
|
||||||
CursorManager.RestoreOriginalCursors();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AppStateMonitor_AppShown(object sender, EventArgs e)
|
private void AppStateMonitor_AppShown(object sender, EventArgs e)
|
||||||
@ -135,7 +127,25 @@ namespace ColorPicker.Mouse
|
|||||||
|
|
||||||
private void MouseHook_OnMouseDown(object sender, Point p)
|
private void MouseHook_OnMouseDown(object sender, Point p)
|
||||||
{
|
{
|
||||||
|
DisposeHook();
|
||||||
OnMouseDown?.Invoke(this, p);
|
OnMouseDown?.Invoke(this, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void DisposeHook()
|
||||||
|
{
|
||||||
|
if (_timer.IsEnabled)
|
||||||
|
{
|
||||||
|
_timer.Stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
_previousMousePosition = new System.Windows.Point(-1, 1);
|
||||||
|
_mouseHook.OnMouseDown -= MouseHook_OnMouseDown;
|
||||||
|
_mouseHook.OnMouseWheel -= MouseHook_OnMouseWheel;
|
||||||
|
|
||||||
|
if (_userSettings.ChangeCursor.Value)
|
||||||
|
{
|
||||||
|
CursorManager.RestoreOriginalCursors();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user