Detecting all kinds of modal message loops

This topic is about SDL3 and Windows 64-bit.


I would like to implement three features in my game:

  1. When resizing a window using the mouse, the main game loop is not executed, because the window resizing is performed in a modal loop controlled by the operating system. During this time, the window content is to be rendered normally (colored game frame).

  2. When a window loses focus, the main loop can continue running or the simulation can be paused and the window’s contents rendered in grayscale (plus additional UI elements).

  3. When the system menu is called, the game loop should be paused and the window content should be rendered in grayscale. The system menu can be called using the keyboard or mouse and is always called using the SDL_ShowWindowSystemMenu function.


Point 1. is implemented by default by the operating system. The modal loop freezes the game thread, the main game loop is not executed. Everything is according to my needs.

Point 2. is easy to implement because SDL provides SDL_EVENT_WINDOW_FOCUS_LOST and SDL_EVENT_WINDOW_FOCUS_GAINED events, so I can set my flag, use its state during frame rendering and choose whether to render in color or grayscale. Here everything is simple.

Point 3. is not simple to handle, because SDL does not generate any meaningful events when the system menu is invoked and closed. When the system menu appears, the window does not lose focus, i.e. SDL does not generate the SDL_EVENT_WINDOW_FOCUS_LOST event. Because I always invoke the system menu using the SDL_ShowWindowSystemMenu function, I know when the menu is shown, but I do not know when it is hidden. In addition, the user can select an option from this menu that starts a modal loop — e.g. selects the Size option from the menu and then a modal loop is started allowing the window to be resized (by mouse or keyboard).


Does anyone know how to detect when the system menu is shown, when it is hidden, and when a modal loop started by selecting an option from that menu ends?

It would be nice if SDL had dedicated events for the system menu and modal loops so that certain aspects of game operation could be controlled from the game logic. Are there any plans for this?

Ok, I know how to handle this. In the message hook callback, I can catch the WM_ENTERMENULOOP and WM_EXITMENULOOP messages to detect when the system menu is invoked and closed; and the WM_ENTERSIZEMOVE and WM_EXITSIZEMOVE messages to know when the modal loop is started and ended.

Unfortunately, the WM_ENTERMENULOOP and WM_ENTERSIZEMOVE messages are not delivered via the hook callback, so I filed and issue:

Ok, added a fix for the problem with the above messages not being delivered via hook callback. These four listed messages are enough to be able to detect when the system menu is shown and hidden, as well as when the modal loop regarding window sizing (using mouse or keyboard) i started and ended. They are enough for me to implement the features that interest me. :wink: