Skip to content

Various tweaks. Text to speech notifications, icons, overlay battery status icon, etc. #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Binary file added OpenVR Display Devices/OpenVR Display Devices.rc
Binary file not shown.
22 changes: 22 additions & 0 deletions OpenVR Display Devices/OpenVR Display Devices.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>..\3rdparty\WinToast\include;..\3rdparty\simpleini;..\3rdparty\imgui\backends;..\3rdparty\imgui;..\3rdparty\openvr\headers;..\3rdparty\gl3w\include;..\3rdparty\glfw\include;..\3rdparty\PlatformFolders\sago;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp20</LanguageStandard>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<OpenMPSupport>true</OpenMPSupport>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -143,6 +146,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>..\3rdparty\glfw\lib-vc2022;..\3rdparty\openvr\lib\win64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>opengl32.lib;glfw3.lib;openvr_api.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
Expand All @@ -169,6 +173,7 @@
<ClInclude Include="configuration.h" />
<ClInclude Include="droid_sans_font.h" />
<ClInclude Include="notifications.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="user_interface.h" />
<ClInclude Include="Webchaussette.h" />
</ItemGroup>
Expand All @@ -184,9 +189,26 @@
<None Include="..\README.md" />
<None Include=".editorconfig" />
<None Include="manifest.vrmanifest" />
<None Include="packages.config" />
<None Include="vcpkg.json" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="OpenVR Display Devices.rc" />
</ItemGroup>
<ItemGroup>
<Image Include="..\icon.ico" />
<Image Include="icon1.ico" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="..\packages\boost.1.86.0\build\boost.targets" Condition="Exists('..\packages\boost.1.86.0\build\boost.targets')" />
<Import Project="..\packages\nlohmann.json.3.11.2\build\native\nlohmann.json.targets" Condition="Exists('..\packages\nlohmann.json.3.11.2\build\native\nlohmann.json.targets')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\boost.1.86.0\build\boost.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost.1.86.0\build\boost.targets'))" />
<Error Condition="!Exists('..\packages\nlohmann.json.3.11.2\build\native\nlohmann.json.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\nlohmann.json.3.11.2\build\native\nlohmann.json.targets'))" />
</Target>
</Project>
17 changes: 17 additions & 0 deletions OpenVR Display Devices/OpenVR Display Devices.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@
<ClInclude Include="battery_checker.h">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
<ClInclude Include="resource.h">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<CopyFileToFolders Include="..\3rdparty\openvr\bin\win64\openvr_api.dll">
Expand All @@ -115,5 +118,19 @@
<None Include="..\.gitignore" />
<None Include=".editorconfig" />
<None Include="..\.github\workflows\msbuild-release.yml" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="OpenVR Display Devices.rc">
<Filter>Fichiers de ressources</Filter>
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<Image Include="icon1.ico">
<Filter>Fichiers de ressources</Filter>
</Image>
<Image Include="..\icon.ico">
<Filter>Fichiers de ressources</Filter>
</Image>
</ItemGroup>
</Project>
150 changes: 134 additions & 16 deletions OpenVR Display Devices/OpenVR-Display-Devices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ double lastFrameStartTime = glfwGetTime();
#pragma comment(linker,"\"/manifestdependency:type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
extern "C" __declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
extern "C" __declspec(dllexport) DWORD AmdPowerXpressRequestHighPerformance = 0x00000001;
//extern "C" __declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
//extern "C" __declspec(dllexport) DWORD AmdPowerXpressRequestHighPerformance = 0x00000001;

//extern void ActivateMultipleDrivers();

void CreateConsole() {
static bool created = false;
Expand Down Expand Up @@ -66,6 +68,8 @@ void InitVR() {
} else if (!vr::VR_IsInterfaceVersionValid(vr::IVROverlay_Version)) {
throw std::runtime_error("OpenVR error: Outdated IVROverlay_Version");
}

//ActivateMultipleDrivers();
}

