@@ -174,6 +174,16 @@ static Uint64 WIN_GetEventTimestamp(void)
174
174
return timestamp ;
175
175
}
176
176
177
+ // A message hook called before TranslateMessage()
178
+ static SDL_WindowsMessageHook g_WindowsMessageHook = NULL ;
179
+ static void * g_WindowsMessageHookData = NULL ;
180
+
181
+ void SDL_SetWindowsMessageHook (SDL_WindowsMessageHook callback , void * userdata )
182
+ {
183
+ g_WindowsMessageHook = callback ;
184
+ g_WindowsMessageHookData = userdata ;
185
+ }
186
+
177
187
static SDL_Scancode WindowsScanCodeToSDLScanCode (LPARAM lParam , WPARAM wParam , Uint16 * rawcode , bool * virtual_key )
178
188
{
179
189
SDL_Scancode code ;
@@ -1042,6 +1052,25 @@ static bool SkipAltGrLeftControl(WPARAM wParam, LPARAM lParam)
1042
1052
return false;
1043
1053
}
1044
1054
1055
+ static bool DispatchModalLoopMessageHook (HWND * hwnd , UINT * msg , WPARAM * wParam , LPARAM * lParam )
1056
+ {
1057
+ MSG dummy ;
1058
+
1059
+ SDL_zero (dummy );
1060
+ dummy .hwnd = * hwnd ;
1061
+ dummy .message = * msg ;
1062
+ dummy .wParam = * wParam ;
1063
+ dummy .lParam = * lParam ;
1064
+ if (g_WindowsMessageHook (g_WindowsMessageHookData , & dummy )) {
1065
+ // Can't modify the hwnd, but everything else is fair game
1066
+ * msg = dummy .message ;
1067
+ * wParam = dummy .wParam ;
1068
+ * lParam = dummy .lParam ;
1069
+ return true;
1070
+ }
1071
+ return false;
1072
+ }
1073
+
1045
1074
LRESULT CALLBACK WIN_WindowProc (HWND hwnd , UINT msg , WPARAM wParam , LPARAM lParam )
1046
1075
{
1047
1076
SDL_WindowData * data ;
@@ -1071,6 +1100,14 @@ LRESULT CALLBACK WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara
1071
1100
}
1072
1101
#endif // WMMSG_DEBUG
1073
1102
1103
+
1104
+ if (g_WindowsMessageHook && data -> in_modal_loop ) {
1105
+ // Synthesize a message for window hooks so they can modify the message if desired
1106
+ if (!DispatchModalLoopMessageHook (& hwnd , & msg , & wParam , & lParam )) {
1107
+ return 0 ;
1108
+ }
1109
+ }
1110
+
1074
1111
#if !defined(SDL_PLATFORM_XBOXONE ) && !defined(SDL_PLATFORM_XBOXSERIES )
1075
1112
if (WIN_HandleIMEMessage (hwnd , msg , wParam , & lParam , data -> videodata )) {
1076
1113
return 0 ;
@@ -1684,12 +1721,15 @@ LRESULT CALLBACK WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara
1684
1721
case WM_ENTERSIZEMOVE :
1685
1722
case WM_ENTERMENULOOP :
1686
1723
{
1687
- data -> initial_size_rect .left = data -> window -> x ;
1688
- data -> initial_size_rect .right = data -> window -> x + data -> window -> w ;
1689
- data -> initial_size_rect .top = data -> window -> y ;
1690
- data -> initial_size_rect .bottom = data -> window -> y + data -> window -> h ;
1724
+ ++ data -> in_modal_loop ;
1725
+ if (data -> in_modal_loop == 1 ) {
1726
+ data -> initial_size_rect .left = data -> window -> x ;
1727
+ data -> initial_size_rect .right = data -> window -> x + data -> window -> w ;
1728
+ data -> initial_size_rect .top = data -> window -> y ;
1729
+ data -> initial_size_rect .bottom = data -> window -> y + data -> window -> h ;
1691
1730
1692
- SetTimer (hwnd , (UINT_PTR )SDL_IterateMainCallbacks , USER_TIMER_MINIMUM , NULL );
1731
+ SetTimer (hwnd , (UINT_PTR )SDL_IterateMainCallbacks , USER_TIMER_MINIMUM , NULL );
1732
+ }
1693
1733
} break ;
1694
1734
1695
1735
case WM_TIMER :
@@ -1703,7 +1743,10 @@ LRESULT CALLBACK WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara
1703
1743
case WM_EXITSIZEMOVE :
1704
1744
case WM_EXITMENULOOP :
1705
1745
{
1706
- KillTimer (hwnd , (UINT_PTR )SDL_IterateMainCallbacks );
1746
+ -- data -> in_modal_loop ;
1747
+ if (data -> in_modal_loop == 0 ) {
1748
+ KillTimer (hwnd , (UINT_PTR )SDL_IterateMainCallbacks );
1749
+ }
1707
1750
} break ;
1708
1751
1709
1752
case WM_SIZING :
@@ -2305,16 +2348,6 @@ static void WIN_UpdateMouseCapture(void)
2305
2348
}
2306
2349
#endif // !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES)
2307
2350
2308
- // A message hook called before TranslateMessage()
2309
- static SDL_WindowsMessageHook g_WindowsMessageHook = NULL ;
2310
- static void * g_WindowsMessageHookData = NULL ;
2311
-
2312
- void SDL_SetWindowsMessageHook (SDL_WindowsMessageHook callback , void * userdata )
2313
- {
2314
- g_WindowsMessageHook = callback ;
2315
- g_WindowsMessageHookData = userdata ;
2316
- }
2317
-
2318
2351
int WIN_WaitEventTimeout (SDL_VideoDevice * _this , Sint64 timeoutNS )
2319
2352
{
2320
2353
if (g_WindowsEnableMessageLoop ) {
0 commit comments