diff --git a/src/Avalonia.X11/Avalonia.X11.csproj b/src/Avalonia.X11/Avalonia.X11.csproj
index b09bea889f0..606cdfd2514 100644
--- a/src/Avalonia.X11/Avalonia.X11.csproj
+++ b/src/Avalonia.X11/Avalonia.X11.csproj
@@ -13,6 +13,7 @@
+
diff --git a/src/Avalonia.X11/Dispatching/GLibDispatcherImpl.cs b/src/Avalonia.X11/Dispatching/GLibDispatcherImpl.cs
index bf5ffa370d1..1757b048776 100644
--- a/src/Avalonia.X11/Dispatching/GLibDispatcherImpl.cs
+++ b/src/Avalonia.X11/Dispatching/GLibDispatcherImpl.cs
@@ -1,4 +1,3 @@
-#nullable enable
using System;
using System.Collections.Generic;
using System.Diagnostics;
@@ -312,4 +311,4 @@ public void Dispose()
}
public X11EventDispatcher EventDispatcher => _x11Events;
-}
\ No newline at end of file
+}
diff --git a/src/Avalonia.X11/Dispatching/X11PlatformThreading.cs b/src/Avalonia.X11/Dispatching/X11PlatformThreading.cs
index 529e2cd8dc5..b071e405fdd 100644
--- a/src/Avalonia.X11/Dispatching/X11PlatformThreading.cs
+++ b/src/Avalonia.X11/Dispatching/X11PlatformThreading.cs
@@ -186,8 +186,8 @@ public void Signal()
public bool CurrentThreadIsLoopThread => Thread.CurrentThread == _mainThread;
- public event Action Signaled;
- public event Action Timer;
+ public event Action? Signaled;
+ public event Action? Timer;
public void UpdateTimer(long? dueTimeInMs)
{
diff --git a/src/Avalonia.X11/Glx/Glx.cs b/src/Avalonia.X11/Glx/Glx.cs
index fceea3718c0..c3b20ad00dc 100644
--- a/src/Avalonia.X11/Glx/Glx.cs
+++ b/src/Avalonia.X11/Glx/Glx.cs
@@ -115,6 +115,9 @@ public static IntPtr SafeGetProcAddress(string proc)
public string[] GetExtensions(IntPtr display)
{
var s = Marshal.PtrToStringAnsi(QueryExtensionsString(display, 0));
+ if (string.IsNullOrEmpty(s))
+ return [];
+
return s.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)
.Select(x => x.Trim()).ToArray();
diff --git a/src/Avalonia.X11/Glx/GlxContext.cs b/src/Avalonia.X11/Glx/GlxContext.cs
index 4801befbed3..94c15d9008d 100644
--- a/src/Avalonia.X11/Glx/GlxContext.cs
+++ b/src/Avalonia.X11/Glx/GlxContext.cs
@@ -1,5 +1,3 @@
-#nullable enable
-
using System;
using System.Collections.Generic;
using System.Threading;
diff --git a/src/Avalonia.X11/Glx/GlxDisplay.cs b/src/Avalonia.X11/Glx/GlxDisplay.cs
index 9ce34ec7c41..0d766fee9c8 100644
--- a/src/Avalonia.X11/Glx/GlxDisplay.cs
+++ b/src/Avalonia.X11/Glx/GlxDisplay.cs
@@ -119,13 +119,13 @@ public GlxContext CreateContext() => CreateContext(CreatePBuffer(), null, Deferr
public GlxContext CreateContext(IGlContext share) => CreateContext(CreatePBuffer(), share,
share.SampleCount, share.StencilSize, true);
- private GlxContext CreateContext(IntPtr defaultXid, IGlContext share,
+ private GlxContext CreateContext(IntPtr defaultXid, IGlContext? share,
int sampleCount, int stencilSize, bool ownsPBuffer)
{
- var sharelist = ((GlxContext)share)?.Handle ?? IntPtr.Zero;
+ var sharelist = ((GlxContext?)share)?.Handle ?? IntPtr.Zero;
IntPtr handle = default;
- GlxContext Create(GlVersion profile)
+ GlxContext? Create(GlVersion profile)
{
var profileMask = GLX_CONTEXT_CORE_PROFILE_BIT_ARB;
if (profile.Type == GlProfileType.OpenGL &&
@@ -149,7 +149,7 @@ GlxContext Create(GlVersion profile)
if (handle != IntPtr.Zero)
{
_version = profile;
- return new GlxContext(new GlxInterface(), handle, this, (GlxContext)share, profile,
+ return new GlxContext(new GlxInterface(), handle, this, (GlxContext?)share, profile,
sampleCount, stencilSize, _x11, defaultXid, ownsPBuffer);
}
@@ -162,7 +162,7 @@ GlxContext Create(GlVersion profile)
return null;
}
- GlxContext rv = null;
+ GlxContext? rv = null;
if (_version.HasValue)
{
rv = Create(_version.Value);
diff --git a/src/Avalonia.X11/Glx/GlxGlPlatformSurface.cs b/src/Avalonia.X11/Glx/GlxGlPlatformSurface.cs
index 0c7c7d21659..a4d6e274519 100644
--- a/src/Avalonia.X11/Glx/GlxGlPlatformSurface.cs
+++ b/src/Avalonia.X11/Glx/GlxGlPlatformSurface.cs
@@ -96,7 +96,7 @@ public void Dispose()
public PixelSize Size => _size ?? _info.Size;
public double Scaling => _info.Scaling;
- public bool IsYFlipped { get; }
+ public bool IsYFlipped => false;
}
}
}
diff --git a/src/Avalonia.X11/Glx/GlxPlatformFeature.cs b/src/Avalonia.X11/Glx/GlxPlatformFeature.cs
index 58336522c1d..356121dc4bc 100644
--- a/src/Avalonia.X11/Glx/GlxPlatformFeature.cs
+++ b/src/Avalonia.X11/Glx/GlxPlatformFeature.cs
@@ -8,23 +8,25 @@ namespace Avalonia.X11.Glx
{
internal class GlxPlatformGraphics : IPlatformGraphics
{
- public GlxDisplay Display { get; private set; }
+ public GlxDisplay Display { get; }
public bool CanCreateContexts => true;
public bool CanShareContexts => true;
public bool UsesSharedContext => false;
IPlatformGraphicsContext IPlatformGraphics.CreateContext() => Display.CreateContext();
public IPlatformGraphicsContext GetSharedContext() => throw new NotSupportedException();
-
- public static GlxPlatformGraphics TryCreate(X11Info x11, IList glProfiles)
+
+ public GlxPlatformGraphics(GlxDisplay display)
+ {
+ Display = display;
+ }
+
+ public static GlxPlatformGraphics? TryCreate(X11Info x11, IList glProfiles)
{
try
{
var disp = new GlxDisplay(x11, glProfiles);
- return new GlxPlatformGraphics
- {
- Display = disp
- };
+ return new GlxPlatformGraphics(disp);
}
catch(Exception e)
{
diff --git a/src/Avalonia.X11/Interop/Glib.cs b/src/Avalonia.X11/Interop/Glib.cs
index 543d2892dd6..84a15819250 100644
--- a/src/Avalonia.X11/Interop/Glib.cs
+++ b/src/Avalonia.X11/Interop/Glib.cs
@@ -1,9 +1,10 @@
#nullable enable
+
using System;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Avalonia.Platform.Interop;
-using static Avalonia.X11.Interop.Glib;
+
namespace Avalonia.X11.Interop;
internal static unsafe class Glib
@@ -75,7 +76,7 @@ public static uint g_timeout_add_once(uint interval, Action cb) =>
private static readonly GDestroyNotify s_gcHandleDestroyNotify = handle => GCHandle.FromIntPtr(handle).Free();
private static readonly GSourceFunc s_sourceFuncDispatchCallback =
- handle => ((Func)GCHandle.FromIntPtr(handle).Target)() ? 1 : 0;
+ handle => ((Func)GCHandle.FromIntPtr(handle).Target!)() ? 1 : 0;
[DllImport(GlibName)]
private static extern uint g_idle_add_full (int priority, GSourceFunc function, IntPtr data, GDestroyNotify notify);
@@ -108,7 +109,7 @@ public enum GIOCondition
public delegate int GUnixFDSourceFunc(int fd, GIOCondition condition, IntPtr user_data);
private static readonly GUnixFDSourceFunc s_unixFdSourceCallback = (fd, cond, handle) =>
- ((Func)GCHandle.FromIntPtr(handle).Target)(fd, cond) ? 1 : 0;
+ ((Func)GCHandle.FromIntPtr(handle).Target!)(fd, cond) ? 1 : 0;
[DllImport(GlibName)]
public static extern uint g_unix_fd_add_full (int priority,
@@ -152,6 +153,7 @@ public void Dispose()
}
public static IDisposable ConnectSignal(IntPtr obj, string name, T handler)
+ where T : notnull
{
var handle = GCHandle.Alloc(handler);
var ptr = Marshal.GetFunctionPointerForDelegate(handler);
@@ -187,4 +189,4 @@ internal unsafe struct GSList
{
public readonly IntPtr Data;
public readonly GSList* Next;
-}
\ No newline at end of file
+}
diff --git a/src/Avalonia.X11/NativeDialogs/Gtk.cs b/src/Avalonia.X11/NativeDialogs/Gtk.cs
index 97874d71f08..70010863bab 100644
--- a/src/Avalonia.X11/NativeDialogs/Gtk.cs
+++ b/src/Avalonia.X11/NativeDialogs/Gtk.cs
@@ -1,10 +1,10 @@
+#nullable enable
+
using System;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using Avalonia.Platform.Interop;
-using Avalonia.Threading;
-using Avalonia.X11.Dispatching;
using Avalonia.X11.Interop;
// ReSharper disable IdentifierTypo
@@ -142,7 +142,7 @@ public static extern void
public static IntPtr GetForeignWindow(IntPtr xid) => gdk_x11_window_foreign_new_for_display(s_display, xid);
static object s_startGtkLock = new();
- static Task s_startGtkTask;
+ static Task? s_startGtkTask;
public static Task StartGtk()
{
diff --git a/src/Avalonia.X11/NativeDialogs/GtkNativeFileDialogs.cs b/src/Avalonia.X11/NativeDialogs/GtkNativeFileDialogs.cs
index 5dfa9a14cef..2ae1dcfd899 100644
--- a/src/Avalonia.X11/NativeDialogs/GtkNativeFileDialogs.cs
+++ b/src/Avalonia.X11/NativeDialogs/GtkNativeFileDialogs.cs
@@ -1,11 +1,8 @@
-#nullable enable
-
-using System;
+using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
-using Avalonia.Controls.Platform;
using Avalonia.Platform;
using Avalonia.Platform.Interop;
using Avalonia.Platform.Storage;
diff --git a/src/Avalonia.X11/SMLib.cs b/src/Avalonia.X11/SMLib.cs
index f8f13e32f8f..60c8d5c7fe4 100644
--- a/src/Avalonia.X11/SMLib.cs
+++ b/src/Avalonia.X11/SMLib.cs
@@ -1,4 +1,3 @@
-#nullable enable
using System;
using System.Runtime.InteropServices;
diff --git a/src/Avalonia.X11/Screens/X11Screen.Providers.cs b/src/Avalonia.X11/Screens/X11Screen.Providers.cs
index 0d3a620c1a5..82eb21b2871 100644
--- a/src/Avalonia.X11/Screens/X11Screen.Providers.cs
+++ b/src/Avalonia.X11/Screens/X11Screen.Providers.cs
@@ -1,10 +1,10 @@
-
-#nullable enable
using System;
+using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using Avalonia.Platform;
using static Avalonia.X11.XLib;
+
namespace Avalonia.X11.Screens;
internal partial class X11Screens
@@ -44,7 +44,7 @@ public virtual void Refresh()
private unsafe Size? GetPhysicalMonitorSizeFromEDID(IntPtr rrOutput)
{
- if (rrOutput == IntPtr.Zero || x11 == null)
+ if (rrOutput == IntPtr.Zero)
return null;
var properties = XRRListOutputProperties(x11.Display, rrOutput, out int propertyCount);
var hasEDID = false;
@@ -130,7 +130,7 @@ internal interface IX11RawScreenInfoProvider
{
nint[] ScreenKeys { get; }
event Action? Changed;
- X11Screen? CreateScreenFromKey(nint key);
+ X11Screen CreateScreenFromKey(nint key);
}
internal unsafe struct MonitorInfo
@@ -211,20 +211,18 @@ private unsafe MonitorInfo[] MonitorInfos
}
}
- public X11Screen? CreateScreenFromKey(nint key)
+ public X11Screen CreateScreenFromKey(nint key)
{
- var info = MonitorInfos.Where(x => x.Name == key).FirstOrDefault();
-
var infos = MonitorInfos;
for (var i = 0; i < infos.Length; i++)
{
if (infos[i].Name == key)
{
- return new X11Screen(info, _x11, _scalingProvider, i);
+ return new X11Screen(infos[i], _x11, _scalingProvider, i);
}
}
- return null;
+ throw new ArgumentOutOfRangeException(nameof(key));
}
}
@@ -248,7 +246,7 @@ public FallbackScreensImpl(AvaloniaX11Platform platform)
private bool UpdateRootWindowGeometry() => XGetGeometry(_info.Display, _info.RootWindow, out _geo);
- public X11Screen? CreateScreenFromKey(nint key)
+ public X11Screen CreateScreenFromKey(nint key)
{
return new FallBackScreen(new PixelRect(0, 0, _geo.width, _geo.height), _info);
}
diff --git a/src/Avalonia.X11/Screens/X11Screens.Scaling.cs b/src/Avalonia.X11/Screens/X11Screens.Scaling.cs
index c6d14d3253d..3398580750b 100644
--- a/src/Avalonia.X11/Screens/X11Screens.Scaling.cs
+++ b/src/Avalonia.X11/Screens/X11Screens.Scaling.cs
@@ -1,4 +1,3 @@
-#nullable enable
using System;
using System.Collections.Generic;
using System.Globalization;
diff --git a/src/Avalonia.X11/Screens/X11Screens.cs b/src/Avalonia.X11/Screens/X11Screens.cs
index 5df34555b7b..b8ff80734c6 100644
--- a/src/Avalonia.X11/Screens/X11Screens.cs
+++ b/src/Avalonia.X11/Screens/X11Screens.cs
@@ -1,12 +1,7 @@
using System;
using System.Collections.Generic;
-using System.Globalization;
-using System.Linq;
-using System.Runtime.InteropServices;
-using System.Threading.Tasks;
using Avalonia.Platform;
using static Avalonia.X11.Screens.X11Screens;
-using static Avalonia.X11.XLib;
namespace Avalonia.X11.Screens
{
diff --git a/src/Avalonia.X11/TransparencyHelper.cs b/src/Avalonia.X11/TransparencyHelper.cs
index dd70643cfdb..50a73a36ce2 100644
--- a/src/Avalonia.X11/TransparencyHelper.cs
+++ b/src/Avalonia.X11/TransparencyHelper.cs
@@ -2,8 +2,6 @@
using System.Collections.Generic;
using Avalonia.Controls;
-#nullable enable
-
namespace Avalonia.X11
{
internal class TransparencyHelper : IDisposable
diff --git a/src/Avalonia.X11/Vulkan/VulkanSupport.cs b/src/Avalonia.X11/Vulkan/VulkanSupport.cs
index 5139d78880f..5f9dcf7953e 100644
--- a/src/Avalonia.X11/Vulkan/VulkanSupport.cs
+++ b/src/Avalonia.X11/Vulkan/VulkanSupport.cs
@@ -1,5 +1,3 @@
-#nullable enable
-
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
diff --git a/src/Avalonia.X11/X11Atoms.cs b/src/Avalonia.X11/X11Atoms.cs
index b00879bd1dd..ad4b841e1eb 100644
--- a/src/Avalonia.X11/X11Atoms.cs
+++ b/src/Avalonia.X11/X11Atoms.cs
@@ -222,7 +222,7 @@ public IntPtr GetAtom(string name)
return atom;
}
- public string GetAtomName(IntPtr atom)
+ public string? GetAtomName(IntPtr atom)
{
if (_atomsToNames.TryGetValue(atom, out var rv))
return rv;
diff --git a/src/Avalonia.X11/X11Clipboard.cs b/src/Avalonia.X11/X11Clipboard.cs
index 637d44d6171..da079458d93 100644
--- a/src/Avalonia.X11/X11Clipboard.cs
+++ b/src/Avalonia.X11/X11Clipboard.cs
@@ -12,11 +12,11 @@ namespace Avalonia.X11
internal class X11Clipboard : IClipboard
{
private readonly X11Info _x11;
- private IDataObject _storedDataObject;
+ private IDataObject? _storedDataObject;
private IntPtr _handle;
- private TaskCompletionSource _storeAtomTcs;
- private TaskCompletionSource _requestedFormatsTcs;
- private TaskCompletionSource