the Fiddler's picture

[NativeWindow] Add ability to hide/show/modify the mouse cursor

Project:The Open Toolkit library
Category:feature request
Assigned:the Fiddler

Currently, the only way to do this is to set System.Windows.Forms.Cursor.Current to an empty cursor (Cursor.Hide() is not supported on Mono).

OpenTK applications should not need to rely on WinForms for this functionality.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture


Priority:normal» critical

Bumping priority.

jdomnitz's picture


If I throw up code for each GLNative implementation (for each platform) will that work? Or do you want a full patch including changing the interfaces leading up to it?

the Fiddler's picture


Status:open» in progress

I just implemented this on X11 but I'm missing windows/mac implementations. I believe I can cook something up for windows without too much trouble but I would love some help with the mac implementation (OpenTK is currently using Carbon).

The API is pretty simple:

gameWindow.CursorVisible = true/false;

A patch against trunk is best but even example code is fine (the changes are pretty simple and self-contained here).

Edit: initial implementation for X11 is committed to trunk, it's still buggy though. You can test the code using Examples->OpenTK->GameWindow States.

jdomnitz's picture


windows is just this:

i'll see if I can work something out for OSX but thats the one platform I don't know a lot about

the Fiddler's picture


Thanks, committed the windows implementation.

jdomnitz's picture


Cool...and then for OSX:

Its CGDisplayHideCursor and CGDisplayShowCursor from the quartz API:

see here:

the Fiddler's picture



The final piece of the puzzle is whether we should confine the pointer inside the window whenever it becomes invisible. We can either provide a different API for this or we do this automatically. Is there any reason why one might like to have an invisible pointer that is *not* confined to the window?

c2woody's picture


Maybe make this an optional parameter to the Hide function. Not sure what the parameter-less function should default to.

jdomnitz's picture


Yea I prefer the ShowCursor and HideCursor approach (how .net does it) compared to the single Property.... but two ways this can be done:
Either stub out APIs for all the platforms just to limit the mouse to a set bounds...or implement the rawhardware backend and not worry about it (if we have a raw hardware handle we really don't care where the cursor is just that its invisible).

the Fiddler's picture


These methods don't hide the cursor globally - once the cursor leaves the window, it becomes visible again. Raw input doesn't affect this.

I'll run a few tests to find out what the best approach is.