crates/cursor-info/README.md
A cross-platform Rust crate for detecting cursor shapes and providing accurate cursor assets with hotspot information.
Add this to your Cargo.toml:
[dependencies]
cap-cursor-info = "0.0.0"
The crate automatically includes platform-specific dependencies:
objc2 and objc2-app-kit for cursor detectionwindows crate for Win32 API integrationuse cap_cursor_info::{CursorShape, CursorShapeMacOS, CursorShapeWindows};
// Create a cursor shape
let cursor = CursorShape::MacOS(CursorShapeMacOS::Arrow);
// Resolve to get SVG asset and hotspot
if let Some(resolved) = cursor.resolve() {
println!("SVG: {}", resolved.raw);
println!("Hotspot: ({}, {})", resolved.hotspot.0, resolved.hotspot.1);
}
// Display cursor information
println!("Cursor: {}", cursor); // Output: "MacOS|Arrow"
#[cfg(target_os = "macos")]
use cap_cursor_info::CursorShapeMacOS;
// Detect cursor from hash (macOS uses image hashing)
let hash = "de2d1f4a81e520b65fd1317b845b00a1c51a4d1f71cca3cd4ccdab52b98d1ac9";
if let Some(cursor) = CursorShapeMacOS::from_hash(hash) {
println!("Detected cursor: {:?}", cursor);
}
#[cfg(target_os = "windows")]
use cap_cursor_info::CursorShape;
use windows::Win32::UI::WindowsAndMessaging::HCURSOR;
// Convert from Windows HCURSOR
let hcursor: HCURSOR = get_current_cursor(); // Your implementation
if let Ok(cursor) = CursorShape::try_from(&hcursor) {
println!("Detected cursor: {}", cursor);
}
The crate supports serde serialization:
use cap_cursor_info::CursorShape;
use serde_json;
let cursor = CursorShape::MacOS(CursorShapeMacOS::Arrow);
let json = serde_json::to_string(&cursor).unwrap();
println!("{}", json); // "MacOS|Arrow"
let deserialized: CursorShape = serde_json::from_str(&json).unwrap();
Arrow - Standard arrow pointerContextualMenu - Context menu indicatorClosedHand - Closed hand for draggingCrosshair - Precision crosshairDragCopy - Copy operation indicatorDragLink - Link operation indicatorIBeam - Text selection cursorIBeamVerticalForVerticalLayout - Vertical text cursorOpenHand - Open hand for grabbable itemsOperationNotAllowed - Prohibited operationPointingHand - Clickable link pointerResizeDown/Up/Left/Right - Directional resize cursorsResizeLeftRight/UpDown - Bidirectional resize cursorsArrow - Standard arrow pointerIBeam - Text selection cursorWait - Loading/busy indicatorCross - Crosshair cursorUpArrow - Vertical selectionSizeNWSE/NESW/WE/NS/All - Various resize cursorsNo - Prohibited operationHand - Clickable link pointerAppStarting - Application loadingHelp - Help/question cursorPin/Person - Specialized cursorsPen - Drawing/writing cursorOpen cursors.html in your browser to:
Run the example to monitor cursor changes in real-time:
cargo run --example cli
This will:
macOS cursor detection uses SHA-256 hashing of the cursor's TIFF image data. This approach is necessary because:
NSCursor instances cannot be compared directlyWindows cursor detection uses HCURSOR handle comparison with a cached lookup table of system cursors loaded at runtime.
All cursor assets are:
assets/ directoriesHotspot coordinates are normalized (0.0 to 1.0) relative to the cursor's dimensions:
(0.0, 0.0) = Top-left corner(1.0, 1.0) = Bottom-right corner(0.5, 0.5) = CenterWe welcome contributions! Please:
This project is released under the Apple User Agreement for macOS assets. See individual license files in the assets directories for specific terms.