440. Xwayland and X11 applications
This page is for anyone running a program that is older than Wayland or was never ported to it. KDOS has no Xorg server. Programs that can only speak the X11 protocol run on Xwayland, an X server that is itself a client of KWin and draws each X11 window as a window of the desktop. This page covers how Xwayland is started, which settings decide whether a program uses it, how to run an X11 program on purpose from a terminal, from another console or inside a box, how to check that X11 and its OpenGL work, and what to look at when an X11 program does not open. Why X is allowed only in this form is explained in No Xorg server, and one carve-out, and how KWin runs it in KWin.
Installation
Xwayland is part of every image that has the desktop, and it is not a service:
- xwayland installs
/usr/bin/Xwayland. Its recipe builds no other X server. - kwin is built with its X11 window management, which it needs to run Xwayland and manage X11 windows, and starts Xwayland itself.
- mesa is built with the X11 platform and GLX behind libglvnd, so an X11 client gets OpenGL.
- xkbcomp compiles the keymaps Xwayland asks for, from xkeyboard-config’s data.
- font-misc-misc, font-cursor-misc and font-adobe-75dpi are the core X fonts, the ones a Motif or Xt program asks the server for by name. They are not in the base the ISO carries:
sudo kdos update install <port>adds each (see Installing software). - The X client libraries,
libX11,libxcband the rest, are ports on thex11shelf and are linked by any application that needs them.
The session’s KWin creates the X display when it starts and puts DISPLAY and XAUTHORITY into the session’s environment, so every program the session starts has them. Xwayland itself starts when the first X11 client connects; KWin then runs plasma-workspace’s /usr/lib/libexec/plasma-setup-xwayland with DISPLAY set, and takes the X11 window-manager selections. The greeter’s KWin starts no X server at all. Nothing is enabled by hand, and fs/etc/X11/ does not exist.
The live medium and an installed system behave the same.
Configuration
The Xwayland build
meson setup build \
--prefix=/usr --sysconfdir=/etc --libdir=lib \
--buildtype=release \
-Dxvfb=false \
-Dsecure-rpc=false \
-Dxwayland_ei=false \
-Dlibdecor=false \
-Dsystemd_notify=false \
-Dxselinux=false \
-Dglamor=true \
-Ddri3=true \
-Dglx=true \
-Dsha1=libcrypto \
-Dxkb_dir=/usr/share/X11/xkb \
-Dxkb_output_dir=/var/lib/xkb \
-Dxkb_bin_dir=/usr/bin \
-Ddefault_font_path=/usr/share/fonts/misc/,/usr/share/fonts/75dpi/ \
-Ddocs=false \
-Ddevel-docs=false
ports/core/x11/xwayland/build.sh, lines 12–30
What each switch does is on the xwayland package page. The keymaps it compiles at run time are written to /var/lib/xkb.
KWin’s settings for X11 programs
Two pages of System Settings change how KWin treats X11 programs:
- Display Configuration → Legacy Applications (X11): whether X11 programs are scaled by KWin, which blurs them on a scaled screen, or apply the scaling themselves.
- Application Permissions → Legacy X11 App Support: whether an X11 program may read the keys typed into Wayland windows, never, only with a modifier, or always. Programs that rely on global key grabs, such as some push-to-talk tools, need it.
Which toolkits choose X11
Every login shell exports the toolkits’ back ends, and Wayland comes first in each that has one:
# Toolkit back ends. GTK and Qt are built with their Wayland and X11 back ends,
# and Wayland comes first; SDL is built with Wayland alone, so its driver
# names no fallback; Tk and Motif have only X11 and run under Xwayland.
# Qt takes a list and falls back to xcb (Xwayland) only when the Wayland
# plugin cannot start, which is a Qt 5 application built without one; a name
# on its own here would leave that application not starting at all. GDK_BACKEND
# is left unset: GDK already tries Wayland first, and a value here would
# override the GDK_BACKEND=x11 an X11-only application sets for itself.
export QT_QPA_PLATFORM="wayland;xcb"
export MOZ_ENABLE_WAYLAND=1
export SDL_VIDEODRIVER=wayland
export CLUTTER_BACKEND=wayland
fs/etc/profile.d/10-wayland.sh, lines 82–93
- GTK tries Wayland first on its own;
GDK_BACKENDis left unset, so a program that setsGDK_BACKEND=x11for itself gets Xwayland. - Qt takes the list
wayland;xcband uses X11 only when its Wayland plugin cannot start. - SDL is built with its Wayland driver alone, so
SDL_VIDEODRIVERnames no fallback. - Clutter and Firefox are told to use Wayland.
- Tk and Motif have only an X11 back end, so every Tk or Motif program runs on Xwayland.
- Java Swing and AWT run on Xwayland.
A port whose program misbehaves on Wayland can force X11 in its own desktop entry. Brasero’s recipe does:
Exec=env GDK_BACKEND=x11 brasero %U
ports/core/optical/brasero/build.sh, lines 40–40
Boxed applications
A box receives no profile environment. Xwayland is one client to KWin, so an X11 window in a box is drawn untagged and nothing it binds is filtered. A box is handed the X11 display anyway unless its profile’s x11 key says no: Tk, Java, Motif, FLTK, GTK 2 and Xt programs have no other way to open a window, and nothing in a package says which toolkit a program draws with. A box handed it is at most tagged, and x11 = no is what confines one. kdos-appbox sets DISPLAY and the cookie itself (src/system/kdos-appbox/main.c):
/*
* DISPLAY, for a box that is handed X11 (profile_x11): every box
* whose profile does not say `x11 = no`. The socket is the authority
* — KWin exports DISPLAY only into what the session started, and a
* launch from a prompt may not have it — and the cookie is the box's
* copy in its own runtime directory, or the session's own where the
* box shares that directory. A box that says `x11 = no` is told there
* is no display, so a toolkit with an X11 fallback does not reach for
* one it would be refused.
*/
src/system/kdos-appbox/main.c, lines 605–614
It also exports QT_QPA_PLATFORM=wayland;xcb and SDL_VIDEODRIVER=wayland,x11 into every box, because Qt 5 and SDL 2 would otherwise take DISPLAY over the tagged Wayland socket; a catalogue or pack env row that forces X11 is exported after them and wins.
When kdos-appbox writes launchers for a boxed application, it removes from the entry’s Exec line the assignments that would force X11, so an application whose distribution entry asks for X11 runs on Wayland:
static const char *X11_FORCING[] = {
"GDK_BACKEND=x11", "CLUTTER_BACKEND=x11", "QT_QPA_PLATFORM=xcb",
"SDL_VIDEODRIVER=x11", "MOZ_ENABLE_WAYLAND=0",
"ELECTRON_OZONE_PLATFORM_HINT=x11", NULL
};
src/system/kdos-appbox/launchers.c, lines 326–330
Usage
Checking that Xwayland is there
In Konsole (
Meta+Return):echo "$DISPLAY" ls /tmp/.X11-unix/DISPLAYnames the display, such as:0, and/tmp/.X11-unix/holds its socket,X0for:0.See whether the server is running at this moment; with no X11 client it is not:
pgrep -a XwaylandWhile a client is connected it prints a line such as
Xwayland :0 -rootless -core -terminate 10 -listenfd 20 -listenfd 21 -displayfd 76 -wm 67. Ten seconds after the last client leaves, the process is gone andX0is still there.kdos doctor’s Desktop section checks the socketDISPLAYnames when it is set. With noDISPLAYit checks that Xwayland is installed and that/tmp/.X11-unixexists, root-owned and mode 1777: KWin does not create that directory, and without it no X11 program opens.
Running a program on X11
To run a GTK program on X11 instead of Wayland, for one start:
GDK_BACKEND=x11 <program>For a Qt program:
QT_QPA_PLATFORM=xcb <program>A Tk program needs nothing; Tk speaks only X11. A test window, which closes when its button is pressed:
echo 'pack [button .b -text "X11 works" -command exit]' | wish
To make the choice for every start of one program, write your own copy of its desktop entry into ~/.local/share/applications/ with env GDK_BACKEND=x11 (or QT_QPA_PLATFORM=xcb) at the front of its Exec line; see The panel and the launcher.
Running an X11 program from tty2 or SSH
A shell outside the session has no DISPLAY, and Xwayland requires the session’s cookie.
Log in as the same account as the session.
Read the display number off the socket, and the cookie’s path from KWin’s own environment:
ls /tmp/.X11-unix/ tr '\0' '\n' < /proc/$(pgrep -u "$USER" -x kwin_wayland)/environ | grep XAUTHORITY DISPLAY=:0 XAUTHORITY=<that path> wish
Checking OpenGL through Xwayland
The host’s mesa-demos port is built for Wayland alone, so glxinfo and glxgears come from a box; the host has es2gears_wayland and none of the three below. The app.mesa-utils catalogue entry builds Debian’s mesa-utils and puts the three X11 programs on the host’s path. This needs a network for the first install; without one it stops at app.mesa-utils: base did not build:
kdos app install app.mesa-utils
glxinfo | head -20
glxgears
es2gears_x11
glxinfo shows the GLX extension, which Xwayland on the host serves, and the renderer, which is the box’s own Mesa: an X11 client in a box draws with its box’s libraries. Comparing es2gears_x11 with the host’s es2gears_wayland shows what the X11 path costs; see Desktop GL and GLX.
Tips
- An X11 video player that blocks the screensaver through
org.freedesktop.ScreenSaver, as VLC does, is answered by PowerDevil, so the screen does not dim during playback. - An X11 window from a box carries no box tag, so it has no box colour on its title bar and none of the box’s restrictions at KWin. That is why a box is handed the display only when it needs it. Its title ends in the box’s host name, as
ImageJ <@app.imagej.<host>>: KWin shows an X11 window’s client machine when it differs from this one’s, and a box’s host name is<box>.<host>. The Task Manager finds its launcher by the window’s class, which the generated launcher’sStartupWMClassnames; see Naming rules. - The on-screen keyboard never rises by itself for an X11 window, which does not speak the text-input protocol; show it from the system tray.
kdos why /usr/bin/Xwaylandnames the package and recipe it came from.
Troubleshooting
An X11 program exits saying it cannot open or connect to the display. Its shell has no DISPLAY or no cookie. Inside the session, start it from Konsole, or set both as in Running an X11 program from tty2 or SSH. In a box, the profile’s x11 key decides: kdos-box profile <box> shows it, and a box with x11 = no is handed no display; remove the line, or set x11 = yes, and start the box again.
There is no socket in /tmp/.X11-unix/. KWin could not create the X display. Read the session log for KWin’s Xwayland lines:
grep -i xwayland ~/.local/share/sddm/wayland-session.log
Check that the package is installed with kpkg info xwayland; the display is created when KWin starts, so log in again after installing it.
An X11 program starts and exits at once with a GLX error, or says no GLX extension is present. Run glxinfo from the box above. When it lists no GLX extension, the X server is the cause: Xwayland serves GLX only when it is built with -Dglx=true, as the xwayland page explains. When the extension is listed and a host program still fails, check that the host’s OpenGL libraries are installed; see Desktop GL and GLX.
A Java program draws a blank or misplaced window. Java’s AWT toolkit does not always recognise the window manager it runs under, and then draws for the wrong kind. The login profile does not set _JAVA_AWT_WM_NONREPARENTING, the variable that tells it not to expect a frame around its window; set it on the command line:
_JAVA_AWT_WM_NONREPARENTING=1 <program>
Typing in an X11 program ignores the input method. An X11 program has an input-method route only when it is a GTK 3 or GTK 4 program on the host, through fcitx5-gtk’s module (Input methods); every other X11 program has none. See X11 programs other than GTK ones get no input method.
A program that has a Wayland back end runs on X11 anyway. Check its environment for a forcing variable (GDK_BACKEND=x11, QT_QPA_PLATFORM=xcb, SDL_VIDEODRIVER=x11) and its desktop entry’s Exec line for an env prefix:
grep -l 'GDK_BACKEND=x11\|QT_QPA_PLATFORM=xcb' /usr/share/applications/*.desktop ~/.local/share/applications/*.desktop
Known gaps
See also
- No Xorg server, and one carve-out: what the carve-out allows and what it keeps out
- Xwayland: how KWin runs it
- Input methods: which X11 windows get one
- The environment a box receives:
DISPLAYand the rest inside a box - Desktop GL and GLX: what an X11 client draws with
- Session and environment, Input methods, Boxes, Graphics drivers, Virtual machines