Skip to content

Commit

Permalink
Keyboard resize fix (#341)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Spodi committed Oct 2, 2023
1 parent 3abe308 commit 0099c48
Showing 1 changed file with 14 additions and 26 deletions.
40 changes: 14 additions & 26 deletions src/graphic/Fast3D/gfx_dxgi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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();
}
}

Expand All @@ -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) {
Expand Down

0 comments on commit 0099c48

Please sign in to comment.