@ -1,13 +1,10 @@
using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Runtime.InteropServices ;
using Avalonia.Controls.Platform.Surfaces ;
using Avalonia.Input ;
using Avalonia.Platform ;
using Avalonia.Platform.Internal ;
using Avalonia.SourceGenerator ;
using Avalonia.Utilities ;
# nullable enable
@ -50,15 +47,14 @@ namespace Avalonia.X11
{ StandardCursorType . TopRightCorner , CursorFontShape . XC_top_right_corner } ,
} ;
[GenerateEnumValueList]
private static partial CursorFontShape [ ] GetAllCursorShapes ( ) ;
public X11CursorFactory ( IntPtr display )
{
_d isplay = display ;
_ nullCursor = GetNullCursor ( display ) ;
_ cursors = GetAllCursorShapes ( )
. ToDictionary ( id = > id , id = > XLib . XCreateFontCursor ( _d isplay , id ) ) ;
// 78 = number of items in CursorFontShape enum
// Unlikely to change, but, do we have a Src Gen for this?
_ cursors = new Dictionary < CursorFontShape , IntPtr > ( 7 8 ) ;
}
public ICursorImpl GetCursor ( StandardCursorType cursorType )
@ -71,8 +67,8 @@ namespace Avalonia.X11
else
{
handle = s_mapping . TryGetValue ( cursorType , out var shape )
? _ cursors [ shape ]
: _ cursors [ CursorFontShape . XC_left_ptr ] ;
? GetCursorHandleLazy ( shape )
: GetCursorHandleLazy ( CursorFontShape . XC_left_ptr ) ;
}
return new CursorImpl ( handle ) ;
}
@ -144,6 +140,14 @@ namespace Avalonia.X11
public IFramebufferRenderTarget CreateFramebufferRenderTarget ( ) = > new FuncFramebufferRenderTarget ( Lock ) ;
}
private nint GetCursorHandleLazy ( CursorFontShape shape )
{
if ( ! _ cursors . TryGetValue ( shape , out var handle ) )
_ cursors [ shape ] = handle = XLib . XCreateFontCursor ( _d isplay , shape ) ;
return handle ;
}
}
internal class CursorImpl : ICursorImpl