diff --git a/Client/GUI_Impls/CrossPlatformGUI.h b/Client/GUI_Impls/CrossPlatformGUI.h index 668a56b..d2495d1 100644 --- a/Client/GUI_Impls/CrossPlatformGUI.h +++ b/Client/GUI_Impls/CrossPlatformGUI.h @@ -16,6 +16,7 @@ constexpr auto GUI_MAX_MESSAGES = 10; constexpr auto GUI_HEIGHT = 350; constexpr auto GUI_WIDTH = 540; constexpr auto FPS = 60; +constexpr auto MS_PER_FRAME = 1000 / FPS; constexpr auto FONT_SIZE = 15.0f; const auto WINDOW_COLOR = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); diff --git a/Client/GUI_Impls/WindowsGUI.cpp b/Client/GUI_Impls/WindowsGUI.cpp index 524bb07..1d22255 100644 --- a/Client/GUI_Impls/WindowsGUI.cpp +++ b/Client/GUI_Impls/WindowsGUI.cpp @@ -49,6 +49,8 @@ void EnterGUIMainLoop(BluetoothWrapper bt) CrossPlatformGUI gui(std::move(bt)); + UINT presentFlags = 0; + // Main loop MSG msg = { 0 }; while (msg.message != WM_QUIT) @@ -58,6 +60,7 @@ void EnterGUIMainLoop(BluetoothWrapper bt) // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application. // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. + if (::PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)) { ::TranslateMessage(&msg); @@ -79,8 +82,16 @@ void EnterGUIMainLoop(BluetoothWrapper bt) g_pd3dDeviceContext->OMSetRenderTargets(1, &g_mainRenderTargetView, NULL); g_pd3dDeviceContext->ClearRenderTargetView(g_mainRenderTargetView, (float*)&WINDOW_COLOR); ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData()); - - g_pSwapChain->Present(1, 0); // Present with vsync + + //We need this because Present doesn't delay when the app is minimized. + if (g_pSwapChain->Present(1, presentFlags) == DXGI_STATUS_OCCLUDED) { + presentFlags = DXGI_PRESENT_TEST; + //Artificial VSYNC when the app is minimized + Sleep(MS_PER_FRAME); + } + else { + presentFlags = 0; + } } // Cleanup @@ -96,6 +107,7 @@ void EnterGUIMainLoop(BluetoothWrapper bt) void DisplayErrorMessagebox(const std::string& message) { MessageBoxA(0, message.c_str(), "Sony Headphones Client | Unrecoverable Error", MB_OK | MB_ICONSTOP); + exit(GetLastError()); } namespace WindowsGUIInternal diff --git a/Client/imgui b/Client/imgui index b898281..4df5713 160000 --- a/Client/imgui +++ b/Client/imgui @@ -1 +1 @@ -Subproject commit b898281e3c75d64ecc4e0f63aba0ec5e9182cce1 +Subproject commit 4df57136e9832327c11e48b5bfe00b0326bd5b63