From 08038dec94ada693d82b706f48a73d4e3d5be71c Mon Sep 17 00:00:00 2001 From: DB P Date: Mon, 2 Jun 2025 18:33:45 +0900 Subject: [PATCH] Improve window drag behavior when transitioning from maximized state --- Flow.Launcher/MainWindow.xaml.cs | 47 +++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 3f8871716..51339208d 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -465,7 +465,52 @@ namespace Flow.Launcher private void OnMouseDown(object sender, MouseButtonEventArgs e) { - if (e.ChangedButton == MouseButton.Left) DragMove(); + if (e.ChangedButton == MouseButton.Left) + { + try + { + if (WindowState == WindowState.Maximized) + { + // 최대화된 창의 크기 기준으로 비율 계산 + double maxWidth = this.ActualWidth; + double maxHeight = this.ActualHeight; + var mousePos = e.GetPosition(this); + double xRatio = mousePos.X / maxWidth; + double yRatio = mousePos.Y / maxHeight; + + // 현재 모니터 정보 + var screen = Screen.FromHandle(new WindowInteropHelper(this).Handle); + var workingArea = screen.WorkingArea; + var screenLeftTop = Win32Helper.TransformPixelsToDIP(this, workingArea.X, workingArea.Y); + + // Normal로 전환 + WindowState = WindowState.Normal; + + Dispatcher.BeginInvoke(new Action(() => + { + double normalWidth = Width; + double normalHeight = Height; + + // 최대화된 창 크기와 Normal 창 크기 차이만큼 비율 적용 + Left = screenLeftTop.X + (maxWidth - normalWidth) * xRatio; + Top = screenLeftTop.Y + (maxHeight - normalHeight) * yRatio; + + if (Mouse.LeftButton == MouseButtonState.Pressed) + { + DragMove(); + } + }), DispatcherPriority.ApplicationIdle); + } + else + { + DragMove(); + } + } + catch (InvalidOperationException) + { + // 무시 + } + } } #endregion