-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
29 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,40 @@ | ||
using Avalonia.Controls; | ||
|
||
namespace PicView.Avalonia.UI; | ||
public readonly struct ScreenSize(double workingAreaWidth, double workingAreaHeight, double scaling) | ||
|
||
public readonly record struct ScreenSize | ||
{ | ||
public double WorkingAreaWidth { get; init; } = workingAreaWidth; | ||
public double WorkingAreaHeight { get; init; } = workingAreaHeight; | ||
public double Scaling { get; init; } = scaling; | ||
public double WorkingAreaWidth { get; init; } | ||
public double WorkingAreaHeight { get; init; } | ||
public double Scaling { get; init; } | ||
} | ||
|
||
public static class ScreenHelper | ||
{ | ||
private static readonly Lock _lock = new(); | ||
private static readonly Lock Lock = new(); | ||
public static ScreenSize ScreenSize { get; private set; } | ||
|
||
public static void UpdateScreenSize(Window window) | ||
{ | ||
// TODO: Add support for dragging between multiple monitors | ||
// Dragging to monitor with different scaling (DPI) causes weird incorrect size behavior, | ||
// but starting the application works fine for either monitor, until you drag it to the other. | ||
// It works most of the time in debug mode, but not so much for AOT release | ||
|
||
// Need to lock it to prevent multiple calls | ||
lock (_lock) | ||
lock (Lock) | ||
{ | ||
var screen = window.Screens.ScreenFromVisual(window); | ||
|
||
var monitorWidth = screen.Bounds.Width / screen.Scaling; | ||
var monitorHeight = screen.Bounds.Height / screen.Scaling; | ||
var monitorWidth = screen.WorkingArea.Width / screen.Scaling; | ||
var monitorHeight = screen.WorkingArea.Height / screen.Scaling; | ||
|
||
ScreenSize = new ScreenSize(monitorWidth, monitorHeight, screen.Scaling) | ||
ScreenSize = new ScreenSize | ||
{ | ||
WorkingAreaWidth = monitorWidth, | ||
WorkingAreaHeight = monitorHeight, | ||
Scaling = screen.Scaling, | ||
}; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters