Skip to content

Commit ed28c8e

Browse files
joevtdingusdev
authored andcommitted
display_sdl: Add SDL_SetWindowKeyboardGrab.
To capture the Alt+Tab or the Meta/Super key in Linux/Windows. Not necessary in macOS for the Command key, and macOS doesn't let you capture Command-Tab.
1 parent e689d62 commit ed28c8e

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

devices/video/display_sdl.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,20 @@ void Display::handle_events(const WindowEvent& wnd_event) {
308308
}
309309
break;
310310

311+
case SDL_WINDOWEVENT_FOCUS_GAINED:
312+
if (wnd_event.window_id == impl->disp_wnd_id) {
313+
SDL_SetHint(SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED, "0");
314+
SDL_SetWindowKeyboardGrab(impl->display_wnd, SDL_TRUE);
315+
}
316+
break;
317+
318+
case SDL_WINDOWEVENT_FOCUS_LOST:
319+
if (wnd_event.window_id == impl->disp_wnd_id) {
320+
SDL_SetHint(SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED, "1");
321+
SDL_SetWindowKeyboardGrab(impl->display_wnd, SDL_FALSE);
322+
}
323+
break;
324+
311325
case DPPC_WINDOWEVENT_WINDOW_SCALE_QUALITY_TOGGLE:
312326
if (wnd_event.window_id == impl->disp_wnd_id) {
313327
auto current_quality = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY);

0 commit comments

Comments
 (0)