Skip to content

Commit cbbd09b

Browse files
committed
Add cursor info class
1 parent 1946afb commit cbbd09b

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.Drawing;
2+
using System.Runtime.InteropServices;
3+
using Windows.Win32;
4+
5+
namespace Flow.Launcher.Infrastructure;
6+
7+
/// <summary>
8+
/// Contains full information about a cursor.
9+
/// </summary>
10+
/// <remarks>
11+
/// Use this class to replace the System.Windows.Forms.Cursor class which can cause possible System.PlatformNotSupportedException.
12+
/// </remarks>
13+
public class CursorInfo
14+
{
15+
public static Point Position
16+
{
17+
get
18+
{
19+
if (!PInvoke.GetCursorPos(out var pt))
20+
{
21+
Marshal.ThrowExceptionForHR(Marshal.GetLastWin32Error());
22+
}
23+
return pt;
24+
}
25+
}
26+
}

Flow.Launcher.Infrastructure/MonitorInfo.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,7 @@ public static unsafe MonitorInfo GetPrimaryDisplayMonitor()
102102
/// <returns>The display monitor that contains the cursor, or null if no monitor is found.</returns>
103103
public static unsafe MonitorInfo GetCursorDisplayMonitor()
104104
{
105-
if (!PInvoke.GetCursorPos(out var pt))
106-
{
107-
Marshal.ThrowExceptionForHR(Marshal.GetLastWin32Error());
108-
}
109-
var cursorMonitor = PInvoke.MonitorFromPoint(pt, MONITOR_FROM_FLAGS.MONITOR_DEFAULTTONEAREST);
105+
var cursorMonitor = PInvoke.MonitorFromPoint(CursorInfo.Position, MONITOR_FROM_FLAGS.MONITOR_DEFAULTTONEAREST);
110106
MonitorInfo cursorMonitorInfo = null;
111107
var callback = new MONITORENUMPROC((monitor, deviceContext, rect, data) =>
112108
{

0 commit comments

Comments
 (0)