-
Notifications
You must be signed in to change notification settings - Fork 909
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
Allow listening to file open events on macos #1759
Allow listening to file open events on macos #1759
Conversation
I created an example repo at https://github.com/ArturKovacs/winit_open_file |
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.
I personally think that adding callbacks to a library that is usually based on an event loop it ships itself makes things extremely annoying to use downstream.
The state management required to integrate with the rest of the application would likely just require locking whenever the shared state is accessed, all of which each downstream user is responsible for themselves.
That's a fair assesment. I made this implementation based on the discussion at #1751. Would you suggest using a platform specific event API instead? Something like: enum Event {
WindowEvent {...}
// All the other events events
PlatformSpecific(PlatformSpecificEvent)
}
enum MacOsEvent {
...
}
impl PlatformSpecificEventMacOsExt for PlatformSpecificEvent {
fn into_macos_event(self) -> MacOsEvent {...}
} |
Events are optional anyways. So it's probably easiest to just emit an event and document clearly when it is emitted. |
I agree but @alvinhochun seemed to be against adding a variant to |
@chrisduerr if you are in executive position I'll just implement this as an event so that this can be closed. Otherwise I'm in a rather uncomfortable situation here as I'm willing to go with either approach but I don't know what I'm supposed to do to get this resolved. I would like to get some guidance for what should be the next step from here. |
I am not. I am not the maintainer of the macOS backend. That would officially be @vbogaevsky I believe, I'm not sure if he's still around. Though if he's not around, I'm probably as good as it's gonna get. |
I just updated the implementation so that now an application level |
It seems to me that I addressed all the feedback. Is there anything I'm missing? |
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.
It seems to me that I addressed all the feedback. Is there anything I'm missing?
I'm not really a fan of how this is done in macOS and the resulting implementation in winit. So I personally don't really feel like it's going to be very beneficial to merge it.
To be honest I'm not really a fan either of how this is done in macOS, but if this is not exposed by winit, how should winit applications open associated files on macOS? I personally don't see any other way, and denying this feature would mean that no image viewer, video player, text editor, etc. could be properly made for macOS using winit. If this PR is not that way to solve the issue, that's fine, but I would be very sad if this wouldn't be solved at all. |
Some things, especially those that do not integrate at all with any other platforms (like this one), are better provided separately outside of winit. |
Okay, that's reasonable if said feature can be implemented outside of winit. I don't see how this could be done outside of winit while using winit for the rest. Please describe how that would be done. |
I wouldn't want to involve other contributors but we seem to be completely stuck with something that I believe is quite important for macOS applications. @francesca64 and @ryanisaacg you both seem to have the skills and the authority required to help find a solution here, so I'd like to ask you to help. |
Sorry, I've never done any macOS-related development. I just happen to have a mac that I can compile code on, but I don't know anything about mac-specific programming. |
It seems that the problem here is the lack of a generic way for users to handle native events that aren't handled by Winit. Since Winit is in control of the If this is true, then Winit should will need to expose these native events for users to intercept them, or perhaps there can be a way to allow the user to set their own I don't know macOS application programming at all so I can't really give any more constructive comments. |
/// This constant represents the one with an identical name in appkit. See: | ||
/// https://developer.apple.com/documentation/appkit/nsapplicationdelegatereply/nsapplicationdelegatereplysuccess?language=occ | ||
#[allow(non_upper_case_globals)] | ||
const NSApplicationDelegateReplySuccess: i32 = 0; |
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.
The ffi
module is our designated dumping ground for constants and such.
I actually wrote the macOS EL2 backend originally, even though I'm not involved in it much anymore. Feel free to ping me on macOS stuff until we find a new maintainer for it! Speaking of, @ArturKovacs, would you be interested in maintaining the macOS backend? You seem very thoughtful, and that's the main qualification (besides having time to burn). The implementation looks reasonable (I can give a proper review later), so it's just the design that's contentious here, wrt platform uniformity? If we don't believe this event will be used on other platforms, we could just add a macOS While there's merit in exploring ways that problems like this could be solved outside of winit, I don't think that's necessary in this case. The implementation is small, self-contained, and straightforward, and seems like a normal thing for winit to cover. |
Does it? It's not related to windowing at all, so it seems far more out of scope than many other topics that have been denied. |
@chrisduerr please address my comment above: #1759 (comment) |
This suprised me and made me very excited. I would definitely be interested, yes.
I would be fine with this. When you say receiver, are you referring to |
Awesome! You've been memberized. And yeah, |
I think the idea proposed by @alvinhochun makes much more sense for winit. Worrying mainly about windowing needs and allowing applications to hook into the platform specific APIs themselves when necessary. |
The part that's not clear to me about using a channel is how would we avoid leaking memory if many of these "events" end up being unhandled. We cannot guarantee that the receiver will be pulled from. In the first commmit of this PR I had an implementation which used the callback approach proposed by @alvinhochun but I didn't make an Admittedly this would require some method by which the closure gets transferred to the application delegate. Although I have to say I'm a bit confused about what's running on separate threads because I would think that the main thread, the event loop callback thread, and the application delegate thread are the same. |
Ah, that's a super good point. We could just only create the channel if the user calls the method to get the receiver, or are you thinking about the case where the user only pulls from it infrequently? Either way, I think I actually prefer the sound of the callback approach, since your point about indicating success sounds like something we definitely want.
Hey, me too! I once observed that the methods on our view were run asynchronously, which was scary... I don't really have a strong mental model of what happens once we cross the barrier into ObjC/AppKit land. |
Now setting the file open callback to `None` behaves identically to not specifying the delegate methods at all.
eb84065
to
2fb602a
Compare
I rebased these changes on top of the master and I don't experience the delay at startup anymore. For the record, the commit onto which this was rebased is 629cd86 |
Weird! There's only 3 commits that could've caused that, right? It might be worth bisecting to verify that it's actually fixed and not just an issue that comes and goes. |
I'm assuming you mean these three: Although these were also added between creating this PR and rebasing: I'm not sure how this could be bisected. If I understand correctly, all changes in this PR are on top of 629cd86, so when checking out a commit before this PR, I can't handle the "file open event". The best idea I had so far is to squash these changes on a local repo and rebase that on top of each of those commits and for each, test if the delay is there. |
I still have a copy of the not-rebased repo locally if that helps. I'm not sure what to do here. I guess the question is how do we become reasonably sure that the delay is fixed. (The difficulty is that it may |
I learned that I've been using the word "spurious" incorrectly 😬 I seem to remember that @madsmtm you mentioned somewhere that you intend to spend some time with this. (Maybe I only dreamt that :D) I just want to add that it would be very helpful because due to this, the macOS release of emulsion is really lacking. |
I spent a few hours trying this locally, and couldn't reproduce the delay you're experiencing - I also tried it on the older branch, and it wasn't present there either (I think, there were quite a lot of conflicts and stuff, so maybe I missed something). So yeah, idk. - it seems to work for me, but I'm not knowledgeable enough in the "savedState" / "restorable" stuff to tell for sure |
Hey; will this still be merged at some point? |
And if needs with help testing and updating this PR, I would be glad to take it as well cc @ArturKovacs |
I've posted some information on how I think the design of this feature should be in #1751 (comment). This does not entirely resolve usability concerns, though I think those are less important than getting something that at least works. I'm truly sorry for never getting this in, but I think the approach I've suggested there should be a good way forward (and could also set precedent for how we solve similar issues). I'll close this PR for now though, since a lot of the discussion + code is out of date, and I want to make space for a new implementation. |
Closes #1751
cargo fmt
has been run on this branchcargo doc
builds successfullyCHANGELOG.md
if knowledge of this change could be valuable to usersI did not check the example program point because I would indeed like to create an example for this but that would need to be bundled with
cargo bundle
and a script would be required to patch theInfo.plist
file in the bundle to allow associating certain file-types with the app. I could create an example program in a separate repo where all this is handled. But I'm not sure how that would be or if that should be referenced from this repo.