|
|
|
@ -8,6 +8,8 @@ namespace Avalonia.X11 |
|
|
|
{ |
|
|
|
class X11CursorFactory : IStandardCursorFactory |
|
|
|
{ |
|
|
|
private static IntPtr _nullCursor; |
|
|
|
|
|
|
|
private readonly IntPtr _display; |
|
|
|
private Dictionary<CursorFontShape, IntPtr> _cursors; |
|
|
|
|
|
|
|
@ -42,16 +44,34 @@ namespace Avalonia.X11 |
|
|
|
public X11CursorFactory(IntPtr display) |
|
|
|
{ |
|
|
|
_display = display; |
|
|
|
_nullCursor = GetNullCursor(display); |
|
|
|
_cursors = Enum.GetValues(typeof(CursorFontShape)).Cast<CursorFontShape>() |
|
|
|
.ToDictionary(id => id, id => XLib.XCreateFontCursor(_display, id)); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public IPlatformHandle GetCursor(StandardCursorType cursorType) |
|
|
|
{ |
|
|
|
var handle = s_mapping.TryGetValue(cursorType, out var shape) |
|
|
|
IntPtr handle; |
|
|
|
if (cursorType == StandardCursorType.None) |
|
|
|
{ |
|
|
|
handle = _nullCursor; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
handle = s_mapping.TryGetValue(cursorType, out var shape) |
|
|
|
? _cursors[shape] |
|
|
|
: _cursors[CursorFontShape.XC_top_left_arrow]; |
|
|
|
} |
|
|
|
return new PlatformHandle(handle, "XCURSOR"); |
|
|
|
} |
|
|
|
|
|
|
|
private static IntPtr GetNullCursor(IntPtr display) |
|
|
|
{ |
|
|
|
XColor color = new XColor(); |
|
|
|
byte[] data = new byte[] { 0 }; |
|
|
|
IntPtr window = XLib.XRootWindow(display, 0); |
|
|
|
IntPtr pixmap = XLib.XCreateBitmapFromData(display, window, data, 1, 1); |
|
|
|
return XLib.XCreatePixmapCursor(display, pixmap, pixmap, ref color, ref color, 0, 0); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|