void CreateGLFWWindow() {
Expand All @@ -77,7 +81,7 @@ void CreateGLFWWindow() {
fboTextureWidth = 1600;
fboTextureHeight = 800;

glfwWindow = glfwCreateWindow(fboTextureWidth, fboTextureHeight, "OpenVR-Display-Devices", NULL, NULL);
glfwWindow = glfwCreateWindow(fboTextureWidth, fboTextureHeight, OPENVR_APPLICATION_NAME/*"OpenVR-Display-Devices"*/, NULL, NULL);
if (!glfwWindow) {
throw std::runtime_error("Failed to create window");
}
Expand All @@ -87,9 +91,9 @@ void CreateGLFWWindow() {
gl3wInit();

// Minimize the window on start if enabled
#ifndef _DEBUG
glfwIconifyWindow(glfwWindow);
#endif
//#ifndef _DEBUG
//glfwIconifyWindow(glfwWindow);
//#endif

ImGui::CreateContext();
ImGuiIO &io = ImGui::GetIO();
Expand Down Expand Up @@ -121,6 +125,75 @@ void CreateGLFWWindow() {
}
}

extern BatteryChecker batteryChecker;
std::string overlayThumbnailCurrent = "";

void UpdateOverlayIcon() {
if (!vr::VROverlay() || !overlayThumbnailHandle)
{
return;
}

std::string iconPath = cwd;

if (batteryChecker.hmdCharging)
{
if (batteryChecker.hmdCharge > 80)
{
iconPath += "\\icons\\c100.png";
}
else if (batteryChecker.hmdCharge > 60)
{
iconPath += "\\icons\\c80.png";
}
else if (batteryChecker.hmdCharge > 40)
{
iconPath += "\\icons\\c60.png";
}
else if (batteryChecker.hmdCharge > 20)
{
iconPath += "\\icons\\c40.png";
}
else
{
iconPath += "\\icons\\c20.png";
}
}
else
{
if (batteryChecker.hmdCharge > 80)
{
iconPath += "\\icons\\100.png";
}
else if (batteryChecker.hmdCharge > 60)
{
iconPath += "\\icons\\80.png";
}
else if (batteryChecker.hmdCharge > 40)
{
iconPath += "\\icons\\60.png";
}
else if (batteryChecker.hmdCharge > 20)
{
iconPath += "\\icons\\40.png";
}
else
{
iconPath += "\\icons\\20.png";
}
}

if (overlayThumbnailCurrent == iconPath.c_str())
{// Unchanged...
return;
}

//printf("icon : %s\n", iconPath.c_str());
vr::VROverlay()->ClearOverlayTexture(overlayThumbnailHandle);
vr::VROverlay()->SetOverlayFromFile(overlayThumbnailHandle, iconPath.c_str());
overlayThumbnailCurrent = iconPath.c_str();
}

void TryCreateVROverlay() {
if (overlayMainHandle || !vr::VROverlay()) {
return;
Expand All @@ -139,10 +212,35 @@ void TryCreateVROverlay() {
vr::VROverlay()->SetOverlayWidthInMeters(overlayMainHandle, 3.0f);
vr::VROverlay()->SetOverlayInputMethod(overlayMainHandle, vr::VROverlayInputMethod_Mouse);
vr::VROverlay()->SetOverlayFlag(overlayMainHandle, vr::VROverlayFlags_SendVRDiscreteScrollEvents, true);

// can set icon here but idc lol
UpdateOverlayIcon();
}

/*void ActivateMultipleDrivers() {
vr::EVRSettingsError vrSettingsError;
bool enabled = vr::VRSettings()->GetBool(vr::k_pch_SteamVR_Section, vr::k_pch_SteamVR_ActivateMultipleDrivers_Bool, &vrSettingsError);

if (vrSettingsError != vr::VRSettingsError_None) {
std::string err = "Could not read \"" + std::string(vr::k_pch_SteamVR_ActivateMultipleDrivers_Bool) + "\" setting: "
+ vr::VRSettings()->GetSettingsErrorNameFromEnum(vrSettingsError);

throw std::runtime_error(err);
}

if (!enabled) {
vr::VRSettings()->SetBool(vr::k_pch_SteamVR_Section, vr::k_pch_SteamVR_ActivateMultipleDrivers_Bool, true, &vrSettingsError);
if (vrSettingsError != vr::VRSettingsError_None) {
std::string err = "Could not set \"" + std::string(vr::k_pch_SteamVR_ActivateMultipleDrivers_Bool) + "\" setting: "
+ vr::VRSettings()->GetSettingsErrorNameFromEnum(vrSettingsError);

throw std::runtime_error(err);
}

std::cerr << "Enabled \"" << vr::k_pch_SteamVR_ActivateMultipleDrivers_Bool << "\" setting" << std::endl;
} else {
std::cerr << "\"" << vr::k_pch_SteamVR_ActivateMultipleDrivers_Bool << "\" setting previously enabled" << std::endl;
}
}*/

void RunLoop() {
while (!glfwWindowShouldClose(glfwWindow)) {
TryCreateVROverlay();
Expand All @@ -154,7 +252,7 @@ void RunLoop() {

if (overlayMainHandle && vr::VROverlay()) {
auto &io = ImGui::GetIO();
dashboardVisible = vr::VROverlay()->IsActiveDashboardOverlay(overlayMainHandle);
dashboardVisible = vr::VROverlay()->IsActiveDashboardOverlay(overlayMainHandle) || vr::VROverlay()->IsDashboardVisible();

vr::VREvent_t vrEvent;
while (vr::VROverlay()->PollNextOverlayEvent(overlayMainHandle, &vrEvent, sizeof(vrEvent))) {
Expand All @@ -180,7 +278,8 @@ void RunLoop() {
}
}

if (windowVisible || dashboardVisible) {
//if (windowVisible || dashboardVisible)
{
auto &io = ImGui::GetIO();
io.DisplaySize = ImVec2((float)fboTextureWidth, (float)fboTextureHeight);
io.DisplayFramebufferScale = ImVec2(1.0f, 1.0f);
Expand All @@ -189,6 +288,7 @@ void RunLoop() {
if (dashboardVisible) {
io.ConfigFlags = io.ConfigFlags | ImGuiConfigFlags_NoMouseCursorChange;
}

ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
Expand All @@ -215,21 +315,39 @@ void RunLoop() {
if (dashboardVisible) {
vr::Texture_t vrTex;
vrTex.eType = vr::TextureType_OpenGL;
vrTex.eColorSpace = vr::ColorSpace_Auto;
//vrTex.eColorSpace = vr::ColorSpace_Auto;
vrTex.eColorSpace = vr::ColorSpace_Linear;

vrTex.handle = (void *)
#if defined _WIN64 || defined _LP64
(uint64_t)
#endif
fboTextureHandle;


vr::HmdVector2_t mouseScale = { (float)fboTextureWidth, (float)fboTextureHeight };
//vrTex.handle = reinterpret_cast<void *>(static_cast<uintptr_t>(fboTextureHandle));

vr::VROverlay()->ClearOverlayTexture(overlayMainHandle);
vr::VROverlay()->SetOverlayTexture(overlayMainHandle, &vrTex);
//vr::VROverlay()->SetOverlayAlpha(overlayMainHandle, 1.0f);

//vr::VROverlay()->ClearOverlayTexture(overlayMainHandle);
//vr::VROverlay()->SetOverlayFromFile(overlayMainHandle, overlayThumbnailCurrent.c_str());

/*vr::Texture_t texture = {(void *)(uintptr_t)&fboTextureHandle, vr::TextureType_OpenGL, vr::ColorSpace_Auto};
vr::VROverlay()->SetOverlayTexture(overlayMainHandle, &texture);*/

vr::HmdVector2_t mouseScale = { (float)fboTextureWidth, (float)fboTextureHeight };
vr::VROverlay()->SetOverlayMouseScale(overlayMainHandle, &mouseScale);

//printf("Overlay set to texture %I64u. Resolution %i x %i.\n", (uint64_t)vrTex.handle, fboTextureWidth, fboTextureHeight);
}
}

if (vr::VROverlay()->IsDashboardVisible()) {
UpdateOverlayIcon();
}

const double dashboardInterval = 1.0 / 90.0; // fps
double waitEventsTimeout = std::max(UPDATE_INTERVAL, dashboardInterval);

Expand Down Expand Up @@ -341,8 +459,8 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance

// Load config then do post-config setup if needed
loadOrInitConfiguration(application_configuration);
if (application_configuration.notificationsWindows) {
enableWindowsNotifications();
if (application_configuration.notificationsSound) {
enableSoundNotifications();
}
if (application_configuration.notificationsXsOverlay) {
enableXsOverlayNotifications();
Expand All @@ -353,8 +471,8 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance
}
RunLoop();

if (application_configuration.notificationsWindows) {
disableWindowsNotifications();
if (application_configuration.notificationsSound) {
disableSoundNotifications();
}
if (application_configuration.notificationsXsOverlay) {
disableXsOverlayNotifications();
Expand Down
Loading