Fix a bug in X11 CursorVisble with custom cursors.

CursorVisible reset to the default cursor when showing the cursor, it
should instead show the custom cursor if it's defined (else the default
cursor).
This commit is contained in:
Fraser Waters 2014-02-24 12:58:41 +00:00 committed by thefiddler
parent 9ed32e4445
commit 2207144aec

View file

@ -117,6 +117,7 @@ namespace OpenTK.Platform.X11
bool _decorations_hidden = false;
MouseCursor cursor = MouseCursor.Default;
IntPtr cursorHandle;
bool cursor_visible = true;
int mouse_rel_x, mouse_rel_y;
@ -1476,16 +1477,23 @@ namespace OpenTK.Platform.X11
{
using (new XLock(window.Display))
{
fixed(byte* pixels = value.Rgba)
if (value == MouseCursor.Default)
{
var xcursorimage = Functions.XcursorImageCreate(32, 32);
xcursorimage->xhot = (uint)value.X;
xcursorimage->yhot = (uint)value.Y;
xcursorimage->pixels = (uint*)pixels;
xcursorimage->delay = 0;
var xcursor = Functions.XcursorImageLoadCursor(window.Display, xcursorimage);
Functions.XDefineCursor(window.Display, window.Handle, xcursor);
Functions.XcursorImageDestroy(xcursorimage);
Functions.XUndefineCursor(window.Display, window.Handle);
}
else
{
fixed(byte* pixels = value.Rgba)
{
var xcursorimage = Functions.XcursorImageCreate(32, 32);
xcursorimage->xhot = (uint)value.X;
xcursorimage->yhot = (uint)value.Y;
xcursorimage->pixels = (uint*)pixels;
xcursorimage->delay = 0;
cursorHandle = Functions.XcursorImageLoadCursor(window.Display, xcursorimage);
Functions.XDefineCursor(window.Display, window.Handle, cursorHandle);
Functions.XcursorImageDestroy(xcursorimage);
}
}
}
}
@ -1505,7 +1513,7 @@ namespace OpenTK.Platform.X11
{
using (new XLock(window.Display))
{
Functions.XUndefineCursor(window.Display, window.Handle);
Functions.XDefineCursor(window.Display, window.Handle, cursorHandle);
cursor_visible = true;
}
}
@ -1742,6 +1750,10 @@ namespace OpenTK.Platform.X11
{
using (new XLock(window.Display))
{
if(cursorHandle != IntPtr.Zero)
{
Functions.XFreeCursor(window.Display, cursorHandle);
}
Functions.XFreeCursor(window.Display, EmptyCursor);
Functions.XDestroyWindow(window.Display, window.Handle);
}