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; bool _decorations_hidden = false;
MouseCursor cursor = MouseCursor.Default; MouseCursor cursor = MouseCursor.Default;
IntPtr cursorHandle;
bool cursor_visible = true; bool cursor_visible = true;
int mouse_rel_x, mouse_rel_y; int mouse_rel_x, mouse_rel_y;
@ -1475,6 +1476,12 @@ namespace OpenTK.Platform.X11
unsafe unsafe
{ {
using (new XLock(window.Display)) using (new XLock(window.Display))
{
if (value == MouseCursor.Default)
{
Functions.XUndefineCursor(window.Display, window.Handle);
}
else
{ {
fixed(byte* pixels = value.Rgba) fixed(byte* pixels = value.Rgba)
{ {
@ -1483,14 +1490,15 @@ namespace OpenTK.Platform.X11
xcursorimage->yhot = (uint)value.Y; xcursorimage->yhot = (uint)value.Y;
xcursorimage->pixels = (uint*)pixels; xcursorimage->pixels = (uint*)pixels;
xcursorimage->delay = 0; xcursorimage->delay = 0;
var xcursor = Functions.XcursorImageLoadCursor(window.Display, xcursorimage); cursorHandle = Functions.XcursorImageLoadCursor(window.Display, xcursorimage);
Functions.XDefineCursor(window.Display, window.Handle, xcursor); Functions.XDefineCursor(window.Display, window.Handle, cursorHandle);
Functions.XcursorImageDestroy(xcursorimage); Functions.XcursorImageDestroy(xcursorimage);
} }
} }
} }
} }
} }
}
#endregion #endregion
@ -1505,7 +1513,7 @@ namespace OpenTK.Platform.X11
{ {
using (new XLock(window.Display)) using (new XLock(window.Display))
{ {
Functions.XUndefineCursor(window.Display, window.Handle); Functions.XDefineCursor(window.Display, window.Handle, cursorHandle);
cursor_visible = true; cursor_visible = true;
} }
} }
@ -1742,6 +1750,10 @@ namespace OpenTK.Platform.X11
{ {
using (new XLock(window.Display)) using (new XLock(window.Display))
{ {
if(cursorHandle != IntPtr.Zero)
{
Functions.XFreeCursor(window.Display, cursorHandle);
}
Functions.XFreeCursor(window.Display, EmptyCursor); Functions.XFreeCursor(window.Display, EmptyCursor);
Functions.XDestroyWindow(window.Display, window.Handle); Functions.XDestroyWindow(window.Display, window.Handle);
} }