-
Notifications
You must be signed in to change notification settings - Fork 1.1k
⚡ Optimizes macOS cursor handling logic. #1427
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,7 +1,4 @@ | ||||||
| use std::collections::HashMap; | ||||||
|
|
||||||
| use cap_cursor_info::{CursorShape, CursorShapeMacOS}; | ||||||
| use sha2::{Digest, Sha256}; | ||||||
| use cap_cursor_info::CursorShape; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing import: Line 21 and 38 reference -use cap_cursor_info::CursorShape;
+use cap_cursor_info::{CursorShape, CursorShapeMacOS};📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
|
|
||||||
| #[allow(unreachable_code)] | ||||||
| fn main() { | ||||||
|
|
@@ -15,45 +12,14 @@ fn main() { | |||||
| fn run() { | ||||||
| use objc2::{MainThreadMarker, rc::Retained}; | ||||||
| use objc2_app_kit::{NSApplication, NSCursor}; | ||||||
| use sha2::{Digest, Sha256}; | ||||||
|
|
||||||
| let mtm = MainThreadMarker::new().expect("Not on main thread"); | ||||||
| let _app: Retained<NSApplication> = NSApplication::sharedApplication(mtm); | ||||||
|
|
||||||
| let cursors = vec![ | ||||||
| ("arrow", NSCursor::arrowCursor()), | ||||||
| ("contextualMenu", NSCursor::contextualMenuCursor()), | ||||||
| ("closedHand", NSCursor::closedHandCursor()), | ||||||
| ("crosshair", NSCursor::crosshairCursor()), | ||||||
| ("disappearingItem", NSCursor::disappearingItemCursor()), | ||||||
| ("dragCopy", NSCursor::dragCopyCursor()), | ||||||
| ("dragLink", NSCursor::dragLinkCursor()), | ||||||
| ("IBeam", NSCursor::IBeamCursor()), | ||||||
| ("openHand", NSCursor::openHandCursor()), | ||||||
| ("operationNotAllowed", NSCursor::operationNotAllowedCursor()), | ||||||
| ("pointingHand", NSCursor::pointingHandCursor()), | ||||||
| ("resizeDown", NSCursor::resizeDownCursor()), | ||||||
| ("resizeLeft", NSCursor::resizeLeftCursor()), | ||||||
| ("resizeLeftRight", NSCursor::resizeLeftRightCursor()), | ||||||
| ("resizeRight", NSCursor::resizeRightCursor()), | ||||||
| ("resizeUp", NSCursor::resizeUpCursor()), | ||||||
| ("resizeUpDown", NSCursor::resizeUpDownCursor()), | ||||||
| ("IBeamVertical", NSCursor::IBeamCursorForVerticalLayout()), | ||||||
| ]; | ||||||
|
|
||||||
| unsafe { | ||||||
| let mut cursor_lookup = HashMap::new(); | ||||||
|
|
||||||
| for (name, cursor) in cursors { | ||||||
| let hash = hex::encode(Sha256::digest( | ||||||
| cursor | ||||||
| .image() | ||||||
| .TIFFRepresentation() | ||||||
| .expect("Failed to get TIFF representation of built-in cursor") | ||||||
| .as_bytes_unchecked(), | ||||||
| )); | ||||||
| println!("{name}: {hash}"); | ||||||
| cursor_lookup.insert(hash, name); | ||||||
| } | ||||||
| let cursor_hash_map = CursorShapeMacOS::get_cursor_cache(); | ||||||
| println!("Cursors hash map: {:#?}", cursor_hash_map); | ||||||
|
|
||||||
| println!("\nStarting cursor monitoring...\n"); | ||||||
|
|
||||||
|
|
||||||
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.
os_infoshould be a regular dependency, not a dev-dependency.The
os_infocrate is used byis_tahoe()which is called fromget_cursor_cache()in production code (e.g.,studio_recording.rs). Dev-dependencies are only available for tests, examples, and benchmarks—not for library code. This will cause compilation failures on macOS builds.Apply this diff to fix the dependency section:
Alternatively, if
objc2andobjc2-app-kitshould remain dev-dependencies (for the CLI example), move onlyos_infoto a separate[target.'cfg(target_os = "macos")'.dependencies]section.📝 Committable suggestion
🤖 Prompt for AI Agents