-
-
Notifications
You must be signed in to change notification settings - Fork 397
Fix issues related to search window maximization and Snap behavior #3606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2b4e95e
8baf1d4
c6ed0bd
08038de
556a4c8
0ecc01d
5aebf3f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,7 +61,7 @@ | |
private MediaPlayer animationSoundWMP; | ||
private SoundPlayer animationSoundWPF; | ||
|
||
// Window WndProc | ||
private HwndSource _hwndSource; | ||
private int _initialWidth; | ||
private int _initialHeight; | ||
|
@@ -80,8 +80,8 @@ | |
public MainWindow() | ||
{ | ||
_settings = Ioc.Default.GetRequiredService<Settings>(); | ||
_theme = Ioc.Default.GetRequiredService<Theme>(); | ||
_viewModel = Ioc.Default.GetRequiredService<MainViewModel>(); | ||
DataContext = _viewModel; | ||
|
||
InitializeComponent(); | ||
|
@@ -108,7 +108,7 @@ | |
{ | ||
var handle = Win32Helper.GetWindowHandle(this, true); | ||
_hwndSource = HwndSource.FromHwnd(handle); | ||
_hwndSource.AddHook(WndProc); | ||
Win32Helper.HideFromAltTab(this); | ||
Win32Helper.DisableControlBox(this); | ||
} | ||
|
@@ -333,7 +333,7 @@ | |
{ | ||
try | ||
{ | ||
_hwndSource.RemoveHook(WndProc); | ||
} | ||
catch (Exception) | ||
{ | ||
|
@@ -457,7 +457,7 @@ | |
} | ||
} | ||
|
||
#pragma warning restore VSTHRD100 // Avoid async void methods | ||
|
||
#endregion | ||
|
||
|
@@ -465,14 +465,59 @@ | |
|
||
private void OnMouseDown(object sender, MouseButtonEventArgs e) | ||
{ | ||
if (e.ChangedButton == MouseButton.Left) DragMove(); | ||
if (e.ChangedButton == MouseButton.Left) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When the window is maximized via Snap, dragging attempts will first switch the window from Maximized to Normal state, and adjust the drag position accordingly. |
||
{ | ||
try | ||
{ | ||
if (WindowState == WindowState.Maximized) | ||
{ | ||
// Calculate ratio based on maximized window dimensions | ||
double maxWidth = this.ActualWidth; | ||
double maxHeight = this.ActualHeight; | ||
var mousePos = e.GetPosition(this); | ||
double xRatio = mousePos.X / maxWidth; | ||
double yRatio = mousePos.Y / maxHeight; | ||
|
||
// Current monitor information | ||
var screen = Screen.FromHandle(new WindowInteropHelper(this).Handle); | ||
var workingArea = screen.WorkingArea; | ||
var screenLeftTop = Win32Helper.TransformPixelsToDIP(this, workingArea.X, workingArea.Y); | ||
|
||
// Switch to Normal state | ||
WindowState = WindowState.Normal; | ||
|
||
Dispatcher.BeginInvoke(new Action(() => | ||
{ | ||
double normalWidth = Width; | ||
double normalHeight = Height; | ||
|
||
// Apply ratio based on the difference between maximized and normal window sizes | ||
Left = screenLeftTop.X + (maxWidth - normalWidth) * xRatio; | ||
Top = screenLeftTop.Y + (maxHeight - normalHeight) * yRatio; | ||
|
||
if (Mouse.LeftButton == MouseButtonState.Pressed) | ||
{ | ||
DragMove(); | ||
} | ||
}), DispatcherPriority.ApplicationIdle); | ||
} | ||
else | ||
{ | ||
DragMove(); | ||
} | ||
} | ||
catch (InvalidOperationException) | ||
{ | ||
// Ignored - can occur if drag operation is already in progress | ||
} | ||
} | ||
} | ||
|
||
#endregion | ||
|
||
#region Window Context Menu Event | ||
|
||
#pragma warning disable VSTHRD100 // Avoid async void methods | ||
|
||
private async void OnContextMenusForSettingsClick(object sender, RoutedEventArgs e) | ||
{ | ||
|
@@ -484,24 +529,31 @@ | |
App.API.OpenSettingDialog(); | ||
} | ||
|
||
#pragma warning restore VSTHRD100 // Avoid async void methods | ||
|
||
#endregion | ||
|
||
#region Window WndProc | ||
|
||
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) | ||
{ | ||
if (msg == Win32Helper.WM_ENTERSIZEMOVE) | ||
{ | ||
_initialWidth = (int)Width; | ||
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) | ||
{ | ||
_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) | ||
{ | ||
|
@@ -527,6 +579,11 @@ | |
|
||
SizeToContent = SizeToContent.Height; | ||
} | ||
else | ||
{ | ||
// Update height when exiting maximized snap state. | ||
SizeToContent = SizeToContent.Height; | ||
} | ||
|
||
if (_initialWidth != (int)Width) | ||
{ | ||
|
@@ -541,7 +598,20 @@ | |
|
||
handled = true; | ||
} | ||
|
||
if (msg == WM_NCLBUTTONDBLCLK) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Block the double click in frame |
||
{ | ||
SizeToContent = SizeToContent.Height; | ||
handled = true; | ||
} | ||
else if (msg == WM_SYSCOMMAND) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Block Maximize/Minimize by Win+Up and Win+Down Arrow |
||
{ | ||
int command = wParam.ToInt32() & 0xFFF0; | ||
if (command == SC_MAXIMIZE || command == SC_MINIMIZE) | ||
{ | ||
SizeToContent = SizeToContent.Height; | ||
handled = true; | ||
} | ||
} | ||
return IntPtr.Zero; | ||
} | ||
|
||
|
@@ -561,7 +631,7 @@ | |
|
||
private void InitSoundEffects() | ||
{ | ||
if (_settings.WMPInstalled) | ||
{ | ||
animationSoundWMP?.Close(); | ||
animationSoundWMP = new MediaPlayer(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eliminated the issue where internal border values remained visible when the window border was forcibly set to a rectangle via Snap. This behavior only applies when blur is enabled; non-blur themes are unaffected.