@@ -465,7 +465,52 @@ private void OnPreviewMouseMove(object sender, MouseEventArgs e)
465
465
466
466
private void OnMouseDown ( object sender , MouseButtonEventArgs e )
467
467
{
468
- if ( e . ChangedButton == MouseButton . Left ) DragMove ( ) ;
468
+ if ( e . ChangedButton == MouseButton . Left )
469
+ {
470
+ try
471
+ {
472
+ if ( WindowState == WindowState . Maximized )
473
+ {
474
+ // Calculate ratio based on maximized window dimensions
475
+ double maxWidth = this . ActualWidth ;
476
+ double maxHeight = this . ActualHeight ;
477
+ var mousePos = e . GetPosition ( this ) ;
478
+ double xRatio = mousePos . X / maxWidth ;
479
+ double yRatio = mousePos . Y / maxHeight ;
480
+
481
+ // Current monitor information
482
+ var screen = Screen . FromHandle ( new WindowInteropHelper ( this ) . Handle ) ;
483
+ var workingArea = screen . WorkingArea ;
484
+ var screenLeftTop = Win32Helper . TransformPixelsToDIP ( this , workingArea . X , workingArea . Y ) ;
485
+
486
+ // Switch to Normal state
487
+ WindowState = WindowState . Normal ;
488
+
489
+ Dispatcher . BeginInvoke ( new Action ( ( ) =>
490
+ {
491
+ double normalWidth = Width ;
492
+ double normalHeight = Height ;
493
+
494
+ // Apply ratio based on the difference between maximized and normal window sizes
495
+ Left = screenLeftTop . X + ( maxWidth - normalWidth ) * xRatio ;
496
+ Top = screenLeftTop . Y + ( maxHeight - normalHeight ) * yRatio ;
497
+
498
+ if ( Mouse . LeftButton == MouseButtonState . Pressed )
499
+ {
500
+ DragMove ( ) ;
501
+ }
502
+ } ) , DispatcherPriority . ApplicationIdle ) ;
503
+ }
504
+ else
505
+ {
506
+ DragMove ( ) ;
507
+ }
508
+ }
509
+ catch ( InvalidOperationException )
510
+ {
511
+ // Ignored - can occur if drag operation is already in progress
512
+ }
513
+ }
469
514
}
470
515
471
516
#endregion
@@ -490,18 +535,25 @@ private async void OnContextMenusForSettingsClick(object sender, RoutedEventArgs
490
535
491
536
#region Window WndProc
492
537
493
- private IntPtr WndProc ( IntPtr hwnd , int msg , IntPtr wParam , IntPtr lParam , ref bool handled )
494
- {
495
- if ( msg == Win32Helper . WM_ENTERSIZEMOVE )
496
- {
497
- _initialWidth = ( int ) Width ;
538
+ private const int WM_NCLBUTTONDBLCLK = 0x00A3 ;
539
+ private const int WM_SYSCOMMAND = 0x0112 ;
540
+ private const int SC_MAXIMIZE = 0xF030 ;
541
+ private const int SC_RESTORE = 0xF120 ;
542
+ private const int SC_MINIMIZE = 0xF020 ;
543
+ private IntPtr WndProc ( IntPtr hwnd , int msg , IntPtr wParam , IntPtr lParam , ref bool handled )
544
+ {
545
+ if ( msg == Win32Helper . WM_ENTERSIZEMOVE )
546
+ {
547
+ _initialWidth = ( int ) Width ;
498
548
_initialHeight = ( int ) Height ;
499
-
500
549
handled = true ;
501
550
}
502
551
else if ( msg == Win32Helper . WM_EXITSIZEMOVE )
503
552
{
504
- if ( _initialHeight != ( int ) Height )
553
+ //Prevent updating the number of results when the window height is below the height of a single result item.
554
+ //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.
555
+ //(Without this check, releasing from a snap can cause the window height to hit the minimum, resulting in only 2 results being shown.)
556
+ if ( _initialHeight != ( int ) Height && Height > ( _settings . WindowHeightSize + _settings . ItemHeightSize ) )
505
557
{
506
558
if ( ! _settings . KeepMaxResults )
507
559
{
@@ -527,6 +579,11 @@ private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref b
527
579
528
580
SizeToContent = SizeToContent . Height ;
529
581
}
582
+ else
583
+ {
584
+ // Update height when exiting maximized snap state.
585
+ SizeToContent = SizeToContent . Height ;
586
+ }
530
587
531
588
if ( _initialWidth != ( int ) Width )
532
589
{
@@ -541,7 +598,20 @@ private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref b
541
598
542
599
handled = true ;
543
600
}
544
-
601
+ if ( msg == WM_NCLBUTTONDBLCLK )
602
+ {
603
+ SizeToContent = SizeToContent . Height ;
604
+ handled = true ;
605
+ }
606
+ else if ( msg == WM_SYSCOMMAND )
607
+ {
608
+ int command = wParam . ToInt32 ( ) & 0xFFF0 ;
609
+ if ( command == SC_MAXIMIZE || command == SC_MINIMIZE )
610
+ {
611
+ SizeToContent = SizeToContent . Height ;
612
+ handled = true ;
613
+ }
614
+ }
545
615
return IntPtr . Zero ;
546
616
}
547
617
0 commit comments