diff --git a/samples/ControlCatalog/Pages/OpenGlPage.xaml.cs b/samples/ControlCatalog/Pages/OpenGlPage.xaml.cs index f7a7e60f894..aaaa3f772b5 100644 --- a/samples/ControlCatalog/Pages/OpenGlPage.xaml.cs +++ b/samples/ControlCatalog/Pages/OpenGlPage.xaml.cs @@ -43,7 +43,7 @@ private async void SnapshotClick(object sender, RoutedEventArgs e) Source = snap } } - }.ShowDialog((Window)TopLevel.GetTopLevel(this)); + }.ShowDialog((Window)TopLevel.GetTopLevel(this)!); } } diff --git a/samples/IntegrationTestApp/IntegrationTestApp.csproj b/samples/IntegrationTestApp/IntegrationTestApp.csproj index 7d23408eddc..65347872263 100644 --- a/samples/IntegrationTestApp/IntegrationTestApp.csproj +++ b/samples/IntegrationTestApp/IntegrationTestApp.csproj @@ -3,7 +3,7 @@ WinExe $(AvsCurrentTargetFramework) enable - $(NoWarn);AVP1012 + $(NoWarn);AVP1012;AVLN3001 app.manifest true diff --git a/samples/IntegrationTestApp/MacOSIntegration.cs b/samples/IntegrationTestApp/MacOSIntegration.cs index f700a5b4e26..b4a06b7f4bd 100644 --- a/samples/IntegrationTestApp/MacOSIntegration.cs +++ b/samples/IntegrationTestApp/MacOSIntegration.cs @@ -21,7 +21,7 @@ static MacOSIntegration() public static long GetOrderedIndex(Window window) { - return Int64_objc_msgSend(window.PlatformImpl!.Handle.Handle, s_orderedIndexSelector); + return Int64_objc_msgSend(window.PlatformImpl!.Handle!.Handle, s_orderedIndexSelector); } } } diff --git a/src/Avalonia.Base/Rendering/UiThreadRenderTimer.cs b/src/Avalonia.Base/Rendering/UiThreadRenderTimer.cs index 940495253ea..42ecc41238e 100644 --- a/src/Avalonia.Base/Rendering/UiThreadRenderTimer.cs +++ b/src/Avalonia.Base/Rendering/UiThreadRenderTimer.cs @@ -1,11 +1,6 @@ using System; using System.Diagnostics; using Avalonia.Metadata; -using Avalonia.Reactive; -using Avalonia.Threading; -using System; -using System.Diagnostics; -using Avalonia.Metadata; using Avalonia.Threading; namespace Avalonia.Rendering; diff --git a/src/Avalonia.Controls/Embedding/Offscreen/OffscreenTopLevelImpl.cs b/src/Avalonia.Controls/Embedding/Offscreen/OffscreenTopLevelImpl.cs index 14bb65f0df6..bdc7c8894b9 100644 --- a/src/Avalonia.Controls/Embedding/Offscreen/OffscreenTopLevelImpl.cs +++ b/src/Avalonia.Controls/Embedding/Offscreen/OffscreenTopLevelImpl.cs @@ -29,7 +29,8 @@ public OffscreenTopLevelImplBase() public abstract IEnumerable Surfaces { get; } - public double DesktopScaling => _scaling; + public virtual double DesktopScaling => _scaling; + public IPlatformHandle? Handle { get; } public Size ClientSize diff --git a/src/Avalonia.Controls/Primitives/OverlayPopupHost.cs b/src/Avalonia.Controls/Primitives/OverlayPopupHost.cs index 3ea7ac54516..2e14b54716c 100644 --- a/src/Avalonia.Controls/Primitives/OverlayPopupHost.cs +++ b/src/Avalonia.Controls/Primitives/OverlayPopupHost.cs @@ -22,7 +22,7 @@ public class OverlayPopupHost : ContentControl, IPopupHost, IManagedPopupPositio private Point _lastRequestedPosition; private PopupPositionRequest? _popupPositionRequest; private Size _popupSize; - private bool _shown, _needsUpdate; + private bool _needsUpdate; public OverlayPopupHost(OverlayLayer overlayLayer) { @@ -63,14 +63,12 @@ bool IPopupHost.Topmost public void Show() { _overlayLayer.Children.Add(this); - _shown = true; } /// public void Hide() { _overlayLayer.Children.Remove(this); - _shown = false; } public void TakeFocus() @@ -78,7 +76,6 @@ public void TakeFocus() // Nothing to do here: overlay popups are implemented inside the window. } - /// [Unstable(ObsoletionMessages.MayBeRemovedInAvalonia12)] public void ConfigurePosition(Visual target, PlacementMode placement, Point offset, PopupAnchor anchor = PopupAnchor.None, PopupGravity gravity = PopupGravity.None, diff --git a/src/Avalonia.DesignerSupport/Remote/PreviewerWindowImpl.cs b/src/Avalonia.DesignerSupport/Remote/PreviewerWindowImpl.cs index 50cebbce8fa..84c1d7db198 100644 --- a/src/Avalonia.DesignerSupport/Remote/PreviewerWindowImpl.cs +++ b/src/Avalonia.DesignerSupport/Remote/PreviewerWindowImpl.cs @@ -37,13 +37,12 @@ public void BeginResizeDrag(WindowEdge edge, PointerPressedEventArgs e) { } - public double DesktopScaling => 1.0; + public override double DesktopScaling => 1.0; public PixelPoint Position { get; set; } public Action PositionChanged { get; set; } public Action Deactivated { get; set; } public Action Activated { get; set; } public Func Closing { get; set; } - public IPlatformHandle Handle { get; } public WindowState WindowState { get; set; } public Action WindowStateChanged { get; set; } public Size MaxAutoSizeHint { get; } = new Size(4096, 4096); diff --git a/src/Avalonia.Native/StorageProviderApi.cs b/src/Avalonia.Native/StorageProviderApi.cs index 4d326ee8c34..6b0a59c8fbc 100644 --- a/src/Avalonia.Native/StorageProviderApi.cs +++ b/src/Avalonia.Native/StorageProviderApi.cs @@ -128,7 +128,7 @@ static int RemoveUse(StorageProviderApi api, string uriString) { fixed (byte* ptr = bytes) { - using var uriString = _native.ReadBookmarkFromBytes(ptr, bytes.Length); + using var uriString = _native.ReadBookmarkFromBytes(ptr, bytes!.Length); return uriString is not null && Uri.TryCreate(uriString.String, UriKind.Absolute, out var uri) ? uri : null; diff --git a/src/Avalonia.Native/TopLevelImpl.cs b/src/Avalonia.Native/TopLevelImpl.cs index 1e434d2854f..efda4bfade0 100644 --- a/src/Avalonia.Native/TopLevelImpl.cs +++ b/src/Avalonia.Native/TopLevelImpl.cs @@ -494,7 +494,7 @@ AvnDragDropEffects IAvnTopLevelEvents.DragEvent(AvnDragEventType type, AvnPoint var args = new RawDragEvent(device, (RawDragEventType)type, _parent._inputRoot, position.ToAvaloniaPoint(), dataObject, (DragDropEffects)effects, (RawInputModifiers)modifiers); - _parent.Input(args); + _parent.Input?.Invoke(args); return (AvnDragDropEffects)args.Effects; } } diff --git a/src/Avalonia.X11/NativeDialogs/GtkNativeFileDialogs.cs b/src/Avalonia.X11/NativeDialogs/GtkNativeFileDialogs.cs index 16e1a1bce8b..e7ff04a2dd7 100644 --- a/src/Avalonia.X11/NativeDialogs/GtkNativeFileDialogs.cs +++ b/src/Avalonia.X11/NativeDialogs/GtkNativeFileDialogs.cs @@ -228,7 +228,10 @@ void Dispose() private static void UpdateParent(IntPtr chooser, IWindowImpl parentWindow) { - var xid = parentWindow.Handle.Handle; + if (parentWindow.Handle is not { } handle) + return; + + var xid = handle.Handle; gtk_widget_realize(chooser); var window = gtk_widget_get_window(chooser); var parent = GetForeignWindow(xid); diff --git a/src/Avalonia.X11/X11Window.cs b/src/Avalonia.X11/X11Window.cs index 73904d5d632..0a254b6b2b3 100644 --- a/src/Avalonia.X11/X11Window.cs +++ b/src/Avalonia.X11/X11Window.cs @@ -1497,8 +1497,8 @@ public void GetWindowsZOrder(Span windows, Span outputZOrder) var indexInWindowsSpan = new Dictionary(); for (var i = 0; i < windows.Length; i++) - if (windows[i].PlatformImpl is { } platformImpl) - indexInWindowsSpan[platformImpl.Handle.Handle] = i; + if (windows[i].PlatformImpl is { Handle: { } handle }) + indexInWindowsSpan[handle.Handle] = i; foreach (var window in windows) { diff --git a/src/Linux/Avalonia.LinuxFramebuffer/EpollDispatcherImpl.cs b/src/Linux/Avalonia.LinuxFramebuffer/EpollDispatcherImpl.cs index 188b5daf882..f395462af3c 100644 --- a/src/Linux/Avalonia.LinuxFramebuffer/EpollDispatcherImpl.cs +++ b/src/Linux/Avalonia.LinuxFramebuffer/EpollDispatcherImpl.cs @@ -54,6 +54,7 @@ private struct epoll_event [DllImport("libc")] private extern static IntPtr read(int fd, void* buf, IntPtr count); +#pragma warning disable CS8981 // The type name only contains lower-cased ascii characters. Such names may become reserved for the language. struct timespec { public IntPtr tv_sec; @@ -65,6 +66,7 @@ struct itimerspec public timespec it_interval; // Interval for periodic timer public timespec it_value; // Initial expiration }; +#pragma warning restore CS8981 // The type name only contains lower-cased ascii characters. Such names may become reserved for the language. [DllImport("libc")] private extern static int timerfd_create(int clockid, int flags); @@ -232,4 +234,4 @@ public void UpdateTimer(long? dueTimeInMs) public bool CanQueryPendingInput => true; public bool HasPendingInput => _inputProvider.HasInput; -} \ No newline at end of file +} diff --git a/src/Windows/Avalonia.Win32/ScreenImpl.cs b/src/Windows/Avalonia.Win32/ScreenImpl.cs index d5762bdbe93..cb9c420c001 100644 --- a/src/Windows/Avalonia.Win32/ScreenImpl.cs +++ b/src/Windows/Avalonia.Win32/ScreenImpl.cs @@ -6,7 +6,7 @@ using Avalonia.Win32.Interop; using Windows.Win32; using static Avalonia.Win32.Interop.UnmanagedMethods; -using winmdroot = global::Windows.Win32; +using Win32Interop = Windows.Win32; namespace Avalonia.Win32; @@ -20,7 +20,7 @@ protected override IReadOnlyList GetAllScreenKeys() var gcHandle = GCHandle.Alloc(screens); try { - PInvoke.EnumDisplayMonitors(default, default(winmdroot.Foundation.RECT*), EnumDisplayMonitorsCallback, (IntPtr)gcHandle); + PInvoke.EnumDisplayMonitors(default, default(Win32Interop.Foundation.RECT*), EnumDisplayMonitorsCallback, (IntPtr)gcHandle); } finally { @@ -29,11 +29,11 @@ protected override IReadOnlyList GetAllScreenKeys() return screens; - static winmdroot.Foundation.BOOL EnumDisplayMonitorsCallback( - winmdroot.Graphics.Gdi.HMONITOR monitor, - winmdroot.Graphics.Gdi.HDC hdcMonitor, - winmdroot.Foundation.RECT* lprcMonitor, - winmdroot.Foundation.LPARAM dwData) + static Win32Interop.Foundation.BOOL EnumDisplayMonitorsCallback( + Win32Interop.Graphics.Gdi.HMONITOR monitor, + Win32Interop.Graphics.Gdi.HDC hdcMonitor, + Win32Interop.Foundation.RECT* lprcMonitor, + Win32Interop.Foundation.LPARAM dwData) { if (GCHandle.FromIntPtr(dwData).Target is List screens) { diff --git a/tests/Avalonia.Controls.UnitTests/Platform/ScreensTests.cs b/tests/Avalonia.Controls.UnitTests/Platform/ScreensTests.cs index 647e18d8999..64c52acda01 100644 --- a/tests/Avalonia.Controls.UnitTests/Platform/ScreensTests.cs +++ b/tests/Avalonia.Controls.UnitTests/Platform/ScreensTests.cs @@ -67,6 +67,7 @@ public void Should_Preserve_Old_Screens_On_Changes_Same_Instance() var screen = screens.GetScreen(1); + Assert.NotNull(screen); Assert.Equal(1, screen.Generation); Assert.Equal(new IntPtr(1), screen.TryGetPlatformHandle()!.Handle); @@ -131,6 +132,8 @@ public void Should_Trigger_Changed_When_Screen_Removed() var hasChangedTimes = 0; var screen = screens.GetScreen(2); + Assert.NotNull(screen); + screens.Changed = () => { Assert.True(screen.Generation < 0); @@ -155,7 +158,7 @@ public void PushNewScreens(IReadOnlyList keys) OnChanged(); } - public TestScreen GetScreen(int key) => TryGetScreen(key, out var screen) ? screen : null; + public TestScreen? GetScreen(int key) => TryGetScreen(key, out var screen) ? screen : null; protected override int GetScreenCount() => _count;