Skip to content
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

Custom HiDPI cursor on MacOS #4094

Open
badgyro opened this issue Jan 27, 2025 · 1 comment
Open

Custom HiDPI cursor on MacOS #4094

badgyro opened this issue Jan 27, 2025 · 1 comment
Labels
DS - macos S - enhancement Wouldn't this be the coolest?

Comments

@badgyro
Copy link

badgyro commented Jan 27, 2025

Description

I’ve noticed that winit doesn’t have an option to set a custom HiDPI mouse cursor on MacOS. Most MacBook and iMac screens are scaled x2, even the mouse cursor is doubled. I think it’s worth considering because a custom cursor is currently blurred on retina displays.

Image

I took a look at the implementation and managed to achieve a sharp cursor by dividing the size of the NSImage by 2. By keeping the physical representation, I only changed the logical representation. It’s worth mentioning that the hotspot also needs to be changed. For testing, I set it to 0. This is just a test, not a final solution.

File src/platform_impl/apple/appkit/cursor.rs

    let image = unsafe {
        NSImage::initWithSize(NSImage::alloc(), NSSize::new((width / 2).into(), (height / 2).into()))
    };
    unsafe { image.addRepresentation(&bitmap) };

    let hotspot = NSPoint::new(0 as f64, 0 as f64);

What do you think about it?

Relevant platforms

macOS

@badgyro badgyro added the S - enhancement Wouldn't this be the coolest? label Jan 27, 2025
@madsmtm
Copy link
Member

madsmtm commented Jan 29, 2025

Hmm, how does this work if you use it on non-HiDPI screens?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DS - macos S - enhancement Wouldn't this be the coolest?
Development

No branches or pull requests

2 participants