Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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