Allow the application to draw while Windows is in a modal move/resize loop

SDL will send an SDL_EVENT_WINDOW_EXPOSED event for your window during the modal interaction and you can use an event watcher to redraw your window directly from the callback.

Fixes https://github.com/libsdl-org/SDL/issues/1059
Closes https://github.com/libsdl-org/SDL/pull/4836
This commit is contained in:
Sam Lantinga
2023-11-08 14:01:00 -08:00
parent 3900fca304
commit 509c70c698
2 changed files with 52 additions and 7 deletions

View File

@@ -110,6 +110,10 @@
#define IS_SURROGATE_PAIR(h, l) (IS_HIGH_SURROGATE(h) && IS_LOW_SURROGATE(l))
#endif
#ifndef USER_TIMER_MINIMUM
#define USER_TIMER_MINIMUM 0x0000000A
#endif
static SDL_Scancode VKeytoScancodeFallback(WPARAM vkey)
{
switch (vkey) {
@@ -675,6 +679,7 @@ WIN_KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam)
LRESULT CALLBACK
WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
static SDL_bool s_ModalMoveResizeLoop;
SDL_WindowData *data;
LRESULT returnCode = -1;
@@ -1253,6 +1258,27 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
}
} break;
case WM_ENTERSIZEMOVE:
case WM_ENTERMENULOOP:
{
SetTimer(hwnd, (UINT_PTR)&s_ModalMoveResizeLoop, USER_TIMER_MINIMUM, NULL);
} break;
case WM_TIMER:
{
if (wParam == (UINT_PTR)&s_ModalMoveResizeLoop) {
// Send an expose event so the application can redraw
SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_EXPOSED, 0, 0);
return 0;
}
} break;
case WM_EXITSIZEMOVE:
case WM_EXITMENULOOP:
{
KillTimer(hwnd, (UINT_PTR)&s_ModalMoveResizeLoop);
} break;
case WM_SIZE:
{
switch (wParam) {