-
Notifications
You must be signed in to change notification settings - Fork 919
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 custom cursor icon support on Windows #1617
Conversation
The PR mentions windows, however you're touching other backends and exposing a new API to some sort. So what's the buffer pixel on Windows(RGBA/ARGB)? On Wayland for example the buffer is in I also can add wayland implementation for such thing, I guess, but it's a bit obscure. And has some edges like scale factor and what user should provide. I'd assume that all HiDPI handling is up to user here, and it should just ensure that buffer is scaled properly. |
I needed to touch the other platforms because this PR makes The public API surface area for this is fairly small - we're just adding a
@kchibisov That'd be great, thanks! On Windows, the OS doesn't do any automatic DPI scaling for the custom cursor, so the user would have to manually upload an appropriately-scaled version of the cursor when the scale factor changes. I'm personally okay with that approach, but it should definitely be documented. |
note, I'll send Wayland impl later(as separate PR), since it'll actually require some rework of Wayland backend before doing so. Just saying so won't end up waiting on something. |
…don't make sense This is the API design strategy recommended by the official Rust book: https://doc.rust-lang.org/book/ch09-03-to-panic-or-not-to-panic.html#guidelines-for-error-handling
1923108
to
54646ae
Compare
I've thought some more about how icon scaling works, and I've changed my mind somewhat. I still don't think that Winit should do any implicit icon scaling beyond what the OS does, but it should provide an API for attaching multiple images at different scales for a single logical
I'll update this PR to expose that API and implement it on Windows. |
I'll just add that on Wayland client draws the cursor itself with the size and scale it wants. winit shouldn't care about size part on it, since sctk does that already for it, so only scale. Since scaling is done by clients, they should just set buffer scale and attach the proper buffer size (just physical size thing). So multiple icons is softly required thing on Wayland (you can in theory draw with some big scale, and rely on compositor downscaling).
Same for Wayland, but since cursor is managed by users, and it's just a normal surface, you get scale changes events for it separately, and so can react and pick proper cursor for that scale, so not a big issue. So if winit wants some consistency across the platforms the cursor DPI scaling should be entirely done by winit, and user should just provide some set of images to pick from.
Not sure how it's related to cursor related things? |
The current API uses the same type for custom window icons and custom cursor icons, so adding support in the public API for this helps improve both the cursor implementation and the window icon implementation. |
src/icon.rs
Outdated
pub struct RgbaIcon<I: Deref<Target = [u8]>> { | ||
pub(crate) rgba: I, | ||
pub(crate) size: PhysicalSize<u32>, | ||
pub(crate) hot_spot: PhysicalPosition<u32>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really like that we have a cursor and normal icons under the same RgbaIcon
, in general, we can name it like RgbaBuffer
, since the intent to have RgbaBuffer
and have Icon
and a new type for cursor icons, which will use that RgbaBuffer
under the hood?
It's just strange that we have a field that shouldn't be used in any ways in certain scenarios, but in other cases it's fine to use them. Such issues should be solved on type system level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a decent point. I've updated the API to split the custom window type and custom cursor type into two parts, though it's not documented yet. Could you take a look at it?
Co-authored-by: Kirill Chibisov <[email protected]>
Co-authored-by: Kirill Chibisov <[email protected]>
Co-authored-by: Kirill Chibisov <[email protected]>
Co-authored-by: Kirill Chibisov <[email protected]>
Co-authored-by: Kirill Chibisov <[email protected]>
This change removes the
|
Yep! That was just an oversight - the implementation was written with |
Closing due to inactivity. Tracked in #3005. |
cargo fmt
has been run on this branchcargo doc
builds successfullyCHANGELOG.md
if knowledge of this change could be valuable to users