Skip to content

Commit 087bbee

Browse files
committed
Fix high dpi float inaccuracy in rect comparison
1 parent 16ff1f3 commit 087bbee

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/ManagedShell.AppBar/AppBarManager.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -402,12 +402,14 @@ public void ABSetPos(AppBarWindow abWindow, double width, double height, AppBarE
402402

403403
// check if new coords
404404
bool isSameCoords = false;
405+
Rect currentRect;
406+
GetWindowRect(abWindow.Handle, out currentRect);
405407
if (!isCreate)
406408
{
407-
bool topUnchanged = abd.rc.Top == Math.Round(abWindow.Top * abWindow.DpiScale);
408-
bool leftUnchanged = abd.rc.Left == Math.Round(abWindow.Left * abWindow.DpiScale);
409-
bool bottomUnchanged = abd.rc.Bottom == Math.Round((abWindow.Top * abWindow.DpiScale) + (abWindow.ActualHeight * abWindow.DpiScale));
410-
bool rightUnchanged = abd.rc.Right == Math.Round((abWindow.Left * abWindow.DpiScale) + (abWindow.ActualWidth * abWindow.DpiScale));
409+
bool topUnchanged = abd.rc.Top == currentRect.Top;
410+
bool leftUnchanged = abd.rc.Left == currentRect.Left;
411+
bool bottomUnchanged = abd.rc.Bottom == currentRect.Bottom;
412+
bool rightUnchanged = abd.rc.Right == currentRect.Right;
411413

412414
isSameCoords = topUnchanged
413415
&& leftUnchanged
@@ -417,7 +419,7 @@ public void ABSetPos(AppBarWindow abWindow, double width, double height, AppBarE
417419

418420
if (!isSameCoords)
419421
{
420-
ShellLogger.Debug($"AppBarManager: {abWindow.Name} changing position (TxLxBxR) to {abd.rc.Top}x{abd.rc.Left}x{abd.rc.Bottom}x{abd.rc.Right} from {abWindow.Top * abWindow.DpiScale}x{abWindow.Left * abWindow.DpiScale}x{Math.Round((abWindow.Top * abWindow.DpiScale) + (abWindow.ActualHeight * abWindow.DpiScale))}x{Math.Round((abWindow.Left * abWindow.DpiScale) + (abWindow.ActualWidth * abWindow.DpiScale))}");
422+
ShellLogger.Debug($"AppBarManager: {abWindow.Name} changing position (TxLxBxR) to {abd.rc.Top}x{abd.rc.Left}x{abd.rc.Bottom}x{abd.rc.Right} from {currentRect.Top}x{currentRect.Left}x{currentRect.Bottom}x{currentRect.Right}");
421423
abWindow.SetAppBarPosition(abd.rc);
422424
}
423425

0 commit comments

Comments
 (0)