2

SDL2 has a structure for handling window events such as moving a window or resizing a window. This structure, SDL_WindowEvent, is useful because Windows's event loop for a window blocks the thread of execution that created the window when the window is being moved or resized. Many SDL2 application developers find such behaviour undesirable, so they poll SDL2 for SDL_WindowEvents with SDL_WindowEventIDs of SDL_WINDOW_MOVED or SDL_WINDOW_RESIZED in order to handle the thread block. For example, physics engines with variable timesteps may potentially receive a dt of several seconds as a result of the user moving the window, and the engine will probably want to discard this time to avoid physics errors.

However, in my experience, SDL_WindowEvents cannot recognize when a window's title bar is "grabbed" by the mouse but not moved, or when a window's resize handles are "grabbed" but the window size does not change. In these cases, Windows blocks the thread of execution owning the window, but neither SDL_WINDOW_MOVED nor SDL_WINDOW_RESIZED are present in any SDL_WindowEvents.

In the example case given, these two cases make no difference, as the physics engine will merely discard the dt or clamp it, but this kind of workaround is not always possible.

Is there a way to detect these cases in which a window move or resize event has occurred that did not affect the location or size of the window?

Martin G
  • 17,357
  • 9
  • 82
  • 98
pmttavara
  • 698
  • 7
  • 16
  • How are you going to handle long timesteps resulting from other causes, such as modal dialogs or excessive page faults? – user253751 Aug 24 '15 at 03:01
  • 3
    The time step problem has many solutions that one could find elsewhere on the Internet. My question was mainly to ask how to detect these events that _are occurring_ but are not being reported by SDL2. Some developers might want to continue running their application while the window is being dragged, similarly to the answer to [this question](http://stackoverflow.com/questions/7106586/keep-window-active-while-being-dragged-sdl-on-win32). – pmttavara Aug 24 '15 at 03:07
  • @pmttavara I definitely don't have the solution, but I don't think it's a stretch to say that the behavior you desire might be platform-specific and might require sticking your hands into the guts of the Windows API. And that is where the light on my land doesn't touch -Mufasa 2015 – CinchBlue Aug 24 '15 at 03:18
  • Were you ever able to find a solution to this? I am currently running into this problem myself. It is both irritating and amusing to see my app "freeze" when I stop moving the window around while dragging it despite using a `SDL_SetEventFilter` function looking for `SDL_WINDOW_MOVED` and `SDL_WINDOW_RESIZED` events. – CodeSurgeon Nov 05 '17 at 05:40
  • No, sadly. If you've already tried [the answers to my linked question](https://stackoverflow.com/q/7106586/3185819), I suggest launching a new thread--just be careful to [check](https://wiki.libsdl.org/SDL_PumpEvents#Remarks) what it can call. Sorry, that's all I have. – pmttavara Nov 05 '17 at 07:17

0 Answers0