Windows: Better cursor (#9451)
Moved `SetCursor` calls to `WM_SETCURSOR`, which occurs when OS is requires set cursor. Release Notes: - N/A
This commit is contained in:
parent
053d05f6f5
commit
5361a4d72d
3 changed files with 60 additions and 29 deletions
|
@ -62,6 +62,8 @@ pub(crate) struct WindowsPlatformInner {
|
|||
pub(crate) dispatch_event: OwnedHandle,
|
||||
pub(crate) settings: RefCell<WindowsPlatformSystemSettings>,
|
||||
pub icon: HICON,
|
||||
// NOTE: standard cursor handles don't need to close.
|
||||
pub(crate) current_cursor: Cell<HCURSOR>,
|
||||
}
|
||||
|
||||
impl WindowsPlatformInner {
|
||||
|
@ -157,6 +159,7 @@ impl WindowsPlatform {
|
|||
let raw_window_handles = RwLock::new(SmallVec::new());
|
||||
let settings = RefCell::new(WindowsPlatformSystemSettings::new());
|
||||
let icon = load_icon().unwrap_or_default();
|
||||
let current_cursor = Cell::new(load_cursor(CursorStyle::Arrow));
|
||||
let inner = Rc::new(WindowsPlatformInner {
|
||||
background_executor,
|
||||
foreground_executor,
|
||||
|
@ -167,6 +170,7 @@ impl WindowsPlatform {
|
|||
dispatch_event,
|
||||
settings,
|
||||
icon,
|
||||
current_cursor,
|
||||
});
|
||||
Self { inner }
|
||||
}
|
||||
|
@ -646,29 +650,7 @@ impl Platform for WindowsPlatform {
|
|||
}
|
||||
|
||||
fn set_cursor_style(&self, style: CursorStyle) {
|
||||
let handle = match style {
|
||||
CursorStyle::IBeam | CursorStyle::IBeamCursorForVerticalLayout => unsafe {
|
||||
load_cursor(IDC_IBEAM)
|
||||
},
|
||||
CursorStyle::Crosshair => unsafe { load_cursor(IDC_CROSS) },
|
||||
CursorStyle::PointingHand | CursorStyle::DragLink => unsafe { load_cursor(IDC_HAND) },
|
||||
CursorStyle::ResizeLeft | CursorStyle::ResizeRight | CursorStyle::ResizeLeftRight => unsafe {
|
||||
load_cursor(IDC_SIZEWE)
|
||||
},
|
||||
CursorStyle::ResizeUp | CursorStyle::ResizeDown | CursorStyle::ResizeUpDown => unsafe {
|
||||
load_cursor(IDC_SIZENS)
|
||||
},
|
||||
CursorStyle::OperationNotAllowed => unsafe { load_cursor(IDC_NO) },
|
||||
_ => unsafe { load_cursor(IDC_ARROW) },
|
||||
};
|
||||
if handle.is_err() {
|
||||
log::error!(
|
||||
"Error loading cursor image: {}",
|
||||
std::io::Error::last_os_error()
|
||||
);
|
||||
return;
|
||||
}
|
||||
let _ = unsafe { SetCursor(HCURSOR(handle.unwrap().0)) };
|
||||
self.inner.current_cursor.set(load_cursor(style));
|
||||
}
|
||||
|
||||
// todo(windows)
|
||||
|
@ -773,10 +755,6 @@ impl Drop for WindowsPlatform {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe fn load_cursor(name: PCWSTR) -> Result<HANDLE> {
|
||||
LoadImageW(None, name, IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE | LR_SHARED).map_err(|e| anyhow!(e))
|
||||
}
|
||||
|
||||
fn open_target(target: &str) {
|
||||
unsafe {
|
||||
let ret = ShellExecuteW(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue