Xwayland rootful - part1

A bit of background

Xwayland is intended as a compatibility layer, to allow legacy X11 applications to continue to work in a Wayland environment.

Most Wayland compositors run Xwayland „rootless“ (using the command line option „-rootless“ when spawning Xwayland) so that X11 clients can integrate seamlessly with the other Wayland native clients, the Wayland compositor taking care of stacking the various windows (or surfaces) regardless of the client being X11 or Wayland native.

That actually works very well, so well that in many cases users do not even realize that any particular client is still running on X11, using Xwayland.

For that to work, the Wayland compositor needs to integrate a fully functional X11 window manager.

Sometimes, however, it is useful to use a separate X11 server to run X11 applications with another X11 window manager or even a full X11 environment.

Nested X11 servers

With X11, it is possible to run a nested X11 server such as Xnest or Xephyr, and run a full X11 environment within those nested X servers.

That can be useful for a number of reasons, like connecting remotely to a remote legacy Unix server using XDMCP (not that I would recommend that anyway!), or for testing a particular X11 application with different window managers, or even because a particular X11 application is certified only with a specific window manager. The possibilities are endless.

$ Xephyr -retro -screen 1024x768 :12

Xephyr running the Motif window manager on a GNOME Shell Wayland session

But Xnest or Xephyr are X11 clients themselves, meaning that they run on top of Xwayland when running on a Wayland compositor. That's a bit of a waste, using two X11 servers on top of a Wayland compositor.

Besides, with X.org development winding down, downstream maintainers and packagers may want to reduce the number of X11 servers they ship and have to maintain in the future.

What's wrong with Xwayland rootful?

Right, so if Xwayland already runs rootful by default, why not just using that instead of Xnest or Xephyr?

Well, up until Xwayland 23.1, Xwayland rootful would take its screen configuration from the Wayland compositor itself (using the wl_output or xdg-output Wayland protocols), meaning that when running rootful, Xwayland would map a surface the size of all the monitors, and the user would have no way to easily move or resize it.

That's far from being practical, especially when using a multi-monitor setup!

Making Xwayland rootful (more) usable

So the first step to help making Xwayland rootful suitable as a nested X11 server is to provide a command line option to specify the desired size of the Xwayland window.

That's the „-geometry“ option introduced in Xwayland 23.1 so that one can specifies the desired size of the Xwayland rootful window:

$ Xwayland -geometry 1024x768 :12

That will grant you with a black window of the specified size. If you want more of a „retro“ look, you can get the classic stipple and the X cursor, you can use:

$ Xwayland -geometry 1024x768 -retro :12

Still, the Xwayland window is missing a title bar that would allow for moving the window around.

This is because Wayland does not decorate its surfaces, this is left to the Wayland client themselves to add window decorations (also known as client side decorations, or CSD for short).

This however would add a lot of complexity to Xwayland (which is primarily an Xserver, not a full fledged Wayland application). Thankfully, there is libdecor which can fence Xwayland from that complexity and provide window decorations for us.

So if libdecor is installed on the system and Xwayland is built with libdecor enabled (this is an optional dependency though), then we can request that Xwayland uses decorations with the „-decorate“ command line option:

$ Xwayland -geometry 1024x768 -retro -decorate :12


No we can have fun running some legacy X11 applications on that Xwayland rootful server:

$ xterm -display :12 &
$ twm -display :12 &
$ xsetroot -solid dodgerblue -display :12


We can even use „xrandr“ to query the size of the Xwayland window and resize it:


New with Xwayland 23.2, the Xwayland window is also resize-able interactively and the resulting display size is available in XRandR, creating an XRandR configuration to match the actual window size set interactively by the user:



Comments

Popular posts from this blog

Xwayland rootful - part 2