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

Commit

Permalink
Add support for Oculus Focus Awareness (#3158)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bluemarvin authored Apr 16, 2020
1 parent c20caf2 commit f41255c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
38 changes: 36 additions & 2 deletions app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ struct DeviceDelegateOculusVR::State {
vrb::Color clearColor;
float near = 0.1f;
float far = 100.f;
bool hasEventFocus = true;
std::vector<ControllerState> controllerStateList;
crow::ElbowModelPtr elbow;
ControllerDelegatePtr controller;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -397,6 +405,10 @@ struct DeviceDelegateOculusVR::State {
return;
}

if (!hasEventFocus) {
return;
}

for (ControllerState& controllerState: controllerStateList) {
if (controllerState.deviceId == ovrDeviceIdType_Invalid) {
continue;
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/oculusvrArmDebug/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
<uses-permission android:name="android.permission.CAMERA" tools:node="remove"/>
<uses-permission android:name="${permissionToRemove}" tools:node="remove" />
<application>
<meta-data android:name="com.samsung.android.vr.application.mode" android:value="vr_only"/>
<meta-data android:name="com.samsung.android.vr.application.mode" android:value="vr_only" />
<activity android:name=".VRBrowserActivity" android:screenOrientation="landscape">
<meta-data android:name="com.oculus.vr.focusaware" android:value="true" />
<meta-data android:name="android.app.lib_name" android:value="native-lib" />
</activity>
</application>
Expand Down
1 change: 1 addition & 0 deletions app/src/oculusvrArmRelease/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
android:supportsPictureInPicture="false"
tools:node="replace"
>
<meta-data android:name="com.oculus.vr.focusaware" android:value="true" />
<meta-data android:name="android.app.lib_name" android:value="native-lib" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down

0 comments on commit f41255c

Please sign in to comment.