From 2b4e95e64a235bd79af1a1b34c4e062624dadb93 Mon Sep 17 00:00:00 2001 From: DB P Date: Mon, 2 Jun 2025 14:55:46 +0900 Subject: [PATCH 1/7] Block window maximize and prevent resizing in WndProc --- Flow.Launcher.Infrastructure/Win32Helper.cs | 7 +++++++ Flow.Launcher/MainWindow.xaml.cs | 21 ++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Flow.Launcher.Infrastructure/Win32Helper.cs b/Flow.Launcher.Infrastructure/Win32Helper.cs index 96d8e925b71..5d340c6f73f 100644 --- a/Flow.Launcher.Infrastructure/Win32Helper.cs +++ b/Flow.Launcher.Infrastructure/Win32Helper.cs @@ -163,6 +163,13 @@ public static void HideFromAltTab(Window window) SetWindowStyle(hwnd, WINDOW_LONG_PTR_INDEX.GWL_EXSTYLE, (int)newExStyle); } + public static void BlockWindowMaximize(Window window, HwndSourceHook hook) + { + var handle = GetWindowHandle(window, true); + var hwndSource = HwndSource.FromHwnd(handle); + hwndSource.AddHook(hook); + } + /// /// Restore window display in the Alt+Tab window list. /// diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index f15091e4a8d..49f180e8092 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -490,6 +490,12 @@ private async void OnContextMenusForSettingsClick(object sender, RoutedEventArgs #region Window WndProc + private const int WM_NCLBUTTONDBLCLK = 0x00A3; + private const int WM_SYSCOMMAND = 0x0112; + private const int SC_MAXIMIZE = 0xF030; + private const int SC_RESTORE = 0xF120; + private const int SC_MINIMIZE = 0xF020; + private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { if (msg == Win32Helper.WM_ENTERSIZEMOVE) @@ -541,7 +547,20 @@ private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref b handled = true; } - + if (msg == WM_NCLBUTTONDBLCLK) + { + SizeToContent = SizeToContent.Height; + handled = true; + } + else if (msg == WM_SYSCOMMAND) + { + int command = wParam.ToInt32() & 0xFFF0; + if (command == SC_MAXIMIZE || command == SC_MINIMIZE) + { + SizeToContent = SizeToContent.Height; + handled = true; + } + } return IntPtr.Zero; } From 8baf1d437e5d203b2eeaf7175927f51c10cbc6c6 Mon Sep 17 00:00:00 2001 From: DB P Date: Mon, 2 Jun 2025 17:44:41 +0900 Subject: [PATCH 2/7] Prevent window height updates when exiting snap state and adjust border brush style --- Flow.Launcher/MainWindow.xaml.cs | 22 ++++++++++++++-------- Flow.Launcher/Themes/Win11Light.xaml | 3 ++- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 49f180e8092..3f887171630 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -495,19 +495,20 @@ private async void OnContextMenusForSettingsClick(object sender, RoutedEventArgs private const int SC_MAXIMIZE = 0xF030; private const int SC_RESTORE = 0xF120; private const int SC_MINIMIZE = 0xF020; - - private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) - { - if (msg == Win32Helper.WM_ENTERSIZEMOVE) - { - _initialWidth = (int)Width; + private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) + { + if (msg == Win32Helper.WM_ENTERSIZEMOVE) + { + _initialWidth = (int)Width; _initialHeight = (int)Height; - handled = true; } else if (msg == Win32Helper.WM_EXITSIZEMOVE) { - if (_initialHeight != (int)Height) + //Prevent updating the number of results when the window height is below the height of a single result item. + //This situation occurs not only when the user manually resizes the window, but also when the window is released from a side snap, as the OS automatically adjusts the window height. + //(Without this check, releasing from a snap can cause the window height to hit the minimum, resulting in only 2 results being shown.) + if (_initialHeight != (int)Height && Height> (_settings.WindowHeightSize + _settings.ItemHeightSize)) { if (!_settings.KeepMaxResults) { @@ -533,6 +534,11 @@ private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref b SizeToContent = SizeToContent.Height; } + else + { + // Update height when exiting maximized snap state. + SizeToContent = SizeToContent.Height; + } if (_initialWidth != (int)Width) { diff --git a/Flow.Launcher/Themes/Win11Light.xaml b/Flow.Launcher/Themes/Win11Light.xaml index 0c3e15c6dd9..06fbf403d47 100644 --- a/Flow.Launcher/Themes/Win11Light.xaml +++ b/Flow.Launcher/Themes/Win11Light.xaml @@ -73,8 +73,9 @@ BasedOn="{StaticResource BaseWindowBorderStyle}" TargetType="{x:Type Border}"> - + +