mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Add cursor info class
This commit is contained in:
parent
1946afbfe8
commit
cbbd09b8a5
2 changed files with 27 additions and 5 deletions
26
Flow.Launcher.Infrastructure/CursorInfo.cs
Normal file
26
Flow.Launcher.Infrastructure/CursorInfo.cs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
using Windows.Win32;
|
||||
|
||||
namespace Flow.Launcher.Infrastructure;
|
||||
|
||||
/// <summary>
|
||||
/// Contains full information about a cursor.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Use this class to replace the System.Windows.Forms.Cursor class which can cause possible System.PlatformNotSupportedException.
|
||||
/// </remarks>
|
||||
public class CursorInfo
|
||||
{
|
||||
public static Point Position
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!PInvoke.GetCursorPos(out var pt))
|
||||
{
|
||||
Marshal.ThrowExceptionForHR(Marshal.GetLastWin32Error());
|
||||
}
|
||||
return pt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -102,11 +102,7 @@ public class MonitorInfo
|
|||
/// <returns>The display monitor that contains the cursor, or null if no monitor is found.</returns>
|
||||
public static unsafe MonitorInfo GetCursorDisplayMonitor()
|
||||
{
|
||||
if (!PInvoke.GetCursorPos(out var pt))
|
||||
{
|
||||
Marshal.ThrowExceptionForHR(Marshal.GetLastWin32Error());
|
||||
}
|
||||
var cursorMonitor = PInvoke.MonitorFromPoint(pt, MONITOR_FROM_FLAGS.MONITOR_DEFAULTTONEAREST);
|
||||
var cursorMonitor = PInvoke.MonitorFromPoint(CursorInfo.Position, MONITOR_FROM_FLAGS.MONITOR_DEFAULTTONEAREST);
|
||||
MonitorInfo cursorMonitorInfo = null;
|
||||
var callback = new MONITORENUMPROC((monitor, deviceContext, rect, data) =>
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue