Expose separate keyboard and mouse grab support

This adds SDL_SetWindowKeyboardGrab(), SDL_GetWindowKeyboardGrab(),
SDL_SetWindowMouseGrab(), SDL_GetWindowMouseGrab(), and new
SDL_WINDOW_KEYBOARD_GRABBED flag. It also updates the test harness to exercise
this functionality and makes a minor fix to X11 that I missed in
https://hg.libsdl.org/SDL/rev/02a2d609369b

To fit in with this new support, SDL_WINDOW_INPUT_CAPTURE has been renamed to
SDL_WINDOW_MOUSE_CAPTURE with the old name remaining as an alias for backwards
compatibility with older code.
This commit is contained in:
Cameron Gutman 2021-01-26 19:16:17 -06:00
parent ff827fc767
commit 6b057c6783
12 changed files with 367 additions and 84 deletions

View file

@ -34,7 +34,7 @@ static const char *video_usage[] = {
"[--icon icon.bmp]", "[--center | --position X,Y]", "[--geometry WxH]",
"[--min-geometry WxH]", "[--max-geometry WxH]", "[--logical WxH]",
"[--scale N]", "[--depth N]", "[--refresh R]", "[--vsync]", "[--noframe]",
"[--resize]", "[--minimize]", "[--maximize]", "[--grab]",
"[--resize]", "[--minimize]", "[--maximize]", "[--grab]", "[--keyboard-grab]",
"[--allow-highdpi]", "[--usable-bounds]"
};
@ -412,7 +412,11 @@ SDLTest_CommonArg(SDLTest_CommonState * state, int index)
return 1;
}
if (SDL_strcasecmp(argv[index], "--grab") == 0) {
state->window_flags |= SDL_WINDOW_INPUT_GRABBED;
state->window_flags |= SDL_WINDOW_MOUSE_GRABBED;
return 1;
}
if (SDL_strcasecmp(argv[index], "--keyboard-grab") == 0) {
state->window_flags |= SDL_WINDOW_KEYBOARD_GRABBED;
return 1;
}
if (SDL_strcasecmp(argv[index], "--rate") == 0) {
@ -1764,13 +1768,22 @@ SDLTest_CommonEvent(SDLTest_CommonState * state, SDL_Event * event, int *done)
break;
case SDLK_g:
if (withControl) {
/* Ctrl-G toggle grab */
/* Ctrl-G toggle mouse grab */
SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
if (window) {
SDL_SetWindowGrab(window, !SDL_GetWindowGrab(window) ? SDL_TRUE : SDL_FALSE);
}
}
break;
case SDLK_k:
if (withControl) {
/* Ctrl-K toggle keyboard grab */
SDL_Window* window = SDL_GetWindowFromID(event->key.windowID);
if (window) {
SDL_SetWindowKeyboardGrab(window, !SDL_GetWindowKeyboardGrab(window) ? SDL_TRUE : SDL_FALSE);
}
}
break;
case SDLK_m:
if (withControl) {
/* Ctrl-M maximize */