-
Notifications
You must be signed in to change notification settings - Fork 904
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
WIP – Android EventLoop 2.0 #1001
Conversation
I don't like abusing command-line arguments for state loading. As you already are (proposing to be) using an ext. trait for saving, why not also use that trait for loading? |
Haha, that's a much better idea! You don't really need an event loop to load state, though, so my recommendation is just a free function, called |
I'm totally down with you reworking Anyhow, you had questions:
We need to put more thought into the IME API and I'm not sure it's applicable on Android, so you should be able to safely ignore it for now.
Ya'know, there's been some discussion on having an "application quit" event in #41, and that may be applicable here. As for now, I'd suggest using
I believe the iOS backend currently panics, but there isn't really a good option here. |
Thanks for working on this! Display cutout support would also be wonderful! On iOS,
I suspect panicking makes sense on android too. I'd have to read a lot more docs to be sure. Neither OS really wants an app to close itself.
Again, I can only speak to what the iOS backend does, but it simply transitions the |
One potential option for |
@mb64 can you clarify how many layers of glue you are looking at reworking? This is my understanding of the current pieces:
I think the following approach would be nicer:
The approach seems much cleaner than the current approach and would reduce coupling between glue and cargo-apk and make it much easier to use the glue crate outside without cargo-apk. I couldn't tell if what you were thinking was similar to this or if you had other thoughts. |
@philip-alldredge This is pretty much what I'm thinking, though with slightly different specifics.
I don't have any attachments to this hierarchy; if it makes more sense to split The order of operations seems to me to be:
|
@mb64 I don't have strong enough feelings about the name to push for renaming. The ordering of things looks reasonable to me. The permission request will require JNI. |
@mb64 after some additional thought, I've reconsidered my comment about renaming and organization of things. Personally, I think it would be best to have That's just my opinion. You are the one putting in the effort to improve things so ultimately, it's up to you. |
I've noticed a lot of traffic on https://github.com/rust-windowing/android-rs-glue. What's the status of this? |
What is blocking this and how can we help? |
Here's the progress so far, and what needs to be done:
Finally,
If you want to help:
|
Where the changes to |
Made some progress, enough to get my port of flutter-rs to winit to display something on android. Still need to figure out how to get the screen density and handle orientation changes correctly and a couple of other issues. |
@dvc94ch Want to submit a PR? |
There's a couple of kinks that need to be worked out. And the |
Depends on rust-mobile/android-rs-glue#220
Starts to help out with #948.
This implementation is not great, undocumented, unfinished, and in some cases, unsound or incorrect. It's intended just to have the overall structure down, to be able to make gradual progress as different pieces of it are switched out for actual, better implementations.
It does, however, minimally work; I am able to log events on my phone.
These are the different "sub-parts" that need work:
The event loop
android-rs-glue
has known issues, as well as hard-to-maintain cross-ffi datastructures and I think a general overhaul is warranted. (Of theglue code – this is (mostly) independant of the build system.)
Currently,
android-rs-glue
startsmain
in a separate thread, then polls events, parses them, and sends them on a mpsc channel. I would like to transition the glue code away from this, instead givingmain
direct access to theALooper
, likely through a nice API that wraps the FFI calls. This gives Winit the ability to parse theAInputEvent
s directly into Winit events, avoiding intermediaries, and also removes a layer (one of many) of glue.This might mean you can't run the event loop in threads other than the main one; I'm not certain/haven't done any tests. (iOS already sets a precedent for only allowing things in the main thread, though.)
When an activity is destroyed, Android asks it to save its state as a
&[u8]
, then gives this data back when it restarts it later. This is somewhat incompatible with the normal C entrypoint ofint main(int argc, char **argv)
. Here's my idea to deal with this:String
."android"
, then the saved state.This part is a fairly major change for
android-rs-glue
, so I'd like to discuss this and get an OK before I work on its implementation.Support for multi-window
Multi-window is Android's term for things like split screen and Samsung's pop-up view floating apps. While it's a nice feature, it does make life more complicated when implementing Window stuff. I mostly ignored it in this initial implementation.
Multiple displays
It is possible to use multiple displays with Android phones. (For example, the Motorola Lapdock.) This implementation assumes only one monitor. This should be fixed.
Hidpi, window attributes, etc.
The hardcoded hidpi factor of 1 should be replaced. Information about display density can be found in the AConfiguration associated with the android_app, and can be mapped to hidpi factors using the table here.
Currently it ignores window attributes; this needs to be implemented.
There are various other details that need attending to, such as:
Docs and tests
Last but not least, the documentation and tests should be updated for Android.
Some of these things are fairly straightforward. Hidpi support is probably the easiest of these items. If my ideas are OK'd, updating
android-rs-glue
will take some work, but seems doable.However, I'm not at all well-versed in API's for multi-window or multiple displays. So if there's an Android guru reading this with free time, consider helping out.
A couple of questions I had along the way:
set_ime_position
supposed to do?run
do when the app is closed?run
do if the event handler sets it toControlFlow::Exit
?