Skip to content

Commit

Permalink
Fix some compiler warnings (AvaloniaUI#17180)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrJul authored Oct 2, 2024
1 parent cd4315b commit fc25c00
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion samples/ControlCatalog/Pages/OpenGlPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private async void SnapshotClick(object sender, RoutedEventArgs e)
Source = snap
}
}
}.ShowDialog((Window)TopLevel.GetTopLevel(this));
}.ShowDialog((Window)TopLevel.GetTopLevel(this)!);
}
}

Expand Down
2 changes: 1 addition & 1 deletion samples/IntegrationTestApp/IntegrationTestApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<OutputType>WinExe</OutputType>
<TargetFramework>$(AvsCurrentTargetFramework)</TargetFramework>
<Nullable>enable</Nullable>
<NoWarn>$(NoWarn);AVP1012</NoWarn>
<NoWarn>$(NoWarn);AVP1012;AVLN3001</NoWarn>
<ApplicationManifest>app.manifest</ApplicationManifest>
<IncludeAvaloniaGenerators>true</IncludeAvaloniaGenerators>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion samples/IntegrationTestApp/MacOSIntegration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
5 changes: 0 additions & 5 deletions src/Avalonia.Base/Rendering/UiThreadRenderTimer.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public OffscreenTopLevelImplBase()

public abstract IEnumerable<object> Surfaces { get; }

public double DesktopScaling => _scaling;
public virtual double DesktopScaling => _scaling;

public IPlatformHandle? Handle { get; }

public Size ClientSize
Expand Down
5 changes: 1 addition & 4 deletions src/Avalonia.Controls/Primitives/OverlayPopupHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -63,22 +63,19 @@ bool IPopupHost.Topmost
public void Show()
{
_overlayLayer.Children.Add(this);
_shown = true;
}

/// <inheritdoc />
public void Hide()
{
_overlayLayer.Children.Remove(this);
_shown = false;
}

public void TakeFocus()
{
// Nothing to do here: overlay popups are implemented inside the window.
}

/// <inheritdoc />
[Unstable(ObsoletionMessages.MayBeRemovedInAvalonia12)]
public void ConfigurePosition(Visual target, PlacementMode placement, Point offset,
PopupAnchor anchor = PopupAnchor.None, PopupGravity gravity = PopupGravity.None,
Expand Down
3 changes: 1 addition & 2 deletions src/Avalonia.DesignerSupport/Remote/PreviewerWindowImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PixelPoint> PositionChanged { get; set; }
public Action Deactivated { get; set; }
public Action Activated { get; set; }
public Func<WindowCloseReason, bool> Closing { get; set; }
public IPlatformHandle Handle { get; }
public WindowState WindowState { get; set; }
public Action<WindowState> WindowStateChanged { get; set; }
public Size MaxAutoSizeHint { get; } = new Size(4096, 4096);
Expand Down
2 changes: 1 addition & 1 deletion src/Avalonia.Native/StorageProviderApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Avalonia.Native/TopLevelImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/Avalonia.X11/NativeDialogs/GtkNativeFileDialogs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/Avalonia.X11/X11Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1497,8 +1497,8 @@ public void GetWindowsZOrder(Span<Window> windows, Span<long> outputZOrder)

var indexInWindowsSpan = new Dictionary<IntPtr, int>();
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)
{
Expand Down
4 changes: 3 additions & 1 deletion src/Linux/Avalonia.LinuxFramebuffer/EpollDispatcherImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -232,4 +234,4 @@ public void UpdateTimer(long? dueTimeInMs)
public bool CanQueryPendingInput => true;

public bool HasPendingInput => _inputProvider.HasInput;
}
}
14 changes: 7 additions & 7 deletions src/Windows/Avalonia.Win32/ScreenImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -20,7 +20,7 @@ protected override IReadOnlyList<nint> 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
{
Expand All @@ -29,11 +29,11 @@ protected override IReadOnlyList<nint> 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<nint> screens)
{
Expand Down
5 changes: 4 additions & 1 deletion tests/Avalonia.Controls.UnitTests/Platform/ScreensTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand All @@ -155,7 +158,7 @@ public void PushNewScreens(IReadOnlyList<int> 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;

Expand Down

0 comments on commit fc25c00

Please sign in to comment.