Skip to content

Commit 266897e

Browse files
Jack251970TBM13
authored andcommitted
Merge pull request Flow-Launcher#3846 from Flow-Launcher/nuget_dependency
Upgrade NuGet Dependencies & Package Lock Json Files
1 parent 1bd7f5a commit 266897e

File tree

16 files changed

+167
-110
lines changed

16 files changed

+167
-110
lines changed

Flow.Launcher.Infrastructure/Flow.Launcher.Infrastructure.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
6060
</PackageReference>
6161
<PackageReference Include="MemoryPack" Version="1.21.4" />
62-
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.106">
62+
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.183">
6363
<PrivateAssets>all</PrivateAssets>
6464
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
6565
</PackageReference>

Flow.Launcher.Infrastructure/NativeMethods.txt

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ WINDOW_STYLE
3434
SetLastError
3535
WINDOW_EX_STYLE
3636

37-
GetSystemMetrics
38-
EnumDisplayMonitors
39-
MonitorFromWindow
40-
GetMonitorInfo
41-
MONITORINFOEXW
42-
4337
WM_ENTERSIZEMOVE
4438
WM_EXITSIZEMOVE
4539
WM_NCLBUTTONDBLCLK
@@ -51,17 +45,7 @@ SC_MINIMIZE
5145
OleInitialize
5246
OleUninitialize
5347

54-
GetKeyboardLayout
5548
GetWindowThreadProcessId
56-
ActivateKeyboardLayout
57-
GetKeyboardLayoutList
58-
PostMessage
59-
WM_INPUTLANGCHANGEREQUEST
60-
INPUTLANGCHANGE_FORWARD
61-
LOCALE_TRANSIENT_KEYBOARD1
62-
LOCALE_TRANSIENT_KEYBOARD2
63-
LOCALE_TRANSIENT_KEYBOARD3
64-
LOCALE_TRANSIENT_KEYBOARD4
6549

6650
SHParseDisplayName
6751
SHOpenFolderAndSelectItems

Flow.Launcher.Infrastructure/Win32Helper.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.Windows.Interop;
1212
using System.Windows.Markup;
1313
using System.Windows.Media;
14+
using Flow.Launcher.Plugin.SharedModels;
1415
using Windows.Win32;
1516
using Windows.Win32.Foundation;
1617
using Windows.Win32.Graphics.Dwm;
@@ -79,9 +80,9 @@ public static unsafe string GetWallpaperPath()
7980

8081
#region Window Foreground
8182

82-
public static nint GetForegroundWindow()
83+
public static unsafe nint GetForegroundWindow()
8384
{
84-
return PInvoke.GetForegroundWindow().Value;
85+
return (nint)PInvoke.GetForegroundWindow().Value;
8586
}
8687

8788
public static bool SetForegroundWindow(Window window)
@@ -240,15 +241,15 @@ public static unsafe bool IsForegroundWindowFullscreen()
240241
{
241242
var hWndDesktop = PInvoke.FindWindowEx(hWnd, HWND.Null, "SHELLDLL_DefView", null);
242243
hWndDesktop = PInvoke.FindWindowEx(hWndDesktop, HWND.Null, "SysListView32", "FolderView");
243-
if (hWndDesktop.Value != IntPtr.Zero)
244+
if (hWndDesktop != HWND.Null)
244245
{
245246
return false;
246247
}
247248
}
248249

249250
var monitorInfo = MonitorInfo.GetNearestDisplayMonitor(hWnd);
250-
return (appBounds.bottom - appBounds.top) == monitorInfo.RectMonitor.Height &&
251-
(appBounds.right - appBounds.left) == monitorInfo.RectMonitor.Width;
251+
return (appBounds.bottom - appBounds.top) == monitorInfo.Bounds.Height &&
252+
(appBounds.right - appBounds.left) == monitorInfo.Bounds.Width;
252253
}
253254

254255
#endregion

Flow.Launcher.Plugin/Flow.Launcher.Plugin.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
7373
</PackageReference>
7474
<PackageReference Include="JetBrains.Annotations" Version="2024.3.0" />
75-
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.106">
75+
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.183">
7676
<PrivateAssets>all</PrivateAssets>
7777
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
7878
</PackageReference>

Flow.Launcher.Plugin/NativeMethods.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,12 @@ GetWindowTextLength
55
WM_KEYDOWN
66
WM_KEYUP
77
WM_SYSKEYDOWN
8-
WM_SYSKEYUP
8+
WM_SYSKEYUP
9+
10+
GetSystemMetrics
11+
EnumDisplayMonitors
12+
MonitorFromWindow
13+
GetMonitorInfo
14+
MONITORINFOEXW
15+
GetCursorPos
16+
MonitorFromPoint

