Browse Source

Updates from code review

pull/9133/head
robloo 3 years ago
parent
commit
6bc689a662
  1. 2
      samples/ControlCatalog/Pages/ScreenPage.cs
  2. 35
      src/Avalonia.Controls/Platform/Screen.cs
  3. 2
      src/Avalonia.Native/WindowImplBase.cs
  4. 2
      src/Avalonia.X11/X11Window.cs
  5. 8
      src/Windows/Avalonia.Win32/TrayIconImpl.cs
  6. 2
      src/Windows/Avalonia.Win32/WindowImpl.cs

2
samples/ControlCatalog/Pages/ScreenPage.cs

@ -62,7 +62,7 @@ namespace ControlCatalog.Pages
CreateFormattedText($"WorkArea: {screen.WorkingArea.Width}:{screen.WorkingArea.Height}"); CreateFormattedText($"WorkArea: {screen.WorkingArea.Width}:{screen.WorkingArea.Height}");
context.DrawText(formattedText, boundsRect.Position.WithY(boundsRect.Size.Height + 20)); context.DrawText(formattedText, boundsRect.Position.WithY(boundsRect.Size.Height + 20));
formattedText = CreateFormattedText($"Scaling: {screen.PixelDensity * 100}%"); formattedText = CreateFormattedText($"Scaling: {screen.Scale * 100}%");
context.DrawText(formattedText, boundsRect.Position.WithY(boundsRect.Size.Height + 40)); context.DrawText(formattedText, boundsRect.Position.WithY(boundsRect.Size.Height + 40));
formattedText = CreateFormattedText($"Primary: {screen.IsPrimary}"); formattedText = CreateFormattedText($"Primary: {screen.IsPrimary}");

35
src/Avalonia.Controls/Platform/Screen.cs

