From f41255cca72d5fd16fa7c095b773cde85b822f87 Mon Sep 17 00:00:00 2001 From: "Randall E. Barker" Date: Thu, 16 Apr 2020 03:13:05 -0700 Subject: [PATCH] Add support for Oculus Focus Awareness (#3158) From the docs: To enable overlay for testing purposes, enter the following commands in a terminal: Go to Setting -> See All -> Experiments and enable New Universal Menu adb shell setprop debug.oculus.dbg_enable_overlay 1 adb shell am force-stop com.oculus.vrshell After entering these commands, if an app has overlay support enabled in its app manifest, pressing the Oculus button from inside the app will cause the Universal Menu to be displayed as an overlay. To disable overlay support, enter the following commands: adb shell setprop debug.oculus.dbg_enable_overlay 0 adb shell am force-stop com.oculus.vrshell --- .../oculusvr/cpp/DeviceDelegateOculusVR.cpp | 38 ++++++++++++++++++- app/src/oculusvrArmDebug/AndroidManifest.xml | 3 +- .../oculusvrArmRelease/AndroidManifest.xml | 1 + 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp b/app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp index c8bfdd9ff..68b3f1a30 100644 --- a/app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp +++ b/app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp @@ -101,6 +101,7 @@ struct DeviceDelegateOculusVR::State { vrb::Color clearColor; float near = 0.1f; float far = 100.f; + bool hasEventFocus = true; std::vector controllerStateList; crow::ElbowModelPtr elbow; ControllerDelegatePtr controller; @@ -330,6 +331,13 @@ struct DeviceDelegateOculusVR::State { controllerState.enabled = false; } + if (!hasEventFocus) { + for (ControllerState& controllerState: controllerStateList) { + controller->SetVisible(controllerState.index, controllerState.enabled); + } + return; + } + uint32_t count = 0; ovrInputCapabilityHeader capsHeader = {}; while (vrapi_EnumerateInputDevices(ovr, count++, &capsHeader) >= 0) { @@ -397,6 +405,10 @@ struct DeviceDelegateOculusVR::State { return; } + if (!hasEventFocus) { + return; + } + for (ControllerState& controllerState: controllerStateList) { if (controllerState.deviceId == ovrDeviceIdType_Invalid) { continue; @@ -794,6 +806,30 @@ DeviceDelegateOculusVR::SetCPULevel(const device::CPULevel aLevel) { void DeviceDelegateOculusVR::ProcessEvents() { + ovrEventDataBuffer eventDataBuffer = {}; + ovrEventHeader* eventHeader = (ovrEventHeader*)(&eventDataBuffer); + // Poll for VrApi events at regular frequency + while (vrapi_PollEvent(eventHeader) == ovrSuccess) { + + switch (eventHeader->EventType) { + case VRAPI_EVENT_FOCUS_GAINED: + // FOCUS_GAINED is sent when the application is in the foreground and has + // input focus. This may be due to a system overlay relinquishing focus + // back to the application. + m.hasEventFocus = true; + break; + case VRAPI_EVENT_FOCUS_LOST: + // FOCUS_LOST is sent when the application is no longer in the foreground and + // therefore does not have input focus. This may be due to a system overlay taking + // focus from the application. The application should take appropriate action when + // this occurs. + m.hasEventFocus = false; + break; + default: + break; + } + } + ovrMessageHandle message; while ((message = ovr_PopMessage()) != nullptr) { switch (ovr_Message_GetType(message)) { @@ -879,8 +915,6 @@ DeviceDelegateOculusVR::StartFrame(const FramePrediction aPrediction) { ovrMatrix4f matrix = vrapi_GetTransformFromPose(&m.predictedTracking.HeadPose.Pose); vrb::Matrix head = vrb::Matrix::FromRowMajor(matrix.M[0]); - - if (m.renderMode == device::RenderMode::StandAlone) { head.TranslateInPlace(kAverageHeight); } diff --git a/app/src/oculusvrArmDebug/AndroidManifest.xml b/app/src/oculusvrArmDebug/AndroidManifest.xml index 46f38efab..5ec863674 100644 --- a/app/src/oculusvrArmDebug/AndroidManifest.xml +++ b/app/src/oculusvrArmDebug/AndroidManifest.xml @@ -5,8 +5,9 @@ - + + diff --git a/app/src/oculusvrArmRelease/AndroidManifest.xml b/app/src/oculusvrArmRelease/AndroidManifest.xml index 3cccfd1be..a24b6f27e 100644 --- a/app/src/oculusvrArmRelease/AndroidManifest.xml +++ b/app/src/oculusvrArmRelease/AndroidManifest.xml @@ -30,6 +30,7 @@ android:supportsPictureInPicture="false" tools:node="replace" > +