Flow.Launcher.Infrastructure/MonitorInfo.cs renamed to Flow.Launcher.Plugin/SharedModels/MonitorInfo.cs

Lines changed: 77 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
using System.Collections.Generic;
2-
using System;
32
using System.Runtime.InteropServices;
43
using System.Windows;
54
using Windows.Win32;
65
using Windows.Win32.Foundation;
76
using Windows.Win32.Graphics.Gdi;
87
using Windows.Win32.UI.WindowsAndMessaging;
98

10-
namespace Flow.Launcher.Infrastructure;
9+
namespace Flow.Launcher.Plugin.SharedModels;
1110

1211
/// <summary>
1312
/// Contains full information about a display monitor.
14-
/// Codes are edited from: <see href="https://github.com/Jack251970/DesktopWidgets3">.
13+
/// Inspired from: https://github.com/Jack251970/DesktopWidgets3.
1514
/// </summary>
16-
internal class MonitorInfo
15+
/// <remarks>
16+
/// Use this class to replace the System.Windows.Forms.Screen class which can cause possible System.PlatformNotSupportedException.
17+
/// </remarks>
18+
public class MonitorInfo
1719
{
1820
/// <summary>
1921
/// Gets the display monitors (including invisible pseudo-monitors associated with the mirroring drivers).
@@ -23,14 +25,14 @@ public static unsafe IList<MonitorInfo> GetDisplayMonitors()
2325
{
2426
var monitorCount = PInvoke.GetSystemMetrics(SYSTEM_METRICS_INDEX.SM_CMONITORS);
2527
var list = new List<MonitorInfo>(monitorCount);
26-
var callback = new MONITORENUMPROC((HMONITOR monitor, HDC deviceContext, RECT* rect, LPARAM data) =>
28+
var callback = new MONITORENUMPROC((monitor, deviceContext, rect, data) =>
2729
{
2830
list.Add(new MonitorInfo(monitor, rect));
2931
return true;
3032
});
3133
var dwData = new LPARAM();
3234
var hdc = new HDC();
33-
bool ok = PInvoke.EnumDisplayMonitors(hdc, (RECT?)null, callback, dwData);
35+
bool ok = PInvoke.EnumDisplayMonitors(hdc, null, callback, dwData);
3436
if (!ok)
3537
{
3638
Marshal.ThrowExceptionForHR(Marshal.GetLastWin32Error());
@@ -43,11 +45,11 @@ public static unsafe IList<MonitorInfo> GetDisplayMonitors()
4345
/// </summary>
4446
/// <param name="hwnd">Window handle</param>
4547
/// <returns>The display monitor that is nearest to a given window, or null if no monitor is found.</returns>
46-
public static unsafe MonitorInfo GetNearestDisplayMonitor(HWND hwnd)
48+
public static unsafe MonitorInfo GetNearestDisplayMonitor(nint hwnd)
4749
{
48-
var nearestMonitor = PInvoke.MonitorFromWindow(hwnd, MONITOR_FROM_FLAGS.MONITOR_DEFAULTTONEAREST);
50+
var nearestMonitor = PInvoke.MonitorFromWindow(new(hwnd), MONITOR_FROM_FLAGS.MONITOR_DEFAULTTONEAREST);
4951
MonitorInfo nearestMonitorInfo = null;
50-
var callback = new MONITORENUMPROC((HMONITOR monitor, HDC deviceContext, RECT* rect, LPARAM data) =>
52+
var callback = new MONITORENUMPROC((monitor, deviceContext, rect, data) =>
5153
{
5254
if (monitor == nearestMonitor)
5355
{
@@ -58,25 +60,83 @@ public static unsafe MonitorInfo GetNearestDisplayMonitor(HWND hwnd)
5860
});
5961
var dwData = new LPARAM();
6062
var hdc = new HDC();
61-
bool ok = PInvoke.EnumDisplayMonitors(hdc, (RECT?)null, callback, dwData);
63+
bool ok = PInvoke.EnumDisplayMonitors(hdc, null, callback, dwData);
6264
if (!ok)
6365
{
6466
Marshal.ThrowExceptionForHR(Marshal.GetLastWin32Error());
6567
}
6668
return nearestMonitorInfo;
6769
}
6870

71+
/// <summary>
72+
/// Gets the primary display monitor (the one that contains the taskbar).
73+
/// </summary>
74+
/// <returns>The primary display monitor, or null if no monitor is found.</returns>
75+
public static unsafe MonitorInfo GetPrimaryDisplayMonitor()
76+
{
77+
var primaryMonitor = PInvoke.MonitorFromWindow(new HWND(nint.Zero), MONITOR_FROM_FLAGS.MONITOR_DEFAULTTOPRIMARY);
78+
MonitorInfo primaryMonitorInfo = null;
79+
var callback = new MONITORENUMPROC((monitor, deviceContext, rect, data) =>
80+
{
81+
if (monitor == primaryMonitor)
82+
{
83+
primaryMonitorInfo = new MonitorInfo(monitor, rect);
84+
return false;
85+
}
86+
return true;
87+
});
88+
var dwData = new LPARAM();
89+
var hdc = new HDC();
90+
bool ok = PInvoke.EnumDisplayMonitors(hdc, null, callback, dwData);
91+
if (!ok)
92+
{
93+
Marshal.ThrowExceptionForHR(Marshal.GetLastWin32Error());
94+
}
95+
return primaryMonitorInfo;
96+
}
97+
98+
/// <summary>
99+
/// Gets the display monitor that contains the cursor.
100+
/// </summary>
101+
/// <returns>The display monitor that contains the cursor, or null if no monitor is found.</returns>
102+
public static unsafe MonitorInfo GetCursorDisplayMonitor()
103+
{
104+
if (!PInvoke.GetCursorPos(out var pt))
105+
{
106+
Marshal.ThrowExceptionForHR(Marshal.GetLastWin32Error());
107+
}
108+
var cursorMonitor = PInvoke.MonitorFromPoint(pt, MONITOR_FROM_FLAGS.MONITOR_DEFAULTTONEAREST);
109+
MonitorInfo cursorMonitorInfo = null;
110+
var callback = new MONITORENUMPROC((monitor, deviceContext, rect, data) =>
111+
{
112+
if (monitor == cursorMonitor)
113+
{
114+
cursorMonitorInfo = new MonitorInfo(monitor, rect);
115+
return false;
116+
}
117+
return true;
118+
});
119+
var dwData = new LPARAM();
120+
var hdc = new HDC();
121+
bool ok = PInvoke.EnumDisplayMonitors(hdc, null, callback, dwData);
122+
if (!ok)
123+
{
124+
Marshal.ThrowExceptionForHR(Marshal.GetLastWin32Error());
125+
}
126+
return cursorMonitorInfo;
127+
}
128+
69129
private readonly HMONITOR _monitor;
70130

71131
internal unsafe MonitorInfo(HMONITOR monitor, RECT* rect)
72132
{
73-
RectMonitor =
133+
Bounds =
74134
new Rect(new Point(rect->left, rect->top),
75135
new Point(rect->right, rect->bottom));
76136
_monitor = monitor;
77137
var info = new MONITORINFOEXW() { monitorInfo = new MONITORINFO() { cbSize = (uint)sizeof(MONITORINFOEXW) } };
78138
GetMonitorInfo(monitor, ref info);
79-
RectWork =
139+
WorkingArea =
80140
new Rect(new Point(info.monitorInfo.rcWork.left, info.monitorInfo.rcWork.top),
81141
new Point(info.monitorInfo.rcWork.right, info.monitorInfo.rcWork.bottom));
82142
Name = new string(info.szDevice.AsSpan()).Replace("\0", "").Trim();
@@ -93,23 +153,23 @@ internal unsafe MonitorInfo(HMONITOR monitor, RECT* rect)
93153
/// <remarks>
94154
/// <note>If the monitor is not the primary display monitor, some of the rectangle's coordinates may be negative values.</note>
95155
/// </remarks>
96-
public Rect RectMonitor { get; }
156+
public Rect Bounds { get; }
97157

98158
/// <summary>
99159
/// Gets the work area rectangle of the display monitor, expressed in virtual-screen coordinates.
100160
/// </summary>
101161
/// <remarks>
102162
/// <note>If the monitor is not the primary display monitor, some of the rectangle's coordinates may be negative values.</note>
103163
/// </remarks>
104-
public Rect RectWork { get; }
164+
public Rect WorkingArea { get; }
105165

106166
/// <summary>
107-
/// Gets if the monitor is the the primary display monitor.
167+
/// Gets if the monitor is the primary display monitor.
108168
/// </summary>
109-
public bool IsPrimary => _monitor == PInvoke.MonitorFromWindow(new(IntPtr.Zero), MONITOR_FROM_FLAGS.MONITOR_DEFAULTTOPRIMARY);
169+
public bool IsPrimary => _monitor == PInvoke.MonitorFromWindow(new(nint.Zero), MONITOR_FROM_FLAGS.MONITOR_DEFAULTTOPRIMARY);
110170

111171
/// <inheritdoc />
112-
public override string ToString() => $"{Name} {RectMonitor.Width}x{RectMonitor.Height}";
172+
public override string ToString() => $"{Name} {Bounds.Width}x{Bounds.Height}";
113173

114174
private static unsafe bool GetMonitorInfo(HMONITOR hMonitor, ref MONITORINFOEXW lpmi)
115175
{

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
using Flow.Launcher.Infrastructure.UserSettings;
1717
using Flow.Launcher.Plugin;
1818
using Flow.Launcher.Plugin.SharedCommands;
19+
using Flow.Launcher.Plugin.SharedModels;
1920
using Flow.Launcher.ViewModel;
2021
using ModernWpf.Controls;
2122
using DataObject = System.Windows.DataObject;
2223
using Key = System.Windows.Input.Key;
2324
using MouseButtons = System.Windows.Forms.MouseButtons;
2425
using NotifyIcon = System.Windows.Forms.NotifyIcon;
25-
using Screen = System.Windows.Forms.Screen;
2626

2727
namespace Flow.Launcher
2828
{
@@ -410,7 +410,7 @@ private void OnMouseDown(object sender, MouseButtonEventArgs e)
410410
double yRatio = mousePos.Y / maxHeight;
411411

412412
// Current monitor information
413-
var screen = Screen.FromHandle(new WindowInteropHelper(this).Handle);
413+
var screen = MonitorInfo.GetNearestDisplayMonitor(new WindowInteropHelper(this).Handle);
414414
var workingArea = screen.WorkingArea;
415415
var screenLeftTop = Win32Helper.TransformPixelsToDIP(this, workingArea.X, workingArea.Y);
416416

@@ -760,67 +760,67 @@ private void GetDpi(out double dpiX, out double dpiY)
760760
}
761761
}
762762

763-
private Screen SelectedScreen()
763+
private MonitorInfo SelectedScreen()
764764
{
765-
Screen screen;
765+
MonitorInfo screen;
766766
switch (_settings.SearchWindowScreen)
767767
{
768768
case SearchWindowScreens.Cursor:
769-
screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
770-
break;
771-
case SearchWindowScreens.Primary:
772-
screen = Screen.PrimaryScreen;
769+
screen = MonitorInfo.GetCursorDisplayMonitor();
773770
break;
774771
case SearchWindowScreens.Focus:
775-
var foregroundWindowHandle = Win32Helper.GetForegroundWindow();
776-
screen = Screen.FromHandle(foregroundWindowHandle);
772+
screen = MonitorInfo.GetNearestDisplayMonitor(Win32Helper.GetForegroundWindow());
773+
break;
774+
case SearchWindowScreens.Primary:
775+
screen = MonitorInfo.GetPrimaryDisplayMonitor();
777776
break;
778777
case SearchWindowScreens.Custom:
779-
if (_settings.CustomScreenNumber <= Screen.AllScreens.Length)
780-
screen = Screen.AllScreens[_settings.CustomScreenNumber - 1];
778+
var allScreens = MonitorInfo.GetDisplayMonitors();
779+
if (_settings.CustomScreenNumber <= allScreens.Count)
780+
screen = allScreens[_settings.CustomScreenNumber - 1];
781781
else
782-
screen = Screen.AllScreens[0];
782+
screen = allScreens[0];
783783
break;
784784
default:
785-
screen = Screen.AllScreens[0];
785+
screen = MonitorInfo.GetDisplayMonitors()[0];
786786
break;
787787
}
788788

789-
return screen ?? Screen.AllScreens[0];
789+
return screen ?? MonitorInfo.GetDisplayMonitors()[0];
790790
}
791791

792-
private double HorizonCenter(Screen screen)
792+
private double HorizonCenter(MonitorInfo screen)
793793
{
794794
var dip1 = Win32Helper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0);
795795
var dip2 = Win32Helper.TransformPixelsToDIP(this, screen.WorkingArea.Width, 0);
796796
var left = (dip2.X - ActualWidth) / 2 + dip1.X;
797797
return left;
798798
}
799799

800-
private double VerticalCenter(Screen screen)
800+
private double VerticalCenter(MonitorInfo screen)
801801
{
802802
var dip1 = Win32Helper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y);
803803
var dip2 = Win32Helper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Height);
804804
var top = (dip2.Y - QueryTextBox.ActualHeight) / 4 + dip1.Y;
805805
return top;
806806
}
807807

808-
private double HorizonRight(Screen screen)
808+
private double HorizonRight(MonitorInfo screen)
809809
{
810810
var dip1 = Win32Helper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0);
811811
var dip2 = Win32Helper.TransformPixelsToDIP(this, screen.WorkingArea.Width, 0);
812812
var left = (dip1.X + dip2.X - ActualWidth) - 10;
813813
return left;
814814
}
815815

816-
private double HorizonLeft(Screen screen)
816+
private double HorizonLeft(MonitorInfo screen)
817817
{
818818
var dip1 = Win32Helper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0);
819819
var left = dip1.X + 10;
820820
return left;
821821
}
822822

823-
public double VerticalTop(Screen screen)
823+
public double VerticalTop(MonitorInfo screen)
824824
{
825825
var dip1 = Win32Helper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y);
826826
var top = dip1.Y + 10;

0 commit comments

Comments
 (0)