enableUnboundedMouseMovement causes mouse cursor to jump in the top center of the screen?

I have a weird mouse cursor behaviour when implementing a Component, which you click on and move mouse up/down to zoom/in out some graphics below this component.

In “void mouseDown(const juce::MouseEvent& event)” I have the following line:
event.source.enableUnboundedMouseMovement(true);

And in “void mouseUp(const juce::MouseEvent& event)” I have the following line:
event.source.enableUnboundedMouseMovement(false);

I don’t touch mouse cursor in any other way anywhere.

Still the cursor has usually moved close to center at the top of the screen after moving the cursor and releasing the mouse button. This seems to happen when the cursor gets out of the top of the screen and I release the mouse button.

Why does the mouse cursor jump where it shouldn’t?

I’ve noticed some issues with it as well. But I couldn’t reproduce it exactly. Are you testing this on different operating systems? I’ve seen these jumps on Linux. On MAc and Windows it seems to work like it should.

I’m on Mac.

enableUnboundedMouseMovement() doesn’t mean that the cursor will remain where it is, it simply means that you can move it around as there were no boundaries to its allowed movement.

If your goal is to preserve the position of the cursor on screen, you should obtain it on mouseDown and restore it on mouseUp after you disable the unbounded movement.

OK, so I can’t assume anything about where the cursor goes once it’s hidden from screen. The weird thing was that the cursor seems to always jump in the center of the screen once it’s out of the screen’s top border, even for a few pixels.

What you suggested works well. Thank you!