Skip to content

Commit 527c27f

Browse files
committed
Remove System.Windows.Forms.Screen reference
1 parent e639412 commit 527c27f

File tree

5 files changed

+28
-32
lines changed

5 files changed

+28
-32
lines changed

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.ComponentModel;
33
using System.Linq;
44
using System.Media;
@@ -30,7 +30,6 @@
3030
using Key = System.Windows.Input.Key;
3131
using MouseButtons = System.Windows.Forms.MouseButtons;
3232
using NotifyIcon = System.Windows.Forms.NotifyIcon;
33-
using Screen = System.Windows.Forms.Screen;
3433

3534
namespace Flow.Launcher
3635
{
@@ -532,7 +531,7 @@ private void OnMouseDown(object sender, MouseButtonEventArgs e)
532531
double yRatio = mousePos.Y / maxHeight;
533532

534533
// Current monitor information
535-
var screen = Screen.FromHandle(new WindowInteropHelper(this).Handle);
534+
var screen = MonitorInfo.GetNearestDisplayMonitor(new WindowInteropHelper(this).Handle);
536535
var workingArea = screen.WorkingArea;
537536
var screenLeftTop = Win32Helper.TransformPixelsToDIP(this, workingArea.X, workingArea.Y);
538537

@@ -954,67 +953,67 @@ private void GetDpi(out double dpiX, out double dpiY)
954953
}
955954
}
956955

957-
private Screen SelectedScreen()
956+
private MonitorInfo SelectedScreen()
958957
{
959-
Screen screen;
958+
MonitorInfo screen;
960959
switch (_settings.SearchWindowScreen)
961960
{
962961
case SearchWindowScreens.Cursor:
963-
screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
964-
break;
965-
case SearchWindowScreens.Primary:
966-
screen = Screen.PrimaryScreen;
962+
screen = MonitorInfo.GetCursorDisplayMonitor();
967963
break;
968964
case SearchWindowScreens.Focus:
969-
var foregroundWindowHandle = Win32Helper.GetForegroundWindow();
970-
screen = Screen.FromHandle(foregroundWindowHandle);
965+
screen = MonitorInfo.GetNearestDisplayMonitor(Win32Helper.GetForegroundWindow());
966+
break;
967+
case SearchWindowScreens.Primary:
968+
screen = MonitorInfo.GetPrimaryDisplayMonitor();
971969
break;
972970
case SearchWindowScreens.Custom:
973-
if (_settings.CustomScreenNumber <= Screen.AllScreens.Length)
974-
screen = Screen.AllScreens[_settings.CustomScreenNumber - 1];
971+
var allScreens = MonitorInfo.GetDisplayMonitors();
972+
if (_settings.CustomScreenNumber <= allScreens.Count)
973+
screen = allScreens[_settings.CustomScreenNumber - 1];
975974
else
976-
screen = Screen.AllScreens[0];
975+
screen = allScreens[0];
977976
break;
978977
default:
979-
screen = Screen.AllScreens[0];
978+
screen = MonitorInfo.GetDisplayMonitors()[0];
980979
break;
981980
}
982981

983-
return screen ?? Screen.AllScreens[0];
982+
return screen ?? MonitorInfo.GetDisplayMonitors()[0];
984983
}
985984

986-
private double HorizonCenter(Screen screen)
985+
private double HorizonCenter(MonitorInfo screen)
987986
{
988987
var dip1 = Win32Helper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0);
989988
var dip2 = Win32Helper.TransformPixelsToDIP(this, screen.WorkingArea.Width, 0);
990989
var left = (dip2.X - ActualWidth) / 2 + dip1.X;
991990
return left;
992991
}
993992

994-
private double VerticalCenter(Screen screen)
993+
private double VerticalCenter(MonitorInfo screen)
995994
{
996995
var dip1 = Win32Helper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y);
997996
var dip2 = Win32Helper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Height);
998997
var top = (dip2.Y - QueryTextBox.ActualHeight) / 4 + dip1.Y;
999998
return top;
1000999
}
10011000

