feat(all): Custom cursor images for all desktop platforms

There seems to be many PRs relating to this issue, but they don't include all
platforms and for some reason lost steam. This PR again tries to make this
feature happen, and does it for all desktop platforms (x11, wayland, macos,
windows, web).

I think the best user of this feature and the reason I'm doing this is Bevy and
game engines in general. There non laggy hardware cursors with custom images are
very important. Game devs also like their PNGs so supporting platform native
cursor files is not that important, but I guess could be added too.

Co-authored-by: daxpedda <daxpedda@gmail.com>
Co-authored-by: Mads Marquart <mads@marquart.dk>
Co-authored-by: Kirill Chibisov <contact@kchibisov.com>
This commit is contained in:
Eero Lehtinen 2023-12-16 22:02:17 +02:00 committed by GitHub
parent 7f6b16a6af
commit af93167237
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
42 changed files with 1243 additions and 57 deletions

View file

@ -101,7 +101,7 @@ use runner::{EventLoopRunner, EventLoopRunnerShared};
use self::runner::RunnerState;
use super::window::set_skip_taskbar;
use super::{window::set_skip_taskbar, SelectedCursor};
type GetPointerFrameInfoHistory = unsafe extern "system" fn(
pointerId: u32,
@ -2011,16 +2011,21 @@ unsafe fn public_window_callback_inner<T: 'static>(
// `WM_MOUSEMOVE` seems to come after `WM_SETCURSOR` for a given cursor movement.
let in_client_area = super::loword(lparam as u32) as u32 == HTCLIENT;
if in_client_area {
Some(window_state.mouse.cursor)
Some(window_state.mouse.selected_cursor.clone())
} else {
None
}
};
match set_cursor_to {
Some(cursor) => {
let cursor = unsafe { LoadCursorW(0, util::to_windows_cursor(cursor)) };
unsafe { SetCursor(cursor) };
Some(selected_cursor) => {
let hcursor = match selected_cursor {
SelectedCursor::Named(cursor_icon) => unsafe {
LoadCursorW(0, util::to_windows_cursor(cursor_icon))
},
SelectedCursor::Custom(cursor) => cursor.as_raw_handle(),
};
unsafe { SetCursor(hcursor) };
result = ProcResult::Value(0);
}
None => result = ProcResult::DefWindowProc(wparam),