Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Costava/6f41383a57a5445a71f12f3e0ef25e74 to your computer and use it in GitHub Desktop.
Save Costava/6f41383a57a5445a71f12f3e0ef25e74 to your computer and use it in GitHub Desktop.

SDL 2.0.9

The title bar of a window is the bar that would have the minimize, maximize, and close buttons.

When you click the title bar of an SDL window to regain focus, the window may begin receiving keyboard events as expected but never mouse events (except for one mouse event at the time of the click).

How to reproduce problem:

  1. Call SDL_SetRelativeMouseMode(SDL_TRUE)
  2. Alt+tab away from the SDL window
  3. Click the title bar of the SDL window
  4. At this point, the window will receive keyboard events as expected, but not mouse events. One mouse event will be received when the title bar is clicked, but no mouse events are received after that, even when the mouse is moved and clicked.

Workaround:

  1. Alt+tab away from the window
  2. Either alt+tab back to the window or click the window itself (not the title bar)

Fix:

  • Whenever you receive event SDL_WINDOWEVENT_FOCUS_LOST call SDL_SetRelativeMouseMode(SDL_FALSE)
  • Whenever you receive event SDL_WINDOWEVENT_FOCUS_GAINED call SDL_SetRelativeMouseMode(SDL_TRUE)

With the fix in place, you can click either the window itself or its title bar and the window will begin receiving mouse events as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment