@@ -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 ;
@@ -1678,12 +1715,15 @@ LRESULT CALLBACK WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara
1678
1715
case WM_ENTERSIZEMOVE :
1679
1716
case WM_ENTERMENULOOP :
1680
1717
{
1681
- data -> initial_size_rect .left = data -> window -> x ;
1682
- data -> initial_size_rect .right = data -> window -> x + data -> window -> w ;
1683
- data -> initial_size_rect .top = data -> window -> y ;
1684
- data -> initial_size_rect .bottom = data -> window -> y + data -> window -> h ;
1718
+ ++ data -> in_modal_loop ;
1719
+ if (data -> in_modal_loop == 1 ) {
1720
+ data -> initial_size_rect .left = data -> window -> x ;
1721
+ data -> initial_size_rect .right = data -> window -> x + data -> window -> w ;
1722
+ data -> initial_size_rect .top = data -> window -> y ;
1723
+ data -> initial_size_rect .bottom = data -> window -> y + data -> window -> h ;
1685
1724
1686
- SetTimer (hwnd , (UINT_PTR )SDL_IterateMainCallbacks , USER_TIMER_MINIMUM , NULL );
1725
+ SetTimer (hwnd , (UINT_PTR )SDL_IterateMainCallbacks , USER_TIMER_MINIMUM , NULL );
1726
+ }
1687
1727
} break ;
1688
1728
1689
1729
case WM_TIMER :
@@ -1697,7 +1737,10 @@ LRESULT CALLBACK WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara
1697
1737
case WM_EXITSIZEMOVE :
1698
1738
case WM_EXITMENULOOP :
1699
1739
{
1700
- KillTimer (hwnd , (UINT_PTR )SDL_IterateMainCallbacks );
1740
+ -- data -> in_modal_loop ;
1741
+ if (data -> in_modal_loop == 0 ) {
1742
+ KillTimer (hwnd , (UINT_PTR )SDL_IterateMainCallbacks );
1743
+ }
1701
1744
} break ;
1702
1745
1703
1746
case WM_SIZING :
@@ -2299,16 +2342,6 @@ static void WIN_UpdateMouseCapture(void)
2299
2342
}
2300
2343
#endif // !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES)
2301
2344
2302
- // A message hook called before TranslateMessage()
2303
- static SDL_WindowsMessageHook g_WindowsMessageHook = NULL ;
2304
- static void * g_WindowsMessageHookData = NULL ;
2305
-
2306
- void SDL_SetWindowsMessageHook (SDL_WindowsMessageHook callback , void * userdata )
2307
- {
2308
- g_WindowsMessageHook = callback ;
2309
- g_WindowsMessageHookData = userdata ;
2310
- }
2311
-
2312
2345
int WIN_WaitEventTimeout (SDL_VideoDevice * _this , Sint64 timeoutNS )
2313
2346
{
2314
2347
if (g_WindowsEnableMessageLoop ) {
0 commit comments