-
Notifications
You must be signed in to change notification settings - Fork 928
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
Implement apple standard keybinding events #3824
Implement apple standard keybinding events #3824
Conversation
755ec91
to
d18a7da
Compare
d18a7da
to
8e756da
Compare
bff5281
to
ffe0825
Compare
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.
Such things should be routed via macOS specific application handler and not be a part of WindowEvent
.
In general, given that macOS application delegate will be exposed, such very specific things could be done out of tree?
But I'll leave it up to @madsmtm , from my point as long as it stays inside the macOS backend only it's fine by me.
I would like to say that from a Linebender perspective, this is very important. To clarify, is the suggested way forward to add a method to fn macos_text_input(&mut self, event_loop: &ActiveEventLoop, window_id: WindowId, event: AppleStandardKeyBindingAction) {} I think this does belong in the winit tree. Any user who is seriously developing an application using Winit will likely need text input; and to implement text input on macOS properly, you need to have access to these events. |
I'm not saying that it shouldn't be in winit, I'm saying that it should be on a macOS specific application handler, that's about it. |
When you say "a macOS specific application handler", would a A |
Handler as in a separate trait with macOS events, etc. similar for link openings, etc. User will just implement that macOS trait and you'll call to them based on whether they implement it. Though, there's an issue with the fact that we accept a generic In general, see rust-windowing/winit-next#4 for ideas, it's already kind of possible to do. |
Hmm... that I'd be keen to avoid blocking practical improvements on designing the perfect API if possible. We can always improve / move the API later, and events/methods that exist in the API but are simply never generated on some platforms seems like a non-issue for users of winit (and is already the case for many winit APIs). Regarding platform-specific traits: Might a simpler approach to just require the appropriate platform-specific traits (in the
(and similar for other platforms the user is targeting) One concern I have around platform-specific traits in general is that they might make it more difficult to share functionality between platforms. For example, where does functionality shared between ios/macos or x11/wayland live in this model? Do we end up with a whole hierarchy of traits? Maybe that's fine. |
I'm saying that you already kind of can do so. I'll look myself in the next few days with a ways to adapt this PR to what winit-next does. |
Trait usually should be per specific feature and not just platform, see e.g. |
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.
@nicoburns: I have updated this PR so that updating the standard key bindings is possible without breaking changes (avoid Other(...)
, use #[non_exhaustive]
). If there is some use-case for Other
that I don't know about, then I'd probably prefer not trying to create an enum, and instead just pass the &str
directly to the user. I also removed noop:
, but unsure if that was correct?
@kchibisov: Additionally, I have made it use an extension trait ApplicationHandlerExtMacOS
. I could not get the app.as_any_mut().downcast_mut()
trick to work that you have outlined in rust-windowing/winit-next#4, since dyn ApplicationHandler
is not Sized
, so I've gone with a suboptimal solution for now. Feel free to push to this PR if there's a better way to solve it.
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.
Should be fine for now.
The other approach doesn't work with raw downcast
you need to have vtable like structure which will require a lot of refactorings in macOS backend, I guess.
The
(relatedly, I'm not sure if there are ever I'm actually thinking that just passing through the
|
Yeah, the problem with the Anyhow, I've pushed a commit to just pass through I've also allowed |
Might make sense to just have a module with a bunch of |
Kinda feel like there isn't much value in that if Nico plans to make a separate crate anyhow. Besides, a typo would be quickly found while testing (and a typo could also be there in our |
Is there anything blocking this now? (It's looking pretty good to me!) |
756448c
to
1860fe0
Compare
I've pushed a commit which fixes the build. But I'm unable to verify that this is actually (still) working due to #3958 |
Ok, by applying #3959 on top of this PR (which fixes keyboard events on macos in the @kchibisov I believe this is just waiting on final signoff from you, having been already reviewed and reworked by @madsmtm. I know there are a number of Rust GUI frameworks eagerly awaiting this functionality (including mine), so let me know if there's anything I can do to help push it along. |
src/changelog/unreleased.md
Outdated
@@ -60,6 +60,7 @@ changelog entry. | |||
and `Serialize` on many types. | |||
- Add `MonitorHandle::current_video_mode()`. | |||
- Add basic iOS IME support. The soft keyboard can now be shown using `Window::set_ime_allowed`. | |||
- Add `WindowEvent::AppleStandardKeyBindingAction`. This can be used to implement standard behaviours such as "go to end of line" on macOS. |
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.
This is outdated and should mention the new application trait/etc.
Allows users to respond to standard system-generated keybinding commands on macOS (https://developer.apple.com/documentation/appkit/nsstandardkeybindingresponding). This is important to make text inputs in Rust GUIs feel native on macOS.
The actual implementation of the commands is left up to the user. This implementation merely passes the events into the event loop to allow the user to do so.
changelog
module if knowledge of this change could be valuable to users