5
\$\begingroup\$

Is there a replacement for SDL_GetAppState function in SDL2 from older SDL versions? Why was it removed? I want to use it so I can check if the user has focused the framebuffer window or not.

I found it in the documentation of the SDL 1.2.15 (Documentation page) but it seems like it disappeared in SDL2.X.

\$\endgroup\$

2 Answers 2

6
\$\begingroup\$

You can use SDL_GetWindowFlags, it returns similar flags (among others) that you can use to check if the window has mouse/input focus.

The API has changed because SDL2 supports multiple windows.

\$\endgroup\$
0
1
\$\begingroup\$

To answer the title question "How do I check if a window has focus in SDL2?":

bool HasWindowFocus(SDL_Window* window)
{
    uint32_t flags = SDL_GetWindowFlags(window);
    // We *don't* want to check mouse focus:
    // SDL_WINDOW_INPUT_FOCUS - input is going to the window
    // SDL_WINDOW_MOUSE_FOCUS - mouse is hovered over the window, regardless of window focus
    return (flags & SDL_WINDOW_INPUT_FOCUS) != 0;
}

Thanks to this answer for explaining the flags.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .