Key improvements: 1. Add image caching to CursorInfo struct to avoid repeated disk reads and decoding 2. Implement Windows cursor handle caching to minimize GDI resource allocation 3. Update all code paths to use cached resources for better performance 4. Remove deprecated/unused functions for cleaner codebase This change significantly reduces CPU usage and improves cursor switching performance.
53 lines
1.3 KiB
Rust
53 lines
1.3 KiB
Rust
// Platform-specific cursor handling
|
|
|
|
// Windows implementation
|
|
#[cfg(windows)]
|
|
mod windows;
|
|
|
|
// macOS implementation
|
|
#[cfg(target_os = "macos")]
|
|
mod macos;
|
|
|
|
// Linux implementation
|
|
#[cfg(target_os = "linux")]
|
|
mod linux;
|
|
|
|
// Unsupported platforms
|
|
#[cfg(not(any(windows, target_os = "macos", target_os = "linux")))]
|
|
mod unsupported;
|
|
|
|
// --- Platform-independent types ---
|
|
|
|
// Define a cross-platform cursor handle type
|
|
#[cfg(windows)]
|
|
pub use windows::types::SyncHCURSOR;
|
|
|
|
#[cfg(not(windows))]
|
|
#[derive(Copy, Clone, Debug)]
|
|
pub struct SyncHCURSOR(pub usize);
|
|
|
|
#[cfg(not(windows))]
|
|
unsafe impl Send for SyncHCURSOR {}
|
|
|
|
#[cfg(not(windows))]
|
|
unsafe impl Sync for SyncHCURSOR {}
|
|
|
|
// --- Public Exports ---
|
|
|
|
// Export the platform-specific functions
|
|
#[cfg(windows)]
|
|
pub use windows::{hide_system_cursor, update_cursor_info, restore_cursor};
|
|
|
|
// Re-export CursorInfo for platform-specific implementations
|
|
pub use crate::app::CursorInfo;
|
|
|
|
#[cfg(target_os = "macos")]
|
|
pub use macos::{hide_system_cursor, update_cursor_info, restore_cursor, render_cursor};
|
|
|
|
#[cfg(target_os = "linux")]
|
|
pub use linux::{hide_system_cursor, update_cursor_info, restore_cursor, render_cursor};
|
|
|
|
// Default implementation for other platforms
|
|
#[cfg(not(any(windows, target_os = "macos", target_os = "linux")))]
|
|
pub use unsupported::{hide_system_cursor, update_cursor_info, restore_cursor, render_cursor};
|