SDL2: set input focus on a window

1.6k views Asked by At

Using SDL2, I have a setup which consists of two monitors and two SDL windows. Each monitor has its own Window set in fullscreen mode.

My goal is to feed keyboard input to one window at a time, and allow switching window by pressing the Tab key. Each of my window has the notion of "keyboard focus", for which I listen on SDL_WINDOWEVENT_FOCUS_GAINED and SDL_WINDOWEVENT_FOCUS_LOST.

The issue I am having is to switch input focus from one window to the next using the tab key. SDL_RaiseWindow() changes the input, but it somehow minimizes the other window completely. I have tried to restore the previous window but that has not work.

If I am to use the mouse, then the code works, but I would prefer to create a hotkey that allows redirecting keyboard from one window to the other.

1

There are 1 answers

0
Twinklebear On BEST ANSWER

From this SDL wiki page: SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS it sounds like the default behavior is to minimize but you can set this option to have the window not minimize. For how to use hints check out CategoryHints on the wiki, I've never used them myself but this might be what you want.