Skip to content

Commit

Permalink
Restore back action using B/Y buttons in non-WebXR mode
Browse files Browse the repository at this point in the history
In a3f4cb4 we removed the possibility of going back with B/Y buttons
because that was interferring with potential action assignments of
those buttons inside WebXR experiences. We were exiting the WebXR
experience instead of executing the action that was set by authors.

However it turns out that these buttons are heavily used by users
in non-immersive sessions as they're very convenient as you don't
really have to hold both controllers to have full control of your
2D navigation.

Fixes #1266
  • Loading branch information
svillar committed Feb 28, 2024
1 parent 18e279a commit db5eefb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
15 changes: 13 additions & 2 deletions app/src/main/cpp/BrowserWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,14 +275,25 @@ BrowserWorld::State::SimulateBack() {
VRBrowser::HandleBack();
}

static bool
wasGoBackButtonClicked(const Controller& controller, bool isPresenting) {
auto WasButtonPressed = [](const Controller& controller, ControllerDelegate::Button button) {
return !(controller.lastButtonState & button) && (controller.buttonState & button);
};

return (WasButtonPressed(controller, ControllerDelegate::BUTTON_APP) ||
(!isPresenting && (WasButtonPressed(controller, ControllerDelegate::BUTTON_B) ||
WasButtonPressed(controller, ControllerDelegate::BUTTON_Y))));
};

void
BrowserWorld::State::CheckBackButton() {
for (Controller& controller: controllers->GetControllers()) {
if (!controller.enabled || (controller.index < 0)) {
continue;
}

if ((!(controller.lastButtonState & ControllerDelegate::BUTTON_APP) && (controller.buttonState & ControllerDelegate::BUTTON_APP))) {
if (wasGoBackButtonClicked(controller, externalVR->IsPresenting())) {
SimulateBack();
webXRInterstialState = WebXRInterstialState::HIDDEN;
} else if (webXRInterstialState == WebXRInterstialState::ALLOW_DISMISS
Expand Down Expand Up @@ -423,7 +434,7 @@ BrowserWorld::State::UpdateControllers(bool& aRelayoutWidgets) {
controller.pointer->Load(device);
}

if ((!(controller.lastButtonState & ControllerDelegate::BUTTON_APP) && (controller.buttonState & ControllerDelegate::BUTTON_APP))) {
if (wasGoBackButtonClicked(controller, externalVR->IsPresenting())) {
if (controller.handActionEnabled && !controller.leftHanded) {
VRBrowser::HandleAppExit();
} else {
Expand Down
4 changes: 2 additions & 2 deletions docs/metrics.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- AUTOGENERATED BY glean_parser v11.0.1. DO NOT EDIT. -->
<!-- AUTOGENERATED BY glean_parser v11.1.0. DO NOT EDIT. -->

# Metrics

Expand All @@ -11,5 +11,5 @@ This means you might have to go searching through the dependency tree to get a f

Data categories are [defined here](https://wiki.mozilla.org/Firefox/Data_Collection).

<!-- AUTOGENERATED BY glean_parser v11.0.1. DO NOT EDIT. -->
<!-- AUTOGENERATED BY glean_parser v11.1.0. DO NOT EDIT. -->

0 comments on commit db5eefb

Please sign in to comment.