From 3cd7c3ce009822566cb6f9330cdf092e39198296 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Wed, 23 Jul 2025 13:52:31 +0800 Subject: [PATCH] Remove CursorInfo class --- .../SharedModels/CursorInfo.cs | 29 ------------------- .../SharedModels/MonitorInfo.cs | 9 ++++-- 2 files changed, 6 insertions(+), 32 deletions(-) delete mode 100644 Flow.Launcher.Plugin/SharedModels/CursorInfo.cs diff --git a/Flow.Launcher.Plugin/SharedModels/CursorInfo.cs b/Flow.Launcher.Plugin/SharedModels/CursorInfo.cs deleted file mode 100644 index 720bf2ae3..000000000 --- a/Flow.Launcher.Plugin/SharedModels/CursorInfo.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.Drawing; -using System.Runtime.InteropServices; -using Windows.Win32; - -namespace Flow.Launcher.Plugin.SharedModels; - -/// -/// Contains full information about a cursor. -/// -/// -/// Use this class to replace the System.Windows.Forms.Cursor class which can cause possible System.PlatformNotSupportedException. -/// -public class CursorInfo -{ - /// - /// Gets the current position of the cursor in screen coordinates. - /// - public static Point Position - { - get - { - if (!PInvoke.GetCursorPos(out var pt)) - { - Marshal.ThrowExceptionForHR(Marshal.GetLastWin32Error()); - } - return pt; - } - } -} diff --git a/Flow.Launcher.Plugin/SharedModels/MonitorInfo.cs b/Flow.Launcher.Plugin/SharedModels/MonitorInfo.cs index 22e09e2f5..6808c9c91 100644 --- a/Flow.Launcher.Plugin/SharedModels/MonitorInfo.cs +++ b/Flow.Launcher.Plugin/SharedModels/MonitorInfo.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Runtime.InteropServices; using System.Windows; using Windows.Win32; @@ -102,7 +101,11 @@ public class MonitorInfo /// The display monitor that contains the cursor, or null if no monitor is found. public static unsafe MonitorInfo GetCursorDisplayMonitor() { - var cursorMonitor = PInvoke.MonitorFromPoint(CursorInfo.Position, MONITOR_FROM_FLAGS.MONITOR_DEFAULTTONEAREST); + if (!PInvoke.GetCursorPos(out var pt)) + { + Marshal.ThrowExceptionForHR(Marshal.GetLastWin32Error()); + } + var cursorMonitor = PInvoke.MonitorFromPoint(pt, MONITOR_FROM_FLAGS.MONITOR_DEFAULTTONEAREST); MonitorInfo cursorMonitorInfo = null; var callback = new MONITORENUMPROC((monitor, deviceContext, rect, data) => {