We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 1795

Summary: Cursor doesn't update properly on alt-tab
Product: SDL Reporter: Alex Szpakowski <amaranth72>
Component: eventsAssignee: (disabled) Jørgen Tjernø <jorgen>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: minor    
Priority: P2 CC: jorgen
Version: HG 2.0   
Hardware: x86_64   
OS: Mac OS X 10.7   
Attachments: Small program for testing the cursor bug

Description Alex Szpakowski 2013-04-10 14:35:07 UTC
Created attachment 1106 [details]
Small program for testing the cursor bug

If I have a custom cursor set, and my cursor is inside an SDL2 window and I alt/cmd-tab to a different program, the cursor will revert to the default system cursor as expected.
However, if I alt/cmd-tab back into the SDL program with the cursor position inside the window bounds, SDL_WINDOWEVENT_ENTER will trigger correctly, but the cursor will not be set to the expected custom one until I move it completely out of the SDL window and back in (triggering a second SDL_WINDOWEVENT_ENTER).

I've been able to work around this bug by explicitly forcing a cursor update (calling SDL_SetCursor(NULL)) when SDL_WINDOWEVENT_ENTER is triggered, but that's just a workaround.

I have only tested this on Mac OS 10.8.3 so I don't know if it's an OS-specific issue.
Comment 1 (disabled) Jørgen Tjernø 2013-04-22 22:26:07 UTC
I'm able to reproduce this on Mac with the code you provided (not tested on other platforms)

This is probably caused by calling -[NSCursor set] on OSX when we get the windowDidBecomeKey: notification, which doesn't work.

Fixes include:
 - Switch to using cursor rects (patch for 1.2's Quartz video backend is here http://hg.libsdl.org/SDL/rev/b8f2db95145e)
 - Schedule the 'set' call to be called in the event loop in a short a timespan as possible.

I also notice that we do +[NSCursor hide] and +[NSCursor unhide] without regard for balancing them. According to the docs, each hide has to be matched with one unhide. We should probably fix that too.
Comment 2 (disabled) Jørgen Tjernø 2013-04-23 21:53:22 UTC
Should be fixed in http://hg.libsdl.org/SDL/rev/ffd910de700b - please reopen if it hasn't been.