1002-
private double HorizonRight(Screen screen)
1001+
private double HorizonRight(MonitorInfo screen)
10031002
{
10041003
var dip1 = Win32Helper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0);
10051004
var dip2 = Win32Helper.TransformPixelsToDIP(this, screen.WorkingArea.Width, 0);
10061005
var left = (dip1.X + dip2.X - ActualWidth) - 10;
10071006
return left;
10081007
}
10091008

1010-
private double HorizonLeft(Screen screen)
1009+
private double HorizonLeft(MonitorInfo screen)
10111010
{
10121011
var dip1 = Win32Helper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0);
10131012
var left = dip1.X + 10;
10141013
return left;
10151014
}
10161015

1017-
public double VerticalTop(Screen screen)
1016+
private double VerticalTop(MonitorInfo screen)
10181017
{
10191018
var dip1 = Win32Helper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y);
10201019
var top = dip1.Y + 10;

Flow.Launcher/Msg.xaml.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.IO;
33
using System.Windows;
4-
using System.Windows.Forms;
54
using System.Windows.Input;
65
using System.Windows.Media.Animation;
76
using Flow.Launcher.Infrastructure;
@@ -16,7 +15,7 @@ public partial class Msg : Window
1615
public Msg()
1716
{
1817
InitializeComponent();
19-
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
18+
var screen = MonitorInfo.GetCursorDisplayMonitor();
2019
var dipWorkingArea = Win32Helper.TransformPixelsToDIP(this,
2120
screen.WorkingArea.Width,
2221
screen.WorkingArea.Height);

Flow.Launcher/MsgWithButton.xaml.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.IO;
33
using System.Windows;
4-
using System.Windows.Forms;
54
using System.Windows.Input;
65
using System.Windows.Media.Animation;
76
using Flow.Launcher.Infrastructure;
@@ -16,7 +15,7 @@ public partial class MsgWithButton : Window
1615
public MsgWithButton()
1716
{
1817
InitializeComponent();
19-
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
18+
var screen = MonitorInfo.GetCursorDisplayMonitor();
2019
var dipWorkingArea = Win32Helper.TransformPixelsToDIP(this,
2120
screen.WorkingArea.Width,
2221
screen.WorkingArea.Height);

Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Windows.Forms;
@@ -111,9 +111,9 @@ public List<int> ScreenNumbers
111111
{
112112
get
113113
{
114-
var screens = Screen.AllScreens;
114+
var screens = MonitorInfo.GetDisplayMonitors();
115115
var screenNumbers = new List<int>();
116-
for (int i = 1; i <= screens.Length; i++)
116+
for (int i = 1; i <= screens.Count; i++)
117117
{
118118
screenNumbers.Add(i);
119119
}

Flow.Launcher/SettingWindow.xaml.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
using Flow.Launcher.SettingPages.Views;
1111
using Flow.Launcher.ViewModel;
1212
using ModernWpf.Controls;
13-
using Screen = System.Windows.Forms.Screen;
1413

1514
namespace Flow.Launcher;
1615

@@ -202,7 +201,7 @@ private void AdjustWindowPosition(ref double top, ref double left)
202201

203202
private static bool IsPositionValid(double top, double left)
204203
{
205-
foreach (var screen in Screen.AllScreens)
204+
foreach (var screen in MonitorInfo.GetDisplayMonitors())
206205
{
207206
var workingArea = screen.WorkingArea;
208207

@@ -217,7 +216,7 @@ private static bool IsPositionValid(double top, double left)
217216

218217
private double WindowLeft()
219218
{
220-
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
219+
var screen = MonitorInfo.GetCursorDisplayMonitor();
221220
var dip1 = Win32Helper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0);
222221
var dip2 = Win32Helper.TransformPixelsToDIP(this, screen.WorkingArea.Width, 0);
223222
var left = (dip2.X - ActualWidth) / 2 + dip1.X;
@@ -226,7 +225,7 @@ private double WindowLeft()
226225

227226
private double WindowTop()
228227
{
229-
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
228+
var screen = MonitorInfo.GetCursorDisplayMonitor();
230229
var dip1 = Win32Helper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y);
231230
var dip2 = Win32Helper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Height);
232231
var top = (dip2.Y - ActualHeight) / 2 + dip1.Y - 20;

0 commit comments

Comments
 (0)