Description of the problem
With Wayland compositors now being able to start
Xwayland on demand, the next logical step is to be able to stop Xwayland when there is no more need for it.
mutter does is to check the X11 clients still connected to
Xwayland using the
XRes extension, with a list of X11 clients that can be safely ignored (typically the GNOME XSettings daemon, the IBus daemon, pulseaudio and even mutter window manager itself). When there is just those known clients remaining,
mutter would automatically kill
But that's racy, because between the time
mutter checks with
Xwayland the remaining clients and the time it actually kills the process, a new X11 client might have come along and won't be able to connect to
mutter is just about to kill. Because of that, the feature “autoclose-xwayland” is marked as an experimental feature in
mutter and not enabled by default.
That means that once Xwayland is started, it would remain running for as long as the session is alive, regardless of any actual meaningful X11 clients.
Thankfully, the Xserver has all it takes to manage that already, and is even capable of terminating itself once all X11 clients are gone (the
-terminate option on the command line). It would be nice if the Wayland compositors could take advantage of that, wouldn't it?
Only thing preventing the Wayland compositors from using that is those long-lived, daemon like X11 clients which keep running with the session and would possibly prevent the Xserver from terminating itself…
Ignore some X11 clients
There comes the idea, if would be nice if the X11 clients could declare themselves disconnect-able, so that the Xserver could simply ignore those X11 clients when checking the remaining clients and terminate itself automatically.
That would be a very small change for the relevant X11 clients, it would avoid the race described above because the Xserver has all that logic already in place, and as cherry on the cake, that would allow for the removal of a large chunk of (fragile) code from the Wayland compositors who try to be smart and guess when they can kill
Let's use XFixes for that!
For that purpose, this adds a couple of simple requests
XFixesGetClientDisconnectMode to XFixes that X11 clients can use to declare themselves disconnect-able by the Xserver.
Is it limited to Xwayland?
No, there is no reason this should be limited to
Xwayland, any Xserver can benefit from this and I can imagine some other Xserver on other platforms benefiting from this as well.
What's in the package?
- xorgproto: xorg/proto/xorgproto!33 (merged)
- libXfixes: xorg/lib/libxfixes!1 (merged)
- xserver: !631 (merged)
How to test?
You can use that simple X11 client client-disconnect-mode.c with the
-terminate option in the Xserver:
- Build and install
xserverfrom the branches above
Xephyr -terminate :12
- Save and build the example
gcc -o client-disconnect-mode client-disconnect-mode.c $(pkg-config --libs --cflags x11 xfixes)
- Run the client with
- Start a regular client such as
Xephyrwill automatically quit , even though the
client-disconnect-modeis still connected.