-
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
Android: Change default implementation to ignore volume keys and let operating system handle them #2748
Android: Change default implementation to ignore volume keys and let operating system handle them #2748
Conversation
Yeah, this seems reasonable to me. By default it's very unlikely an application wants to intercept the volume keys so this is pretty terrible behaviour atm. It seems like ideally Winit would also support the notion that an application might not handle a key event and would have a way for apps to give that feedback which we could just forward to One thing I'm not 100% sure of atm is the status of any embargo from wanting to land the Keyboard 2.0 changes in Winit? Would we be able to land a change like this atm @kchibisov / @msiglreith ? I think the Keyboard 2.0 changes need some reworking for Android anyway though, so I tend to think it would be reasonable to land this now. |
Use To sum up, for now abuse the extensions for Android, they should just work for you.
I general I wanted to merge the keyboard input v2 PR, given that it has some approvals, was used for a long time in some projects, and had only minor issues which were trivial to resolve(or look trivial to resolve). However the things got stalled due to MIA of its authors and I can't take over it myself really.
As long as you can submit android patches for keyboard v2 yourself you can merge stuff. I'll do something like that with Wayland anyway. P.s. I swear I've replied to it, but I have no clue where my reply is, given that you like post similar things on multiple issues(which is good, but I listen to all the issue and process them in a queue) I might already replied to you in the past. |
Yeah, as you say other platforms don't generally let apps return a filter status like on Android, so returning a status probably wouldn't be a great fit for other platforms. This kind of It's surely pretty uncommon to want to change the behaviour of your volume keys, so it makes sense that this PR changes the default behaviour but still provides a way to intercept the volume keys if really needed. You could imagine some situations where you might want to be able to change this dynamically but we could add an extension for that later if necessary.
Yeah, I'd be happy to provide updated Android changes for the keyboard 2.0 work if needed.
Right, sorry if I missed something. Was it something about Keyboard 2.0 changes? I haven't really followed the Keyboard 2.0 work that closely. The only thing I can really recall commenting on related to keyboard 2.0 was the Android code that surprisingly dug into My impression was that it should be (hopefully) straight forward to address this - and I don't mind doing that at some point if there's a consensus about landing this PR. |
On Windows there is a similar use case regarding handling of system keybinds ( |
The thing is that we'd likely want keyboard v2 to have a way to pass some identity of the key events to the winit or so. Is windows have a per-key basis for passthrough, or is it more like all or nothing? |
Windows would be on a per key basis similar to Android. Looking at the v2 branch, a key event extension might be useful. |
I'm not aware of what new functionality the new Keyboard 2.0 The PR does not describe what it does?
I personally feel that the new functionality introduced here is so limited in scope that it can easily be removed if it turns out that Keyboard 2.0 does indeed solve this functionality later on. And having the ability to configure more advanced use-cases using a |
Keyboard v2 defines key related functions and key codes in crossplatform way, so you can at least use them to pass into window builder. |
If it makes ppl more at ease I can also remove the |
I still tend to think that this change is pretty much reasonable as is - even though I also raised the idea that maybe it would be ideal if Winit had a way for apps to report when a key was handled or not. The default behaviour for volume keys is basically broken for most Android apps currently, and this PR addresses that. An Android-specific Seems a bit like one of those "don't let perfect be the enemy of good" things. Ideally we wouldn't need to wait for keyboard 2.0 or a redesign of the input APIs to address this issue in Android for now. |
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.
fine for me as we also have a rough outline how to adjust it in the future once keyboard v2 lands
Yeah when that lands changes are expected. Seeing that it has been reviewed, what is the process for this to be merged? I also see that a few of the checks are failing due to unrelated things. I'm also unsure if this counts as a breaking change or not. I would in this case not view it as a breaking change as this behavior is the expected default behavior. But if you rely on having the audio be handled by the app this is definitely a change you will notice as it may break the experience... |
sry for the delay! With the keyboard event refactoring merged would you mind rebasing? |
7ff041b
to
0772b2f
Compare
@msiglreith I just rebased now |
I wouldn't call it unlikely, we rely on it for very simple use-cases. Unfortunately I only got pinged about this just now that #1919 was closed. Wasn't keyboard v2 (which is also now merged) supposed to fix this proper? |
Well, properly is more like, we have a way to refer to keys now, it's just default is flipped, so you can opt-in. |
@MarijnS95 in your case you would need to specify the following when creating the event loop. let event_loop = EventLoopBuilder::with_user_event()
.with_android_app(app)
.handle_volume_keys() // Add this line to make your app handle the volume keys
.build(); Then things should work as they did before this change. Or do you for see that this will cause any other problems? |
@Hoodad I know what to do to fix it, I just don't like having to fix it like that. But that's part of a bigger issue where we can supposedly still not ad-hoc decide whether or not to handle a |
@MarijnS95 can't we have an extension on a |
On Android, change default implementation to ignore volume keys and let operating system handle them (rust-windowing#2748)
…et operating system handle them (rust-windowing#2748)
…et operating system handle them (rust-windowing#2748)
…et operating system handle them (rust-windowing#2748)
It seems that discussions around rust-windowing#2748 being a poor workaround that should rather be implemented properly/differently drowned out the fact that the workaround was implemented incorrectly to begin with. By having the `if` inside the match arm, rather than /on/ the match arm the `keycode =>` path is /never/ used for `Volume*` keys and this event is thus never passed on to the user, defeating the purpose of calling `handle_volume_keys()`. Only the `Handled`/`Unhandled` state is affected by the `ignore_volume_keys` workaround, as set by `EventLoopBuilderExtAndroid::handle_volume_keys()`. Fix this by moving the `if` workaround on the match arm, so that disabling it via `EventLoopBuilderExtAndroid::handle_volume_keys()` causes `Volume*` events to be delivered to user code once again.
It seems that discussions around rust-windowing#2748 being a poor workaround that should rather be implemented properly/differently drowned out the fact that the workaround was implemented incorrectly to begin with. By having the `if` inside the match arm, rather than /on/ the match arm the `keycode =>` path is /never/ used for `Volume*` keys and this event is thus never passed on to the user, defeating the purpose of calling `handle_volume_keys()`. Only the `Handled`/`Unhandled` state is affected by the `ignore_volume_keys` workaround, as set by `EventLoopBuilderExtAndroid::handle_volume_keys()`. Fix this by moving the `if` workaround on the match arm, so that disabling it via `EventLoopBuilderExtAndroid::handle_volume_keys()` causes `Volume*` events to be delivered to user code once again.
It seems that discussions around rust-windowing#2748 being a poor workaround that should rather be implemented properly/differently drowned out the fact that the workaround was implemented incorrectly to begin with. By having the `if` inside the match arm, rather than /on/ the match arm the `keycode =>` path is /never/ used for `Volume*` keys and this event is thus never passed on to the user, defeating the purpose of calling `handle_volume_keys()`. Only the `Handled`/`Unhandled` state is affected by the `ignore_volume_keys` workaround, as set by `EventLoopBuilderExtAndroid::handle_volume_keys()`. Fix this by moving the `if` workaround on the match arm, so that disabling it via `EventLoopBuilderExtAndroid::handle_volume_keys()` causes `Volume*` events to be delivered to user code once again.
It seems that discussions around rust-windowing#2748 being a poor workaround that should rather be implemented properly/differently drowned out the fact that the workaround was implemented incorrectly to begin with. By having the `if` inside the match arm, rather than /on/ the match arm the `keycode =>` path is /never/ used for `Volume*` keys and this event is thus never passed on to the user, defeating the purpose of calling `handle_volume_keys()`. Only the `Handled`/`Unhandled` state is affected by the `ignore_volume_keys` workaround, as set by `EventLoopBuilderExtAndroid::handle_volume_keys()`. Fix this by moving the `if` workaround on the match arm, so that disabling it via `EventLoopBuilderExtAndroid::handle_volume_keys()` causes `Volume*` events to be delivered to user code once again.
It seems that discussions around rust-windowing#2748 being a poor workaround that should rather be implemented properly/differently drowned out the fact that the workaround was implemented incorrectly to begin with. By having the `if` inside the match arm, rather than /on/ the match arm the `keycode =>` path is /never/ used for `Volume*` keys and this event is thus never passed on to the user, defeating the purpose of calling `handle_volume_keys()`. Only the `Handled`/`Unhandled` state is affected by the `ignore_volume_keys` workaround, as set by `EventLoopBuilderExtAndroid::handle_volume_keys()`. Fix this by moving the `if` workaround on the match arm, so that disabling it via `EventLoopBuilderExtAndroid::handle_volume_keys()` causes `Volume*` events to be delivered to user code once again.
It seems that discussions around rust-windowing#2748 being a poor workaround that should rather be implemented properly/differently drowned out the fact that the workaround was implemented incorrectly to begin with. By having the `if` inside the match arm, rather than /on/ the match arm the `keycode =>` path is /never/ used for `Volume*` keys and this event is thus never passed on to the user, defeating the purpose of calling `handle_volume_keys()`. Only the `Handled`/`Unhandled` state is affected by the `ignore_volume_keys` workaround, as set by `EventLoopBuilderExtAndroid::handle_volume_keys()`. Fix this by moving the `if` workaround on the match arm, so that disabling it via `EventLoopBuilderExtAndroid::handle_volume_keys()` causes `Volume*` events to be delivered to user code once again.
The Issue
Current Android implementation will always mark the volume keys as handled by the application (window) overriding the default operating system behavior. This is a bit unexpected I would argue the opposite would be expected as default, to opt in to override default operating system behavior.
The Change
Volume Up/Down & Mute
will all be marked as unhandled by the application. Letting the operating system handle them.EventLoopBuilderExtAndroid::handle_volume_keys
for applications that want to manually handle the volume keys.Remarks
This could be considered a breaking change from a users point of view, even though I would argue this is the "correct" default. So I'm not sure how or if that should be reflected in the
CHANGELOG.md
.This PR is heavily inspired by the PR #1919
CHANGELOG.md
if knowledge of this change could be valuable to usersHow to make the app handle volume keys