Tuesday, May 19, 2020

xisxwayland checks for Xwayland ... or not

One of the more common issues we encounter debugging things is that users don't always know whether they're running on a Wayland or X11 session. Which I guess is a good advertisement for how far some of the compositors have come. The question "are you running on Xorg or Wayland" thus comes up a lot and suggestions previously included things like "run xeyes", "grep xinput list", "check xrandr" and so on and so forth. None of those are particularly scriptable, so there's a new tool around now: xisxwayland.

Run without arguments it simply exits with exit code 0 if the X server is Xwayland, or 1 otherwise. Which means use can use it like this:

$ cat my-xorg-only-script.sh

if xisxwayland; then
   echo "This is an Xwayland server!";
   exit 1

Or, in the case where you have a human user (gasp!), you can ask them to run:
$ xisxwayland --verbose
Xwayland: YES
And even non-technical users should be able to interpret that.

Note that the script checks for Xwayland (hence the name) via the $DISPLAY environment variable, just like any X application. It does not check whether there's a Wayland compositor running but for most use-cases this doesn't matter anyway. For those where it matters you get to write your own script. Congratulations, I guess.


Peter said...

I know this is a bikeshedding, but since you envision interactive use, it seems much more user-friendly to have the verbose output by default and to provide a -q switch for use in scripts.

Peter Hutterer said...

I thought about it, but I still think that the primary use-case here is for scripts. I guess history will tell us...

Bar A. said...
This comment has been removed by a blog administrator.
S├ębastien Wilmet said...

Personally I use xlsclients (but not in a script).

To know what the compositor supports, why not a command that outputs something like:
- wayland-only
- wayland-xwayland
- x11

Peter Hutterer said...

Simple: it's harder to write and the use-case is a bit harder to define so it's a lot harder to get right because of various corner-cases. In most cases, the need we/users have is to figure out if that X application is connecting to a "real" X server, so checking for X wayland is good enough.