Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit f41255c

Browse files
authored
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
1 parent c20caf2 commit f41255c

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ struct DeviceDelegateOculusVR::State {
101101
vrb::Color clearColor;
102102
float near = 0.1f;
103103
float far = 100.f;
104+
bool hasEventFocus = true;
104105
std::vector<ControllerState> controllerStateList;
105106
crow::ElbowModelPtr elbow;
106107
ControllerDelegatePtr controller;
@@ -330,6 +331,13 @@ struct DeviceDelegateOculusVR::State {
330331
controllerState.enabled = false;
331332
}
332333

334+
if (!hasEventFocus) {
335+
for (ControllerState& controllerState: controllerStateList) {
336+
controller->SetVisible(controllerState.index, controllerState.enabled);
337+
}
338+
return;
339+
}
340+
333341
uint32_t count = 0;
334342
ovrInputCapabilityHeader capsHeader = {};
335343
while (vrapi_EnumerateInputDevices(ovr, count++, &capsHeader) >= 0) {
@@ -397,6 +405,10 @@ struct DeviceDelegateOculusVR::State {
397405
return;
398406
}
399407

408+
if (!hasEventFocus) {
409+
return;
410+
}
411+
400412
for (ControllerState& controllerState: controllerStateList) {
401413
if (controllerState.deviceId == ovrDeviceIdType_Invalid) {
402414
continue;
@@ -794,6 +806,30 @@ DeviceDelegateOculusVR::SetCPULevel(const device::CPULevel aLevel) {
794806

795807
void
796808
DeviceDelegateOculusVR::ProcessEvents() {
809+
ovrEventDataBuffer eventDataBuffer = {};
810+
ovrEventHeader* eventHeader = (ovrEventHeader*)(&eventDataBuffer);
811+
// Poll for VrApi events at regular frequency
812+
while (vrapi_PollEvent(eventHeader) == ovrSuccess) {
813+
814+
switch (eventHeader->EventType) {
815+
case VRAPI_EVENT_FOCUS_GAINED:
816+
// FOCUS_GAINED is sent when the application is in the foreground and has
817+
// input focus. This may be due to a system overlay relinquishing focus
818+
// back to the application.
819+
m.hasEventFocus = true;
820+
break;
821+
case VRAPI_EVENT_FOCUS_LOST:
822+
// FOCUS_LOST is sent when the application is no longer in the foreground and
823+
// therefore does not have input focus. This may be due to a system overlay taking
824+
// focus from the application. The application should take appropriate action when
825+
// this occurs.
826+
m.hasEventFocus = false;
827+
break;
828+
default:
829+
break;
830+
}
831+
}
832+
797833
ovrMessageHandle message;
798834
while ((message = ovr_PopMessage()) != nullptr) {
799835
switch (ovr_Message_GetType(message)) {
@@ -879,8 +915,6 @@ DeviceDelegateOculusVR::StartFrame(const FramePrediction aPrediction) {
879915
ovrMatrix4f matrix = vrapi_GetTransformFromPose(&m.predictedTracking.HeadPose.Pose);
880916
vrb::Matrix head = vrb::Matrix::FromRowMajor(matrix.M[0]);
881917

882-
883-
884918
if (m.renderMode == device::RenderMode::StandAlone) {
885919
head.TranslateInPlace(kAverageHeight);
886920
}

app/src/oculusvrArmDebug/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
<uses-permission android:name="android.permission.CAMERA" tools:node="remove"/>
66
<uses-permission android:name="${permissionToRemove}" tools:node="remove" />
77
<application>
8-
<meta-data android:name="com.samsung.android.vr.application.mode" android:value="vr_only"/>
8+
<meta-data android:name="com.samsung.android.vr.application.mode" android:value="vr_only" />
99
<activity android:name=".VRBrowserActivity" android:screenOrientation="landscape">
10+
<meta-data android:name="com.oculus.vr.focusaware" android:value="true" />
1011
<meta-data android:name="android.app.lib_name" android:value="native-lib" />
1112
</activity>
1213
</application>

app/src/oculusvrArmRelease/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
android:supportsPictureInPicture="false"
3131
tools:node="replace"
3232
>
33+
<meta-data android:name="com.oculus.vr.focusaware" android:value="true" />
3334
<meta-data android:name="android.app.lib_name" android:value="native-lib" />
3435
<intent-filter>
3536
<action android:name="android.intent.action.MAIN" />

0 commit comments

Comments
 (0)