Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mini-window controls alignment across multi-resolution monitors #140

Merged
merged 1 commit into from
Feb 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions vATIS.Desktop/Ui/Windows/CompactWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
// </copyright>

using System;
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
Expand Down Expand Up @@ -71,27 +69,29 @@ private void OnPositionChanged(object? sender, PixelPointEventArgs e)
model.UpdatePosition(this);
}

// Get the bounding rectangle of all screens combined
var totalScreenBounds = Screens.All
.Select(s => s.WorkingArea)
.Aggregate((acc, next) => acc.Union(next));

var totalLeft = totalScreenBounds.X;
var totalRight = totalScreenBounds.X + totalScreenBounds.Width;
// Get the screen the window is currently on
var currentScreen = Screens.ScreenFromPoint(Position);
if (currentScreen == null) return;

var screenBounds = currentScreen.WorkingArea;
var windowLeft = Position.X;
var windowRight = windowLeft + (int)Width;

var isRightOffScreen = windowRight > totalRight;
var isRightFullyVisible = windowRight <= totalRight && windowLeft >= totalLeft;
var isRightOffScreen = windowRight > screenBounds.X + screenBounds.Width;
var isLeftOffScreen = windowLeft < screenBounds.X;

// Update alignment only if the window is partially off-screen
// Adjust alignment based on visibility
if (isRightOffScreen)
{
WindowControls.HorizontalAlignment = HorizontalAlignment.Left;
}
else if (isRightFullyVisible)
else if (isLeftOffScreen)
{
WindowControls.HorizontalAlignment = HorizontalAlignment.Right;
}
else
{
// Keep default alignment when fully visible
WindowControls.HorizontalAlignment = HorizontalAlignment.Right;
}
}
Expand Down