rust-windowing / rust-windowing/winit

Custom HiDPI cursor on MacOS

Open
#4,094 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

DS - appkit S - enhancement
Dominant language
Rust
Stars
6.2k
Forks
1.3k
Avg merge
2d 19h
Merged PRs (30d)
9

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read src/platform_impl/apple/appkit/cursor.rs first, focusing on how the NSImage size and cursor hotspot are currently created. Reproduce the custom-cursor behavior on a Retina macOS display, then verify that the cursor is sharp and that its hotspot remains correct after the logical-size change.

Written by the indexing model from the issue text.

Assessment

Tech stack
macos, rust
Domain
desktop
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.