@ -1,4 +1,6 @@
namespace Avalonia.Platform using System;
namespace Avalonia.Platform
{ {
/// <summary> /// <summary>
/// Represents a single display screen. /// Represents a single display screen.
@ -6,34 +8,47 @@
public class Screen public class Screen
{ {
/// <summary> /// <summary>
/// Gets the pixel density of the screen. /// Gets the scaling factor applied to the screen by the operating system.
/// This is a scaling factor so multiply by 100 to get a percentage.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// Both X and Y density are assumed uniform. /// Multiply this value by 100 to get a percentage.
/// Both X and Y scaling factors are assumed uniform.
/// </remarks> /// </remarks>
public double PixelDensity { get; } public double Scale { get; }
/// <inheritdoc cref="Scale"/>
[Obsolete("Use the Scale property instead.")]
public double PixelDensity => Scale;
/// <summary> /// <summary>
/// Gets the overall pixel-size of the screen. /// Gets the overall pixel-size of the screen.
/// This generally is the raw pixel counts in both the X and Y direction.
/// </summary> /// </summary>
/// <remarks>
/// This generally is the raw pixel counts in both the X and Y direction.
/// </remarks>
public PixelRect Bounds { get; } public PixelRect Bounds { get; }
/// <summary> /// <summary>
/// Gets the actual working-area pixel-size of the screen. /// Gets the actual working-area pixel-size of the screen.
/// This may be smaller to account for notches and other block-out areas.
/// </summary> /// </summary>
/// <remarks>
/// This area may be smaller than <see href="Bounds"/> to account for notches and
/// other block-out areas such as taskbars etc.
/// </remarks>
public PixelRect WorkingArea { get; } public PixelRect WorkingArea { get; }
/// <summary> /// <summary>
/// Gets a value indicating whether the screen is the primary one. /// Gets a value indicating whether the screen is the primary one.
/// </summary> /// </summary>
public bool IsPrimary { get; } public bool IsPrimary { get; }
public Screen(double pixelDensity, PixelRect bounds, PixelRect workingArea, bool isPrimary) /// <inheritdoc cref="IsPrimary"/>
[Obsolete("Use the IsPrimary property instead.")]
public bool Primary => IsPrimary;
public Screen(double scale, PixelRect bounds, PixelRect workingArea, bool isPrimary)
{ {
this.PixelDensity = pixelDensity; this.Scale = scale;
this.Bounds = bounds; this.Bounds = bounds;
this.WorkingArea = workingArea; this.WorkingArea = workingArea;
this.IsPrimary = isPrimary; this.IsPrimary = isPrimary;

2
src/Avalonia.Native/WindowImplBase.cs

@ -92,7 +92,7 @@ namespace Avalonia.Native
_savedScaling = RenderScaling; _savedScaling = RenderScaling;
_nativeControlHost = new NativeControlHostImpl(_native.CreateNativeControlHost()); _nativeControlHost = new NativeControlHostImpl(_native.CreateNativeControlHost());
var monitor = Screen.AllScreens.OrderBy(x => x.PixelDensity) var monitor = Screen.AllScreens.OrderBy(x => x.Scale)
.FirstOrDefault(m => m.Bounds.Contains(Position)); .FirstOrDefault(m => m.Bounds.Contains(Position));
Resize(new Size(monitor.WorkingArea.Width * 0.75d, monitor.WorkingArea.Height * 0.7d), PlatformResizeReason.Layout); Resize(new Size(monitor.WorkingArea.Width * 0.75d, monitor.WorkingArea.Height * 0.7d), PlatformResizeReason.Layout);

2
src/Avalonia.X11/X11Window.cs

@ -120,7 +120,7 @@ namespace Avalonia.X11
if (!_popup && Screen != null) if (!_popup && Screen != null)
{ {
var monitor = Screen.AllScreens.OrderBy(x => x.PixelDensity) var monitor = Screen.AllScreens.OrderBy(x => x.Scale)
.FirstOrDefault(m => m.Bounds.Contains(Position)); .FirstOrDefault(m => m.Bounds.Contains(Position));
if (monitor != null) if (monitor != null)

8
src/Windows/Avalonia.Win32/TrayIconImpl.cs

@ -216,7 +216,7 @@ namespace Avalonia.Win32
{ {
Anchor = PopupAnchor.TopLeft, Anchor = PopupAnchor.TopLeft,
Gravity = PopupGravity.BottomRight, Gravity = PopupGravity.BottomRight,
AnchorRectangle = new Rect(Position.ToPoint(1) / Screens.Primary.PixelDensity, new Size(1, 1)), AnchorRectangle = new Rect(Position.ToPoint(1) / Screens.Primary.Scale, new Size(1, 1)),
Size = finalRect.Size, Size = finalRect.Size,
ConstraintAdjustment = PopupPositionerConstraintAdjustment.FlipX | PopupPositionerConstraintAdjustment.FlipY, ConstraintAdjustment = PopupPositionerConstraintAdjustment.FlipX | PopupPositionerConstraintAdjustment.FlipY,
}); });
@ -244,16 +244,16 @@ namespace Avalonia.Win32
{ {
var point = _hiddenWindow.Screens.Primary.Bounds.TopLeft; var point = _hiddenWindow.Screens.Primary.Bounds.TopLeft;
var size = _hiddenWindow.Screens.Primary.Bounds.Size; var size = _hiddenWindow.Screens.Primary.Bounds.Size;
return new Rect(point.X, point.Y, size.Width * _hiddenWindow.Screens.Primary.PixelDensity, size.Height * _hiddenWindow.Screens.Primary.PixelDensity); return new Rect(point.X, point.Y, size.Width * _hiddenWindow.Screens.Primary.Scale, size.Height * _hiddenWindow.Screens.Primary.Scale);
} }
} }
public void MoveAndResize(Point devicePoint, Size virtualSize) public void MoveAndResize(Point devicePoint, Size virtualSize)
{ {
_moveResize(new PixelPoint((int)devicePoint.X, (int)devicePoint.Y), virtualSize, _hiddenWindow.Screens.Primary.PixelDensity); _moveResize(new PixelPoint((int)devicePoint.X, (int)devicePoint.Y), virtualSize, _hiddenWindow.Screens.Primary.Scale);
} }
public double Scaling => _hiddenWindow.Screens.Primary.PixelDensity; public double Scaling => _hiddenWindow.Screens.Primary.Scale;
} }
} }

2
src/Windows/Avalonia.Win32/WindowImpl.cs

@ -224,7 +224,7 @@ namespace Avalonia.Win32
} }
} }
private double PrimaryScreenRenderScaling => Screen.AllScreens.FirstOrDefault(screen => screen.IsPrimary)?.PixelDensity ?? 1; private double PrimaryScreenRenderScaling => Screen.AllScreens.FirstOrDefault(screen => screen.IsPrimary)?.Scale ?? 1;
public double RenderScaling => _scaling; public double RenderScaling => _scaling;

Loading…
Cancel
Save