@@ -465,15 +465,18 @@ private void OnPreviewMouseMove(object sender, MouseEventArgs e)
465
465
466
466
private void OnMouseDown ( object sender , MouseButtonEventArgs e )
467
467
{
468
+ // When the window is maximized via Snap,
469
+ // dragging attempts will first switch the window from Maximized to Normal state,
470
+ // and adjust the drag position accordingly.
468
471
if ( e . ChangedButton == MouseButton . Left )
469
472
{
470
473
try
471
474
{
472
475
if ( WindowState == WindowState . Maximized )
473
476
{
474
477
// Calculate ratio based on maximized window dimensions
475
- double maxWidth = this . ActualWidth ;
476
- double maxHeight = this . ActualHeight ;
478
+ double maxWidth = ActualWidth ;
479
+ double maxHeight = ActualHeight ;
477
480
var mousePos = e . GetPosition ( this ) ;
478
481
double xRatio = mousePos . X / maxWidth ;
479
482
double yRatio = mousePos . Y / maxHeight ;
@@ -486,7 +489,7 @@ private void OnMouseDown(object sender, MouseButtonEventArgs e)
486
489
// Switch to Normal state
487
490
WindowState = WindowState . Normal ;
488
491
489
- Dispatcher . BeginInvoke ( new Action ( ( ) =>
492
+ Application . Current ? . Dispatcher . Invoke ( new Action ( ( ) =>
490
493
{
491
494
double normalWidth = Width ;
492
495
double normalHeight = Height ;
@@ -535,83 +538,78 @@ private async void OnContextMenusForSettingsClick(object sender, RoutedEventArgs
535
538
536
539
#region Window WndProc
537
540
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
541
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 ;
548
- _initialHeight = ( int ) Height ;
549
- handled = true ;
550
- }
551
- else if ( msg == Win32Helper . WM_EXITSIZEMOVE )
542
+ {
543
+ switch ( msg )
552
544
{
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 ) )
557
- {
558
- if ( ! _settings . KeepMaxResults )
545
+ case Win32Helper . WM_ENTERSIZEMOVE :
546
+ _initialWidth = ( int ) Width ;
547
+ _initialHeight = ( int ) Height ;
548
+ handled = true ;
549
+ break ;
550
+ case Win32Helper . WM_EXITSIZEMOVE :
551
+ //Prevent updating the number of results when the window height is below the height of a single result item.
552
+ //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.
553
+ //(Without this check, releasing from a snap can cause the window height to hit the minimum, resulting in only 2 results being shown.)
554
+ if ( _initialHeight != ( int ) Height && Height > ( _settings . WindowHeightSize + _settings . ItemHeightSize ) )
559
555
{
560
- // Get shadow margin
561
- var shadowMargin = 0 ;
562
- var ( _, useDropShadowEffect ) = _theme . GetActualValue ( ) ;
563
- if ( useDropShadowEffect )
556
+ if ( ! _settings . KeepMaxResults )
564
557
{
565
- shadowMargin = 32 ;
566
- }
558
+ // Get shadow margin
559
+ var shadowMargin = 0 ;
560
+ var ( _, useDropShadowEffect ) = _theme . GetActualValue ( ) ;
561
+ if ( useDropShadowEffect )
562
+ {
563
+ shadowMargin = 32 ;
564
+ }
567
565
568
- // Calculate max results to show
569
- var itemCount = ( Height - ( _settings . WindowHeightSize + 14 ) - shadowMargin ) / _settings . ItemHeightSize ;
570
- if ( itemCount < 2 )
571
- {
572
- _settings . MaxResultsToShow = 2 ;
573
- }
574
- else
575
- {
576
- _settings . MaxResultsToShow = Convert . ToInt32 ( Math . Truncate ( itemCount ) ) ;
566
+ // Calculate max results to show
567
+ var itemCount = ( Height - ( _settings . WindowHeightSize + 14 ) - shadowMargin ) / _settings . ItemHeightSize ;
568
+ if ( itemCount < 2 )
569
+ {
570
+ _settings . MaxResultsToShow = 2 ;
571
+ }
572
+ else
573
+ {
574
+ _settings . MaxResultsToShow = Convert . ToInt32 ( Math . Truncate ( itemCount ) ) ;
575
+ }
577
576
}
578
- }
579
-
580
- SizeToContent = SizeToContent . Height ;
581
- }
582
- else
583
- {
584
- // Update height when exiting maximized snap state.
585
- SizeToContent = SizeToContent . Height ;
586
- }
587
577
588
- if ( _initialWidth != ( int ) Width )
589
- {
590
- if ( ! _settings . KeepMaxResults )
578
+ SizeToContent = SizeToContent . Height ;
579
+ }
580
+ else
591
581
{
592
- // Update width
593
- _viewModel . MainWindowWidth = Width ;
582
+ // Update height when exiting maximized snap state.
583
+ SizeToContent = SizeToContent . Height ;
594
584
}
595
585
596
- SizeToContent = SizeToContent . Height ;
597
- }
586
+ if ( _initialWidth != ( int ) Width )
587
+ {
588
+ if ( ! _settings . KeepMaxResults )
589
+ {
590
+ // Update width
591
+ _viewModel . MainWindowWidth = Width ;
592
+ }
598
593
599
- handled = true ;
600
- }
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
- {
594
+ SizeToContent = SizeToContent . Height ;
595
+ }
596
+
597
+ handled = true ;
598
+ break ;
599
+ case Win32Helper . WM_NCLBUTTONDBLCLK : // Block the double click in frame
611
600
SizeToContent = SizeToContent . Height ;
612
601
handled = true ;
613
- }
602
+ break ;
603
+ case Win32Helper . WM_SYSCOMMAND : // Block Maximize/Minimize by Win+Up and Win+Down Arrow
604
+ var command = wParam . ToInt32 ( ) & 0xFFF0 ;
605
+ if ( command == Win32Helper . SC_MAXIMIZE || command == Win32Helper . SC_MINIMIZE )
606
+ {
607
+ SizeToContent = SizeToContent . Height ;
608
+ handled = true ;
609
+ }
610
+ break ;
614
611
}
612
+
615
613
return IntPtr . Zero ;
616
614
}
617
615
0 commit comments