wayland: Add multi-seat support

Wayland environments can expose more than one seat for multiple collections of input devices, which can include multiple, simultaneously active, desktop pointers and keyboards with independent layouts. The Wayland input backend previously presumed that only one seat could exist, which caused broken behavior if the compositor exposed more than one, which is possible on wlroots based compositors such as Sway. This introduces support for handling multiple seats, including proper handling of dynamically added and removed seats and capabilities at run time.

The SDL Wayland input system was accreted over time, and the assumption that only one seat will ever exist resulted in state and related objects not always being tied to their most appropriate owner in a multi-seat scenario, so refactoring was required to manage several bits of state per-seat, instead of per-window or globally.

As Wayland keyboards can have per-seat layouts, fast keymap switching is required when multiplexing input from multiple seats to the global SDL keyboard device. A parameter was added to the keymap creation function to specify if the keymap lifetime should be externally managed to facilitate keymap reuse, and some layout info was moved from the global keyboard state to the keymap state to avoid unnecessarily redetermining it whenever a reused keymap is bound. This reduces the overhead of switching keymaps to setting a single pointer.

Multiple seats also means that multiple windows can have keyboard and/or mouse focus at the same time on some compositors, but this is not currently a well-handled case in SDL, and will require more work to support, if necessary.
This commit is contained in:
Frank Praznik
2025-03-11 18:18:15 -04:00
parent 4093e4a193
commit 113475acbd
25 changed files with 1852 additions and 1450 deletions

View File

@@ -2511,7 +2511,13 @@ SDL_AppResult SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const
/* Ctrl-G toggle mouse grab */
SDL_Window *window = SDL_GetWindowFromEvent(event);
if (window) {
SDL_SetWindowMouseGrab(window, !SDL_GetWindowMouseGrab(window));
if (SDL_RectEmpty(SDL_GetWindowMouseRect(window))) {
SDL_Rect r = { 10, 10, 200, 200};
SDL_SetWindowMouseRect(window, &r);
} else {
SDL_SetWindowMouseRect(window, NULL);
}
//SDL_SetWindowMouseGrab(window, !SDL_GetWindowMouseGrab(window));
}
}
break;