Skip to content

Commit

Permalink
Merge pull request #700 from overte-org/fix/oculus_plugin
Browse files Browse the repository at this point in the history
Disable Oculus plugin by default and add a setting to enable it
  • Loading branch information
ksuprynowicz authored Nov 5, 2023
2 parents 77af9f2 + 9d5da27 commit e08aa2f
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ PreferencesDialog {
id: root
objectName: "GeneralPreferencesDialog"
title: "General Settings"
showCategories: ["User Interface", "Mouse Sensitivity", "HMD", "Snapshots", "Privacy"]
showCategories: ["User Interface", "Mouse Sensitivity", "HMD", "Snapshots", "Privacy", "Plugins"]
property var settings: Settings {
category: root.objectName
property alias x: root.x
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ StackView {
TabletPreferencesDialog {
id: root
objectName: "TabletGeneralPreferences"
showCategories: ["User Interface", "Mouse Sensitivity", "HMD", "Snapshots", "Privacy"]
showCategories: ["User Interface", "Mouse Sensitivity", "HMD", "Snapshots", "Privacy", "Plugins"]
}
}
9 changes: 9 additions & 0 deletions interface/src/ui/PreferencesDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <OffscreenUi.h>
#include <Preferences.h>
#include <plugins/PluginUtils.h>
#include <plugins/PluginManager.h>
#include <display-plugins/CompositorHelper.h>
#include <display-plugins/hmd/HmdDisplayPlugin.h>
#include "scripting/RenderScriptingInterface.h"
Expand Down Expand Up @@ -637,4 +638,12 @@ void setupPreferences() {
preferences->addPreference(preference);
}
}

static const QString PLUGIN_CATEGORY{ "Plugins" };
auto pluginManager = PluginManager::getInstance();
{
auto getter = [pluginManager]()->bool { return pluginManager->getEnableOculusPluginSetting(); };
auto setter = [pluginManager](bool value) { pluginManager->setEnableOculusPluginSetting(value); };
preferences->addPreference(new CheckPreference(PLUGIN_CATEGORY, "Enable Oculus Platform Plugin", getter, setter));
}
}
21 changes: 15 additions & 6 deletions libraries/plugins/src/plugins/PluginManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,18 +211,27 @@ const OculusPlatformPluginPointer PluginManager::getOculusPlatformPlugin() {
static OculusPlatformPluginPointer oculusPlatformPlugin;
static std::once_flag once;
std::call_once(once, [&] {
// Now grab the dynamic plugins
for (auto loader : getLoadedPlugins()) {
OculusPlatformProvider* oculusPlatformProvider = qobject_cast<OculusPlatformProvider*>(loader->instance());
if (oculusPlatformProvider) {
oculusPlatformPlugin = oculusPlatformProvider->getOculusPlatformPlugin();
break;
// Now grab the dynamic plugins if the setting allows it
if (_enableOculusPluginSetting.get()) {
qCDebug(plugins) << "PluginManager::getOculusPlatformPlugin: Oculus plugin enabled by a setting";
for (auto loader : getLoadedPlugins()) {
OculusPlatformProvider* oculusPlatformProvider = qobject_cast<OculusPlatformProvider*>(loader->instance());
if (oculusPlatformProvider) {
oculusPlatformPlugin = oculusPlatformProvider->getOculusPlatformPlugin();
break;
}
}
} else {
qCDebug(plugins) << "PluginManager::getOculusPlatformPlugin: Oculus plugin disabled by a setting";
}
});
return oculusPlatformPlugin;
}

void PluginManager::setEnableOculusPluginSetting(bool value) {
_enableOculusPluginSetting.set(value);
}

DisplayPluginList PluginManager::getAllDisplayPlugins() {
return _displayPlugins;
}
Expand Down
5 changes: 5 additions & 0 deletions libraries/plugins/src/plugins/PluginManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class PluginManager : public QObject, public Dependency {
void setPluginFilter(PluginFilter pluginFilter) { _pluginFilter = pluginFilter; }
Q_INVOKABLE DisplayPluginList getAllDisplayPlugins();

bool getEnableOculusPluginSetting() { return _enableOculusPluginSetting.get(); }
void setEnableOculusPluginSetting(bool value);

signals:
void inputDeviceRunningChanged(const QString& pluginName, bool isRunning, const QStringList& runningDevices);

Expand All @@ -76,6 +79,8 @@ class PluginManager : public QObject, public Dependency {
Setting::Handle<bool> _enableScriptingPlugins {
"private/enableScriptingPlugins", (bool)qgetenv("enableScriptingPlugins").toInt()
};

Setting::Handle<bool> _enableOculusPluginSetting { "enableOculusPluginSetting", false };
};

// TODO: we should define this value in CMake, and then use CMake
Expand Down
24 changes: 16 additions & 8 deletions plugins/openvr/src/OpenVrHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <controllers/Pose.h>
#include <NumericalConstants.h>
#include <ui-plugins/PluginContainer.h>
#include <plugins/PluginManager.h>

#include <ui/Menu.h>
#include "../../interface/src/Menu.h"

Expand Down Expand Up @@ -50,15 +52,21 @@ static const uint32_t RELEASE_OPENVR_HMD_DELAY_MS = 5000;

bool isOculusPresent() {
bool result = false;
#ifdef Q_OS_WIN
HANDLE oculusServiceEvent = ::OpenEventW(SYNCHRONIZE, FALSE, L"OculusHMDConnected");
// The existence of the service indicates a running Oculus runtime
if (oculusServiceEvent) {
// A signaled event indicates a connected HMD
if (WAIT_OBJECT_0 == ::WaitForSingleObject(oculusServiceEvent, 0)) {
result = true;
#ifdef Q_OS_WIN
// Only check for Oculus presence if Oculus plugin is enabled
if (PluginManager::getInstance()->getEnableOculusPluginSetting()) {
qDebug() << "isOculusPresent: Oculus plugin enabled by a setting";
HANDLE oculusServiceEvent = ::OpenEventW(SYNCHRONIZE, FALSE, L"OculusHMDConnected");
// The existence of the service indicates a running Oculus runtime
if (oculusServiceEvent) {
// A signaled event indicates a connected HMD
if (WAIT_OBJECT_0 == ::WaitForSingleObject(oculusServiceEvent, 0)) {
result = true;
}
::CloseHandle(oculusServiceEvent);
}
::CloseHandle(oculusServiceEvent);
} else {
qDebug() << "isOculusPresent: Oculus plugin disabled by a setting";
}
#endif
return result;
Expand Down

0 comments on commit e08aa2f

Please sign in to comment.