From db5eefbf00372d5aeda000bf5aeb6e00fa030ed4 Mon Sep 17 00:00:00 2001 From: Sergio Villar Senin Date: Wed, 28 Feb 2024 11:21:28 +0100 Subject: [PATCH] Restore back action using B/Y buttons in non-WebXR mode In a3f4cb4c 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 --- app/src/main/cpp/BrowserWorld.cpp | 15 +++++++++++++-- docs/metrics.md | 4 ++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/src/main/cpp/BrowserWorld.cpp b/app/src/main/cpp/BrowserWorld.cpp index e54a290226..9e284f9114 100644 --- a/app/src/main/cpp/BrowserWorld.cpp +++ b/app/src/main/cpp/BrowserWorld.cpp @@ -275,6 +275,17 @@ 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()) { @@ -282,7 +293,7 @@ BrowserWorld::State::CheckBackButton() { 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 @@ -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 { diff --git a/docs/metrics.md b/docs/metrics.md index d54983a958..864931ba7c 100644 --- a/docs/metrics.md +++ b/docs/metrics.md @@ -1,4 +1,4 @@ - + # Metrics @@ -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). - +