@@ -17,7 +17,7 @@ internal partial class X11CursorFactory : ICursorFactory
17
17
private static IntPtr _nullCursor ;
18
18
19
19
private readonly IntPtr _display ;
20
- private Dictionary < CursorFontShape , IntPtr > _cursors ;
20
+ private Dictionary < StandardCursorType , IntPtr > _cursors ;
21
21
22
22
private static readonly Dictionary < StandardCursorType , CursorFontShape > s_mapping =
23
23
new Dictionary < StandardCursorType , CursorFontShape >
@@ -47,29 +47,29 @@ internal partial class X11CursorFactory : ICursorFactory
47
47
{ StandardCursorType . TopRightCorner , CursorFontShape . XC_top_right_corner } ,
48
48
} ;
49
49
50
+ private static readonly Dictionary < StandardCursorType , string > s_libraryCursors = new ( )
51
+ {
52
+ { StandardCursorType . DragCopy , "dnd-copy" } ,
53
+ { StandardCursorType . DragLink , "dnd-link" } ,
54
+ { StandardCursorType . DragMove , "dnd-move" } ,
55
+ // TODO: Check if other platforms have dnd-none, dnd-no-drop and dnd-ask
56
+ } ;
57
+
50
58
public X11CursorFactory ( IntPtr display )
51
59
{
52
60
_display = display ;
53
61
_nullCursor = GetNullCursor ( display ) ;
54
62
55
- // 78 = number of items in CursorFontShape enum
56
- // Unlikely to change, but, do we have a Src Gen for this?
57
- _cursors = new Dictionary < CursorFontShape , IntPtr > ( 78 ) ;
63
+ _cursors = new Dictionary < StandardCursorType , IntPtr > ( ) ;
58
64
}
59
65
60
66
public ICursorImpl GetCursor ( StandardCursorType cursorType )
61
67
{
62
68
IntPtr handle ;
63
69
if ( cursorType == StandardCursorType . None )
64
- {
65
70
handle = _nullCursor ;
66
- }
67
71
else
68
- {
69
- handle = s_mapping . TryGetValue ( cursorType , out var shape )
70
- ? GetCursorHandleLazy ( shape )
71
- : GetCursorHandleLazy ( CursorFontShape . XC_left_ptr ) ;
72
- }
72
+ handle = GetCursorHandleCached ( cursorType ) ;
73
73
return new CursorImpl ( handle ) ;
74
74
}
75
75
@@ -141,10 +141,25 @@ public ILockedFramebuffer Lock()
141
141
public IFramebufferRenderTarget CreateFramebufferRenderTarget ( ) => new FuncFramebufferRenderTarget ( Lock ) ;
142
142
}
143
143
144
- private nint GetCursorHandleLazy ( CursorFontShape shape )
144
+ private nint GetCursorHandleCached ( StandardCursorType type )
145
145
{
146
- if ( ! _cursors . TryGetValue ( shape , out var handle ) )
147
- _cursors [ shape ] = handle = XLib . XCreateFontCursor ( _display , shape ) ;
146
+ if ( ! _cursors . TryGetValue ( type , out var handle ) )
147
+ {
148
+ if ( s_libraryCursors . TryGetValue ( type , out var cursorName ) )
149
+ handle = XLib . XcursorLibraryLoadCursor ( _display , cursorName ) ;
150
+ else if ( s_mapping . TryGetValue ( type , out var cursorShape ) )
151
+ handle = XLib . XCreateFontCursor ( _display , cursorShape ) ;
152
+
153
+ if ( handle == IntPtr . Zero )
154
+ {
155
+ if ( type != StandardCursorType . Arrow )
156
+ handle = GetCursorHandleCached ( StandardCursorType . Arrow ) ;
157
+ else
158
+ handle = _nullCursor ;
159
+ }
160
+
161
+ _cursors [ type ] = handle ;
162
+ }
148
163
149
164
return handle ;
150
165
}
0 commit comments