Skip to content

wayland: Add multi-seat support #12626

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Apr 12, 2025

Conversation

Kontrabant
Copy link
Contributor

@Kontrabant Kontrabant commented Mar 23, 2025

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 adding and removing 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 facilitte 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 subsequently bound. This reduces the overhead of switching keymaps to setting a single pointer.

This was tested in Sway with two mouse/keyboard sets split across two seats, including each keyboard having a different language layout. testmanymouse and Woodeneye-008 are now usable on Wayland with the appropriate input configuration, and testime can accept input from both keyboards at once, with each delivering the appropriate layout-specific text.

Multi-seat in Wayland can even support multiple windows having simultaneous mouse/keyboard focus, however, the SDL core assumes that only one of the app's windows at a time can have focus, so proper support for this would require changes to the video/input core, which can come later.

@icculus, if you have a moment, could you test the tablet changes in this branch? The changes on the tablet side are minimal, but I don't have the hardware to check it properly myself.

@Kontrabant Kontrabant force-pushed the wl_multi_seat_final branch from 01e7666 to c91efa9 Compare March 23, 2025 21:55
@slouken slouken added this to the 3.4.0 milestone Mar 23, 2025
@Kontrabant Kontrabant force-pushed the wl_multi_seat_final branch 2 times, most recently from 002be63 to 99db823 Compare March 25, 2025 15:06
@Kontrabant Kontrabant force-pushed the wl_multi_seat_final branch 3 times, most recently from b77e974 to 5182f4e Compare April 2, 2025 19:06
@Kontrabant Kontrabant force-pushed the wl_multi_seat_final branch 4 times, most recently from 4afdf19 to b65f3c4 Compare April 9, 2025 16:49
@Kontrabant
Copy link
Contributor Author

This should be good to go at this point. Going to go over it once again tomorrow for final review and testing.

Things can still get a little weird in the multi-seat case if two different windows both have input focus from different seats at the same time, but I plan on looking into that separately. The overwhelmingly common single-seat case still works as it did before, with no noticeable difference.

@Kontrabant Kontrabant force-pushed the wl_multi_seat_final branch 3 times, most recently from 096e0eb to 77a6133 Compare April 11, 2025 16:09
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.
@Kontrabant Kontrabant force-pushed the wl_multi_seat_final branch from 77a6133 to d620f1a Compare April 11, 2025 16:51
@Kontrabant
Copy link
Contributor Author

I've been testing and going over this for the last couple of days, and aside from one minor bug (missed NULL check) and a couple of tweaks, I haven't seen any regressions, or other major work needed.

This should be good-to-go, and I'll be standing by to quickly address any missed bugs or regressions that shake-out.

@Kontrabant Kontrabant merged commit 113475a into libsdl-org:main Apr 12, 2025
39 checks passed
@Kontrabant Kontrabant deleted the wl_multi_seat_final branch April 12, 2025 17:39
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants