From fc718026fd84576425578c7b6d0cc34755ea36d1 Mon Sep 17 00:00:00 2001 From: thefiddler Date: Tue, 13 May 2014 09:27:21 +0200 Subject: [PATCH] [X11] Fixed Cursor when CursorVisible = false Setting Cursor will no longer override CursorVisible. --- Source/OpenTK/Platform/X11/X11GLNative.cs | 25 +++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/Source/OpenTK/Platform/X11/X11GLNative.cs b/Source/OpenTK/Platform/X11/X11GLNative.cs index 13b429d7..968a4303 100644 --- a/Source/OpenTK/Platform/X11/X11GLNative.cs +++ b/Source/OpenTK/Platform/X11/X11GLNative.cs @@ -1441,11 +1441,18 @@ namespace OpenTK.Platform.X11 { unsafe { + if (value == cursor) + return; + using (new XLock(window.Display)) { if (value == MouseCursor.Default) { - Functions.XUndefineCursor(window.Display, window.Handle); + cursorHandle = IntPtr.Zero; + } + else if (value == MouseCursor.Empty) + { + cursorHandle = EmptyCursor; } else { @@ -1457,16 +1464,28 @@ namespace OpenTK.Platform.X11 xcursorimage->pixels = (uint*)pixels; xcursorimage->delay = 0; cursorHandle = Functions.XcursorImageLoadCursor(window.Display, xcursorimage); - Functions.XDefineCursor(window.Display, window.Handle, cursorHandle); Functions.XcursorImageDestroy(xcursorimage); } } + + // If the cursor is visible set it now. + // Otherwise, it will be set in CursorVisible = true. + if (CursorVisible) + { + Functions.XDefineCursor(window.Display, window.Handle, cursorHandle); + } + cursor = value; } } } } + void SetCursor(IntPtr handle) + { + Functions.XDefineCursor(window.Display, window.Handle, cursorHandle); + } + #endregion #region CursorVisible @@ -1480,6 +1499,8 @@ namespace OpenTK.Platform.X11 { using (new XLock(window.Display)) { + // Note: if cursorHandle = IntPtr.Zero, this function + // is equivalent to XUndefineCursor. Functions.XDefineCursor(window.Display, window.Handle, cursorHandle); cursor_visible = true; }