From 24cc4757b4d924158885edf36071097794ba08a5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 Jun 2024 22:40:45 +0000 Subject: [PATCH 01/23] Bump Microsoft.Data.Sqlite from 8.0.3 to 8.0.6 Bumps [Microsoft.Data.Sqlite](https://github.com/dotnet/efcore) from 8.0.3 to 8.0.6. - [Release notes](https://github.com/dotnet/efcore/releases) - [Commits](https://github.com/dotnet/efcore/compare/v8.0.3...v8.0.6) --- updated-dependencies: - dependency-name: Microsoft.Data.Sqlite dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .../Flow.Launcher.Plugin.BrowserBookmark.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Flow.Launcher.Plugin.BrowserBookmark.csproj b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Flow.Launcher.Plugin.BrowserBookmark.csproj index 234afe28a..9177813f4 100644 --- a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Flow.Launcher.Plugin.BrowserBookmark.csproj +++ b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Flow.Launcher.Plugin.BrowserBookmark.csproj @@ -95,7 +95,7 @@ - + From 37ccf259405e4ac70c2587b1f7b3a5e8c45159ec Mon Sep 17 00:00:00 2001 From: DB p Date: Wed, 5 Jun 2024 04:53:31 +0900 Subject: [PATCH 02/23] Add Top Positioning per monitor --- Flow.Launcher/MainWindow.xaml.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 22799a63d..6c0889295 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -306,15 +306,15 @@ namespace Flow.Launcher break; case SearchWindowAligns.CenterTop: Left = HorizonCenter(screen); - Top = 10; + Top = VerticalTop(screen); break; case SearchWindowAligns.LeftTop: Left = HorizonLeft(screen); - Top = 10; + Top = VerticalTop(screen); break; case SearchWindowAligns.RightTop: Left = HorizonRight(screen); - Top = 10; + Top = VerticalTop(screen); break; case SearchWindowAligns.Custom: Left = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.X + _settings.CustomWindowLeft, 0).X; @@ -727,6 +727,13 @@ namespace Flow.Launcher return left; } + public double VerticalTop(Screen screen) + { + var dip1 = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y); + var top = dip1.Y +10; + return top; + } + /// /// Register up and down key /// todo: any way to put this in xaml ? From 63ce735169afe7cf871d3d2a8eb6086e49fefa9a Mon Sep 17 00:00:00 2001 From: DB p Date: Wed, 5 Jun 2024 06:42:33 +0900 Subject: [PATCH 03/23] =?UTF-8?q?When=20using=20the=20=E2=80=9Cremember=20?= =?UTF-8?q?last=20position=E2=80=9D=20setting,=20if=20the=20resolution=20o?= =?UTF-8?q?r=20dpi=20has=20changed,=20the=20position=20will=20be=20rescale?= =?UTF-8?q?d=20proportionally?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Flow.Launcher/MainWindow.xaml.cs | 33 +++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 6c0889295..87e818154 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -27,6 +27,7 @@ using DataObject = System.Windows.DataObject; using System.Windows.Media; using System.Windows.Interop; using System.Runtime.InteropServices; +using System.Drawing; namespace Flow.Launcher { @@ -48,6 +49,10 @@ namespace Flow.Launcher private MediaPlayer animationSoundWMP; private SoundPlayer animationSoundWPF; + private double _previousScreenWidth; + private double _previousScreenHeight; + private double _previousDpiX; + private double _previousDpiY; #endregion @@ -288,8 +293,31 @@ namespace Flow.Launcher }; } + private (double X, double Y) GetCurrentDpi(Screen screen) + { + using (Graphics g = Graphics.FromHwnd(IntPtr.Zero)) + { + return (g.DpiX, g.DpiY); + } + } private void InitializePosition() { + var screen = SelectedScreen(); + var currentDpi = GetCurrentDpi(screen); + double currentScreenWidth = screen.WorkingArea.Width; + double currentScreenHeight = screen.WorkingArea.Height; + + if (_previousScreenWidth != 0 && _previousScreenHeight != 0 && _previousDpiX != 0 && _previousDpiY != 0) + { + double widthRatio = currentScreenWidth / _previousScreenWidth; + double heightRatio = currentScreenHeight / _previousScreenHeight; + double dpiXRatio = currentDpi.X / _previousDpiX; + double dpiYRatio = currentDpi.Y / _previousDpiY; + + _settings.WindowLeft *= widthRatio * dpiXRatio; + _settings.WindowTop *= heightRatio * dpiYRatio; + } + if (_settings.SearchWindowScreen == SearchWindowScreens.RememberLastLaunchLocation) { Top = _settings.WindowTop; @@ -297,7 +325,6 @@ namespace Flow.Launcher } else { - var screen = SelectedScreen(); switch (_settings.SearchWindowAlign) { case SearchWindowAligns.Center: @@ -323,6 +350,10 @@ namespace Flow.Launcher } } + _previousScreenWidth = currentScreenWidth; + _previousScreenHeight = currentScreenHeight; + _previousDpiX = currentDpi.X; + _previousDpiY = currentDpi.Y; } private void UpdateNotifyIconText() From ae0ec8ecf292ee56417da240966f516028f4c88d Mon Sep 17 00:00:00 2001 From: DB p Date: Wed, 5 Jun 2024 06:51:25 +0900 Subject: [PATCH 04/23] Revert "Fix blurry situation when changed dpi in some case" This reverts commit 2869812a74160517b2cd4ba6a7436b40eaa59195. --- Flow.Launcher/app.manifest | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Flow.Launcher/app.manifest b/Flow.Launcher/app.manifest index c45508fcf..52d1c3932 100644 --- a/Flow.Launcher/app.manifest +++ b/Flow.Launcher/app.manifest @@ -49,12 +49,13 @@ DPIs. Windows Presentation Foundation (WPF) applications are automatically DPI-aware and do not need to opt in. Windows Forms applications targeting .NET Framework 4.6 that opt into this setting, should also set the 'EnableWindowsFormsHighDpiAutoResizing' setting to 'true' in their app.config. --> + From 45dd84a3fa39e5784d9101bde4aabd5eff7e7969 Mon Sep 17 00:00:00 2001 From: DB p Date: Wed, 5 Jun 2024 07:03:26 +0900 Subject: [PATCH 05/23] Adjust Code --- Flow.Launcher/MainWindow.xaml.cs | 96 +++++++++++++++++--------------- 1 file changed, 52 insertions(+), 44 deletions(-) diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 87e818154..927067f93 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -307,53 +307,61 @@ namespace Flow.Launcher double currentScreenWidth = screen.WorkingArea.Width; double currentScreenHeight = screen.WorkingArea.Height; - if (_previousScreenWidth != 0 && _previousScreenHeight != 0 && _previousDpiX != 0 && _previousDpiY != 0) + if (!( + _previousScreenWidth == currentScreenWidth && + _previousScreenHeight == currentScreenHeight && + _previousDpiX == currentDpi.X && + _previousDpiY == currentDpi.Y + )) { - double widthRatio = currentScreenWidth / _previousScreenWidth; - double heightRatio = currentScreenHeight / _previousScreenHeight; - double dpiXRatio = currentDpi.X / _previousDpiX; - double dpiYRatio = currentDpi.Y / _previousDpiY; - - _settings.WindowLeft *= widthRatio * dpiXRatio; - _settings.WindowTop *= heightRatio * dpiYRatio; - } - - if (_settings.SearchWindowScreen == SearchWindowScreens.RememberLastLaunchLocation) - { - Top = _settings.WindowTop; - Left = _settings.WindowLeft; - } - else - { - switch (_settings.SearchWindowAlign) + if (_previousScreenWidth != 0 && _previousScreenHeight != 0 && _previousDpiX != 0 && _previousDpiY != 0) { - case SearchWindowAligns.Center: - Left = HorizonCenter(screen); - Top = VerticalCenter(screen); - break; - case SearchWindowAligns.CenterTop: - Left = HorizonCenter(screen); - Top = VerticalTop(screen); - break; - case SearchWindowAligns.LeftTop: - Left = HorizonLeft(screen); - Top = VerticalTop(screen); - break; - case SearchWindowAligns.RightTop: - Left = HorizonRight(screen); - Top = VerticalTop(screen); - break; - case SearchWindowAligns.Custom: - Left = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.X + _settings.CustomWindowLeft, 0).X; - Top = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y + _settings.CustomWindowTop).Y; - break; - } - } + double widthRatio = currentScreenWidth / _previousScreenWidth; + double heightRatio = currentScreenHeight / _previousScreenHeight; + double dpiXRatio = currentDpi.X / _previousDpiX; + double dpiYRatio = currentDpi.Y / _previousDpiY; - _previousScreenWidth = currentScreenWidth; - _previousScreenHeight = currentScreenHeight; - _previousDpiX = currentDpi.X; - _previousDpiY = currentDpi.Y; + _settings.WindowLeft *= widthRatio * dpiXRatio; + _settings.WindowTop *= heightRatio * dpiYRatio; + } + + if (_settings.SearchWindowScreen == SearchWindowScreens.RememberLastLaunchLocation) + { + Top = _settings.WindowTop; + Left = _settings.WindowLeft; + } + else + { + switch (_settings.SearchWindowAlign) + { + case SearchWindowAligns.Center: + Left = HorizonCenter(screen); + Top = VerticalCenter(screen); + break; + case SearchWindowAligns.CenterTop: + Left = HorizonCenter(screen); + Top = VerticalTop(screen); + break; + case SearchWindowAligns.LeftTop: + Left = HorizonLeft(screen); + Top = VerticalTop(screen); + break; + case SearchWindowAligns.RightTop: + Left = HorizonRight(screen); + Top = VerticalTop(screen); + break; + case SearchWindowAligns.Custom: + Left = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.X + _settings.CustomWindowLeft, 0).X; + Top = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y + _settings.CustomWindowTop).Y; + break; + } + } + + _previousScreenWidth = currentScreenWidth; + _previousScreenHeight = currentScreenHeight; + _previousDpiX = currentDpi.X; + _previousDpiY = currentDpi.Y; + } } private void UpdateNotifyIconText() From e0cdc92766b7a3602385be45911c187754ea9637 Mon Sep 17 00:00:00 2001 From: DB p Date: Thu, 6 Jun 2024 06:02:26 +0900 Subject: [PATCH 06/23] Revert "Adjust Code" This reverts commit 45dd84a3fa39e5784d9101bde4aabd5eff7e7969. --- Flow.Launcher/MainWindow.xaml.cs | 96 +++++++++++++++----------------- 1 file changed, 44 insertions(+), 52 deletions(-) diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 927067f93..87e818154 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -307,61 +307,53 @@ namespace Flow.Launcher double currentScreenWidth = screen.WorkingArea.Width; double currentScreenHeight = screen.WorkingArea.Height; - if (!( - _previousScreenWidth == currentScreenWidth && - _previousScreenHeight == currentScreenHeight && - _previousDpiX == currentDpi.X && - _previousDpiY == currentDpi.Y - )) + if (_previousScreenWidth != 0 && _previousScreenHeight != 0 && _previousDpiX != 0 && _previousDpiY != 0) { - if (_previousScreenWidth != 0 && _previousScreenHeight != 0 && _previousDpiX != 0 && _previousDpiY != 0) - { - double widthRatio = currentScreenWidth / _previousScreenWidth; - double heightRatio = currentScreenHeight / _previousScreenHeight; - double dpiXRatio = currentDpi.X / _previousDpiX; - double dpiYRatio = currentDpi.Y / _previousDpiY; + double widthRatio = currentScreenWidth / _previousScreenWidth; + double heightRatio = currentScreenHeight / _previousScreenHeight; + double dpiXRatio = currentDpi.X / _previousDpiX; + double dpiYRatio = currentDpi.Y / _previousDpiY; - _settings.WindowLeft *= widthRatio * dpiXRatio; - _settings.WindowTop *= heightRatio * dpiYRatio; - } - - if (_settings.SearchWindowScreen == SearchWindowScreens.RememberLastLaunchLocation) - { - Top = _settings.WindowTop; - Left = _settings.WindowLeft; - } - else - { - switch (_settings.SearchWindowAlign) - { - case SearchWindowAligns.Center: - Left = HorizonCenter(screen); - Top = VerticalCenter(screen); - break; - case SearchWindowAligns.CenterTop: - Left = HorizonCenter(screen); - Top = VerticalTop(screen); - break; - case SearchWindowAligns.LeftTop: - Left = HorizonLeft(screen); - Top = VerticalTop(screen); - break; - case SearchWindowAligns.RightTop: - Left = HorizonRight(screen); - Top = VerticalTop(screen); - break; - case SearchWindowAligns.Custom: - Left = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.X + _settings.CustomWindowLeft, 0).X; - Top = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y + _settings.CustomWindowTop).Y; - break; - } - } - - _previousScreenWidth = currentScreenWidth; - _previousScreenHeight = currentScreenHeight; - _previousDpiX = currentDpi.X; - _previousDpiY = currentDpi.Y; + _settings.WindowLeft *= widthRatio * dpiXRatio; + _settings.WindowTop *= heightRatio * dpiYRatio; } + + if (_settings.SearchWindowScreen == SearchWindowScreens.RememberLastLaunchLocation) + { + Top = _settings.WindowTop; + Left = _settings.WindowLeft; + } + else + { + switch (_settings.SearchWindowAlign) + { + case SearchWindowAligns.Center: + Left = HorizonCenter(screen); + Top = VerticalCenter(screen); + break; + case SearchWindowAligns.CenterTop: + Left = HorizonCenter(screen); + Top = VerticalTop(screen); + break; + case SearchWindowAligns.LeftTop: + Left = HorizonLeft(screen); + Top = VerticalTop(screen); + break; + case SearchWindowAligns.RightTop: + Left = HorizonRight(screen); + Top = VerticalTop(screen); + break; + case SearchWindowAligns.Custom: + Left = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.X + _settings.CustomWindowLeft, 0).X; + Top = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y + _settings.CustomWindowTop).Y; + break; + } + } + + _previousScreenWidth = currentScreenWidth; + _previousScreenHeight = currentScreenHeight; + _previousDpiX = currentDpi.X; + _previousDpiY = currentDpi.Y; } private void UpdateNotifyIconText() From 5c6f539c6ffc469b70bdfc5839d2ed2ff0fcfae3 Mon Sep 17 00:00:00 2001 From: DB p Date: Thu, 6 Jun 2024 06:02:36 +0900 Subject: [PATCH 07/23] Reapply "Fix blurry situation when changed dpi in some case" This reverts commit ae0ec8ecf292ee56417da240966f516028f4c88d. --- Flow.Launcher/app.manifest | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Flow.Launcher/app.manifest b/Flow.Launcher/app.manifest index 52d1c3932..c45508fcf 100644 --- a/Flow.Launcher/app.manifest +++ b/Flow.Launcher/app.manifest @@ -49,13 +49,12 @@ DPIs. Windows Presentation Foundation (WPF) applications are automatically DPI-aware and do not need to opt in. Windows Forms applications targeting .NET Framework 4.6 that opt into this setting, should also set the 'EnableWindowsFormsHighDpiAutoResizing' setting to 'true' in their app.config. --> - From 4f16a1123fb2e28bf86b3bea711869a36d42f31f Mon Sep 17 00:00:00 2001 From: DB p Date: Thu, 6 Jun 2024 06:02:52 +0900 Subject: [PATCH 08/23] Revert "Fix blurry situation when changed dpi in some case" This reverts commit 2869812a74160517b2cd4ba6a7436b40eaa59195. --- Flow.Launcher/app.manifest | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Flow.Launcher/app.manifest b/Flow.Launcher/app.manifest index c45508fcf..52d1c3932 100644 --- a/Flow.Launcher/app.manifest +++ b/Flow.Launcher/app.manifest @@ -49,12 +49,13 @@ DPIs. Windows Presentation Foundation (WPF) applications are automatically DPI-aware and do not need to opt in. Windows Forms applications targeting .NET Framework 4.6 that opt into this setting, should also set the 'EnableWindowsFormsHighDpiAutoResizing' setting to 'true' in their app.config. --> + From d2472084a2804bd2e3795051d6e1bf28ad08b0ee Mon Sep 17 00:00:00 2001 From: DB p Date: Thu, 6 Jun 2024 06:02:55 +0900 Subject: [PATCH 09/23] =?UTF-8?q?Revert=20"When=20using=20the=20=E2=80=9Cr?= =?UTF-8?q?emember=20last=20position=E2=80=9D=20setting,=20if=20the=20reso?= =?UTF-8?q?lution=20or=20dpi=20has=20changed,=20the=20position=20will=20be?= =?UTF-8?q?=20rescaled=20proportionally"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 63ce735169afe7cf871d3d2a8eb6086e49fefa9a. --- Flow.Launcher/MainWindow.xaml.cs | 33 +------------------------------- 1 file changed, 1 insertion(+), 32 deletions(-) diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 87e818154..6c0889295 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -27,7 +27,6 @@ using DataObject = System.Windows.DataObject; using System.Windows.Media; using System.Windows.Interop; using System.Runtime.InteropServices; -using System.Drawing; namespace Flow.Launcher { @@ -49,10 +48,6 @@ namespace Flow.Launcher private MediaPlayer animationSoundWMP; private SoundPlayer animationSoundWPF; - private double _previousScreenWidth; - private double _previousScreenHeight; - private double _previousDpiX; - private double _previousDpiY; #endregion @@ -293,31 +288,8 @@ namespace Flow.Launcher }; } - private (double X, double Y) GetCurrentDpi(Screen screen) - { - using (Graphics g = Graphics.FromHwnd(IntPtr.Zero)) - { - return (g.DpiX, g.DpiY); - } - } private void InitializePosition() { - var screen = SelectedScreen(); - var currentDpi = GetCurrentDpi(screen); - double currentScreenWidth = screen.WorkingArea.Width; - double currentScreenHeight = screen.WorkingArea.Height; - - if (_previousScreenWidth != 0 && _previousScreenHeight != 0 && _previousDpiX != 0 && _previousDpiY != 0) - { - double widthRatio = currentScreenWidth / _previousScreenWidth; - double heightRatio = currentScreenHeight / _previousScreenHeight; - double dpiXRatio = currentDpi.X / _previousDpiX; - double dpiYRatio = currentDpi.Y / _previousDpiY; - - _settings.WindowLeft *= widthRatio * dpiXRatio; - _settings.WindowTop *= heightRatio * dpiYRatio; - } - if (_settings.SearchWindowScreen == SearchWindowScreens.RememberLastLaunchLocation) { Top = _settings.WindowTop; @@ -325,6 +297,7 @@ namespace Flow.Launcher } else { + var screen = SelectedScreen(); switch (_settings.SearchWindowAlign) { case SearchWindowAligns.Center: @@ -350,10 +323,6 @@ namespace Flow.Launcher } } - _previousScreenWidth = currentScreenWidth; - _previousScreenHeight = currentScreenHeight; - _previousDpiX = currentDpi.X; - _previousDpiY = currentDpi.Y; } private void UpdateNotifyIconText() From ab40e7a2e4045772a36b6a6b6f712187e24be377 Mon Sep 17 00:00:00 2001 From: DB p Date: Thu, 6 Jun 2024 07:37:13 +0900 Subject: [PATCH 10/23] Adjust logic --- .../UserSettings/Settings.cs | 4 + Flow.Launcher/MainWindow.xaml.cs | 114 +++++++++++++++++- 2 files changed, 116 insertions(+), 2 deletions(-) diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index 458846665..c44e0369a 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -205,6 +205,10 @@ namespace Flow.Launcher.Infrastructure.UserSettings public double WindowLeft { get; set; } public double WindowTop { get; set; } + public double PreviousScreenWidth { get; set; } + public double PreviousScreenHeight { get; set; } + public double PreviousDpiX { get; set; } + public double PreviousDpiY { get; set; } /// /// Custom left position on selected monitor diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 6c0889295..a699eaa64 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -27,6 +27,7 @@ using DataObject = System.Windows.DataObject; using System.Windows.Media; using System.Windows.Interop; using System.Runtime.InteropServices; +using System.Runtime.Intrinsics.Arm; namespace Flow.Launcher { @@ -292,11 +293,39 @@ namespace Flow.Launcher { if (_settings.SearchWindowScreen == SearchWindowScreens.RememberLastLaunchLocation) { - Top = _settings.WindowTop; + // Get the previous screen width, height, DPI X, and DPI Y + double previousScreenWidth = _settings.PreviousScreenWidth; + double previousScreenHeight = _settings.PreviousScreenHeight; + double previousDpiX = _settings.PreviousDpiX; + double previousDpiY = _settings.PreviousDpiY; + + // Save current screen width, height, DPI X, and DPI Y + _settings.PreviousScreenWidth = SystemParameters.VirtualScreenWidth; + _settings.PreviousScreenHeight = SystemParameters.VirtualScreenHeight; + _settings.PreviousDpiX = GetDpiX(); + _settings.PreviousDpiY = GetDpiY(); + + // If previous screen width, height, DPI X, or DPI Y are not zero + if (previousScreenWidth != 0 && previousScreenHeight != 0 && + previousDpiX != 0 && previousDpiY != 0) + { + // If previous and current screen properties are different, adjust position + if (previousScreenWidth != SystemParameters.VirtualScreenWidth || + previousScreenHeight != SystemParameters.VirtualScreenHeight || + previousDpiX != GetDpiX() || previousDpiY != GetDpiY()) + { + AdjustPositionForResolutionChange(); + return; + } + } + + // If previous screen width, height, DPI X, and DPI Y are the same, initialize with previous position Left = _settings.WindowLeft; + Top = _settings.WindowTop; } else { + // Keep the existing logic var screen = SelectedScreen(); switch (_settings.SearchWindowAlign) { @@ -322,9 +351,90 @@ namespace Flow.Launcher break; } } - } + private void AdjustPositionForResolutionChange() + { + double screenWidth = SystemParameters.VirtualScreenWidth; + double screenHeight = SystemParameters.VirtualScreenHeight; + double screenLeft = SystemParameters.VirtualScreenLeft; + double screenTop = SystemParameters.VirtualScreenTop; + double currentDpiX = GetDpiX(); + double currentDpiY = GetDpiY(); + + // Get current screen width, height, left, top, and DPI X, DPI Y + double currentScreenWidth = screenWidth; + double currentScreenHeight = screenHeight; + double currentScreenLeft = screenLeft; + double currentScreenTop = screenTop; + + // Get previous window left, top, and DPI X, DPI Y + double previousLeft = _settings.WindowLeft; + double previousTop = _settings.WindowTop; + double previousDpiX = _settings.PreviousDpiX; + double previousDpiY = _settings.PreviousDpiY; + + // Calculate ratios for width, height, DPI X, and DPI Y + double widthRatio = currentScreenWidth / _settings.PreviousScreenWidth; + double heightRatio = currentScreenHeight / _settings.PreviousScreenHeight; + double dpiXRatio = currentDpiX / previousDpiX; + double dpiYRatio = currentDpiY / previousDpiY; + + // Adjust previous position according to current resolution and DPI + double newLeft = previousLeft * widthRatio * dpiXRatio; + double newTop = previousTop * heightRatio * dpiYRatio; + + // Ensure the adjusted position is within the current screen boundaries + if (newLeft + ActualWidth > currentScreenLeft + currentScreenWidth) + { + newLeft = currentScreenLeft + currentScreenWidth - ActualWidth; + } + else if (newLeft < currentScreenLeft) + { + newLeft = currentScreenLeft; + } + + if (newTop + ActualHeight > currentScreenTop + currentScreenHeight) + { + newTop = currentScreenTop + currentScreenHeight - ActualHeight; + } + else if (newTop < currentScreenTop) + { + newTop = currentScreenTop; + } + + // Set the new position + Left = newLeft; + Top = newTop; + } + + private double GetDpiX() + { + // Get the PresentationSource for this visual + PresentationSource source = PresentationSource.FromVisual(this); + // Check if the PresentationSource and its CompositionTarget are not null + if (source != null && source.CompositionTarget != null) + { + // Get the transform matrix for the CompositionTarget + Matrix m = source.CompositionTarget.TransformToDevice; + // Calculate DPI in X direction + double dpiX = 96 * m.M11; + return dpiX; + } + return 96; //Return a default DPI of 96 if PresentationSource or CompositionTarget is null + } + + private double GetDpiY() + { + PresentationSource source = PresentationSource.FromVisual(this); + if (source != null && source.CompositionTarget != null) + { + Matrix m = source.CompositionTarget.TransformToDevice; + double dpiY = 96 * m.M22; + return dpiY; + } + return 96; + } private void UpdateNotifyIconText() { var menu = contextMenu; From 5df736267426dd5e2191e1d757895eae99ad1015 Mon Sep 17 00:00:00 2001 From: DB p Date: Thu, 6 Jun 2024 08:10:40 +0900 Subject: [PATCH 11/23] - Add Logic in settingwindow --- Flow.Launcher/SettingWindow.xaml.cs | 34 ++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/Flow.Launcher/SettingWindow.xaml.cs b/Flow.Launcher/SettingWindow.xaml.cs index de4fd1f91..99c363222 100644 --- a/Flow.Launcher/SettingWindow.xaml.cs +++ b/Flow.Launcher/SettingWindow.xaml.cs @@ -112,23 +112,45 @@ public partial class SettingWindow { if (_settings.SettingWindowTop == null || _settings.SettingWindowLeft == null) { - Top = WindowTop(); - Left = WindowLeft(); + SetWindowPosition(WindowTop(), WindowLeft()); } else { - Top = _settings.SettingWindowTop.Value; - Left = _settings.SettingWindowLeft.Value; + double left = _settings.SettingWindowLeft.Value; + double top = _settings.SettingWindowTop.Value; + AdjustWindowPosition(ref top, ref left); + SetWindowPosition(top, left); } WindowState = _settings.SettingWindowState; } + private void SetWindowPosition(double top, double left) + { + // Ensure window does not exceed screen boundaries + top = Math.Max(top, SystemParameters.VirtualScreenTop); + left = Math.Max(left, SystemParameters.VirtualScreenLeft); + top = Math.Min(top, SystemParameters.VirtualScreenHeight - ActualHeight); + left = Math.Min(left, SystemParameters.VirtualScreenWidth - ActualWidth); + + Top = top; + Left = left; + } + + private void AdjustWindowPosition(ref double top, ref double left) + { + // Adjust window position if it exceeds screen boundaries + top = Math.Max(top, SystemParameters.VirtualScreenTop); + left = Math.Max(left, SystemParameters.VirtualScreenLeft); + top = Math.Min(top, SystemParameters.VirtualScreenHeight - ActualHeight); + left = Math.Min(left, SystemParameters.VirtualScreenWidth - ActualWidth); + } + private double WindowLeft() { var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position); var dip1 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0); var dip2 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.Width, 0); - var left = (dip2.X - this.ActualWidth) / 2 + dip1.X; + var left = (dip2.X - ActualWidth) / 2 + dip1.X; return left; } @@ -137,7 +159,7 @@ public partial class SettingWindow var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position); var dip1 = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y); var dip2 = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Height); - var top = (dip2.Y - this.ActualHeight) / 2 + dip1.Y - 20; + var top = (dip2.Y - ActualHeight) / 2 + dip1.Y; return top; } From 88c6fe3acbeef0e3cbb53d9d8f1308afb5a67678 Mon Sep 17 00:00:00 2001 From: DB p Date: Thu, 6 Jun 2024 09:32:46 +0900 Subject: [PATCH 12/23] Adjust Code --- Flow.Launcher/MainWindow.xaml.cs | 111 ++++++++++--------------------- 1 file changed, 34 insertions(+), 77 deletions(-) diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index a699eaa64..b9b82909d 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -293,39 +293,31 @@ namespace Flow.Launcher { if (_settings.SearchWindowScreen == SearchWindowScreens.RememberLastLaunchLocation) { - // Get the previous screen width, height, DPI X, and DPI Y double previousScreenWidth = _settings.PreviousScreenWidth; double previousScreenHeight = _settings.PreviousScreenHeight; - double previousDpiX = _settings.PreviousDpiX; - double previousDpiY = _settings.PreviousDpiY; + double previousDpiX, previousDpiY; + GetDpi(out previousDpiX, out previousDpiY); - // Save current screen width, height, DPI X, and DPI Y _settings.PreviousScreenWidth = SystemParameters.VirtualScreenWidth; _settings.PreviousScreenHeight = SystemParameters.VirtualScreenHeight; - _settings.PreviousDpiX = GetDpiX(); - _settings.PreviousDpiY = GetDpiY(); + double currentDpiX, currentDpiY; + GetDpi(out currentDpiX, out currentDpiY); - // If previous screen width, height, DPI X, or DPI Y are not zero if (previousScreenWidth != 0 && previousScreenHeight != 0 && - previousDpiX != 0 && previousDpiY != 0) + previousDpiX != 0 && previousDpiY != 0 && + (previousScreenWidth != SystemParameters.VirtualScreenWidth || + previousScreenHeight != SystemParameters.VirtualScreenHeight || + previousDpiX != currentDpiX || previousDpiY != currentDpiY)) { - // If previous and current screen properties are different, adjust position - if (previousScreenWidth != SystemParameters.VirtualScreenWidth || - previousScreenHeight != SystemParameters.VirtualScreenHeight || - previousDpiX != GetDpiX() || previousDpiY != GetDpiY()) - { - AdjustPositionForResolutionChange(); - return; - } + AdjustPositionForResolutionChange(); + return; } - // If previous screen width, height, DPI X, and DPI Y are the same, initialize with previous position Left = _settings.WindowLeft; Top = _settings.WindowTop; } else { - // Keep the existing logic var screen = SelectedScreen(); switch (_settings.SearchWindowAlign) { @@ -346,8 +338,10 @@ namespace Flow.Launcher Top = VerticalTop(screen); break; case SearchWindowAligns.Custom: - Left = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.X + _settings.CustomWindowLeft, 0).X; - Top = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y + _settings.CustomWindowTop).Y; + var customLeft = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.X + _settings.CustomWindowLeft, 0); + var customTop = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y + _settings.CustomWindowTop); + Left = customLeft.X; + Top = customTop.Y; break; } } @@ -357,83 +351,46 @@ namespace Flow.Launcher { double screenWidth = SystemParameters.VirtualScreenWidth; double screenHeight = SystemParameters.VirtualScreenHeight; - double screenLeft = SystemParameters.VirtualScreenLeft; - double screenTop = SystemParameters.VirtualScreenTop; - double currentDpiX = GetDpiX(); - double currentDpiY = GetDpiY(); + double currentDpiX, currentDpiY; + GetDpi(out currentDpiX, out currentDpiY); - // Get current screen width, height, left, top, and DPI X, DPI Y - double currentScreenWidth = screenWidth; - double currentScreenHeight = screenHeight; - double currentScreenLeft = screenLeft; - double currentScreenTop = screenTop; - - // Get previous window left, top, and DPI X, DPI Y double previousLeft = _settings.WindowLeft; double previousTop = _settings.WindowTop; - double previousDpiX = _settings.PreviousDpiX; - double previousDpiY = _settings.PreviousDpiY; + double previousDpiX, previousDpiY; + GetDpi(out previousDpiX, out previousDpiY); - // Calculate ratios for width, height, DPI X, and DPI Y - double widthRatio = currentScreenWidth / _settings.PreviousScreenWidth; - double heightRatio = currentScreenHeight / _settings.PreviousScreenHeight; + double widthRatio = screenWidth / _settings.PreviousScreenWidth; + double heightRatio = screenHeight / _settings.PreviousScreenHeight; double dpiXRatio = currentDpiX / previousDpiX; double dpiYRatio = currentDpiY / previousDpiY; - // Adjust previous position according to current resolution and DPI double newLeft = previousLeft * widthRatio * dpiXRatio; double newTop = previousTop * heightRatio * dpiYRatio; - // Ensure the adjusted position is within the current screen boundaries - if (newLeft + ActualWidth > currentScreenLeft + currentScreenWidth) - { - newLeft = currentScreenLeft + currentScreenWidth - ActualWidth; - } - else if (newLeft < currentScreenLeft) - { - newLeft = currentScreenLeft; - } + double screenLeft = SystemParameters.VirtualScreenLeft; + double screenTop = SystemParameters.VirtualScreenTop; - if (newTop + ActualHeight > currentScreenTop + currentScreenHeight) - { - newTop = currentScreenTop + currentScreenHeight - ActualHeight; - } - else if (newTop < currentScreenTop) - { - newTop = currentScreenTop; - } + double maxX = screenLeft + screenWidth - ActualWidth; + double maxY = screenTop + screenHeight - ActualHeight; - // Set the new position - Left = newLeft; - Top = newTop; + Left = Math.Max(screenLeft, Math.Min(newLeft, maxX)); + Top = Math.Max(screenTop, Math.Min(newTop, maxY)); } - private double GetDpiX() - { - // Get the PresentationSource for this visual - PresentationSource source = PresentationSource.FromVisual(this); - // Check if the PresentationSource and its CompositionTarget are not null - if (source != null && source.CompositionTarget != null) - { - // Get the transform matrix for the CompositionTarget - Matrix m = source.CompositionTarget.TransformToDevice; - // Calculate DPI in X direction - double dpiX = 96 * m.M11; - return dpiX; - } - return 96; //Return a default DPI of 96 if PresentationSource or CompositionTarget is null - } - - private double GetDpiY() + private void GetDpi(out double dpiX, out double dpiY) { PresentationSource source = PresentationSource.FromVisual(this); if (source != null && source.CompositionTarget != null) { Matrix m = source.CompositionTarget.TransformToDevice; - double dpiY = 96 * m.M22; - return dpiY; + dpiX = 96 * m.M11; + dpiY = 96 * m.M22; + } + else + { + dpiX = 96; + dpiY = 96; } - return 96; } private void UpdateNotifyIconText() { From 1bd9e8131d2a50ccd28a3600c15e0049bc34fdc8 Mon Sep 17 00:00:00 2001 From: DB p Date: Thu, 6 Jun 2024 09:35:44 +0900 Subject: [PATCH 13/23] Fix app manifest --- Flow.Launcher/app.manifest | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Flow.Launcher/app.manifest b/Flow.Launcher/app.manifest index 52d1c3932..b6944273a 100644 --- a/Flow.Launcher/app.manifest +++ b/Flow.Launcher/app.manifest @@ -49,13 +49,12 @@ DPIs. Windows Presentation Foundation (WPF) applications are automatically DPI-aware and do not need to opt in. Windows Forms applications targeting .NET Framework 4.6 that opt into this setting, should also set the 'EnableWindowsFormsHighDpiAutoResizing' setting to 'true' in their app.config. --> - From e863d998ab4698dbdf73bb813f59d543e620e223 Mon Sep 17 00:00:00 2001 From: DB p Date: Thu, 6 Jun 2024 09:36:25 +0900 Subject: [PATCH 14/23] Adjust Typo --- Flow.Launcher/app.manifest | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher/app.manifest b/Flow.Launcher/app.manifest index b6944273a..c45508fcf 100644 --- a/Flow.Launcher/app.manifest +++ b/Flow.Launcher/app.manifest @@ -49,7 +49,7 @@ DPIs. Windows Presentation Foundation (WPF) applications are automatically DPI-aware and do not need to opt in. Windows Forms applications targeting .NET Framework 4.6 that opt into this setting, should also set the 'EnableWindowsFormsHighDpiAutoResizing' setting to 'true' in their app.config. --> - + true PerMonitorV2, PerMonitor From ce100c46278eb3d94fae35ba0b34a7ab9171f633 Mon Sep 17 00:00:00 2001 From: Hongtao Zhang Date: Wed, 19 Jun 2024 11:38:34 -0700 Subject: [PATCH 15/23] refactor code with Point2D.cs --- .../UserSettings/Point2D.cs | 46 +++++ .../UserSettings/Settings.cs | 10 +- Flow.Launcher/MainWindow.xaml.cs | 177 ++++++++---------- Flow.Launcher/ViewModel/MainViewModel.cs | 6 +- 4 files changed, 133 insertions(+), 106 deletions(-) create mode 100644 Flow.Launcher.Infrastructure/UserSettings/Point2D.cs diff --git a/Flow.Launcher.Infrastructure/UserSettings/Point2D.cs b/Flow.Launcher.Infrastructure/UserSettings/Point2D.cs new file mode 100644 index 000000000..4c47ba6c0 --- /dev/null +++ b/Flow.Launcher.Infrastructure/UserSettings/Point2D.cs @@ -0,0 +1,46 @@ +using System; + +namespace Flow.Launcher.Infrastructure.UserSettings; + +public record struct Point2D(double X, double Y) +{ + public static implicit operator Point2D((double X, double Y) point) + { + return new Point2D(point.X, point.Y); + } + + public static Point2D operator +(Point2D point1, Point2D point2) + { + return new Point2D(point1.X + point2.X, point1.Y + point2.Y); + } + + public static Point2D operator -(Point2D point1, Point2D point2) + { + return new Point2D(point1.X - point2.X, point1.Y - point2.Y); + } + + public static Point2D operator *(Point2D point, double scalar) + { + return new Point2D(point.X * scalar, point.Y * scalar); + } + + public static Point2D operator /(Point2D point, double scalar) + { + return new Point2D(point.X / scalar, point.Y / scalar); + } + + public static Point2D operator /(Point2D point1, Point2D point2) + { + return new Point2D(point1.X / point2.X, point1.Y / point2.Y); + } + + public static Point2D operator *(Point2D point1, Point2D point2) + { + return new Point2D(point1.X * point2.X, point1.Y * point2.Y); + } + + public Point2D Clamp(Point2D min, Point2D max) + { + return new Point2D(Math.Clamp(X, min.X, max.X), Math.Clamp(Y, min.Y, max.Y)); + } +} diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index c44e0369a..c216efad2 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -203,12 +203,10 @@ namespace Flow.Launcher.Infrastructure.UserSettings public bool AutoUpdates { get; set; } = false; - public double WindowLeft { get; set; } - public double WindowTop { get; set; } - public double PreviousScreenWidth { get; set; } - public double PreviousScreenHeight { get; set; } - public double PreviousDpiX { get; set; } - public double PreviousDpiY { get; set; } + + public Point2D WindowPosition { get; set; } + public Point2D PreviousScreen { get; set; } + public Point2D PreviousDpi { get; set; } /// /// Custom left position on selected monitor diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index b9b82909d..3516d7e69 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -73,11 +73,7 @@ namespace Flow.Launcher }; } - DispatcherTimer timer = new DispatcherTimer - { - Interval = new TimeSpan(0, 0, 0, 0, 500), - IsEnabled = false - }; + DispatcherTimer timer = new DispatcherTimer { Interval = new TimeSpan(0, 0, 0, 0, 500), IsEnabled = false }; public MainWindow() { @@ -88,6 +84,7 @@ namespace Flow.Launcher private const int WM_EXITSIZEMOVE = 0x0232; private int _initialWidth; private int _initialHeight; + private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { if (msg == WM_ENTERSIZEMOVE) @@ -96,18 +93,22 @@ namespace Flow.Launcher _initialHeight = (int)Height; handled = true; } + if (msg == WM_EXITSIZEMOVE) { - if ( _initialHeight != (int)Height) + if (_initialHeight != (int)Height) { OnResizeEnd(); } + if (_initialWidth != (int)Width) { FlowMainWindow.SizeToContent = SizeToContent.Height; } + handled = true; } + return IntPtr.Zero; } @@ -132,6 +133,7 @@ namespace Flow.Launcher _settings.MaxResultsToShow = Convert.ToInt32(Math.Truncate(itemCount)); } } + FlowMainWindow.SizeToContent = SizeToContent.Height; _viewModel.MainWindowWidth = Width; } @@ -176,6 +178,7 @@ namespace Flow.Launcher private void OnInitialized(object sender, EventArgs e) { } + private void OnLoaded(object sender, RoutedEventArgs _) { // MouseEventHandler @@ -207,6 +210,7 @@ namespace Flow.Launcher { SoundPlay(); } + UpdatePosition(); PreviewReset(); Activate(); @@ -218,7 +222,8 @@ namespace Flow.Launcher _viewModel.LastQuerySelected = true; } - if (_viewModel.ProgressBarVisibility == Visibility.Visible && isProgressBarStoryboardPaused) + if (_viewModel.ProgressBarVisibility == Visibility.Visible && + isProgressBarStoryboardPaused) { _progressBarStoryboard.Begin(ProgressBar, true); isProgressBarStoryboardPaused = false; @@ -259,9 +264,12 @@ namespace Flow.Launcher MoveQueryTextToEnd(); _viewModel.QueryTextCursorMovedToEnd = false; } + break; case nameof(MainViewModel.GameModeStatus): - _notifyIcon.Icon = _viewModel.GameModeStatus ? Properties.Resources.gamemode : Properties.Resources.app; + _notifyIcon.Icon = _viewModel.GameModeStatus + ? Properties.Resources.gamemode + : Properties.Resources.app; break; } }; @@ -279,11 +287,8 @@ namespace Flow.Launcher case nameof(Settings.Hotkey): UpdateNotifyIconText(); break; - case nameof(Settings.WindowLeft): - Left = _settings.WindowLeft; - break; - case nameof(Settings.WindowTop): - Top = _settings.WindowTop; + case nameof(Settings.WindowPosition): + (Left, Top) = _settings.WindowPosition; break; } }; @@ -293,28 +298,24 @@ namespace Flow.Launcher { if (_settings.SearchWindowScreen == SearchWindowScreens.RememberLastLaunchLocation) { - double previousScreenWidth = _settings.PreviousScreenWidth; - double previousScreenHeight = _settings.PreviousScreenHeight; - double previousDpiX, previousDpiY; - GetDpi(out previousDpiX, out previousDpiY); + var previousScreen = _settings.PreviousScreen; - _settings.PreviousScreenWidth = SystemParameters.VirtualScreenWidth; - _settings.PreviousScreenHeight = SystemParameters.VirtualScreenHeight; - double currentDpiX, currentDpiY; - GetDpi(out currentDpiX, out currentDpiY); + var previousDpi = _settings.PreviousDpi; - if (previousScreenWidth != 0 && previousScreenHeight != 0 && - previousDpiX != 0 && previousDpiY != 0 && - (previousScreenWidth != SystemParameters.VirtualScreenWidth || - previousScreenHeight != SystemParameters.VirtualScreenHeight || - previousDpiX != currentDpiX || previousDpiY != currentDpiY)) + _settings.PreviousScreen = (SystemParameters.VirtualScreenWidth, SystemParameters.VirtualScreenHeight); + + var currentDpi = GetDpi(); + + if (previousScreen != default || + previousDpi != default || + (previousScreen != (SystemParameters.VirtualScreenWidth, SystemParameters.VirtualScreenHeight) || + previousDpi != currentDpi)) { AdjustPositionForResolutionChange(); return; } - Left = _settings.WindowLeft; - Top = _settings.WindowTop; + (Left, Top) = _settings.WindowPosition; } else { @@ -338,8 +339,10 @@ namespace Flow.Launcher Top = VerticalTop(screen); break; case SearchWindowAligns.Custom: - var customLeft = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.X + _settings.CustomWindowLeft, 0); - var customTop = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y + _settings.CustomWindowTop); + var customLeft = WindowsInteropHelper.TransformPixelsToDIP(this, + screen.WorkingArea.X + _settings.CustomWindowLeft, 0); + var customTop = WindowsInteropHelper.TransformPixelsToDIP(this, 0, + screen.WorkingArea.Y + _settings.CustomWindowTop); Left = customLeft.X; Top = customTop.Y; break; @@ -349,58 +352,48 @@ namespace Flow.Launcher private void AdjustPositionForResolutionChange() { - double screenWidth = SystemParameters.VirtualScreenWidth; - double screenHeight = SystemParameters.VirtualScreenHeight; - double currentDpiX, currentDpiY; - GetDpi(out currentDpiX, out currentDpiY); + Point2D screenBound = (SystemParameters.VirtualScreenWidth, SystemParameters.VirtualScreenHeight); - double previousLeft = _settings.WindowLeft; - double previousTop = _settings.WindowTop; - double previousDpiX, previousDpiY; - GetDpi(out previousDpiX, out previousDpiY); + var currentDpi = GetDpi(); - double widthRatio = screenWidth / _settings.PreviousScreenWidth; - double heightRatio = screenHeight / _settings.PreviousScreenHeight; - double dpiXRatio = currentDpiX / previousDpiX; - double dpiYRatio = currentDpiY / previousDpiY; + var previousPosition = _settings.WindowPosition; - double newLeft = previousLeft * widthRatio * dpiXRatio; - double newTop = previousTop * heightRatio * dpiYRatio; + var ratio = screenBound / _settings.PreviousScreen; - double screenLeft = SystemParameters.VirtualScreenLeft; - double screenTop = SystemParameters.VirtualScreenTop; + var dpiXRatio = currentDpi / _settings.PreviousDpi; - double maxX = screenLeft + screenWidth - ActualWidth; - double maxY = screenTop + screenHeight - ActualHeight; + var newPosition = previousPosition * ratio * dpiXRatio; - Left = Math.Max(screenLeft, Math.Min(newLeft, maxX)); - Top = Math.Max(screenTop, Math.Min(newTop, maxY)); + Point2D screenPosition = (SystemParameters.VirtualScreenLeft, SystemParameters.VirtualScreenTop); + + var maxPosition = screenPosition + screenBound - (ActualWidth, ActualHeight); + + (Left, Top) = newPosition.Clamp(screenPosition, maxPosition); } - private void GetDpi(out double dpiX, out double dpiY) + private Point2D GetDpi() { PresentationSource source = PresentationSource.FromVisual(this); - if (source != null && source.CompositionTarget != null) + Point2D point = (96, 96); + if (source is { CompositionTarget: not null }) { Matrix m = source.CompositionTarget.TransformToDevice; - dpiX = 96 * m.M11; - dpiY = 96 * m.M22; - } - else - { - dpiX = 96; - dpiY = 96; + point.X = 96 * m.M11; + point.Y = 96 * m.M22; } + + return point; } + private void UpdateNotifyIconText() { var menu = contextMenu; - ((MenuItem)menu.Items[0]).Header = InternationalizationManager.Instance.GetTranslation("iconTrayOpen") + " (" + _settings.Hotkey + ")"; + ((MenuItem)menu.Items[0]).Header = InternationalizationManager.Instance.GetTranslation("iconTrayOpen") + + " (" + _settings.Hotkey + ")"; ((MenuItem)menu.Items[1]).Header = InternationalizationManager.Instance.GetTranslation("GameMode"); ((MenuItem)menu.Items[2]).Header = InternationalizationManager.Instance.GetTranslation("PositionReset"); ((MenuItem)menu.Items[3]).Header = InternationalizationManager.Instance.GetTranslation("iconTraySettings"); ((MenuItem)menu.Items[4]).Header = InternationalizationManager.Instance.GetTranslation("iconTrayExit"); - } private void InitializeNotifyIcon() @@ -412,50 +405,34 @@ namespace Flow.Launcher Visible = !_settings.HideNotifyIcon }; - var openIcon = new FontIcon - { - Glyph = "\ue71e" - }; + var openIcon = new FontIcon { Glyph = "\ue71e" }; var open = new MenuItem { - Header = InternationalizationManager.Instance.GetTranslation("iconTrayOpen") + " (" + _settings.Hotkey + ")", + Header = InternationalizationManager.Instance.GetTranslation("iconTrayOpen") + " (" + + _settings.Hotkey + ")", Icon = openIcon }; - var gamemodeIcon = new FontIcon - { - Glyph = "\ue7fc" - }; + var gamemodeIcon = new FontIcon { Glyph = "\ue7fc" }; var gamemode = new MenuItem { - Header = InternationalizationManager.Instance.GetTranslation("GameMode"), - Icon = gamemodeIcon - }; - var positionresetIcon = new FontIcon - { - Glyph = "\ue73f" + Header = InternationalizationManager.Instance.GetTranslation("GameMode"), Icon = gamemodeIcon }; + var positionresetIcon = new FontIcon { Glyph = "\ue73f" }; var positionreset = new MenuItem { Header = InternationalizationManager.Instance.GetTranslation("PositionReset"), Icon = positionresetIcon }; - var settingsIcon = new FontIcon - { - Glyph = "\ue713" - }; + var settingsIcon = new FontIcon { Glyph = "\ue713" }; var settings = new MenuItem { Header = InternationalizationManager.Instance.GetTranslation("iconTraySettings"), Icon = settingsIcon }; - var exitIcon = new FontIcon - { - Glyph = "\ue7e8" - }; + var exitIcon = new FontIcon { Glyph = "\ue7e8" }; var exit = new MenuItem { - Header = InternationalizationManager.Instance.GetTranslation("iconTrayExit"), - Icon = exitIcon + Header = InternationalizationManager.Instance.GetTranslation("iconTrayExit"), Icon = exitIcon }; open.Click += (o, e) => _viewModel.ToggleFlowLauncher(); @@ -488,6 +465,7 @@ namespace Flow.Launcher { _ = SetForegroundWindow(hwndSource.Handle); } + contextMenu.Focus(); break; } @@ -521,8 +499,10 @@ namespace Flow.Launcher private void InitProgressbarAnimation() { - var da = new DoubleAnimation(ProgressBar.X2, ActualWidth + 100, new Duration(new TimeSpan(0, 0, 0, 0, 1600))); - var da1 = new DoubleAnimation(ProgressBar.X1, ActualWidth + 0, new Duration(new TimeSpan(0, 0, 0, 0, 1600))); + var da = new DoubleAnimation(ProgressBar.X2, ActualWidth + 100, + new Duration(new TimeSpan(0, 0, 0, 0, 1600))); + var da1 = new DoubleAnimation(ProgressBar.X1, ActualWidth + 0, + new Duration(new TimeSpan(0, 0, 0, 0, 1600))); Storyboard.SetTargetProperty(da, new PropertyPath("(Line.X2)")); Storyboard.SetTargetProperty(da1, new PropertyPath("(Line.X1)")); _progressBarStoryboard.Children.Add(da); @@ -624,14 +604,14 @@ namespace Flow.Launcher iconsb.Children.Add(IconOpacity); windowsb.Completed += (_, _) => _animating = false; - _settings.WindowLeft = Left; - _settings.WindowTop = Top; + _settings.WindowPosition = (Left, Top); isArrowKeyPressed = false; if (QueryTextBox.Text.Length == 0) { clocksb.Begin(ClockPanel); } + iconsb.Begin(SearchIcon); windowsb.Begin(FlowMainWindow); } @@ -685,8 +665,7 @@ namespace Flow.Launcher private async void OnDeactivated(object sender, EventArgs e) { - _settings.WindowLeft = Left; - _settings.WindowTop = Top; + _settings.WindowPosition = (Left, Top); //This condition stops extra hide call when animator is on, // which causes the toggling to occasional hide instead of show. if (_viewModel.MainWindowVisibilityStatus) @@ -717,8 +696,7 @@ namespace Flow.Launcher return; if (_settings.SearchWindowScreen == SearchWindowScreens.RememberLastLaunchLocation) { - _settings.WindowLeft = Left; - _settings.WindowTop = Top; + _settings.WindowPosition = (Left, Top); } } @@ -738,7 +716,7 @@ namespace Flow.Launcher public Screen SelectedScreen() { Screen screen = null; - switch(_settings.SearchWindowScreen) + switch (_settings.SearchWindowScreen) { case SearchWindowScreens.Cursor: screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position); @@ -760,6 +738,7 @@ namespace Flow.Launcher screen = Screen.AllScreens[0]; break; } + return screen ?? Screen.AllScreens[0]; } @@ -797,7 +776,7 @@ namespace Flow.Launcher public double VerticalTop(Screen screen) { var dip1 = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y); - var top = dip1.Y +10; + var top = dip1.Y + 10; return top; } @@ -836,6 +815,7 @@ namespace Flow.Launcher _viewModel.LoadContextMenuCommand.Execute(null); e.Handled = true; } + break; case Key.Left: if (!_viewModel.SelectedIsFromQueryResults() && QueryTextBox.CaretIndex == 0) @@ -843,6 +823,7 @@ namespace Flow.Launcher _viewModel.EscCommand.Execute(null); e.Handled = true; } + break; case Key.Back: if (specialKeyState.CtrlPressed) @@ -861,12 +842,13 @@ namespace Flow.Launcher } } } + break; default: break; - } } + private void OnKeyUp(object sender, KeyEventArgs e) { if (e.Key == Key.Up || e.Key == Key.Down) @@ -882,6 +864,7 @@ namespace Flow.Launcher e.Handled = true; // Ignore Mouse Hover when press Arrowkeys } } + public void PreviewReset() { _viewModel.ResetPreview(); diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index a793ceaa5..406d2af58 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -543,20 +543,20 @@ namespace Flow.Launcher.ViewModel private void IncreaseWidth() { Settings.WindowSize += 100; - Settings.WindowLeft -= 50; + Settings.WindowPosition -= (50, 0); OnPropertyChanged(nameof(MainWindowWidth)); } [RelayCommand] private void DecreaseWidth() { - if (MainWindowWidth - 100 < 400 || Settings.WindowSize == 400) + if (MainWindowWidth - 100 < 400 || Math.Abs(Settings.WindowSize - 400) < 0.01) { Settings.WindowSize = 400; } else { - Settings.WindowLeft += 50; + Settings.WindowPosition += (50, 0); Settings.WindowSize -= 100; } From feaf6c45c128fb59d0e9f9bbfe75e4e7cc472d35 Mon Sep 17 00:00:00 2001 From: Hongtao Zhang Date: Wed, 19 Jun 2024 11:42:37 -0700 Subject: [PATCH 16/23] fix a variable name --- Flow.Launcher/MainWindow.xaml.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index ae57e7934..4fd0145db 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -360,15 +360,15 @@ namespace Flow.Launcher var ratio = screenBound / _settings.PreviousScreen; - var dpiXRatio = currentDpi / _settings.PreviousDpi; + var dpiRatio = currentDpi / _settings.PreviousDpi; - var newPosition = previousPosition * ratio * dpiXRatio; + var newPosition = previousPosition * ratio * dpiRatio; - Point2D screenPosition = (SystemParameters.VirtualScreenLeft, SystemParameters.VirtualScreenTop); + Point2D minPosition = (SystemParameters.VirtualScreenLeft, SystemParameters.VirtualScreenTop); - var maxPosition = screenPosition + screenBound - (ActualWidth, ActualHeight); + var maxPosition = minPosition + screenBound - (ActualWidth, ActualHeight); - (Left, Top) = newPosition.Clamp(screenPosition, maxPosition); + (Left, Top) = newPosition.Clamp(minPosition, maxPosition); } private Point2D GetDpi() From 70a24e077459309a62b19481741b29d5509c96e3 Mon Sep 17 00:00:00 2001 From: Hongtao Zhang Date: Wed, 19 Jun 2024 11:43:23 -0700 Subject: [PATCH 17/23] remove unused intrinsic --- Flow.Launcher/MainWindow.xaml.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 4fd0145db..9e09c3470 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -27,7 +27,6 @@ using DataObject = System.Windows.DataObject; using System.Windows.Media; using System.Windows.Interop; using System.Runtime.InteropServices; -using System.Runtime.Intrinsics.Arm; namespace Flow.Launcher { From 58caa493bcec26ef74e5b93653b94111ca1356fb Mon Sep 17 00:00:00 2001 From: Hongtao Zhang Date: Wed, 19 Jun 2024 11:45:23 -0700 Subject: [PATCH 18/23] fix logic --- 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 9e09c3470..4027e7698 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -305,8 +305,8 @@ namespace Flow.Launcher var currentDpi = GetDpi(); - if (previousScreen != default || - previousDpi != default || + if (previousScreen == default || + previousDpi == default || (previousScreen != (SystemParameters.VirtualScreenWidth, SystemParameters.VirtualScreenHeight) || previousDpi != currentDpi)) { From 79ce5057c247ddac5bf478fdca52db18a5f700c3 Mon Sep 17 00:00:00 2001 From: Yusyuriv Date: Thu, 20 Jun 2024 09:54:01 +0600 Subject: [PATCH 19/23] Settings: fix creating/editing custom shortcuts --- Flow.Launcher/CustomShortcutSetting.xaml.cs | 17 ++++++++++------- .../ViewModels/SettingsPaneHotkeyViewModel.cs | 13 ++++++++++--- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/Flow.Launcher/CustomShortcutSetting.xaml.cs b/Flow.Launcher/CustomShortcutSetting.xaml.cs index 82efb4869..531b29d50 100644 --- a/Flow.Launcher/CustomShortcutSetting.xaml.cs +++ b/Flow.Launcher/CustomShortcutSetting.xaml.cs @@ -1,31 +1,34 @@ using Flow.Launcher.Core.Resource; -using Flow.Launcher.ViewModel; using System; using System.Windows; using System.Windows.Input; +using Flow.Launcher.SettingPages.ViewModels; namespace Flow.Launcher { public partial class CustomShortcutSetting : Window { + private readonly SettingsPaneHotkeyViewModel _hotkeyVm; public string Key { get; set; } = String.Empty; public string Value { get; set; } = String.Empty; - private string originalKey { get; init; } = null; - private string originalValue { get; init; } = null; - private bool update { get; init; } = false; + private string originalKey { get; } = null; + private string originalValue { get; } = null; + private bool update { get; } = false; - public CustomShortcutSetting(SettingWindowViewModel vm) + public CustomShortcutSetting(SettingsPaneHotkeyViewModel vm) { + _hotkeyVm = vm; InitializeComponent(); } - public CustomShortcutSetting(string key, string value) + public CustomShortcutSetting(string key, string value, SettingsPaneHotkeyViewModel vm) { Key = key; Value = value; originalKey = key; originalValue = value; update = true; + _hotkeyVm = vm; InitializeComponent(); } @@ -43,7 +46,7 @@ namespace Flow.Launcher return; } // Check if key is modified or adding a new one - if ((update && originalKey != Key) || !update) + if (((update && originalKey != Key) || !update) && _hotkeyVm.DoesShortcutExist(Key)) { MessageBox.Show(InternationalizationManager.Instance.GetTranslation("duplicateShortcut")); return; diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneHotkeyViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneHotkeyViewModel.cs index 7eb05d945..a4488a037 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneHotkeyViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneHotkeyViewModel.cs @@ -1,4 +1,5 @@ -using System.Windows; +using System.Linq; +using System.Windows; using CommunityToolkit.Mvvm.Input; using Flow.Launcher.Core.Resource; using Flow.Launcher.Helper; @@ -114,7 +115,7 @@ public partial class SettingsPaneHotkeyViewModel : BaseModel return; } - var window = new CustomShortcutSetting(item.Key, item.Value); + var window = new CustomShortcutSetting(item.Key, item.Value, this); if (window.ShowDialog() is not true) return; var index = Settings.CustomShortcuts.IndexOf(item); @@ -124,11 +125,17 @@ public partial class SettingsPaneHotkeyViewModel : BaseModel [RelayCommand] private void CustomShortcutAdd() { - var window = new CustomShortcutSetting(null); + var window = new CustomShortcutSetting(this); if (window.ShowDialog() is true) { var shortcut = new CustomShortcutModel(window.Key, window.Value); Settings.CustomShortcuts.Add(shortcut); } } + + internal bool DoesShortcutExist(string key) + { + return Settings.CustomShortcuts.Any(v => v.Key == key) || + Settings.BuiltinShortcuts.Any(v => v.Key == key); + } } From 6bf23c939db096e79a6da603612ddef534261627 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 24 Jun 2024 23:07:12 +0000 Subject: [PATCH 20/23] Bump BitFaster.Caching from 2.5.0 to 2.5.1 Bumps [BitFaster.Caching](https://github.com/bitfaster/BitFaster.Caching) from 2.5.0 to 2.5.1. - [Release notes](https://github.com/bitfaster/BitFaster.Caching/releases) - [Commits](https://github.com/bitfaster/BitFaster.Caching/compare/v2.5.0...v2.5.1) --- updated-dependencies: - dependency-name: BitFaster.Caching dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .../Flow.Launcher.Infrastructure.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher.Infrastructure/Flow.Launcher.Infrastructure.csproj b/Flow.Launcher.Infrastructure/Flow.Launcher.Infrastructure.csproj index 7d6448c43..688b40c83 100644 --- a/Flow.Launcher.Infrastructure/Flow.Launcher.Infrastructure.csproj +++ b/Flow.Launcher.Infrastructure/Flow.Launcher.Infrastructure.csproj @@ -49,7 +49,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive From d167813e66f38f440f65f419b1a0d234f35f6619 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 24 Jun 2024 23:08:21 +0000 Subject: [PATCH 21/23] Bump Microsoft.NET.Test.Sdk from 17.9.0 to 17.10.0 Bumps [Microsoft.NET.Test.Sdk](https://github.com/microsoft/vstest) from 17.9.0 to 17.10.0. - [Release notes](https://github.com/microsoft/vstest/releases) - [Changelog](https://github.com/microsoft/vstest/blob/main/docs/releases.md) - [Commits](https://github.com/microsoft/vstest/compare/v17.9.0...v17.10.0) --- updated-dependencies: - dependency-name: Microsoft.NET.Test.Sdk dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- Flow.Launcher.Test/Flow.Launcher.Test.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher.Test/Flow.Launcher.Test.csproj b/Flow.Launcher.Test/Flow.Launcher.Test.csproj index fd967de4a..9f2b64134 100644 --- a/Flow.Launcher.Test/Flow.Launcher.Test.csproj +++ b/Flow.Launcher.Test/Flow.Launcher.Test.csproj @@ -54,7 +54,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + \ No newline at end of file From 83830472cbae4c2b1181b4a038c2127360e6d00c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 24 Jun 2024 23:09:41 +0000 Subject: [PATCH 22/23] Bump FSharp.Core from 7.0.401 to 8.0.300 Bumps [FSharp.Core](https://github.com/dotnet/fsharp) from 7.0.401 to 8.0.300. - [Release notes](https://github.com/dotnet/fsharp/releases) - [Changelog](https://github.com/dotnet/fsharp/blob/main/release-notes.md) - [Commits](https://github.com/dotnet/fsharp/commits) --- updated-dependencies: - dependency-name: FSharp.Core dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- Flow.Launcher.Core/Flow.Launcher.Core.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher.Core/Flow.Launcher.Core.csproj b/Flow.Launcher.Core/Flow.Launcher.Core.csproj index fe2cb7e58..6d97e1c52 100644 --- a/Flow.Launcher.Core/Flow.Launcher.Core.csproj +++ b/Flow.Launcher.Core/Flow.Launcher.Core.csproj @@ -54,7 +54,7 @@ - + From 44d8af33f2a210d488077f5df36ff3e33e6b1d7a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 25 Jun 2024 11:50:26 +0000 Subject: [PATCH 23/23] Bump Meziantou.Framework.Win32.Jobs from 3.2.1 to 3.4.0 Bumps [Meziantou.Framework.Win32.Jobs](https://github.com/meziantou/Meziantou.Framework) from 3.2.1 to 3.4.0. - [Commits](https://github.com/meziantou/Meziantou.Framework/commits) --- updated-dependencies: - dependency-name: Meziantou.Framework.Win32.Jobs dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- Flow.Launcher.Core/Flow.Launcher.Core.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher.Core/Flow.Launcher.Core.csproj b/Flow.Launcher.Core/Flow.Launcher.Core.csproj index 6d97e1c52..851541fc2 100644 --- a/Flow.Launcher.Core/Flow.Launcher.Core.csproj +++ b/Flow.Launcher.Core/Flow.Launcher.Core.csproj @@ -55,7 +55,7 @@ - +