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