-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Add animated cursors #14241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add animated cursors #14241
Conversation
Generalizes the animated cursor info, so it can be used for custom cursors as well.
In general this looks good. Two questions:
|
Can you update testcustomcursor to also test animated cursors? |
957feb1
to
1250636
Compare
It's standard among the system level implementations, and adds flexibility without a lot of complexity. The old Windows hourglass wait cursor, for example, uses different durations to make the vertical frame hold longer than the turning frames. It also allows for easily creating one-shot animations by setting the last frame duration to 0 (infinite).
The current implementations don't need this, and wouldn't benefit from it, as the cursors are handled as close to the system-level as possible. X and Windows pass the frames to the desktop and get a single Cursor/HCURSOR object that the system animates itself. Wayland does a single buffer pool allocation and commits suballocated wl_buffer objects in the cursor surface frame callback, just as it has to do with animated system cursors on compositors without the cursor shape protocol. Mac needs some manual handling, but that is still a simple matter of using an NSTimer and invalidating the cursor rect when it fires. Unless some platform eventually needs this functionality generalized, it's not yet worth the time or effort imo. |
1250636
to
b05a359
Compare
Okay, that makes sense, especially if it's supported in all the backends.
I agree that having the system do the animation is ideal. It might be worth implementing the fallback for the case that is currently a static one frame cursor, and then we can say it's supported everywhere? |
This would be pretty trivial to do, and I'm happy to add that after this PR lands, if you want. |
2155711
to
0137762
Compare
There are two added cases that make the custom arrow cursor flash: a looping animated sample, and a one-shot that slows down and stops. I'll add loading an image sequence from files a bit later. |
f7b447d
to
f3db7b9
Compare
Suggestion: For one shot animations, maybe it could get the fallback static cursor from the last frame instead of the first? Other animations can always be rearranged so they start on a suitable frame, but that's not possible for one shots. |
7d97a81
to
c48d7f9
Compare
The long term plan is to have a generic fallback that animated cursors at a higher level for backends without animation support, but for now, this is a good idea. Done. |
I added a couple of comments, but this generally looks good to me. Feel free to merge when ready! |
Adds support for animated cursors on Cocoa, Wayland, Win32, and X11. testcursor can take a semicolon separated list of filenames and load an animated cursor from them.
c48d7f9
to
da49b41
Compare
Merged! |
Add animated cursors to Cocoa, Wayland, Win32, and X11.
Animated cursors are composed of a series of images, with a duration specified for each.
Cursors are handled as close to the system level as possible:
Currently, SDL_CreateAnimatedCursor() falls back to creating a static cursor from the first frame if the platform doesn't support animated cursors. Should it just fail instead?
TODO:
Closes #14198
Closes #14248