Skip to content
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

macOS: Fix selector response checking for undocumented cursors #4033

Merged
merged 1 commit into from
Dec 8, 2024

Conversation

slice
Copy link
Contributor

@slice slice commented Dec 8, 2024

AnyClass::responds_to delegates to class_respondsToSelector, a function provided by the Objective-C runtime. However, at some point, this began to return false for selectors referring to undocumented cursors, despite the cursors remaining accessible via said selectors. That this check fails prevents the cursors from being used.

We can instead send respondsToSelector: to the NSCursor class itself. As an instance method, this is nominally impossible; however, Apple grants an exemption that permits class objects to perform instance methods defined in the root class.

Checking for the undocumented cursors in this way gets them working again, at least on macOS Sequoia 15.1.1.

  • Tested on all platforms changed
  • Added an entry to the changelog module if knowledge of this change could be valuable to users
  • Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior
  • Created or updated an example program if it would help users understand this functionality

This is my first contribution to winit so please let me know if I missed anything! cc @madsmtm

This should fix #3724.

`AnyClass::responds_to` delegates to `class_respondsToSelector`, a
function provided by the Objective-C runtime. However, at some point,
this began to return `false` for selectors referring to undocumented
cursors, despite the cursors remaining accessible via said selectors.
That this check fails prevents the cursors from being used.

We can instead send `respondsToSelector:` to the `NSCursor` class
itself. As an instance method, this is nominally impossible; however,
Apple grants an exemption[1] that permits class objects to perform
instance methods defined in the root class.

[1]: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocObjectsClasses.html#//apple_ref/doc/uid/TP30001163-CH11-TPXREF120

Checking for the undocumented cursors in this way gets them working
again, at least on macOS Sequoia 15.1.1.
@slice slice requested a review from madsmtm as a code owner December 8, 2024 20:53
@madsmtm madsmtm added DS - macos B - crash The bug results in crashing B - bug Dang, that shouldn't have happened and removed B - crash The bug results in crashing labels Dec 8, 2024
Copy link
Member

@madsmtm madsmtm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@madsmtm madsmtm merged commit 5835c91 into rust-windowing:master Dec 8, 2024
58 checks passed
@madsmtm madsmtm added this to the Version 0.30.6 milestone Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B - bug Dang, that shouldn't have happened DS - macos
Development

Successfully merging this pull request may close these issues.

Various cursors cannot be displayed on macOS
2 participants