Skip to content

xfixes: Add ClientDisconnectMode

Olivier Fourdan requested to merge ofourdan/xserver:xfixes-ignore-client into master

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.

Currently, what 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 Xwayland.

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 Xwayland that 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 Xwayland, like mutter does.

Let's use XFixes for that!

For that purpose, this adds a couple of simple requests XFixesSetClientDisconnectMode and 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?

How to test?

You can use that simple X11 client client-disconnect-mode.c with the -terminate option in the Xserver:

  1. Build and install xorgproto, libxfixes and the xserver from the branches above
  2. Run Xephyr -terminate :12
  3. Save and build the example gcc -o client-disconnect-mode client-disconnect-mode.c $(pkg-config --libs --cflags x11 xfixes)
  4. Run the client with DISPLAY=:12 ./client-disconnect-mode
  5. Start a regular client such as DISPLAY=:12 xterm
  6. Exit xterm
  7. Xephyr will automatically quit , even though the client-disconnect-mode is still connected.
Edited by Olivier Fourdan

Merge request reports

Loading