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

Set ActivationPolicy::Regular for macos in window example #3959

Closed

Conversation

nicoburns
Copy link
Contributor

@nicoburns nicoburns commented Oct 23, 2024

  • 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
  • Updated feature matrix, if new features were added or implemented

This fixes #3958. But possibly the default in Winit ought to change back, as it doesn't seem right that all users on macOS need to set this policy.

If I'm reading #3920 right, then it may be that this needs to be explicitly set when a rust binary is run standalone, but will be set automatically if the rust binary is wrapped in a macOS app package. I'm not quite sure how best to handle this. Perhaps we can detect which environment we're in somehow.

Unfortunately NSApplication::activationPolicy() seems to return 2 regardless of whether the setActivationPolicy() method is called, but keyboard events only work if it is.

@nicoburns
Copy link
Contributor Author

@purajit Perhaps you might have a recommendation?

@purajit
Copy link
Contributor

purajit commented Oct 23, 2024

(Just a disclaimer I'm not a Mac developer, just an infra engineer who happened to look into
this issue, and if anyone has differing opinions they're probably more correct than mine)

I actually did wonder about what to do for the window example in that PR. As for the general
case of standalone non-bundled applications, I agree it doesn't make sense to have every
developer explicitly set ActivationPolicy. I see that NSRunningApplication provides bundle
information via bundleIdentifier, which should help us out here.

The value of this property will be nil if the application does not have an Info.plist.

I can PR this some time tomorrow, and hopefully that would mean the window example should
work as expected with no changes. If this is serious/urgent enough (like blocking a release), I'm
OK with having my PR reverted, and I can re-do it with the bundleIdentifier fix.

And apologies to anyone who hit this problem! Since a release hasn't yet been cut, I hope it didn't
impact too many people, and that this was caught early.

@madsmtm
Copy link
Member

madsmtm commented Oct 25, 2024

Thanks for submitting the issue and both PRs, I prefer the solution in #3961.

@madsmtm madsmtm closed this Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

macOS: window example doesn't accept keyboard focus
3 participants