csharpdeeb25a2 | 1 | using Avalonia.Controls; |
| 2 | using Avalonia.Controls.ApplicationLifetimes; |
| 3 | |
| 4 | namespace CascadeIDE.Services.Presentation; |
| 5 | |
| 6 | /// <summary>Reads Avalonia screens for <see cref="PresentationTierResolver"/>.</summary> |
| 7 | public static class PresentationMonitorProbe |
| 8 | { |
| 9 | public static PresentationMonitorSnapshot Capture() |
| 10 | { |
| 11 | try |
| 12 | { |
| 13 | if (Avalonia.Application.Current?.ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime lifetime) |
| 14 | return PresentationMonitorSnapshot.SingleFallback; |
| 15 | |
| 16 | var main = lifetime.MainWindow; |
| 17 | var all = main?.Screens?.All; |
| 18 | if (all is null || all.Count == 0) |
| 19 | return PresentationMonitorSnapshot.SingleFallback; |
| 20 | |
| 21 | var ordered = PresentationMonitorTopology.OrderScreensForPresentation(all); |
| 22 | var primary = ordered[0].WorkingArea; |
| 23 | var totalW = 0; |
| 24 | for (var i = 0; i < ordered.Count; i++) |
| 25 | totalW += ordered[i].WorkingArea.Width; |
| 26 | |
| 27 | return new PresentationMonitorSnapshot( |
| 28 | ordered.Count, |
| 29 | primary.Width, |
| 30 | primary.Height, |
| 31 | totalW); |
| 32 | } |
| 33 | catch |
| 34 | { |
| 35 | return PresentationMonitorSnapshot.SingleFallback; |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | |
View only · write via MCP/CIDE