From 0099c480696a9756f2020ee20d1a811e9eb85bcc Mon Sep 17 00:00:00 2001 From: Spodi Date: Tue, 3 Oct 2023 01:32:14 +0200 Subject: [PATCH] Keyboard resize fix (#341) * Move run_one_game_iter() out of WM_PAINT Use the function that was already there for the message queue and just run dxgi.run_one_game_iter() in a loop. This should be more in line with how this works in SDL/OpenGL. Fixes bugged (jittery) resize/move with keyboard through the window menu. Although the game pauses when moved/resized or the window menu is open (also like in SDL/OpenGL). * Fixed game never stopped running after last commit * Attempt to gracefully close on logout * Only close if endsession is not canceled --- src/graphic/Fast3D/gfx_dxgi.cpp | 40 ++++++++++++--------------------- 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/src/graphic/Fast3D/gfx_dxgi.cpp b/src/graphic/Fast3D/gfx_dxgi.cpp index 441a2d33b..9ab373739 100644 --- a/src/graphic/Fast3D/gfx_dxgi.cpp +++ b/src/graphic/Fast3D/gfx_dxgi.cpp @@ -42,8 +42,6 @@ using namespace Microsoft::WRL; // For ComPtr static struct { HWND h_wnd; - bool in_paint; - bool recursive_paint_detected; // These four only apply in windowed mode. uint32_t current_width, current_height; // Width and height of client areas @@ -375,24 +373,13 @@ static LRESULT CALLBACK gfx_dxgi_wnd_proc(HWND h_wnd, UINT message, WPARAM w_par GetMonitorHzPeriod(dxgi.h_Monitor, dxgi.detected_hz, dxgi.display_period); } break; - case WM_DESTROY: - PostQuitMessage(0); + case WM_CLOSE: + dxgi.is_running = false; break; - case WM_PAINT: - if (dxgi.in_paint) { - dxgi.recursive_paint_detected = true; - return DefWindowProcW(h_wnd, message, w_param, l_param); - } else { - if (dxgi.run_one_game_iter != nullptr) { - dxgi.in_paint = true; - dxgi.run_one_game_iter(); - dxgi.in_paint = false; - if (dxgi.recursive_paint_detected) { - dxgi.recursive_paint_detected = false; - InvalidateRect(h_wnd, nullptr, false); - UpdateWindow(h_wnd); - } - } + case WM_ENDSESSION: + // This hopefully gives the game a chance to shut down, before windows kills it. + if (w_param == TRUE) { + dxgi.is_running = false; } break; case WM_ACTIVATEAPP: @@ -554,11 +541,8 @@ static void gfx_dxgi_set_keyboard_callbacks(bool (*on_key_down)(int scancode), b static void gfx_dxgi_main_loop(void (*run_one_game_iter)(void)) { dxgi.run_one_game_iter = run_one_game_iter; - - MSG msg; - while (GetMessage(&msg, nullptr, 0, 0) && dxgi.is_running) { - TranslateMessage(&msg); - DispatchMessage(&msg); + while (dxgi.is_running) { + dxgi.run_one_game_iter(); } } @@ -570,11 +554,15 @@ static void gfx_dxgi_get_dimensions(uint32_t* width, uint32_t* height, int32_t* } static void gfx_dxgi_handle_events(void) { - /*MSG msg; + MSG msg; while (PeekMessageW(&msg, nullptr, 0, 0, PM_REMOVE)) { + if (msg.message == WM_QUIT) { + dxgi.is_running = false; + break; + } TranslateMessage(&msg); DispatchMessage(&msg); - }*/ + } } static uint64_t qpc_to_ns(uint64_t qpc) {