xref: /aosp_15_r20/external/wayland/doc/publican/sources/Xwayland.xml (revision 84e872a0dc482bffdb63672969dd03a827d67c73)
1*84e872a0SLloyd Pique<?xml version='1.0' encoding='utf-8' ?>
2*84e872a0SLloyd Pique<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
3*84e872a0SLloyd Pique<!ENTITY % BOOK_ENTITIES SYSTEM "Wayland.ent">
4*84e872a0SLloyd Pique%BOOK_ENTITIES;
5*84e872a0SLloyd Pique]>
6*84e872a0SLloyd Pique<chapter id="chap-X11-Application-Support">
7*84e872a0SLloyd Pique  <title>X11 Application Support</title>
8*84e872a0SLloyd Pique  <section id="sect-X11-Application-Support-introduction">
9*84e872a0SLloyd Pique    <title>Introduction</title>
10*84e872a0SLloyd Pique    <para>
11*84e872a0SLloyd Pique      Being able to run existing X11 applications is crucial for the adoption
12*84e872a0SLloyd Pique      of Wayland, especially on desktops, as there will always be X11
13*84e872a0SLloyd Pique      applications that have not been or cannot be converted into Wayland
14*84e872a0SLloyd Pique      applications, and throwing them all away would be prohibitive.
15*84e872a0SLloyd Pique      Therefore a Wayland compositor often needs to support running X11
16*84e872a0SLloyd Pique      applications.
17*84e872a0SLloyd Pique    </para>
18*84e872a0SLloyd Pique    <para>
19*84e872a0SLloyd Pique      X11 and Wayland are different enough that there is no "simple" way to
20*84e872a0SLloyd Pique      translate between them. Most of X11 is uninteresting to a Wayland
21*84e872a0SLloyd Pique      compositor. That, combined with the gigantic implementation effort needed
22*84e872a0SLloyd Pique      to support X11, makes it intractable to just write X11 support directly in
23*84e872a0SLloyd Pique      a Wayland compositor. The implementation would be nothing short of a
24*84e872a0SLloyd Pique      real X11 server.
25*84e872a0SLloyd Pique    </para>
26*84e872a0SLloyd Pique    <para>
27*84e872a0SLloyd Pique      Therefore, Wayland compositors should use Xwayland, the X11 server that
28*84e872a0SLloyd Pique      lives in the Xorg server source code repository and shares most of the
29*84e872a0SLloyd Pique      implementation with the Xorg server. Xwayland is a complete X11 server,
30*84e872a0SLloyd Pique      just like Xorg is, but instead of driving the displays and opening input
31*84e872a0SLloyd Pique      devices, it acts as a Wayland client. The rest of this chapter talks
32*84e872a0SLloyd Pique      about how Xwayland works.
33*84e872a0SLloyd Pique    </para>
34*84e872a0SLloyd Pique    <para>
35*84e872a0SLloyd Pique      For integration and architecture reasons, while Xwayland is a Wayland
36*84e872a0SLloyd Pique      client of the Wayland compositor, the Wayland compositor is an X11 client
37*84e872a0SLloyd Pique      of Xwayland. This circular dependency requires special care from the
38*84e872a0SLloyd Pique      Wayland compositor.
39*84e872a0SLloyd Pique    </para>
40*84e872a0SLloyd Pique  </section>
41*84e872a0SLloyd Pique  <section id="sect-X11-Application-Support-two-modes">
42*84e872a0SLloyd Pique    <title>Two Modes for Foreign Windows</title>
43*84e872a0SLloyd Pique    <para>
44*84e872a0SLloyd Pique      In general, windows from a foreign window system can be presented in one
45*84e872a0SLloyd Pique      of two ways: rootless and rootful (not rootless).
46*84e872a0SLloyd Pique    </para>
47*84e872a0SLloyd Pique    <para>
48*84e872a0SLloyd Pique      In rootful mode, the foreign window system as a whole is represented as a
49*84e872a0SLloyd Pique      window (or more) of its own. You have a native window, inside which all
50*84e872a0SLloyd Pique      the foreign windows are. The advantage of this approach in Xwayland's
51*84e872a0SLloyd Pique      case is that you can run your favourite X11 window manager to manage your
52*84e872a0SLloyd Pique      X11 applications. The disadvantage is that the foreign windows do not
53*84e872a0SLloyd Pique      integrate with the native desktop. Therefore this mode is not usually
54*84e872a0SLloyd Pique      used.
55*84e872a0SLloyd Pique    </para>
56*84e872a0SLloyd Pique    <para>
57*84e872a0SLloyd Pique      In rootless mode, each foreign window is a first-class resident among the
58*84e872a0SLloyd Pique      native windows. Foreign windows are not confined inside a native window
59*84e872a0SLloyd Pique      but act as if they were native windows. The advantage is that one can
60*84e872a0SLloyd Pique      freely stack and mix native and foreign windows, which is not possible in
61*84e872a0SLloyd Pique      rootful mode. The disadvantage is that this mode is harder to implement
62*84e872a0SLloyd Pique      and fundamental differences in window systems may prevent some things
63*84e872a0SLloyd Pique      from working. With rootless Xwayland, the Wayland compositor must take
64*84e872a0SLloyd Pique      the role as the X11 window manager, and one cannot use any other X11
65*84e872a0SLloyd Pique      window manager in its place.
66*84e872a0SLloyd Pique    </para>
67*84e872a0SLloyd Pique    <para>
68*84e872a0SLloyd Pique      This chapter concentrates on the rootless mode, and ignores the rootful
69*84e872a0SLloyd Pique      mode.
70*84e872a0SLloyd Pique    </para>
71*84e872a0SLloyd Pique  </section>
72*84e872a0SLloyd Pique  <section id="sect-X11-Application-Support-architecture">
73*84e872a0SLloyd Pique    <title>Architecture</title>
74*84e872a0SLloyd Pique    <para>
75*84e872a0SLloyd Pique      A Wayland compositor usually takes care of launching Xwayland.
76*84e872a0SLloyd Pique      Xwayland works in cooperation with a Wayland compositor as follows:
77*84e872a0SLloyd Pique    </para>
78*84e872a0SLloyd Pique    <figure>
79*84e872a0SLloyd Pique      <title>Xwayland architecture diagram</title>
80*84e872a0SLloyd Pique      <mediaobjectco>
81*84e872a0SLloyd Pique	<imageobjectco>
82*84e872a0SLloyd Pique	  <imageobject>
83*84e872a0SLloyd Pique	    <imagedata fileref="images/xwayland-architecture.png" format="PNG" />
84*84e872a0SLloyd Pique	  </imageobject>
85*84e872a0SLloyd Pique	</imageobjectco>
86*84e872a0SLloyd Pique      </mediaobjectco>
87*84e872a0SLloyd Pique    </figure>
88*84e872a0SLloyd Pique    <para>
89*84e872a0SLloyd Pique      An X11 application connects to Xwayland just like it would connect to any
90*84e872a0SLloyd Pique      X server. Xwayland processes all the X11 requests. On the other end,
91*84e872a0SLloyd Pique      Xwayland is a Wayland client that connects to the Wayland compositor.
92*84e872a0SLloyd Pique    </para>
93*84e872a0SLloyd Pique    <para>
94*84e872a0SLloyd Pique      The X11 window manager (XWM) is an integral part of the Wayland
95*84e872a0SLloyd Pique      compositor. XWM uses the usual X11 window management protocol to manage
96*84e872a0SLloyd Pique      all X11 windows in Xwayland. Most importantly, XWM acts as a bridge
97*84e872a0SLloyd Pique      between Xwayland window state and the Wayland compositor's window manager
98*84e872a0SLloyd Pique      (WWM). This way WWM can manage all windows, both native Wayland and X11
99*84e872a0SLloyd Pique      (Xwayland) windows. This is very important for a coherent user
100*84e872a0SLloyd Pique      experience.
101*84e872a0SLloyd Pique    </para>
102*84e872a0SLloyd Pique    <para>
103*84e872a0SLloyd Pique      Since Xwayland uses Wayland for input and output, it does not have any
104*84e872a0SLloyd Pique      use for the device drivers that Xorg uses. None of the xf86-video-* or
105*84e872a0SLloyd Pique      xf86-input-* modules are used. There also is no configuration file for
106*84e872a0SLloyd Pique      the Xwayland server. For optional hardware accelerated rendering,
107*84e872a0SLloyd Pique      Xwayland uses GLAMOR.
108*84e872a0SLloyd Pique    </para>
109*84e872a0SLloyd Pique    <para>
110*84e872a0SLloyd Pique      A Wayland compositor usually spawns only one Xwayland instance. This is
111*84e872a0SLloyd Pique      because many X11 applications assume they can communicate with other X11
112*84e872a0SLloyd Pique      applications through the X server, and this requires a shared X server
113*84e872a0SLloyd Pique      instance. This also means that Xwayland does not protect nor isolate X11
114*84e872a0SLloyd Pique      clients from each other, unless the Wayland compositor specifically
115*84e872a0SLloyd Pique      chooses to break the X11 client intercommunications by spawning
116*84e872a0SLloyd Pique      application specific Xwayland instances. X11 clients are naturally
117*84e872a0SLloyd Pique      isolated from Wayland clients.
118*84e872a0SLloyd Pique    </para>
119*84e872a0SLloyd Pique    <para>
120*84e872a0SLloyd Pique      Xwayland compatibility compared to a native X server will probably never
121*84e872a0SLloyd Pique      reach 100%. Desktop environment (DE) components, specifically X11 window
122*84e872a0SLloyd Pique      managers, are practically never supported. An X11 window manager would
123*84e872a0SLloyd Pique      not know about native Wayland windows, so it could manage only X11
124*84e872a0SLloyd Pique      windows. On the other hand, there must be an XWM that reserves the
125*84e872a0SLloyd Pique      exclusive window manager role so that the Wayland compositor could show
126*84e872a0SLloyd Pique      the X11 windows appropriately. For other DE components, like pagers and
127*84e872a0SLloyd Pique      panels, adding the necessary interfaces to support them in WWM through XWM
128*84e872a0SLloyd Pique      is often considered not worthwhile.
129*84e872a0SLloyd Pique    </para>
130*84e872a0SLloyd Pique  </section>
131*84e872a0SLloyd Pique  <section id="sect-X11-Application-Support-xwm">
132*84e872a0SLloyd Pique    <title>X Window Manager (XWM)</title>
133*84e872a0SLloyd Pique    <para>
134*84e872a0SLloyd Pique      From the X11 point of view, the X window manager (XWM) living inside a
135*84e872a0SLloyd Pique      Wayland compositor is just like any other window manager. The difference
136*84e872a0SLloyd Pique      is mostly in which process it resides in, and the few extra conventions
137*84e872a0SLloyd Pique      in the X11 protocol to support Wayland window management (WWM)
138*84e872a0SLloyd Pique      specifically.
139*84e872a0SLloyd Pique    </para>
140*84e872a0SLloyd Pique    <para>
141*84e872a0SLloyd Pique      There are two separate asynchronous communication channels between
142*84e872a0SLloyd Pique      Xwayland and a Wayland compositor: one uses the Wayland protocol, and the
143*84e872a0SLloyd Pique      other one, solely for XWM, uses X11 protocol. This setting demands great
144*84e872a0SLloyd Pique      care from the XWM implementation to avoid (random) deadlocks with
145*84e872a0SLloyd Pique      Xwayland. It is often nearly impossible to prove that synchronous or
146*84e872a0SLloyd Pique      blocking X11 calls from XWM cannot cause a deadlock, and therefore it is
147*84e872a0SLloyd Pique      strongly recommended to make all X11 communications asynchronous. All
148*84e872a0SLloyd Pique      Wayland communications are already asynchronous by design.
149*84e872a0SLloyd Pique    </para>
150*84e872a0SLloyd Pique    <section id="sect-X11-Application-Support-xwm-window-identification">
151*84e872a0SLloyd Pique      <title>Window identification</title>
152*84e872a0SLloyd Pique      <para>
153*84e872a0SLloyd Pique	In Xwayland, an X11 window may have a corresponding wl_surface object
154*84e872a0SLloyd Pique	in Wayland. The wl_surface object is used for input and output: it is
155*84e872a0SLloyd Pique	referenced by input events and used to provide the X11 window content
156*84e872a0SLloyd Pique	to the Wayland compositor. The X11 window and the wl_surface live in
157*84e872a0SLloyd Pique	different protocol streams, and they need to be matched for XWM to do
158*84e872a0SLloyd Pique	its job.
159*84e872a0SLloyd Pique      </para>
160*84e872a0SLloyd Pique      <para>
161*84e872a0SLloyd Pique	When Xwayland creates a wl_surface on Wayland, it will also send an X11
162*84e872a0SLloyd Pique	ClientMessage of type atom "WL_SURFACE_ID" to the X11 window carrying
163*84e872a0SLloyd Pique	the wl_surface Wayland object ID as the first 32-bit data element. This
164*84e872a0SLloyd Pique	is how XWM can associate a wl_surface with an X11 window. Note that
165*84e872a0SLloyd Pique	the request to create a wl_surface and the ID message may arrive in any
166*84e872a0SLloyd Pique	order in the Wayland compositor.
167*84e872a0SLloyd Pique      </para>
168*84e872a0SLloyd Pique    </section>
169*84e872a0SLloyd Pique  </section>
170*84e872a0SLloyd Pique</chapter>
171