We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4396 - SDL_WINDOW_INPUT_FOCUS always on after initialisation
Summary: SDL_WINDOW_INPUT_FOCUS always on after initialisation
Status: NEW
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: 2.0.9
Hardware: x86_64 Windows 10
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-11-21 13:09 UTC by Michel Rouzic
Modified: 2018-11-21 13:09 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michel Rouzic 2018-11-21 13:09:23 UTC
Let's say I launch my SDL program, but because I click on my web browser as the SDL program is about to launch my SDL program's window gets created in the background, without focus. This is normal, but what's not normal is that SDL_GetWindowFlags(window) & SDL_WINDOW_INPUT_FOCUS would always return 1 after creation even when it doesn't have the focus, and there's no event that indicates a loss of focus, so no matter what I do there's nothing I can do to check whether or not my window is actually in focus or not, which is a big problem when like me you poll the mouse globally to handle clicking and movement.

Just to be clear, SDL_WINDOW_INPUT_FOCUS is accurate if the window is created while in the foreground, and it gets updated correctly and produces the correct events when the focus changes, just not in case the window is created in the background, as it seems to assume this shouldn't happen.

To reproduce just log the value of SDL_GetWindowFlags(window) & SDL_WINDOW_INPUT_FOCUS or window events and then launch the app but click repeatedly on another window before it gets created (might help to put a little SDL_Delay(2000); before the window creation, also don't launch it from Visual Studio as VS will bring the window to the foreground), and you'll see that it believes to be in focus from the start even when it isn't.