diff --git a/OpenVR-SpaceCalibrator/Configuration.cpp b/OpenVR-SpaceCalibrator/Configuration.cpp index 538cfff..91b4cd5 100644 --- a/OpenVR-SpaceCalibrator/Configuration.cpp +++ b/OpenVR-SpaceCalibrator/Configuration.cpp @@ -11,6 +11,7 @@ static void UpgradeProfileV1(CalibrationContext &ctx); static void ParseProfileV2(CalibrationContext &ctx, std::istream &stream); + static std::string ConfigFileName() { std::string vrRuntimeConfigName = vr::VR_RuntimePath(); @@ -127,3 +128,41 @@ static void UpgradeProfileV1(CalibrationContext &ctx) file.close(); std::remove("openvr_space_calibration.txt"); } + +void WriteActivateMultipleDriversToConfig() +{ + std::string configPath = vr::VR_RuntimePath(); + configPath += "\\..\\..\\..\\config\\steamvr.vrsettings"; + + std::ifstream ifile(configPath); + if (!ifile.good()) + throw std::runtime_error("failed to read steamvr.vrsettings"); + + picojson::value v; + std::string err = picojson::parse(v, ifile); + if (!err.empty()) + throw std::runtime_error(err); + + ifile.close(); + + if (!v.is()) + throw std::runtime_error("steamvr.vrsettings is empty"); + + auto &root = v.get(); + + if (!root["steamvr"].is()) + throw std::runtime_error("steamvr.vrsettings is missing \"steamvr\" key"); + + auto &steamvr = root["steamvr"].get(); + + const bool tru = true; // MSVC picks the wrong specialization when passing a literal... + steamvr["activateMultipleDrivers"].set(tru); + + std::ofstream ofile(configPath); + if (!ofile.good()) + throw std::runtime_error("failed to write steamvr.vrsettings"); + + v.serialize(std::ostream_iterator(ofile), true); + + std::cout << "Successfully set activateMultipleDrivers to true" << std::endl; +} diff --git a/OpenVR-SpaceCalibrator/Configuration.h b/OpenVR-SpaceCalibrator/Configuration.h index 43623a4..0a06366 100644 --- a/OpenVR-SpaceCalibrator/Configuration.h +++ b/OpenVR-SpaceCalibrator/Configuration.h @@ -4,3 +4,4 @@ void LoadProfile(CalibrationContext &ctx); void SaveProfile(CalibrationContext &ctx); +void WriteActivateMultipleDriversToConfig(); diff --git a/OpenVR-SpaceCalibrator/OpenVR-SpaceCalibrator.cpp b/OpenVR-SpaceCalibrator/OpenVR-SpaceCalibrator.cpp index 55fe745..65e6655 100644 --- a/OpenVR-SpaceCalibrator/OpenVR-SpaceCalibrator.cpp +++ b/OpenVR-SpaceCalibrator/OpenVR-SpaceCalibrator.cpp @@ -37,10 +37,13 @@ void GLFWErrorCallback(int error, const char* description) fprintf(stderr, "GLFW Error %d: %s\n", error, description); } -GLFWwindow *glfwWindow = nullptr; -vr::VROverlayHandle_t overlayMainHandle = 0, overlayThumbnailHandle = 0; -GLuint fboHandle = 0, fboTextureHandle = 0; -int fboTextureWidth = 0, fboTextureHeight = 0; + +static void HandleCommandLine(LPWSTR lpCmdLine); + +static GLFWwindow *glfwWindow = nullptr; +static vr::VROverlayHandle_t overlayMainHandle = 0, overlayThumbnailHandle = 0; +static GLuint fboHandle = 0, fboTextureHandle = 0; +static int fboTextureWidth = 0, fboTextureHeight = 0; static char cwd[MAX_PATH]; @@ -62,6 +65,8 @@ void CreateGLFWWindow() glfwSwapInterval(1); gl3wInit(); + glfwIconifyWindow(glfwWindow); + ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; @@ -165,10 +170,12 @@ void RunLoop() static bool keyboardOpen = false, keyboardJustClosed = false; + // After closing the keyboard, this code waits one frame for ImGui to pick up the new text from SetActiveText + // before clearing the active widget. Then it waits another frame before allowing the keyboard to open again, + // otherwise it will do so instantly since WantTextInput is still true on the second frame. if (keyboardJustClosed && keyboardOpen) { ImGui::ClearActiveID(); - io.WantTextInput = false; keyboardOpen = false; } else if (keyboardJustClosed) @@ -177,6 +184,7 @@ void RunLoop() } else if (!io.WantTextInput) { + // User might close the keyboard without hitting Done, so we unset the flag to allow it to open again. keyboardOpen = false; } else if (io.WantTextInput && !keyboardOpen && !keyboardJustClosed) @@ -223,19 +231,6 @@ void RunLoop() } } - /*if (width != fboTextureWidth || height != fboTextureHeight) - { - if (overlayMainHandle) - { - vr::VROverlay()->ClearOverlayTexture(overlayMainHandle); - } - fboTextureWidth = width; - fboTextureHeight = height; - glBindTexture(GL_TEXTURE_2D, fboTextureHandle); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fboTextureWidth, fboTextureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); - // OpenVR stops rendering the overlay if we recreate the texture storage smaller than it was originally. - }*/ - ImGui_ImplGlfw_SetReadMouseFromGlfw(!dashboardVisible); ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplGlfw_NewFrame(); @@ -279,13 +274,11 @@ void RunLoop() } } -static void handleCommandLine(LPWSTR lpCmdLine); - int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow) { _getcwd(cwd, MAX_PATH); //CreateConsole(); - handleCommandLine(lpCmdLine); + HandleCommandLine(lpCmdLine); if (!glfwInit()) { @@ -329,7 +322,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance return 0; } -static void handleCommandLine(LPWSTR lpCmdLine) +static void HandleCommandLine(LPWSTR lpCmdLine) { if (lstrcmp(lpCmdLine, L"-openvrpath") == 0) { @@ -339,7 +332,6 @@ static void handleCommandLine(LPWSTR lpCmdLine) { printf("%s", vr::VR_RuntimePath()); vr::VR_Shutdown(); - Sleep(2000); exit(0); } fprintf(stderr, "Failed to initialize OpenVR: %s\n", vr::VR_GetVRInitErrorAsEnglishDescription(vrErr)); @@ -382,8 +374,7 @@ static void handleCommandLine(LPWSTR lpCmdLine) vr::VRApplications()->SetApplicationAutoLaunch(OPENVR_APPLICATION_KEY, true); } vr::VR_Shutdown(); - Sleep(2000); - exit(0); + exit(-2); } fprintf(stderr, "Failed to initialize OpenVR: %s\n", vr::VR_GetVRInitErrorAsEnglishDescription(vrErr)); vr::VR_Shutdown(); @@ -403,11 +394,34 @@ static void handleCommandLine(LPWSTR lpCmdLine) vr::VRApplications()->RemoveApplicationManifest(manifestPath.c_str()); } vr::VR_Shutdown(); - Sleep(2000); exit(0); } fprintf(stderr, "Failed to initialize OpenVR: %s\n", vr::VR_GetVRInitErrorAsEnglishDescription(vrErr)); vr::VR_Shutdown(); exit(-2); } + else if (lstrcmp(lpCmdLine, L"-activatemultipledrivers") == 0) + { + int ret = -2; + auto vrErr = vr::VRInitError_None; + vr::VR_Init(&vrErr, vr::VRApplication_Utility); + if (vrErr == vr::VRInitError_None) + { + try + { + WriteActivateMultipleDriversToConfig(); + ret = 0; + } + catch (std::runtime_error &e) + { + std::cerr << "Failed to set activateMultipleDrivers: " << e.what() << std::endl; + } + } + else + { + fprintf(stderr, "Failed to initialize OpenVR: %s\n", vr::VR_GetVRInitErrorAsEnglishDescription(vrErr)); + } + vr::VR_Shutdown(); + exit(ret); + } } diff --git a/OpenVR-SpaceCalibratorDriver/Logging.h b/OpenVR-SpaceCalibratorDriver/Logging.h index 88ce0a0..5ecb9de 100644 --- a/OpenVR-SpaceCalibratorDriver/Logging.h +++ b/OpenVR-SpaceCalibratorDriver/Logging.h @@ -17,7 +17,7 @@ void LogFlush(); } while (0) #endif -//#define TRACE(...) {} +#define TRACE(...) {} #ifndef TRACE #define TRACE LOG diff --git a/install/installer.nsi b/install/installer.nsi index 1e2333f..fc4ee98 100644 --- a/install/installer.nsi +++ b/install/installer.nsi @@ -1,4 +1,3 @@ - ;-------------------------------- ;Include Modern UI @@ -10,18 +9,12 @@ !define OVERLAY_BASEDIR "..\client_overlay\bin\win64" !define DRIVER_RESDIR "..\OpenVR-SpaceCalibratorDriver\01spacecalibrator" - ;Name and file Name "OpenVR-SpaceCalibrator" OutFile "OpenVR-SpaceCalibrator.exe" - - ;Default installation folder InstallDir "$PROGRAMFILES64\OpenVR-SpaceCalibrator" - - ;Get installation folder from registry if available InstallDirRegKey HKLM "Software\OpenVR-SpaceCalibrator\Main" "" - - ;Request application privileges for Windows Vista RequestExecutionLevel admin + ShowInstDetails show ;-------------------------------- ;Variables @@ -103,14 +96,12 @@ Section "Install" SecInstall SetOutPath "$INSTDIR" - ;ADD YOUR OWN FILES HERE... File "..\LICENSE" File "..\x64\Release\OpenVR-SpaceCalibrator.exe" File "..\x64\Release\openvr_api.dll" File "..\OpenVR-SpaceCalibrator\manifest.vrmanifest" File "..\OpenVR-SpaceCalibrator\icon.png" - ; Install redistributable ExecWait '"$INSTDIR\vcredist_x64.exe" /install /quiet' Var /GLOBAL vrRuntimePath @@ -142,11 +133,9 @@ Section "Install" SecInstall SetOutPath "$vrRuntimePath\drivers\01spacecalibrator\bin\win64" File "..\x64\Release\driver_01spacecalibrator.dll" - ;Store installation folder WriteRegStr HKLM "Software\OpenVR-SpaceCalibrator\Main" "" $INSTDIR WriteRegStr HKLM "Software\OpenVR-SpaceCalibrator\Driver" "" $vrRuntimePath - ;Create uninstaller WriteUninstaller "$INSTDIR\Uninstall.exe" WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenVRSpaceCalibrator" "DisplayName" "OpenVR-SpaceCalibrator" WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenVRSpaceCalibrator" "UninstallString" "$\"$INSTDIR\Uninstall.exe$\"" @@ -155,6 +144,7 @@ Section "Install" SecInstall SetOutPath "$INSTDIR" nsExec::ExecToLog '"$INSTDIR\OpenVR-SpaceCalibrator.exe" -installmanifest' + nsExec::ExecToLog '"$INSTDIR\OpenVR-SpaceCalibrator.exe" -activatemultipledrivers' SectionEnd @@ -169,9 +159,9 @@ Section "Uninstall" "SteamVR is still running. Cannot uninstall this software.$\nPlease close SteamVR and try again." Abort + SetOutPath "$INSTDIR" nsExec::ExecToLog '"$INSTDIR\OpenVR-SpaceCalibrator.exe" -removemanifest' - ; Delete installed files Var /GLOBAL vrRuntimePath2 ReadRegStr $vrRuntimePath2 HKLM "Software\OpenVR-SpaceCalibrator\Driver" "" DetailPrint "VR runtime path: $vrRuntimePath2"