Improve window drag behavior when transitioning from maximized state

This commit is contained in:
DB P 2025-06-02 18:33:45 +09:00
parent c6ed0bdc2a
commit 08038dec94

View file

@ -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