sway
sway copied to clipboard
sway/server: Implement wayland socket handover
This PR implements the compositor side of the Wayland socket handover protocol as described in the KDE Wiki. The CLI options are chosen so that they are compatible with Kwin (and Hyprland):
Sway now accepts the CLI options --socket NAME and --wayland-fd FD, which pass the name of the Wayland display socket and the Wayland display socket fd number respectively. If given, Sway will use these instead of finding a free Wayland display socket name and creating it.
This allows for Sway to be used with a helper tool that automatically restarts the compositor on crashes, and allowing clients to reconnect after the compositor restart and survive the crash. The reconnecting clients look like new clients to Sway and perform all the same steps as a fresh Wayland client would. No additional handling is required on the side of Sway.
The helper tool finds and creates the Wayland socket and launches Sway with the new CLI options, restarting it when it exits with a non-zero exit code. Two such helper tools currently exist as far as I know:
kwin_wayland_wrapper(only for KDE)wl-restart(developed by me)
Update: Labwc is unsure whether the Kwin CLI options are the right path forward. Before merging this, we should consider alternative mechanisms before multiple compositors standardize on a subpar mechanism. See this wl-restart issue.
I think this would be a nice feature. I've dropped my thoughts in https://github.com/Ferdi265/wl-restart/issues/2#issuecomment-2419679363, and pinged KDE folks about it.