From 55b247f5407cab91af14b45abbd701f8e43b7dd2 Mon Sep 17 00:00:00 2001 From: DB p Date: Mon, 13 Mar 2023 12:29:52 +0900 Subject: [PATCH 1/9] - Add Primary/Second/Custom Position in window position setting - Adjust Strings - Rename WindowPosition Setting --- .../UserSettings/Settings.cs | 23 +++-- Flow.Launcher/Languages/en.xaml | 14 ++- Flow.Launcher/MainWindow.xaml.cs | 95 ++++++++++++++----- Flow.Launcher/SettingWindow.xaml | 75 ++++++++++++--- .../ViewModel/SettingWindowViewModel.cs | 42 ++++++-- 5 files changed, 194 insertions(+), 55 deletions(-) diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index bfd7e4b87..d7b29aa46 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -195,6 +195,8 @@ namespace Flow.Launcher.Infrastructure.UserSettings public double WindowLeft { get; set; } public double WindowTop { get; set; } + public double CustomWindowLeft { get; set; } = 0; + public double CustomWindowTop { get; set; } = 0; public int MaxResultsToShow { get; set; } = 5; public int ActivateTimes { get; set; } @@ -227,7 +229,9 @@ namespace Flow.Launcher.Infrastructure.UserSettings } public bool LeaveCmdOpen { get; set; } public bool HideWhenDeactivated { get; set; } = true; - public SearchWindowPositions SearchWindowPosition { get; set; } = SearchWindowPositions.MouseScreenCenter; + + public SearchWindowScreens SearchWindowScreen { get; set; } = SearchWindowScreens.RememberLastLaunchLocation; + public SearchWindowAligns SearchWindowAlign { get; set; } = SearchWindowAligns.Center; public bool IgnoreHotkeysOnFullscreen { get; set; } public HttpProxy Proxy { get; set; } = new HttpProxy(); @@ -253,12 +257,19 @@ namespace Flow.Launcher.Infrastructure.UserSettings Light, Dark } - public enum SearchWindowPositions + public enum SearchWindowScreens { RememberLastLaunchLocation, - MouseScreenCenter, - MouseScreenCenterTop, - MouseScreenLeftTop, - MouseScreenRightTop + MouseScreen, + PrimaryScreen, + SecondaryScreen, + CustomPosition + } + public enum SearchWindowAligns + { + Center, + CenterTop, + LeftTop, + RightTop } } diff --git a/Flow.Launcher/Languages/en.xaml b/Flow.Launcher/Languages/en.xaml index 9e86d9305..a39adac54 100644 --- a/Flow.Launcher/Languages/en.xaml +++ b/Flow.Launcher/Languages/en.xaml @@ -38,11 +38,15 @@ Hide Flow Launcher when focus is lost Do not show new version notifications Search Window Position - Remember Last Position - Mouse Focused Screen - Center - Mouse Focused Screen - Center Top - Mouse Focused Screen - Left Top - Mouse Focused Screen - Right Top + Remember Last Position + Mouse Focused Monitor + Primary Monitor + Secondary Monitor + Custom Position + Center + Center Top + Left Top + Right Top Language Last Query Style Show/Hide previous results when Flow Launcher is reactivated. diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 550648b24..a465345be 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -24,6 +24,7 @@ using System.Windows.Threading; using System.Windows.Data; using ModernWpf.Controls; using Key = System.Windows.Input.Key; +using System.Threading; namespace Flow.Launcher { @@ -201,29 +202,39 @@ namespace Flow.Launcher private void InitializePosition() { - switch (_settings.SearchWindowPosition) + if (_settings.SearchWindowScreen == SearchWindowScreens.RememberLastLaunchLocation) { - case SearchWindowPositions.RememberLastLaunchLocation: - Top = _settings.WindowTop; - Left = _settings.WindowLeft; - break; - case SearchWindowPositions.MouseScreenCenter: - Left = HorizonCenter(); - Top = VerticalCenter(); - break; - case SearchWindowPositions.MouseScreenCenterTop: - Left = HorizonCenter(); - Top = 10; - break; - case SearchWindowPositions.MouseScreenLeftTop: - Left = 10; - Top = 10; - break; - case SearchWindowPositions.MouseScreenRightTop: - Left = HorizonRight(); - Top = 10; - break; + Top = _settings.WindowTop; + Left = _settings.WindowLeft; } + else if (_settings.SearchWindowScreen == SearchWindowScreens.CustomPosition) + { + Top = _settings.CustomWindowTop; + Left = _settings.CustomWindowLeft; + } + else + { + switch (_settings.SearchWindowAlign) + { + case SearchWindowAligns.Center: + Left = HorizonCenter(); + Top = VerticalCenter(); + break; + case SearchWindowAligns.CenterTop: + Left = HorizonCenter(); + Top = 10; + break; + case SearchWindowAligns.LeftTop: + Left = HorizonLeft(); + Top = 10; + break; + case SearchWindowAligns.RightTop: + Left = HorizonRight(); + Top = 10; + break; + } + } + } private void UpdateNotifyIconText() @@ -503,7 +514,7 @@ namespace Flow.Launcher { if (_animating) return; - if (_settings.SearchWindowPosition == SearchWindowPositions.RememberLastLaunchLocation) + if (_settings.SearchWindowScreen == SearchWindowScreens.RememberLastLaunchLocation) { _settings.WindowLeft = Left; _settings.WindowTop = Top; @@ -523,9 +534,32 @@ namespace Flow.Launcher } } + public Screen SelectedScreen() + { + if (_settings.SearchWindowScreen == SearchWindowScreens.MouseScreen) + { + var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position); + return screen; + } + else if (_settings.SearchWindowScreen == SearchWindowScreens.PrimaryScreen) + { + var screen = Screen.PrimaryScreen; + return screen; + } + else if (_settings.SearchWindowScreen == SearchWindowScreens.SecondaryScreen) + { + var screen = Screen.AllScreens[1]; + return screen; + } + else + { + var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position); + return screen; + } + } public double HorizonCenter() { - var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position); + var screen = SelectedScreen(); var dip1 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0); var dip2 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.Width, 0); var left = (dip2.X - ActualWidth) / 2 + dip1.X; @@ -534,7 +568,7 @@ namespace Flow.Launcher public double VerticalCenter() { - var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position); + var screen = SelectedScreen(); var dip1 = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y); var dip2 = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Height); var top = (dip2.Y - QueryTextBox.ActualHeight) / 4 + dip1.Y; @@ -543,10 +577,19 @@ namespace Flow.Launcher public double HorizonRight() { - var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position); + var screen = SelectedScreen(); var dip1 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0); var dip2 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.Width, 0); - var left = (dip2.X - ActualWidth) - 10; + var left = (dip1.X + dip2.X - ActualWidth) - 10; + return left; + } + + public double HorizonLeft() + { + var screen = SelectedScreen(); + var dip1 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0); + var dip2 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.Width, 0); + var left = dip1.X + 10; return left; } diff --git a/Flow.Launcher/SettingWindow.xaml b/Flow.Launcher/SettingWindow.xaml index 07f23ff6a..4a16e9610 100644 --- a/Flow.Launcher/SettingWindow.xaml +++ b/Flow.Launcher/SettingWindow.xaml @@ -698,17 +698,70 @@ - + + + + + + + + + + + + + + + + diff --git a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs index 37587ce59..7e3060384 100644 --- a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs +++ b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs @@ -22,6 +22,7 @@ using Flow.Launcher.Plugin.SharedModels; using System.Collections.ObjectModel; using CommunityToolkit.Mvvm.Input; using System.Globalization; +using static Flow.Launcher.ViewModel.SettingWindowViewModel; namespace Flow.Launcher.ViewModel { @@ -463,23 +464,50 @@ namespace Flow.Launcher.ViewModel } } - public class SearchWindowPosition + public class SearchWindowScreen { public string Display { get; set; } - public SearchWindowPositions Value { get; set; } + public SearchWindowScreens Value { get; set; } } - public List SearchWindowPositions + public List SearchWindowScreens { get { - List modes = new List(); - var enums = (SearchWindowPositions[])Enum.GetValues(typeof(SearchWindowPositions)); + List modes = new List(); + var enums = (SearchWindowScreens[])Enum.GetValues(typeof(SearchWindowScreens)); foreach (var e in enums) { - var key = $"SearchWindowPosition{e}"; + var key = $"SearchWindowScreen{e}"; var display = _translater.GetTranslation(key); - var m = new SearchWindowPosition + var m = new SearchWindowScreen + { + Display = display, + Value = e, + }; + modes.Add(m); + } + return modes; + } + } + + public class SearchWindowAlign + { + public string Display { get; set; } + public SearchWindowAligns Value { get; set; } + } + + public List SearchWindowAligns + { + get + { + List modes = new List(); + var enums = (SearchWindowAligns[])Enum.GetValues(typeof(SearchWindowAligns)); + foreach (var e in enums) + { + var key = $"SearchWindowAlign{e}"; + var display = _translater.GetTranslation(key); + var m = new SearchWindowAlign { Display = display, Value = e, }; From 975ea3c1b85bf54df0556f87a37274dbbd201e11 Mon Sep 17 00:00:00 2001 From: Vic <10308169+VictoriousRaptor@users.noreply.github.com> Date: Thu, 16 Mar 2023 11:05:34 +0800 Subject: [PATCH 2/9] Update WindowsInteropHelper.cs --- Flow.Launcher/Helper/WindowsInteropHelper.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Flow.Launcher/Helper/WindowsInteropHelper.cs b/Flow.Launcher/Helper/WindowsInteropHelper.cs index 4811eb224..16a96cd64 100644 --- a/Flow.Launcher/Helper/WindowsInteropHelper.cs +++ b/Flow.Launcher/Helper/WindowsInteropHelper.cs @@ -35,25 +35,25 @@ namespace Flow.Launcher.Helper } [DllImport("user32.dll", SetLastError = true)] - private static extern int GetWindowLong(IntPtr hWnd, int nIndex); + internal static extern int GetWindowLong(IntPtr hWnd, int nIndex); + + [DllImport("user32.dll")] + internal static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); [DllImport("user32.dll")] - private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); + internal static extern IntPtr GetForegroundWindow(); [DllImport("user32.dll")] - private static extern IntPtr GetForegroundWindow(); + internal static extern IntPtr GetDesktopWindow(); [DllImport("user32.dll")] - private static extern IntPtr GetDesktopWindow(); - - [DllImport("user32.dll")] - private static extern IntPtr GetShellWindow(); + internal static extern IntPtr GetShellWindow(); [DllImport("user32.dll", SetLastError = true)] - private static extern int GetWindowRect(IntPtr hwnd, out RECT rc); + internal static extern int GetWindowRect(IntPtr hwnd, out RECT rc); [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] - private static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount); + internal static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount); [DllImport("user32.DLL")] public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow); From a337c8a32609f0045424d86481728e7dc94d1073 Mon Sep 17 00:00:00 2001 From: Vic <10308169+VictoriousRaptor@users.noreply.github.com> Date: Thu, 16 Mar 2023 11:13:42 +0800 Subject: [PATCH 3/9] Refactor multi monitor support --- .../UserSettings/Settings.cs | 30 +++++-- Flow.Launcher/MainWindow.xaml.cs | 79 +++++++++---------- 2 files changed, 62 insertions(+), 47 deletions(-) diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index d7b29aa46..824c75cef 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -195,8 +195,17 @@ namespace Flow.Launcher.Infrastructure.UserSettings public double WindowLeft { get; set; } public double WindowTop { get; set; } + + /// + /// Custom left position on selected monitor + /// public double CustomWindowLeft { get; set; } = 0; + + /// + /// Custom top position on selected monitor + /// public double CustomWindowTop { get; set; } = 0; + public int MaxResultsToShow { get; set; } = 5; public int ActivateTimes { get; set; } @@ -229,9 +238,15 @@ namespace Flow.Launcher.Infrastructure.UserSettings } public bool LeaveCmdOpen { get; set; } public bool HideWhenDeactivated { get; set; } = true; - + + [JsonConverter(typeof(JsonStringEnumConverter))] public SearchWindowScreens SearchWindowScreen { get; set; } = SearchWindowScreens.RememberLastLaunchLocation; + + [JsonConverter(typeof(JsonStringEnumConverter))] public SearchWindowAligns SearchWindowAlign { get; set; } = SearchWindowAligns.Center; + + public string CustomScreenDeviceName { get; set; } = string.Empty; + public bool IgnoreHotkeysOnFullscreen { get; set; } public HttpProxy Proxy { get; set; } = new HttpProxy(); @@ -257,19 +272,22 @@ namespace Flow.Launcher.Infrastructure.UserSettings Light, Dark } + public enum SearchWindowScreens { RememberLastLaunchLocation, - MouseScreen, - PrimaryScreen, - SecondaryScreen, - CustomPosition + Cursor, + Focus, + Primary, + Custom } + public enum SearchWindowAligns { Center, CenterTop, LeftTop, - RightTop + RightTop, + Custom } } diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index a2d0eedfe..d59247729 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -24,9 +24,8 @@ using System.Windows.Threading; using System.Windows.Data; using ModernWpf.Controls; using Key = System.Windows.Input.Key; -using System.Threading; using System.Media; - +using System.Linq; namespace Flow.Launcher { @@ -207,31 +206,31 @@ namespace Flow.Launcher Top = _settings.WindowTop; Left = _settings.WindowLeft; } - else if (_settings.SearchWindowScreen == SearchWindowScreens.CustomPosition) - { - Top = _settings.CustomWindowTop; - Left = _settings.CustomWindowLeft; - } else { + var screen = SelectedScreen(); switch (_settings.SearchWindowAlign) { case SearchWindowAligns.Center: - Left = HorizonCenter(); - Top = VerticalCenter(); + Left = HorizonCenter(screen); + Top = VerticalCenter(screen); break; case SearchWindowAligns.CenterTop: - Left = HorizonCenter(); + Left = HorizonCenter(screen); Top = 10; break; case SearchWindowAligns.LeftTop: - Left = HorizonLeft(); + Left = HorizonLeft(screen); Top = 10; break; case SearchWindowAligns.RightTop: - Left = HorizonRight(); + Left = HorizonRight(screen); Top = 10; break; + case SearchWindowAligns.Custom: + Left = screen.WorkingArea.Left + _settings.CustomWindowLeft; + Top = screen.WorkingArea.Top + _settings.CustomWindowTop; + break; } } @@ -351,8 +350,9 @@ namespace Flow.Launcher { _viewModel.Show(); await Task.Delay(300); // If don't give a time, Positioning will be weird. - Left = HorizonCenter(); - Top = VerticalCenter(); + var screen = SelectedScreen(); + Left = HorizonCenter(screen); + Top = VerticalCenter(screen); } private void InitProgressbarAnimation() @@ -536,59 +536,56 @@ namespace Flow.Launcher public Screen SelectedScreen() { - if (_settings.SearchWindowScreen == SearchWindowScreens.MouseScreen) + Screen screen = null; + switch(_settings.SearchWindowScreen) { - var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position); - return screen; - } - else if (_settings.SearchWindowScreen == SearchWindowScreens.PrimaryScreen) - { - var screen = Screen.PrimaryScreen; - return screen; - } - else if (_settings.SearchWindowScreen == SearchWindowScreens.SecondaryScreen) - { - var screen = Screen.AllScreens[1]; - return screen; - } - else - { - var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position); - return screen; + case SearchWindowScreens.Cursor: + screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position); + break; + case SearchWindowScreens.Primary: + screen = Screen.PrimaryScreen; + break; + case SearchWindowScreens.Focus: + IntPtr foregroundWindowHandle = WindowsInteropHelper.GetForegroundWindow(); + screen = Screen.FromHandle(foregroundWindowHandle); + break; + case SearchWindowScreens.Custom: + screen = Screen.AllScreens.FirstOrDefault(s => s.DeviceName == _settings.CustomScreenDeviceName); + break; + default: + screen = Screen.AllScreens[0]; + break; } + return screen ?? Screen.AllScreens[0]; } - public double HorizonCenter() + + public double HorizonCenter(Screen screen) { - var screen = SelectedScreen(); var dip1 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0); var dip2 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.Width, 0); var left = (dip2.X - ActualWidth) / 2 + dip1.X; return left; } - public double VerticalCenter() + public double VerticalCenter(Screen screen) { - var screen = SelectedScreen(); var dip1 = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y); var dip2 = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Height); var top = (dip2.Y - QueryTextBox.ActualHeight) / 4 + dip1.Y; return top; } - public double HorizonRight() + public double HorizonRight(Screen screen) { - var screen = SelectedScreen(); var dip1 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0); var dip2 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.Width, 0); var left = (dip1.X + dip2.X - ActualWidth) - 10; return left; } - public double HorizonLeft() + public double HorizonLeft(Screen screen) { - var screen = SelectedScreen(); var dip1 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0); - var dip2 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.Width, 0); var left = dip1.X + 10; return left; } From e020cef2ecbd2af69d4e5780f4952217ab54078b Mon Sep 17 00:00:00 2001 From: Vic <10308169+VictoriousRaptor@users.noreply.github.com> Date: Thu, 16 Mar 2023 14:09:31 +0800 Subject: [PATCH 4/9] Add localization for mulit monitor support --- Flow.Launcher/Languages/en.xaml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Flow.Launcher/Languages/en.xaml b/Flow.Launcher/Languages/en.xaml index a39adac54..f18553903 100644 --- a/Flow.Launcher/Languages/en.xaml +++ b/Flow.Launcher/Languages/en.xaml @@ -39,14 +39,15 @@ Do not show new version notifications Search Window Position Remember Last Position - Mouse Focused Monitor - Primary Monitor - Secondary Monitor - Custom Position + Monitor with Mouse Cursor + Monitor with Focused Window + Primary Monitor + Custom Monitor Center Center Top Left Top Right Top + Custom Position Language Last Query Style Show/Hide previous results when Flow Launcher is reactivated. From 56adac6dd82644d2f1efafd7c1bca2f0c15f9eda Mon Sep 17 00:00:00 2001 From: Vic <10308169+VictoriousRaptor@users.noreply.github.com> Date: Thu, 16 Mar 2023 14:09:46 +0800 Subject: [PATCH 5/9] Tweak UI for multi monitor --- Flow.Launcher/SettingWindow.xaml | 185 +++++++++++++++++++------------ 1 file changed, 115 insertions(+), 70 deletions(-) diff --git a/Flow.Launcher/SettingWindow.xaml b/Flow.Launcher/SettingWindow.xaml index 4a16e9610..082f68ce6 100644 --- a/Flow.Launcher/SettingWindow.xaml +++ b/Flow.Launcher/SettingWindow.xaml @@ -694,78 +694,123 @@ - - - - - - - - - + + + + +  + + + - - - - - - - - - - - - - -  - - + + + + + + + + + + + + + + + + + + + + + + + + +  + + + + From b9bdbd9c6e5f22122bfb5156c3ad861cffb880a0 Mon Sep 17 00:00:00 2001 From: Vic <10308169+VictoriousRaptor@users.noreply.github.com> Date: Thu, 16 Mar 2023 14:41:14 +0800 Subject: [PATCH 6/9] Fix custom position --- Flow.Launcher/MainWindow.xaml.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index d59247729..098684211 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -228,8 +228,8 @@ namespace Flow.Launcher Top = 10; break; case SearchWindowAligns.Custom: - Left = screen.WorkingArea.Left + _settings.CustomWindowLeft; - Top = screen.WorkingArea.Top + _settings.CustomWindowTop; + Left = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.X + _settings.CustomWindowLeft, 0).X; // TODO not working + Top = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y + _settings.CustomWindowTop).Y; break; } } From 278f0eba305dd508035eee06bfb54292e112bf1f Mon Sep 17 00:00:00 2001 From: Vic <10308169+VictoriousRaptor@users.noreply.github.com> Date: Thu, 16 Mar 2023 14:41:58 +0800 Subject: [PATCH 7/9] Remove comment --- Flow.Launcher/MainWindow.xaml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 098684211..1469abe0b 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -228,7 +228,7 @@ namespace Flow.Launcher Top = 10; break; case SearchWindowAligns.Custom: - Left = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.X + _settings.CustomWindowLeft, 0).X; // TODO not working + Left = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.X + _settings.CustomWindowLeft, 0).X; Top = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y + _settings.CustomWindowTop).Y; break; } From 115d3a58f477fca819418fefd049bfc0830ca635 Mon Sep 17 00:00:00 2001 From: Vic <10308169+VictoriousRaptor@users.noreply.github.com> Date: Mon, 20 Mar 2023 17:50:53 +0800 Subject: [PATCH 8/9] Add custom monitor number selection combobox --- .../UserSettings/Settings.cs | 2 +- Flow.Launcher/MainWindow.xaml.cs | 5 ++++- Flow.Launcher/SettingWindow.xaml | 6 ++---- Flow.Launcher/ViewModel/SettingWindowViewModel.cs | 14 ++++++++++++++ 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index 824c75cef..7f62d82c8 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -245,7 +245,7 @@ namespace Flow.Launcher.Infrastructure.UserSettings [JsonConverter(typeof(JsonStringEnumConverter))] public SearchWindowAligns SearchWindowAlign { get; set; } = SearchWindowAligns.Center; - public string CustomScreenDeviceName { get; set; } = string.Empty; + public int CustomScreenNumber { get; set; } = 1; public bool IgnoreHotkeysOnFullscreen { get; set; } diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 1469abe0b..4477da5f4 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -550,7 +550,10 @@ namespace Flow.Launcher screen = Screen.FromHandle(foregroundWindowHandle); break; case SearchWindowScreens.Custom: - screen = Screen.AllScreens.FirstOrDefault(s => s.DeviceName == _settings.CustomScreenDeviceName); + if (_settings.CustomScreenNumber <= Screen.AllScreens.Length) + screen = Screen.AllScreens[_settings.CustomScreenNumber - 1]; + else + screen = Screen.AllScreens[0]; break; default: screen = Screen.AllScreens[0]; diff --git a/Flow.Launcher/SettingWindow.xaml b/Flow.Launcher/SettingWindow.xaml index 082f68ce6..67f53c940 100644 --- a/Flow.Launcher/SettingWindow.xaml +++ b/Flow.Launcher/SettingWindow.xaml @@ -719,11 +719,9 @@ MinWidth="160" Margin="0,0,18,0" VerticalAlignment="Center" - DisplayMemberPath="Display" FontSize="14" - ItemsSource="{Binding SearchWindowAligns}" - SelectedValue="{Binding Settings.SearchWindowAlign}" - SelectedValuePath="Value"> + ItemsSource="{Binding ScreenNumbers}" + SelectedValue="{Binding Settings.CustomScreenNumber}"> + +