-
Notifications
You must be signed in to change notification settings - Fork 902
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 support of using custom image as cursor icon on windows #2833
Conversation
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.
Thanks!
I would prefer a dedicated cusor type, where to user can create cursor with a standard icon or with a custom one. At least on X11 IIRC the cursor and icons are different types and mixing them will lead to issues. This would also help to keep a single entry point for the setting the cursor.
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 would prefer a dedicated cusor type, where to user can create cursor with a standard icon or with a custom one. At least on X11 IIRC the cursor and icons are different types and mixing them will lead to issues. This would also help to keep a single entry point for the setting the cursor.
Fully agree, custom cursors are also supportable on macOS and web, both of which define PlatformIcon
as NoIcon
.
We should also consider how this will interact with the cursor-icon
crate.
Yeah, we might add a variant to |
Instead, we could do something like this (in // Bikeshed names
pub struct CustomCursorRGBA { ... }
pub struct CustomCursorURL { ... }
trait CursorIconTrait: Sealed { ... }
impl CursorIconTrait for cursor_icon::CursorIcon { ... }
impl CursorIconTrait for CustomCursorRGBA { ... }
impl CursorIconTrait for CustomCursorURL { ... }
impl Window {
fn set_cursor_icon(&self, icon: impl CursorIconTrait) { ... }
}
//
// Or alternatively:
//
// Bikeshed name
#[non_exhaustive]
pub enum CursorIconEnum {
Standard(cursor_icon::CursorIcon),
CustomRGBA(...),
// E.g. for web
CustomURL(Url),
}
impl From<cursor_icon::CursorIcon> for CursorIconEnum { ... }
impl From<...> for CursorIconEnum { ... }
impl From<Url> for CursorIconEnum { ... }
impl Window {
fn set_cursor_icon(&self, icon: impl Into<CursorIconEnum>) { ... }
} |
Thank you for reviews! My intention was to implement this feature quickly so that it would be available as soon as possible, but this did really lack design as well. In addition, I suggest we collect the features of the custom mouse pointer under each platform, including the types supported (built-in, general image, proprietary format, url, animated cursor, etc.). I am more familiar with windows and web: On Windows, it supports both general images like png and its proprietary format (.cur & .ani), but with different winapi, which means if a Vec is provided it is hard to determind which kind of winapi should be used. For general images, hotspot should be provided or it will use the center of image. On Web, it supports built-ins, url and binary(Data URI). And for the latter two cases, general images like png, a Windows proprietary format .cur (.ani is not supported) and even SVG is supported. In addition, for general images or SVG, hotspot should be provided or it will a default value. So, it may not be enough to just divide them to standard, RGBA and URL. For all cases on all the platforms, a sheet shall be made to help tidy it up. |
I could add that on Wayland you simply provide and RGBA buffer because you draw the cursor. The animation is also done by you or by compositor, when using named cursors. |
de5671f
to
9607eee
Compare
Fix a compatibility issue with fully transparent images
df9e06b
to
56b973b
Compare
Superseded by #3218 |
CHANGELOG.md
if knowledge of this change could be valuable to usersAdds a
Window::set_cursor_custom_icon
method, which we can pass anIcon
to. And this icon is sightly different from a icon created byIcon::from_rgba
, because it lacks of hotspot infomation (default to the center of image in fact), so I add anIcon::from_rgba_cursor
which has extra hotspot parameters.A custom cursor icon has higher priority than system cursor once it is set (when processing WM_SETCURSOR). And custom cursor icon will be dropped if
Window::set_cursor_icon
is called again.This feature is only added to Windows platform for now, and
.cur
or.ani
format is also not supported for potential cross-platform requirements.Maybe a common
Cursor
struct should be added instead of reusingIcon
, but on Windows an icon or cursor is not strictly differentiated and I haven't delved into the api of other platforms yet. So I just make minimal changes.