From e561bd8c65a2f60d463ae6e56c52ad4aaea61ac5 Mon Sep 17 00:00:00 2001 From: Jonathan Pobst Date: Tue, 11 Jul 2023 20:28:11 -0500 Subject: [PATCH] Update to Avalonia@e621edbe (Apr 30 2023) (#31) --- build/update-avalonia.csx | 2 + .../Avalonia.Mac/PopupImpl.cs | 3 +- .../Avalonia.Mac/WindowImplBase.cs | 8 +-- .../Avalonia.Win32/PopupImpl.cs | 3 +- .../Avalonia.Win32/WindowImpl.AppWndProc.cs | 6 +- .../Avalonia.Win32/WindowImpl.cs | 14 ++--- .../Avalonia.X11/X11Window.cs | 14 ++--- src/Modern.WindowKit/Dispatcher.Invoke.cs | 45 +++++++------- src/Modern.WindowKit/ICursorFactory.cs | 2 + src/Modern.WindowKit/IDispatcherImpl.cs | 8 +-- src/Modern.WindowKit/ITopLevelImpl.cs | 36 +---------- src/Modern.WindowKit/IWindowImpl.cs | 2 +- src/Modern.WindowKit/IWindowingPlatform.cs | 2 +- src/Modern.WindowKit/PrivateApiAttribute.cs | 9 +++ src/Modern.WindowKit/ScreenHelper.cs | 3 +- src/Modern.WindowKit/Screens.cs | 38 +++++++++++- src/Modern.WindowKit/UnstableAttribute.cs | 20 ++++++ .../WindowResizedEventArgs.cs | 61 +++++++++++++++++++ 18 files changed, 187 insertions(+), 89 deletions(-) create mode 100644 src/Modern.WindowKit/PrivateApiAttribute.cs create mode 100644 src/Modern.WindowKit/WindowResizedEventArgs.cs diff --git a/build/update-avalonia.csx b/build/update-avalonia.csx index 34bd351..83ea4c2 100644 --- a/build/update-avalonia.csx +++ b/build/update-avalonia.csx @@ -102,6 +102,7 @@ CopyFile ("Avalonia.Base/Platform/PlatformColorValues.cs", "PlatformColorValues. CopyFile ("Avalonia.Base/Platform/PlatformHandle.cs", "PlatformHandle.cs"); CopyFile ("Avalonia.Base/Point.cs", "Point.cs"); CopyFile ("Avalonia.Base/Input/Pointer.cs", "Pointer.cs"); +CopyFile ("Avalonia.Base/Metadata/PrivateApiAttribute.cs", "PrivateApiAttribute.cs"); CopyFile ("Shared/RawEventGrouping.cs", "RawEventGrouper.cs"); CopyFile ("Avalonia.Base/Input/Raw/RawInputEventArgs.cs", "RawInputEventArgs.cs"); CopyFile ("Avalonia.Base/Input/Raw/RawKeyEventArgs.cs", "RawKeyEventArgs.cs"); @@ -134,6 +135,7 @@ CopyFile ("Avalonia.Base/Platform/ICursorFactory.cs", "ICursorFactory.cs"); CopyFile ("Avalonia.Base/Platform/ICursorImpl.cs", "ICursorImpl.cs"); CopyFile ("Avalonia.Controls/WindowTransparencyLevel.cs", "WindowTransparencyLevel.cs"); CopyFile ("Avalonia.Controls/WindowClosingEventArgs.cs", "WindowClosingEventArgs.cs"); +CopyFile ("Avalonia.Controls/WindowResizedEventArgs.cs", "WindowResizedEventArgs.cs"); CopyFile ("Avalonia.Controls/AcrylicPlatformCompensationLevels.cs", "AcrylicPlatformCompensationLevels.cs"); // Mac Backend diff --git a/src/Modern.WindowKit/Avalonia.Mac/PopupImpl.cs b/src/Modern.WindowKit/Avalonia.Mac/PopupImpl.cs index 7ce1954..ccf4218 100644 --- a/src/Modern.WindowKit/Avalonia.Mac/PopupImpl.cs +++ b/src/Modern.WindowKit/Avalonia.Mac/PopupImpl.cs @@ -1,4 +1,5 @@ using System; +using Modern.WindowKit.Controls; using Modern.WindowKit.Controls.Primitives.PopupPositioning; using Modern.WindowKit.Mac.Interop; using Modern.WindowKit.Platform; @@ -29,7 +30,7 @@ public PopupImpl(IAvaloniaNativeFactory factory, private void MoveResize(PixelPoint position, Size size, double scaling) { Position = position; - Resize(size, PlatformResizeReason.Layout); + Resize(size, WindowResizeReason.Layout); //TODO: We ignore the scaling override for now } diff --git a/src/Modern.WindowKit/Avalonia.Mac/WindowImplBase.cs b/src/Modern.WindowKit/Avalonia.Mac/WindowImplBase.cs index 8a20bac..91c5b38 100644 --- a/src/Modern.WindowKit/Avalonia.Mac/WindowImplBase.cs +++ b/src/Modern.WindowKit/Avalonia.Mac/WindowImplBase.cs @@ -95,7 +95,7 @@ protected void Init(IAvnWindowBase window, IAvnScreens screens) var monitor = Screen.AllScreens.OrderBy(x => x.Scaling) .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), WindowResizeReason.Layout); } public IAvnWindowBase Native => _native; @@ -160,7 +160,7 @@ public ILockedFramebuffer Lock() public Action LostFocus { get; set; } public Action Paint { get; set; } - public Action Resized { get; set; } + public Action Resized { get; set; } public Action Closed { get; set; } public IMouseDevice MouseDevice => _mouse; public abstract IPopupImpl CreatePopup(); @@ -211,7 +211,7 @@ void IAvnWindowBaseEvents.Resized(AvnSize* size, AvnPlatformResizeReason reason) { var s = new Size(size->Width, size->Height); _parent._savedLogicalSize = s; - _parent.Resized?.Invoke(s, (PlatformResizeReason)reason); + _parent.Resized?.Invoke(s, (WindowResizeReason)reason); } } @@ -360,7 +360,7 @@ public void RawMouseEvent(AvnRawMouseEventType type, uint timeStamp, AvnInputMod } } - public void Resize(Size clientSize, PlatformResizeReason reason) + public void Resize(Size clientSize, WindowResizeReason reason) { _native?.Resize(clientSize.Width, clientSize.Height, (AvnPlatformResizeReason)reason); } diff --git a/src/Modern.WindowKit/Avalonia.Win32/PopupImpl.cs b/src/Modern.WindowKit/Avalonia.Win32/PopupImpl.cs index 4a5c5e1..849c43b 100644 --- a/src/Modern.WindowKit/Avalonia.Win32/PopupImpl.cs +++ b/src/Modern.WindowKit/Avalonia.Win32/PopupImpl.cs @@ -1,4 +1,5 @@ using System; +using Modern.WindowKit.Controls; using Modern.WindowKit.Controls.Primitives.PopupPositioning; using Modern.WindowKit.Platform; using Modern.WindowKit.Win32.Interop; @@ -135,7 +136,7 @@ private PopupImpl(IWindowBaseImpl parent, bool dummy) private void MoveResize(PixelPoint position, Size size, double scaling) { Move(position); - Resize(size, PlatformResizeReason.Layout); + Resize(size, WindowResizeReason.Layout); //TODO: We ignore the scaling override for now } diff --git a/src/Modern.WindowKit/Avalonia.Win32/WindowImpl.AppWndProc.cs b/src/Modern.WindowKit/Avalonia.Win32/WindowImpl.AppWndProc.cs index d2b3177..b52fd81 100644 --- a/src/Modern.WindowKit/Avalonia.Win32/WindowImpl.AppWndProc.cs +++ b/src/Modern.WindowKit/Avalonia.Win32/WindowImpl.AppWndProc.cs @@ -133,7 +133,7 @@ protected virtual unsafe IntPtr AppWndProc(IntPtr hWnd, uint msg, IntPtr wParam, _scaling = dpi / 96.0; ScalingChanged?.Invoke(_scaling); - using (SetResizeReason(PlatformResizeReason.DpiChange)) + using (SetResizeReason(WindowResizeReason.DpiChange)) { SetWindowPos(hWnd, IntPtr.Zero, @@ -611,7 +611,7 @@ protected virtual unsafe IntPtr AppWndProc(IntPtr hWnd, uint msg, IntPtr wParam, case WindowsMessage.WM_ENTERSIZEMOVE: - _resizeReason = PlatformResizeReason.User; + _resizeReason = WindowResizeReason.User; break; case WindowsMessage.WM_SIZE: @@ -658,7 +658,7 @@ protected virtual unsafe IntPtr AppWndProc(IntPtr hWnd, uint msg, IntPtr wParam, } case WindowsMessage.WM_EXITSIZEMOVE: - _resizeReason = PlatformResizeReason.Unspecified; + _resizeReason = WindowResizeReason.Unspecified; break; case WindowsMessage.WM_MOVE: diff --git a/src/Modern.WindowKit/Avalonia.Win32/WindowImpl.cs b/src/Modern.WindowKit/Avalonia.Win32/WindowImpl.cs index 3297a7a..aee2682 100644 --- a/src/Modern.WindowKit/Avalonia.Win32/WindowImpl.cs +++ b/src/Modern.WindowKit/Avalonia.Win32/WindowImpl.cs @@ -59,7 +59,7 @@ internal partial class WindowImpl : IWindowImpl //, EglGlPlatformSurface.IEglWin private double _extendTitleBarHint = -1; private readonly bool _isUsingComposition; private readonly IBlurHost? _blurHost; - private PlatformResizeReason _resizeReason; + private WindowResizeReason _resizeReason; private MOUSEMOVEPOINT _lastWmMousePoint; #if USE_MANAGED_DRAG @@ -200,7 +200,7 @@ private IInputRoot Owner public Action? Paint { get; set; } - public Action? Resized { get; set; } + public Action? Resized { get; set; } public Action? ScalingChanged { get; set; } @@ -588,7 +588,7 @@ public void SetMinMaxSize(Size minSize, Size maxSize) //public IRenderer CreateRenderer(IRenderRoot root) => // new CompositingRenderer(root, Win32Platform.Compositor, () => Surfaces); - public void Resize(Size value, PlatformResizeReason reason) + public void Resize(Size value, WindowResizeReason reason) { if (WindowState != WindowState.Normal) return; @@ -1053,7 +1053,7 @@ private void ExtendClientArea() _offScreenMargin = new Thickness(); _extendedMargins = new Thickness(); - Resize(new Size(rcWindow.Width / RenderScaling, rcWindow.Height / RenderScaling), PlatformResizeReason.Layout); + Resize(new Size(rcWindow.Width / RenderScaling, rcWindow.Height / RenderScaling), WindowResizeReason.Layout); unsafe { @@ -1462,7 +1462,7 @@ public void SetExtendClientAreaTitleBarHeightHint(double titleBarHeight) /// public AcrylicPlatformCompensationLevels AcrylicCompensationLevels { get; } = new AcrylicPlatformCompensationLevels(1, 0.8, 0); - private ResizeReasonScope SetResizeReason(PlatformResizeReason reason) + private ResizeReasonScope SetResizeReason(WindowResizeReason reason) { var old = _resizeReason; _resizeReason = reason; @@ -1487,9 +1487,9 @@ private struct WindowProperties private struct ResizeReasonScope : IDisposable { private readonly WindowImpl _owner; - private readonly PlatformResizeReason _restore; + private readonly WindowResizeReason _restore; - public ResizeReasonScope(WindowImpl owner, PlatformResizeReason restore) + public ResizeReasonScope(WindowImpl owner, WindowResizeReason restore) { _owner = owner; _restore = restore; diff --git a/src/Modern.WindowKit/Avalonia.X11/X11Window.cs b/src/Modern.WindowKit/Avalonia.X11/X11Window.cs index be78659..f7a8c9b 100644 --- a/src/Modern.WindowKit/Avalonia.X11/X11Window.cs +++ b/src/Modern.WindowKit/Avalonia.X11/X11Window.cs @@ -352,7 +352,7 @@ public double RenderScaling public IEnumerable Surfaces { get; } public Action? Input { get; set; } public Action? Paint { get; set; } - public Action? Resized { get; set; } + public Action? Resized { get; set; } //TODO public Action? ScalingChanged { get; set; } public Action? Deactivated { get; set; } @@ -509,7 +509,7 @@ private void OnEvent(ref XEvent ev) UpdateImePosition(); if (changedSize && !updatedSizeViaScaling && !_popup) - Resized?.Invoke(ClientSize, PlatformResizeReason.Unspecified); + Resized?.Invoke(ClientSize, WindowResizeReason.Unspecified); }, DispatcherPriority.Layout); if (_useRenderWindow) @@ -590,7 +590,7 @@ private bool UpdateScaling(bool skipResize = false) UpdateImePosition(); SetMinMaxSize(_scaledMinMaxSize.minSize, _scaledMinMaxSize.maxSize); if(!skipResize) - Resize(oldScaledSize, true, PlatformResizeReason.DpiChange); + Resize(oldScaledSize, true, WindowResizeReason.DpiChange); return true; } @@ -642,7 +642,7 @@ private void OnPropertyChange(IntPtr atom, bool hasValue) { // Occurs once the window has been mapped, which is the earliest the extents // can be retrieved, so invoke event to force update of TopLevel.FrameSize. - Resized?.Invoke(ClientSize, PlatformResizeReason.Unspecified); + Resized?.Invoke(ClientSize, WindowResizeReason.Unspecified); } if (atom == _x11.Atoms._NET_WM_STATE) @@ -959,19 +959,19 @@ public void SetSystemDecorations(SystemDecorations enabled) } - public void Resize(Size clientSize, PlatformResizeReason reason) => Resize(clientSize, false, reason); + public void Resize(Size clientSize, WindowResizeReason reason) => Resize(clientSize, false, reason); public void Move(PixelPoint point) => Position = point; private void MoveResize(PixelPoint position, Size size, double scaling) { Move(position); _scalingOverride = scaling; UpdateScaling(true); - Resize(size, true, PlatformResizeReason.Layout); + Resize(size, true, WindowResizeReason.Layout); } private PixelSize ToPixelSize(Size size) => new PixelSize((int)(size.Width * RenderScaling), (int)(size.Height * RenderScaling)); - private void Resize(Size clientSize, bool force, PlatformResizeReason reason) + private void Resize(Size clientSize, bool force, WindowResizeReason reason) { if (!force && clientSize == ClientSize) return; diff --git a/src/Modern.WindowKit/Dispatcher.Invoke.cs b/src/Modern.WindowKit/Dispatcher.Invoke.cs index 9c0ca1e..f9f40c9 100644 --- a/src/Modern.WindowKit/Dispatcher.Invoke.cs +++ b/src/Modern.WindowKit/Dispatcher.Invoke.cs @@ -1,5 +1,4 @@ using System; -using System.ComponentModel; using System.Diagnostics; using System.Threading; using System.Threading.Tasks; @@ -118,11 +117,11 @@ public void Invoke(Action callback, DispatcherPriority priority, CancellationTok } /// - /// Executes the specified Func synchronously on the + /// Executes the specified Func<TResult> synchronously on the /// thread that the Dispatcher was created on. /// /// - /// A Func delegate to invoke through the dispatcher. + /// A Func<TResult> delegate to invoke through the dispatcher. /// /// /// The return value from the delegate being invoked. @@ -136,11 +135,11 @@ public TResult Invoke(Func callback) } /// - /// Executes the specified Func synchronously on the + /// Executes the specified Func<TResult> synchronously on the /// thread that the Dispatcher was created on. /// /// - /// A Func delegate to invoke through the dispatcher. + /// A Func<TResult> delegate to invoke through the dispatcher. /// /// /// The priority that determines in what order the specified @@ -156,11 +155,11 @@ public TResult Invoke(Func callback, DispatcherPriority priori } /// - /// Executes the specified Func synchronously on the + /// Executes the specified Func<TResult> synchronously on the /// thread that the Dispatcher was created on. /// /// - /// A Func delegate to invoke through the dispatcher. + /// A Func<TResult> delegate to invoke through the dispatcher. /// /// /// The priority that determines in what order the specified @@ -183,11 +182,11 @@ public TResult Invoke(Func callback, DispatcherPriority priori } /// - /// Executes the specified Func synchronously on the + /// Executes the specified Func<TResult> synchronously on the /// thread that the Dispatcher was created on. /// /// - /// A Func delegate to invoke through the dispatcher. + /// A Func<TResult> delegate to invoke through the dispatcher. /// /// /// The priority that determines in what order the specified @@ -317,11 +316,11 @@ public DispatcherOperation InvokeAsync(Action callback, DispatcherPriority prior } /// - /// Executes the specified Func asynchronously on the + /// Executes the specified Func<TResult> asynchronously on the /// thread that the Dispatcher was created on. /// /// - /// A Func delegate to invoke through the dispatcher. + /// A Func<TResult> delegate to invoke through the dispatcher. /// /// /// An operation representing the queued delegate to be invoked. @@ -335,11 +334,11 @@ public DispatcherOperation InvokeAsync(Func callback) } /// - /// Executes the specified Func asynchronously on the + /// Executes the specified Func<TResult> asynchronously on the /// thread that the Dispatcher was created on. /// /// - /// A Func delegate to invoke through the dispatcher. + /// A Func<TResult> delegate to invoke through the dispatcher. /// /// /// The priority that determines in what order the specified @@ -355,11 +354,11 @@ public DispatcherOperation InvokeAsync(Func callback, } /// - /// Executes the specified Func asynchronously on the + /// Executes the specified Func<TResult> asynchronously on the /// thread that the Dispatcher was created on. /// /// - /// A Func delegate to invoke through the dispatcher. + /// A Func<TResult> delegate to invoke through the dispatcher. /// /// /// The priority that determines in what order the specified @@ -479,7 +478,7 @@ internal void InvokeAsyncImpl(DispatcherOperation operation, CancellationToken c // operation has already started when the timeout expires, // we still wait for it to complete. This is different // than simply waiting on the operation with a timeout - // because we are the ones queueing the dispatcher + // because we are the ones queuing the dispatcher // operation, not the caller. We can't leave the operation // in a state that it might execute if we return that it did not // invoke. @@ -492,12 +491,12 @@ internal void InvokeAsyncImpl(DispatcherOperation operation, CancellationToken c // Old async semantics return from Wait without // throwing an exception if the operation was aborted. - // There is no need to test the timout condition, since + // There is no need to test the timeout condition, since // the old async semantics would just return the result, // which would be null. // This should not block because either the operation - // is using the old async sematics, or the operation + // is using the old async semantics, or the operation // completed successfully. result = operation.GetResult(); } @@ -543,11 +542,11 @@ public void Post(Action action, DispatcherPriority priority = default) } /// - /// Executes the specified Func asynchronously on the + /// Executes the specified Func<Task> asynchronously on the /// thread that the Dispatcher was created on /// /// - /// A Func delegate to invoke through the dispatcher. + /// A Func<Task> delegate to invoke through the dispatcher. /// /// /// The priority that determines in what order the specified @@ -564,11 +563,11 @@ public Task InvokeAsync(Func callback, DispatcherPriority priority = defau } /// - /// Executes the specified Func> asynchronously on the + /// Executes the specified Func<Task<TResult>> asynchronously on the /// thread that the Dispatcher was created on /// - /// - /// A Func> delegate to invoke through the dispatcher. + /// + /// A Func<Task<TResult>> delegate to invoke through the dispatcher. /// /// /// The priority that determines in what order the specified diff --git a/src/Modern.WindowKit/ICursorFactory.cs b/src/Modern.WindowKit/ICursorFactory.cs index a7fb8a9..8daa6d3 100644 --- a/src/Modern.WindowKit/ICursorFactory.cs +++ b/src/Modern.WindowKit/ICursorFactory.cs @@ -1,9 +1,11 @@ using Modern.WindowKit.Input; +using Modern.WindowKit.Metadata; #nullable enable namespace Modern.WindowKit.Platform { + [PrivateApi] public interface ICursorFactory { ICursorImpl GetCursor(StandardCursorType cursorType); diff --git a/src/Modern.WindowKit/IDispatcherImpl.cs b/src/Modern.WindowKit/IDispatcherImpl.cs index 8170c63..5f413d4 100644 --- a/src/Modern.WindowKit/IDispatcherImpl.cs +++ b/src/Modern.WindowKit/IDispatcherImpl.cs @@ -6,7 +6,7 @@ namespace Modern.WindowKit.Threading; -[Unstable] +[PrivateApi] public interface IDispatcherImpl { bool CurrentThreadIsLoopThread { get; } @@ -19,7 +19,7 @@ public interface IDispatcherImpl void UpdateTimer(long? dueTimeInMs); } -[Unstable] +[PrivateApi] public interface IDispatcherImplWithPendingInput : IDispatcherImpl { // Checks if dispatcher implementation can @@ -28,14 +28,14 @@ public interface IDispatcherImplWithPendingInput : IDispatcherImpl bool HasPendingInput { get; } } -[Unstable] +[PrivateApi] public interface IDispatcherImplWithExplicitBackgroundProcessing : IDispatcherImpl { event Action ReadyForBackgroundProcessing; void RequestBackgroundProcessing(); } -[Unstable] +[PrivateApi] public interface IControlledDispatcherImpl : IDispatcherImplWithPendingInput { // Runs the event loop diff --git a/src/Modern.WindowKit/ITopLevelImpl.cs b/src/Modern.WindowKit/ITopLevelImpl.cs index fbea7e1..42917bf 100644 --- a/src/Modern.WindowKit/ITopLevelImpl.cs +++ b/src/Modern.WindowKit/ITopLevelImpl.cs @@ -9,40 +9,6 @@ namespace Modern.WindowKit.Platform { - /// - /// Describes the reason for a message. - /// - public enum PlatformResizeReason - { - /// - /// The resize reason is unknown or unspecified. - /// - Unspecified, - - /// - /// The resize was due to the user resizing the window, for example by dragging the - /// window frame. - /// - User, - - /// - /// The resize was initiated by the application, for example by setting one of the sizing- - /// related properties on such as or - /// . - /// - Application, - - /// - /// The resize was initiated by the layout system. - /// - Layout, - - /// - /// The resize was due to a change in DPI. - /// - DpiChange, - } - /// /// Defines a platform-specific top-level window implementation. /// @@ -93,7 +59,7 @@ public partial interface ITopLevelImpl : IOptionalFeatureProvider, IDisposable /// /// Gets or sets a method called when the toplevel is resized. /// - Action? Resized { get; set; } + Action? Resized { get; set; } /// /// Gets or sets a method called when the toplevel's scaling changes. diff --git a/src/Modern.WindowKit/IWindowImpl.cs b/src/Modern.WindowKit/IWindowImpl.cs index 4f7f26f..5da7baf 100644 --- a/src/Modern.WindowKit/IWindowImpl.cs +++ b/src/Modern.WindowKit/IWindowImpl.cs @@ -114,7 +114,7 @@ public interface IWindowImpl : IWindowBaseImpl /// /// The new client size. /// The reason for the resize. - void Resize(Size clientSize, PlatformResizeReason reason = PlatformResizeReason.Application); + void Resize(Size clientSize, WindowResizeReason reason = WindowResizeReason.Application); /// /// Sets the client size of the top level. diff --git a/src/Modern.WindowKit/IWindowingPlatform.cs b/src/Modern.WindowKit/IWindowingPlatform.cs index fd34f9c..33bb55c 100644 --- a/src/Modern.WindowKit/IWindowingPlatform.cs +++ b/src/Modern.WindowKit/IWindowingPlatform.cs @@ -2,7 +2,7 @@ namespace Modern.WindowKit.Platform { - [Unstable] + [Unstable, PrivateApi] public interface IWindowingPlatform { IWindowImpl CreateWindow(); diff --git a/src/Modern.WindowKit/PrivateApiAttribute.cs b/src/Modern.WindowKit/PrivateApiAttribute.cs new file mode 100644 index 0000000..a828dff --- /dev/null +++ b/src/Modern.WindowKit/PrivateApiAttribute.cs @@ -0,0 +1,9 @@ +using System; + +namespace Modern.WindowKit.Metadata; + +[AttributeUsage(AttributeTargets.Interface)] +public sealed class PrivateApiAttribute : Attribute +{ + +} diff --git a/src/Modern.WindowKit/ScreenHelper.cs b/src/Modern.WindowKit/ScreenHelper.cs index 0a05c5b..520cd9b 100644 --- a/src/Modern.WindowKit/ScreenHelper.cs +++ b/src/Modern.WindowKit/ScreenHelper.cs @@ -1,11 +1,12 @@ using System.Collections.Generic; +using Modern.WindowKit.Controls; using Modern.WindowKit.Utilities; #nullable enable namespace Modern.WindowKit.Platform { - public static class ScreenHelper + internal static class ScreenHelper { public static Screen? ScreenFromPoint(PixelPoint point, IReadOnlyList screens) { diff --git a/src/Modern.WindowKit/Screens.cs b/src/Modern.WindowKit/Screens.cs index f028d77..143dbf1 100644 --- a/src/Modern.WindowKit/Screens.cs +++ b/src/Modern.WindowKit/Screens.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using Modern.WindowKit.Platform; -//using Modern.WindowKit.VisualTree; #nullable enable @@ -38,21 +37,58 @@ public Screens(IScreenImpl iScreenImpl) _iScreenImpl = iScreenImpl; } + /// + /// Retrieves a Screen for the display that contains the rectangle. + /// + /// Bounds that specifies the area for which to retrieve the display. + /// The . public Screen? ScreenFromBounds(PixelRect bounds) { return _iScreenImpl.ScreenFromRect(bounds); } + ///// + ///// Retrieves a Screen for the display that contains the specified . + ///// + ///// The window for which to retrieve the Screen. + ///// Window platform implementation was already disposed. + ///// The . + //public Screen? ScreenFromWindow(WindowBase window) + //{ + // if (window.PlatformImpl is null) + // { + // throw new ObjectDisposedException("Window platform implementation was already disposed."); + // } + + // return _iScreenImpl.ScreenFromWindow(window.PlatformImpl); + //} + + /// + /// Retrieves a Screen for the display that contains the specified . + /// + /// The window impl for which to retrieve the Screen. + /// The . + [Obsolete("Use ScreenFromWindow(WindowBase) overload.")] public Screen? ScreenFromWindow(IWindowBaseImpl window) { return _iScreenImpl.ScreenFromWindow(window); } + /// + /// Retrieves a Screen for the display that contains the specified point. + /// + /// A Point that specifies the location for which to retrieve a Screen. + /// The . public Screen? ScreenFromPoint(PixelPoint point) { return _iScreenImpl.ScreenFromPoint(point); } + ///// + ///// Retrieves a Screen for the display that contains the specified . + ///// + ///// A Visual for which to retrieve a Screen. + ///// The . //public Screen? ScreenFromVisual(Visual visual) //{ // var tl = visual.PointToScreen(visual.Bounds.TopLeft); diff --git a/src/Modern.WindowKit/UnstableAttribute.cs b/src/Modern.WindowKit/UnstableAttribute.cs index f050937..8cf8e32 100644 --- a/src/Modern.WindowKit/UnstableAttribute.cs +++ b/src/Modern.WindowKit/UnstableAttribute.cs @@ -9,5 +9,25 @@ namespace Modern.WindowKit.Metadata [AttributeUsage(AttributeTargets.All)] public sealed class UnstableAttribute : Attribute { + /// + /// Initializes a new instance of the class. + /// + public UnstableAttribute() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The text string that describes alternative workarounds. + public UnstableAttribute(string? message) + { + Message = message; + } + + /// + /// Gets a value that indicates whether the compiler will treat usage of the obsolete program element as an error. + /// + public string? Message { get; } } } diff --git a/src/Modern.WindowKit/WindowResizedEventArgs.cs b/src/Modern.WindowKit/WindowResizedEventArgs.cs new file mode 100644 index 0000000..ab1c155 --- /dev/null +++ b/src/Modern.WindowKit/WindowResizedEventArgs.cs @@ -0,0 +1,61 @@ +using System; +//using Modern.WindowKit.Layout; + +namespace Modern.WindowKit.Controls +{ + /// + /// Describes the reason for a event. + /// + public enum WindowResizeReason + { + /// + /// The resize reason is unknown or unspecified. + /// + Unspecified, + + /// + /// The resize was due to the user resizing the window, for example by dragging the + /// window frame. + /// + User, + + /// + /// The resize was initiated by the application, for example by setting one of the sizing- + /// related properties on such as or + /// . + /// + Application, + + /// + /// The resize was initiated by the layout system. + /// + Layout, + + /// + /// The resize was due to a change in DPI. + /// + DpiChange, + } + + /// + /// Provides data for the event. + /// + public class WindowResizedEventArgs : EventArgs + { + internal WindowResizedEventArgs(Size clientSize, WindowResizeReason reason) + { + ClientSize = clientSize; + Reason = reason; + } + + /// + /// Gets the new client size of the window in device-independent pixels. + /// + public Size ClientSize { get; } + + /// + /// Gets the reason for the resize. + /// + public WindowResizeReason Reason { get; } + } +}