xref: /aosp_15_r20/external/wayland/doc/publican/sources/Protocol.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-Protocol">
7*84e872a0SLloyd Pique  <title>Wayland Protocol and Model of Operation</title>
8*84e872a0SLloyd Pique  <section id="sect-Protocol-Basic-Principles">
9*84e872a0SLloyd Pique    <title>Basic Principles</title>
10*84e872a0SLloyd Pique    <para>
11*84e872a0SLloyd Pique      The Wayland protocol is an asynchronous object oriented protocol.  All
12*84e872a0SLloyd Pique      requests are method invocations on some object.  The requests include
13*84e872a0SLloyd Pique      an object ID that uniquely identifies an object on the server.  Each
14*84e872a0SLloyd Pique      object implements an interface and the requests include an opcode that
15*84e872a0SLloyd Pique      identifies which method in the interface to invoke.
16*84e872a0SLloyd Pique    </para>
17*84e872a0SLloyd Pique    <para>
18*84e872a0SLloyd Pique      The protocol is message-based.  A message sent by a client to the server
19*84e872a0SLloyd Pique      is called request.  A message from the server to a client is called event.
20*84e872a0SLloyd Pique      A message has a number of arguments, each of which has a certain type (see
21*84e872a0SLloyd Pique      <xref linkend="sect-Protocol-Wire-Format"/> for a list of argument types).
22*84e872a0SLloyd Pique    </para>
23*84e872a0SLloyd Pique    <para>
24*84e872a0SLloyd Pique      Additionally, the protocol can specify <type>enum</type>s which associate
25*84e872a0SLloyd Pique      names to specific numeric enumeration values.  These are primarily just
26*84e872a0SLloyd Pique      descriptive in nature: at the wire format level enums are just integers.
27*84e872a0SLloyd Pique      But they also serve a secondary purpose to enhance type safety or
28*84e872a0SLloyd Pique      otherwise add context for use in language bindings or other such code.
29*84e872a0SLloyd Pique      This latter usage is only supported so long as code written before these
30*84e872a0SLloyd Pique      attributes were introduced still works after; in other words, adding an
31*84e872a0SLloyd Pique      enum should not break API, otherwise it puts backwards compatibility at
32*84e872a0SLloyd Pique      risk.
33*84e872a0SLloyd Pique    </para>
34*84e872a0SLloyd Pique    <para>
35*84e872a0SLloyd Pique      <type>enum</type>s can be defined as just a set of integers, or as
36*84e872a0SLloyd Pique      bitfields.  This is specified via the <type>bitfield</type> boolean
37*84e872a0SLloyd Pique      attribute in the <type>enum</type> definition.  If this attribute is true,
38*84e872a0SLloyd Pique      the enum is intended to be accessed primarily using bitwise operations,
39*84e872a0SLloyd Pique      for example when arbitrarily many choices of the enum can be ORed
40*84e872a0SLloyd Pique      together; if it is false, or the attribute is omitted, then the enum
41*84e872a0SLloyd Pique      arguments are a just a sequence of numerical values.
42*84e872a0SLloyd Pique    </para>
43*84e872a0SLloyd Pique    <para>
44*84e872a0SLloyd Pique      The <type>enum</type> attribute can be used on either <type>uint</type>
45*84e872a0SLloyd Pique      or <type>int</type> arguments, however if the <type>enum</type> is
46*84e872a0SLloyd Pique      defined as a <type>bitfield</type>, it can only be used on
47*84e872a0SLloyd Pique      <type>uint</type> args.
48*84e872a0SLloyd Pique    </para>
49*84e872a0SLloyd Pique    <para>
50*84e872a0SLloyd Pique      The server sends back events to the client, each event is emitted from
51*84e872a0SLloyd Pique      an object.  Events can be error conditions.  The event includes the
52*84e872a0SLloyd Pique      object ID and the event opcode, from which the client can determine
53*84e872a0SLloyd Pique      the type of event.  Events are generated both in response to requests
54*84e872a0SLloyd Pique      (in which case the request and the event constitutes a round trip) or
55*84e872a0SLloyd Pique      spontaneously when the server state changes.
56*84e872a0SLloyd Pique    </para>
57*84e872a0SLloyd Pique    <para>
58*84e872a0SLloyd Pique      <itemizedlist>
59*84e872a0SLloyd Pique	<listitem>
60*84e872a0SLloyd Pique	  <para>
61*84e872a0SLloyd Pique	    State is broadcast on connect, events are sent
62*84e872a0SLloyd Pique	    out when state changes. Clients must listen for
63*84e872a0SLloyd Pique	    these changes and cache the state.
64*84e872a0SLloyd Pique	    There is no need (or mechanism) to query server state.
65*84e872a0SLloyd Pique	  </para>
66*84e872a0SLloyd Pique	</listitem>
67*84e872a0SLloyd Pique	<listitem>
68*84e872a0SLloyd Pique	  <para>
69*84e872a0SLloyd Pique	    The server will broadcast the presence of a number of global objects,
70*84e872a0SLloyd Pique	    which in turn will broadcast their current state.
71*84e872a0SLloyd Pique	  </para>
72*84e872a0SLloyd Pique	</listitem>
73*84e872a0SLloyd Pique      </itemizedlist>
74*84e872a0SLloyd Pique    </para>
75*84e872a0SLloyd Pique  </section>
76*84e872a0SLloyd Pique  <section id="sect-Protocol-Code-Generation">
77*84e872a0SLloyd Pique    <title>Code Generation</title>
78*84e872a0SLloyd Pique    <para>
79*84e872a0SLloyd Pique      The interfaces, requests and events are defined in
80*84e872a0SLloyd Pique      <filename>protocol/wayland.xml</filename>.
81*84e872a0SLloyd Pique      This xml is used to generate the function prototypes that can be used by
82*84e872a0SLloyd Pique      clients and compositors.
83*84e872a0SLloyd Pique    </para>
84*84e872a0SLloyd Pique    <para>
85*84e872a0SLloyd Pique      The protocol entry points are generated as inline functions which just
86*84e872a0SLloyd Pique      wrap the <function>wl_proxy_*</function> functions.  The inline functions aren't
87*84e872a0SLloyd Pique      part of the library ABI and language bindings should generate their
88*84e872a0SLloyd Pique      own stubs for the protocol entry points from the xml.
89*84e872a0SLloyd Pique    </para>
90*84e872a0SLloyd Pique  </section>
91*84e872a0SLloyd Pique  <section id="sect-Protocol-Wire-Format">
92*84e872a0SLloyd Pique    <title>Wire Format</title>
93*84e872a0SLloyd Pique    <para>
94*84e872a0SLloyd Pique      The protocol is sent over a UNIX domain stream socket, where the endpoint
95*84e872a0SLloyd Pique      usually is named <systemitem class="service">wayland-0</systemitem>
96*84e872a0SLloyd Pique      (although it can be changed via <emphasis>WAYLAND_DISPLAY</emphasis>
97*84e872a0SLloyd Pique      in the environment). Beginning in Wayland 1.15, implementations can
98*84e872a0SLloyd Pique      optionally support server socket endpoints located at arbitrary
99*84e872a0SLloyd Pique      locations in the filesystem by setting <emphasis>WAYLAND_DISPLAY</emphasis>
100*84e872a0SLloyd Pique      to the absolute path at which the server endpoint listens.
101*84e872a0SLloyd Pique    </para>
102*84e872a0SLloyd Pique    <para>
103*84e872a0SLloyd Pique      Every message is structured as 32-bit words; values are represented in the
104*84e872a0SLloyd Pique      host's byte-order.  The message header has 2 words in it:
105*84e872a0SLloyd Pique      <itemizedlist>
106*84e872a0SLloyd Pique	<listitem>
107*84e872a0SLloyd Pique	  <para>
108*84e872a0SLloyd Pique	    The first word is the sender's object ID (32-bit).
109*84e872a0SLloyd Pique	  </para>
110*84e872a0SLloyd Pique	</listitem>
111*84e872a0SLloyd Pique	<listitem>
112*84e872a0SLloyd Pique	  <para>
113*84e872a0SLloyd Pique	    The second has 2 parts of 16-bit.  The upper 16-bits are the message
114*84e872a0SLloyd Pique	    size in bytes, starting at the header (i.e. it has a minimum value of 8).The lower is the request/event opcode.
115*84e872a0SLloyd Pique	  </para>
116*84e872a0SLloyd Pique	</listitem>
117*84e872a0SLloyd Pique      </itemizedlist>
118*84e872a0SLloyd Pique      The payload describes the request/event arguments.  Every argument is always
119*84e872a0SLloyd Pique      aligned to 32-bits. Where padding is required, the value of padding bytes is
120*84e872a0SLloyd Pique      undefined. There is no prefix that describes the type, but it is
121*84e872a0SLloyd Pique      inferred implicitly from the xml specification.
122*84e872a0SLloyd Pique    </para>
123*84e872a0SLloyd Pique    <para>
124*84e872a0SLloyd Pique
125*84e872a0SLloyd Pique      The representation of argument types are as follows:
126*84e872a0SLloyd Pique      <variablelist>
127*84e872a0SLloyd Pique	<varlistentry>
128*84e872a0SLloyd Pique	  <term>int</term>
129*84e872a0SLloyd Pique	  <term>uint</term>
130*84e872a0SLloyd Pique	  <listitem>
131*84e872a0SLloyd Pique	    <para>
132*84e872a0SLloyd Pique	      The value is the 32-bit value of the signed/unsigned
133*84e872a0SLloyd Pique	      int.
134*84e872a0SLloyd Pique	    </para>
135*84e872a0SLloyd Pique	  </listitem>
136*84e872a0SLloyd Pique	</varlistentry>
137*84e872a0SLloyd Pique	<varlistentry>
138*84e872a0SLloyd Pique	  <term>fixed</term>
139*84e872a0SLloyd Pique	  <listitem>
140*84e872a0SLloyd Pique	    <para>
141*84e872a0SLloyd Pique	      Signed 24.8 decimal numbers. It is a signed decimal type which
142*84e872a0SLloyd Pique	      offers a sign bit, 23 bits of integer precision and 8 bits of
143*84e872a0SLloyd Pique	      decimal precision. This is exposed as an opaque struct with
144*84e872a0SLloyd Pique	      conversion helpers to and from double and int on the C API side.
145*84e872a0SLloyd Pique	    </para>
146*84e872a0SLloyd Pique	  </listitem>
147*84e872a0SLloyd Pique	</varlistentry>
148*84e872a0SLloyd Pique	<varlistentry>
149*84e872a0SLloyd Pique	  <term>string</term>
150*84e872a0SLloyd Pique	  <listitem>
151*84e872a0SLloyd Pique	    <para>
152*84e872a0SLloyd Pique	      Starts with an unsigned 32-bit length (including null terminator),
153*84e872a0SLloyd Pique	      followed by the string contents, including terminating null byte,
154*84e872a0SLloyd Pique	      then padding to a 32-bit boundary. A null value is represented
155*84e872a0SLloyd Pique	      with a length of 0.
156*84e872a0SLloyd Pique	    </para>
157*84e872a0SLloyd Pique	  </listitem>
158*84e872a0SLloyd Pique	</varlistentry>
159*84e872a0SLloyd Pique	<varlistentry>
160*84e872a0SLloyd Pique	  <term>object</term>
161*84e872a0SLloyd Pique	  <listitem>
162*84e872a0SLloyd Pique	    <para>
163*84e872a0SLloyd Pique	      32-bit object ID. A null value is represented with an ID of 0.
164*84e872a0SLloyd Pique	    </para>
165*84e872a0SLloyd Pique	  </listitem>
166*84e872a0SLloyd Pique	</varlistentry>
167*84e872a0SLloyd Pique	<varlistentry>
168*84e872a0SLloyd Pique	  <term>new_id</term>
169*84e872a0SLloyd Pique	  <listitem>
170*84e872a0SLloyd Pique	    <para>
171*84e872a0SLloyd Pique	      The 32-bit object ID.  Generally, the interface used for the new
172*84e872a0SLloyd Pique	      object is inferred from the xml, but in the case where it's not
173*84e872a0SLloyd Pique	      specified, a new_id is preceded by a <code>string</code> specifying
174*84e872a0SLloyd Pique	      the interface name, and a <code>uint</code> specifying the version.
175*84e872a0SLloyd Pique	    </para>
176*84e872a0SLloyd Pique	  </listitem>
177*84e872a0SLloyd Pique	</varlistentry>
178*84e872a0SLloyd Pique	<varlistentry>
179*84e872a0SLloyd Pique	  <term>array</term>
180*84e872a0SLloyd Pique	  <listitem>
181*84e872a0SLloyd Pique	    <para>
182*84e872a0SLloyd Pique	      Starts with 32-bit array size in bytes, followed by the array
183*84e872a0SLloyd Pique	      contents verbatim, and finally padding to a 32-bit boundary.
184*84e872a0SLloyd Pique	    </para>
185*84e872a0SLloyd Pique	  </listitem>
186*84e872a0SLloyd Pique	</varlistentry>
187*84e872a0SLloyd Pique	<varlistentry>
188*84e872a0SLloyd Pique	  <term>fd</term>
189*84e872a0SLloyd Pique	  <listitem>
190*84e872a0SLloyd Pique	    <para>
191*84e872a0SLloyd Pique	      The file descriptor is not stored in the message buffer, but in
192*84e872a0SLloyd Pique	      the ancillary data of the UNIX domain socket message (msg_control).
193*84e872a0SLloyd Pique	    </para>
194*84e872a0SLloyd Pique	  </listitem>
195*84e872a0SLloyd Pique	</varlistentry>
196*84e872a0SLloyd Pique      </variablelist>
197*84e872a0SLloyd Pique    </para>
198*84e872a0SLloyd Pique    <para>
199*84e872a0SLloyd Pique      The protocol does not specify the exact position of the ancillary data
200*84e872a0SLloyd Pique      in the stream, except that the order of file descriptors is the same as
201*84e872a0SLloyd Pique      the order of messages and <code>fd</code> arguments within messages on
202*84e872a0SLloyd Pique      the wire.
203*84e872a0SLloyd Pique    </para>
204*84e872a0SLloyd Pique    <para>
205*84e872a0SLloyd Pique      In particular, it means that any byte of the stream, even the message
206*84e872a0SLloyd Pique      header, may carry the ancillary data with file descriptors.
207*84e872a0SLloyd Pique    </para>
208*84e872a0SLloyd Pique    <para>
209*84e872a0SLloyd Pique      Clients and compositors should queue incoming data until they have
210*84e872a0SLloyd Pique      whole messages to process, as file descriptors may arrive earlier
211*84e872a0SLloyd Pique      or later than the corresponding data bytes.
212*84e872a0SLloyd Pique    </para>
213*84e872a0SLloyd Pique  </section>
214*84e872a0SLloyd Pique  <xi:include href="ProtocolInterfaces.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
215*84e872a0SLloyd Pique  <section id="sect-Protocol-Versioning">
216*84e872a0SLloyd Pique    <title>Versioning</title>
217*84e872a0SLloyd Pique    <para>
218*84e872a0SLloyd Pique      Every interface is versioned and every protocol object implements a
219*84e872a0SLloyd Pique      particular version of its interface.  For global objects, the maximum
220*84e872a0SLloyd Pique      version supported by the server is advertised with the global and the
221*84e872a0SLloyd Pique      actual version of the created protocol object is determined by the
222*84e872a0SLloyd Pique      version argument passed to wl_registry.bind().  For objects that are
223*84e872a0SLloyd Pique      not globals, their version is inferred from the object that created
224*84e872a0SLloyd Pique      them.
225*84e872a0SLloyd Pique    </para>
226*84e872a0SLloyd Pique    <para>
227*84e872a0SLloyd Pique      In order to keep things sane, this has a few implications for
228*84e872a0SLloyd Pique      interface versions:
229*84e872a0SLloyd Pique      <itemizedlist>
230*84e872a0SLloyd Pique	<listitem>
231*84e872a0SLloyd Pique	  <para>
232*84e872a0SLloyd Pique	    The object creation hierarchy must be a tree.  Otherwise,
233*84e872a0SLloyd Pique	    inferring object versions from the parent object becomes a much
234*84e872a0SLloyd Pique	    more difficult to properly track.
235*84e872a0SLloyd Pique	  </para>
236*84e872a0SLloyd Pique	</listitem>
237*84e872a0SLloyd Pique	<listitem>
238*84e872a0SLloyd Pique	  <para>
239*84e872a0SLloyd Pique	    When the version of an interface increases, so does the version
240*84e872a0SLloyd Pique	    of its parent (recursively until you get to a global interface)
241*84e872a0SLloyd Pique	  </para>
242*84e872a0SLloyd Pique	</listitem>
243*84e872a0SLloyd Pique	<listitem>
244*84e872a0SLloyd Pique	  <para>
245*84e872a0SLloyd Pique	    A global interface's version number acts like a counter for all
246*84e872a0SLloyd Pique	    of its child interfaces.  Whenever a child interface gets
247*84e872a0SLloyd Pique	    modified, the global parent's interface version number also
248*84e872a0SLloyd Pique	    increases (see above).  The child interface then takes on the
249*84e872a0SLloyd Pique	    same version number as the new version of its parent global
250*84e872a0SLloyd Pique	    interface.
251*84e872a0SLloyd Pique	  </para>
252*84e872a0SLloyd Pique	</listitem>
253*84e872a0SLloyd Pique      </itemizedlist>
254*84e872a0SLloyd Pique    </para>
255*84e872a0SLloyd Pique    <para>
256*84e872a0SLloyd Pique      To illustrate the above, consider the wl_compositor interface.  It
257*84e872a0SLloyd Pique      has two children, wl_surface and wl_region.  As of wayland version
258*84e872a0SLloyd Pique      1.2, wl_surface and wl_compositor are both at version 3.  If
259*84e872a0SLloyd Pique      something is added to the wl_region interface, both wl_region and
260*84e872a0SLloyd Pique      wl_compositor will get bumpped to version 4.  If, afterwards,
261*84e872a0SLloyd Pique      wl_surface is changed, both wl_compositor and wl_surface will be at
262*84e872a0SLloyd Pique      version 5.  In this way the global interface version is used as a
263*84e872a0SLloyd Pique      sort of "counter" for all of its child interfaces.  This makes it
264*84e872a0SLloyd Pique      very simple to know the version of the child given the version of its
265*84e872a0SLloyd Pique      parent.  The child is at the highest possible interface version that
266*84e872a0SLloyd Pique      is less than or equal to its parent's version.
267*84e872a0SLloyd Pique    </para>
268*84e872a0SLloyd Pique    <para>
269*84e872a0SLloyd Pique      It is worth noting a particular exception to the above versioning
270*84e872a0SLloyd Pique      scheme.  The wl_display (and, by extension, wl_registry) interface
271*84e872a0SLloyd Pique      cannot change because it is the core protocol object and its version
272*84e872a0SLloyd Pique      is never advertised nor is there a mechanism to request a different
273*84e872a0SLloyd Pique      version.
274*84e872a0SLloyd Pique    </para>
275*84e872a0SLloyd Pique  </section>
276*84e872a0SLloyd Pique  <section id="sect-Protocol-Connect-Time">
277*84e872a0SLloyd Pique    <title>Connect Time</title>
278*84e872a0SLloyd Pique    <para>
279*84e872a0SLloyd Pique      There is no fixed connection setup information, the server emits
280*84e872a0SLloyd Pique      multiple events at connect time, to indicate the presence and
281*84e872a0SLloyd Pique      properties of global objects: outputs, compositor, input devices.
282*84e872a0SLloyd Pique    </para>
283*84e872a0SLloyd Pique  </section>
284*84e872a0SLloyd Pique  <section id="sect-Protocol-Security-and-Authentication">
285*84e872a0SLloyd Pique    <title>Security and Authentication</title>
286*84e872a0SLloyd Pique    <para>
287*84e872a0SLloyd Pique      <itemizedlist>
288*84e872a0SLloyd Pique	<listitem>
289*84e872a0SLloyd Pique	  <para>
290*84e872a0SLloyd Pique	    mostly about access to underlying buffers, need new drm auth
291*84e872a0SLloyd Pique	    mechanism (the grant-to ioctl idea), need to check the cmd stream?
292*84e872a0SLloyd Pique	  </para>
293*84e872a0SLloyd Pique	</listitem>
294*84e872a0SLloyd Pique	<listitem>
295*84e872a0SLloyd Pique	  <para>
296*84e872a0SLloyd Pique	    getting the server socket depends on the compositor type, could
297*84e872a0SLloyd Pique	    be a system wide name, through fd passing on the session dbus.
298*84e872a0SLloyd Pique	    or the client is forked by the compositor and the fd is
299*84e872a0SLloyd Pique	    already opened.
300*84e872a0SLloyd Pique	  </para>
301*84e872a0SLloyd Pique	</listitem>
302*84e872a0SLloyd Pique      </itemizedlist>
303*84e872a0SLloyd Pique    </para>
304*84e872a0SLloyd Pique  </section>
305*84e872a0SLloyd Pique  <section id="sect-Protocol-Creating-Objects">
306*84e872a0SLloyd Pique    <title>Creating Objects</title>
307*84e872a0SLloyd Pique    <para>
308*84e872a0SLloyd Pique      Each object has a unique ID.  The IDs are allocated by the entity
309*84e872a0SLloyd Pique      creating the object (either client or server).  IDs allocated by the
310*84e872a0SLloyd Pique      client are in the range [1, 0xfeffffff] while IDs allocated by the
311*84e872a0SLloyd Pique      server are in the range [0xff000000, 0xffffffff].  The 0 ID is
312*84e872a0SLloyd Pique      reserved to represent a null or non-existent object.
313*84e872a0SLloyd Pique
314*84e872a0SLloyd Pique      For efficiency purposes, the IDs are densely packed in the sense that
315*84e872a0SLloyd Pique      the ID N will not be used until N-1 has been used.  Any ID allocation
316*84e872a0SLloyd Pique      algorithm that does not maintain this property is incompatible with
317*84e872a0SLloyd Pique      the implementation in libwayland.
318*84e872a0SLloyd Pique    </para>
319*84e872a0SLloyd Pique  </section>
320*84e872a0SLloyd Pique  <section id="sect-Protocol-Compositor">
321*84e872a0SLloyd Pique    <title>Compositor</title>
322*84e872a0SLloyd Pique    <para>
323*84e872a0SLloyd Pique      The compositor is a global object, advertised at connect time.
324*84e872a0SLloyd Pique    </para>
325*84e872a0SLloyd Pique    <para>
326*84e872a0SLloyd Pique      See <xref linkend="protocol-spec-wl_compositor"/> for the
327*84e872a0SLloyd Pique      protocol description.
328*84e872a0SLloyd Pique    </para>
329*84e872a0SLloyd Pique  </section>
330*84e872a0SLloyd Pique  <section id="sect-Protocol-Surface">
331*84e872a0SLloyd Pique    <title>Surfaces</title>
332*84e872a0SLloyd Pique    <para>
333*84e872a0SLloyd Pique      A surface manages a rectangular grid of pixels that clients create
334*84e872a0SLloyd Pique      for displaying their content to the screen.  Clients don't know
335*84e872a0SLloyd Pique      the global position of their surfaces, and cannot access other
336*84e872a0SLloyd Pique      clients' surfaces.
337*84e872a0SLloyd Pique    </para>
338*84e872a0SLloyd Pique    <para>
339*84e872a0SLloyd Pique      Once the client has finished writing pixels, it 'commits' the
340*84e872a0SLloyd Pique      buffer; this permits the compositor to access the buffer and read
341*84e872a0SLloyd Pique      the pixels.  When the compositor is finished, it releases the
342*84e872a0SLloyd Pique      buffer back to the client.
343*84e872a0SLloyd Pique    </para>
344*84e872a0SLloyd Pique    <para>
345*84e872a0SLloyd Pique      See <xref linkend="protocol-spec-wl_surface"/> for the protocol
346*84e872a0SLloyd Pique      description.
347*84e872a0SLloyd Pique    </para>
348*84e872a0SLloyd Pique  </section>
349*84e872a0SLloyd Pique  <section id="sect-Protocol-Input">
350*84e872a0SLloyd Pique    <title>Input</title>
351*84e872a0SLloyd Pique    <para>
352*84e872a0SLloyd Pique      A seat represents a group of input devices including mice,
353*84e872a0SLloyd Pique      keyboards and touchscreens. It has a keyboard and pointer
354*84e872a0SLloyd Pique      focus. Seats are global objects. Pointer events are delivered
355*84e872a0SLloyd Pique      in surface-local coordinates.
356*84e872a0SLloyd Pique    </para>
357*84e872a0SLloyd Pique    <para>
358*84e872a0SLloyd Pique      The compositor maintains an implicit grab when a button is
359*84e872a0SLloyd Pique      pressed, to ensure that the corresponding button release
360*84e872a0SLloyd Pique      event gets delivered to the same surface. But there is no way
361*84e872a0SLloyd Pique      for clients to take an explicit grab. Instead, surfaces can
362*84e872a0SLloyd Pique      be mapped as 'popup', which combines transient window semantics
363*84e872a0SLloyd Pique      with a pointer grab.
364*84e872a0SLloyd Pique    </para>
365*84e872a0SLloyd Pique    <para>
366*84e872a0SLloyd Pique      To avoid race conditions, input events that are likely to
367*84e872a0SLloyd Pique      trigger further requests (such as button presses, key events,
368*84e872a0SLloyd Pique      pointer motions) carry serial numbers, and requests such as
369*84e872a0SLloyd Pique      wl_surface.set_popup require that the serial number of the
370*84e872a0SLloyd Pique      triggering event is specified. The server maintains a
371*84e872a0SLloyd Pique      monotonically increasing counter for these serial numbers.
372*84e872a0SLloyd Pique    </para>
373*84e872a0SLloyd Pique    <para>
374*84e872a0SLloyd Pique      Input events also carry timestamps with millisecond granularity.
375*84e872a0SLloyd Pique      Their base is undefined, so they can't be compared against
376*84e872a0SLloyd Pique      system time (as obtained with clock_gettime or gettimeofday).
377*84e872a0SLloyd Pique      They can be compared with each other though, and for instance
378*84e872a0SLloyd Pique      be used to identify sequences of button presses as double
379*84e872a0SLloyd Pique      or triple clicks.
380*84e872a0SLloyd Pique    </para>
381*84e872a0SLloyd Pique    <para>
382*84e872a0SLloyd Pique      See <xref linkend="protocol-spec-wl_seat"/> for the
383*84e872a0SLloyd Pique      protocol description.
384*84e872a0SLloyd Pique    </para>
385*84e872a0SLloyd Pique    <para>
386*84e872a0SLloyd Pique      Talk about:
387*84e872a0SLloyd Pique
388*84e872a0SLloyd Pique      <itemizedlist>
389*84e872a0SLloyd Pique	<listitem>
390*84e872a0SLloyd Pique	  <para>
391*84e872a0SLloyd Pique	    keyboard map, change events
392*84e872a0SLloyd Pique	  </para>
393*84e872a0SLloyd Pique	</listitem>
394*84e872a0SLloyd Pique	<listitem>
395*84e872a0SLloyd Pique	  <para>
396*84e872a0SLloyd Pique	    xkb on Wayland
397*84e872a0SLloyd Pique	  </para>
398*84e872a0SLloyd Pique	</listitem>
399*84e872a0SLloyd Pique	<listitem>
400*84e872a0SLloyd Pique	  <para>
401*84e872a0SLloyd Pique	    multi pointer Wayland
402*84e872a0SLloyd Pique	  </para>
403*84e872a0SLloyd Pique	</listitem>
404*84e872a0SLloyd Pique      </itemizedlist>
405*84e872a0SLloyd Pique    </para>
406*84e872a0SLloyd Pique    <para>
407*84e872a0SLloyd Pique      A surface can change the pointer image when the surface is the pointer
408*84e872a0SLloyd Pique      focus of the input device.  Wayland doesn't automatically change the
409*84e872a0SLloyd Pique      pointer image when a pointer enters a surface, but expects the
410*84e872a0SLloyd Pique      application to set the cursor it wants in response to the pointer
411*84e872a0SLloyd Pique      focus and motion events.  The rationale is that a client has to manage
412*84e872a0SLloyd Pique      changing pointer images for UI elements within the surface in response
413*84e872a0SLloyd Pique      to motion events anyway, so we'll make that the only mechanism for
414*84e872a0SLloyd Pique      setting or changing the pointer image.  If the server receives a request
415*84e872a0SLloyd Pique      to set the pointer image after the surface loses pointer focus, the
416*84e872a0SLloyd Pique      request is ignored.  To the client this will look like it successfully
417*84e872a0SLloyd Pique      set the pointer image.
418*84e872a0SLloyd Pique    </para>
419*84e872a0SLloyd Pique    <para>
420*84e872a0SLloyd Pique      Setting the pointer image to NULL causes the cursor to be hidden.
421*84e872a0SLloyd Pique    </para>
422*84e872a0SLloyd Pique    <para>
423*84e872a0SLloyd Pique      The compositor will revert the pointer image back to a default image
424*84e872a0SLloyd Pique      when no surface has the pointer focus for that device.
425*84e872a0SLloyd Pique    </para>
426*84e872a0SLloyd Pique    <para>
427*84e872a0SLloyd Pique      What if the pointer moves from one window which has set a special
428*84e872a0SLloyd Pique      pointer image to a surface that doesn't set an image in response to
429*84e872a0SLloyd Pique      the motion event?  The new surface will be stuck with the special
430*84e872a0SLloyd Pique      pointer image.  We can't just revert the pointer image on leaving a
431*84e872a0SLloyd Pique      surface, since if we immediately enter a surface that sets a different
432*84e872a0SLloyd Pique      image, the image will flicker.  If a client does not set a pointer image
433*84e872a0SLloyd Pique      when the pointer enters a surface, the pointer stays with the image set
434*84e872a0SLloyd Pique      by the last surface that changed it, possibly even hidden.  Such a client
435*84e872a0SLloyd Pique      is likely just broken.
436*84e872a0SLloyd Pique    </para>
437*84e872a0SLloyd Pique  </section>
438*84e872a0SLloyd Pique  <section id="sect-Protocol-Output">
439*84e872a0SLloyd Pique    <title>Output</title>
440*84e872a0SLloyd Pique    <para>
441*84e872a0SLloyd Pique      An output is a global object, advertised at connect time or as it
442*84e872a0SLloyd Pique      comes and goes.
443*84e872a0SLloyd Pique    </para>
444*84e872a0SLloyd Pique    <para>
445*84e872a0SLloyd Pique      See <xref linkend="protocol-spec-wl_output"/> for the protocol
446*84e872a0SLloyd Pique      description.
447*84e872a0SLloyd Pique    </para>
448*84e872a0SLloyd Pique    <para>
449*84e872a0SLloyd Pique    </para>
450*84e872a0SLloyd Pique    <itemizedlist>
451*84e872a0SLloyd Pique      <listitem>
452*84e872a0SLloyd Pique	<para>
453*84e872a0SLloyd Pique	  laid out in a big (compositor) coordinate system
454*84e872a0SLloyd Pique	</para>
455*84e872a0SLloyd Pique      </listitem>
456*84e872a0SLloyd Pique      <listitem>
457*84e872a0SLloyd Pique	<para>
458*84e872a0SLloyd Pique	  basically xrandr over Wayland
459*84e872a0SLloyd Pique	</para>
460*84e872a0SLloyd Pique      </listitem>
461*84e872a0SLloyd Pique      <listitem>
462*84e872a0SLloyd Pique	<para>
463*84e872a0SLloyd Pique	  geometry needs position in compositor coordinate system
464*84e872a0SLloyd Pique	</para>
465*84e872a0SLloyd Pique      </listitem>
466*84e872a0SLloyd Pique      <listitem>
467*84e872a0SLloyd Pique	<para>
468*84e872a0SLloyd Pique	  events to advertise available modes, requests to move and change
469*84e872a0SLloyd Pique	  modes
470*84e872a0SLloyd Pique	</para>
471*84e872a0SLloyd Pique      </listitem>
472*84e872a0SLloyd Pique    </itemizedlist>
473*84e872a0SLloyd Pique  </section>
474*84e872a0SLloyd Pique  <section id="sect-Protocol-data-sharing">
475*84e872a0SLloyd Pique    <title>Data sharing between clients</title>
476*84e872a0SLloyd Pique    <para>
477*84e872a0SLloyd Pique      The Wayland protocol provides clients a mechanism for sharing
478*84e872a0SLloyd Pique      data that allows the implementation of copy-paste and
479*84e872a0SLloyd Pique      drag-and-drop. The client providing the data creates a
480*84e872a0SLloyd Pique      <function>wl_data_source</function> object and the clients
481*84e872a0SLloyd Pique      obtaining the data will see it as <function>wl_data_offer</function>
482*84e872a0SLloyd Pique      object. This interface allows the clients to agree on a mutually
483*84e872a0SLloyd Pique      supported mime type and transfer the data via a file descriptor
484*84e872a0SLloyd Pique      that is passed through the protocol.
485*84e872a0SLloyd Pique    </para>
486*84e872a0SLloyd Pique    <para>
487*84e872a0SLloyd Pique      The next section explains the negotiation between data source and
488*84e872a0SLloyd Pique      data offer objects. <xref linkend="sect-Protocol-data-sharing-devices"/>
489*84e872a0SLloyd Pique      explains how these objects are created and passed to different
490*84e872a0SLloyd Pique      clients using the <function>wl_data_device</function> interface
491*84e872a0SLloyd Pique      that implements copy-paste and drag-and-drop support.
492*84e872a0SLloyd Pique    </para>
493*84e872a0SLloyd Pique    <para>
494*84e872a0SLloyd Pique      See <xref linkend="protocol-spec-wl_data_offer"/>,
495*84e872a0SLloyd Pique      <xref linkend="protocol-spec-wl_data_source"/>,
496*84e872a0SLloyd Pique      <xref linkend="protocol-spec-wl_data_device"/> and
497*84e872a0SLloyd Pique      <xref linkend="protocol-spec-wl_data_device_manager"/> for
498*84e872a0SLloyd Pique      protocol descriptions.
499*84e872a0SLloyd Pique    </para>
500*84e872a0SLloyd Pique    <para>
501*84e872a0SLloyd Pique      MIME is defined in RFC's 2045-2049. A
502*84e872a0SLloyd Pique      <ulink url="https://www.iana.org/assignments/media-types/media-types.xhtml">
503*84e872a0SLloyd Pique      registry of MIME types</ulink> is maintained by the Internet Assigned
504*84e872a0SLloyd Pique      Numbers Authority (IANA).
505*84e872a0SLloyd Pique    </para>
506*84e872a0SLloyd Pique    <section>
507*84e872a0SLloyd Pique      <title>Data negotiation</title>
508*84e872a0SLloyd Pique      <para>
509*84e872a0SLloyd Pique	A client providing data to other clients will create a <function>wl_data_source</function>
510*84e872a0SLloyd Pique	object and advertise the mime types for the formats it supports for
511*84e872a0SLloyd Pique	that data through the <function>wl_data_source.offer</function>
512*84e872a0SLloyd Pique	request. On the receiving end, the data offer object will generate one
513*84e872a0SLloyd Pique	<function>wl_data_offer.offer</function> event for each supported mime
514*84e872a0SLloyd Pique	type.
515*84e872a0SLloyd Pique      </para>
516*84e872a0SLloyd Pique      <para>
517*84e872a0SLloyd Pique	The actual data transfer happens when the receiving client sends a
518*84e872a0SLloyd Pique	<function>wl_data_offer.receive</function> request. This request takes
519*84e872a0SLloyd Pique	a mime type and a file descriptor as arguments. This request will generate a
520*84e872a0SLloyd Pique	<function>wl_data_source.send</function> event on the sending client
521*84e872a0SLloyd Pique	with the same arguments, and the latter client is expected to write its
522*84e872a0SLloyd Pique	data to the given file descriptor using the chosen mime type.
523*84e872a0SLloyd Pique      </para>
524*84e872a0SLloyd Pique    </section>
525*84e872a0SLloyd Pique    <section id="sect-Protocol-data-sharing-devices">
526*84e872a0SLloyd Pique      <title>Data devices</title>
527*84e872a0SLloyd Pique      <para>
528*84e872a0SLloyd Pique	Data devices glue data sources and offers together. A data device is
529*84e872a0SLloyd Pique	associated with a <function>wl_seat</function> and is obtained by the clients using the
530*84e872a0SLloyd Pique	<function>wl_data_device_manager</function> factory object, which is also responsible for
531*84e872a0SLloyd Pique	creating data sources.
532*84e872a0SLloyd Pique      </para>
533*84e872a0SLloyd Pique      <para>
534*84e872a0SLloyd Pique	Clients are informed of new data offers through the
535*84e872a0SLloyd Pique	<function>wl_data_device.data_offer</function> event. After this
536*84e872a0SLloyd Pique	event is generated the data offer will advertise the available mime
537*84e872a0SLloyd Pique	types. New data offers are introduced prior to their use for
538*84e872a0SLloyd Pique	copy-paste or drag-and-drop.
539*84e872a0SLloyd Pique      </para>
540*84e872a0SLloyd Pique      <section>
541*84e872a0SLloyd Pique	<title>Selection</title>
542*84e872a0SLloyd Pique	<para>
543*84e872a0SLloyd Pique	  Each data device has a selection data source. Clients create a data
544*84e872a0SLloyd Pique	  source object using the device manager and may set it as the
545*84e872a0SLloyd Pique	  current selection for a given data device. Whenever the current
546*84e872a0SLloyd Pique	  selection changes, the client with keyboard focus receives a
547*84e872a0SLloyd Pique	  <function>wl_data_device.selection</function> event. This event is
548*84e872a0SLloyd Pique	  also generated on a client immediately before it receives keyboard
549*84e872a0SLloyd Pique	  focus.
550*84e872a0SLloyd Pique	</para>
551*84e872a0SLloyd Pique	<para>
552*84e872a0SLloyd Pique	  The data offer is introduced with
553*84e872a0SLloyd Pique	  <function>wl_data_device.data_offer</function> event before the
554*84e872a0SLloyd Pique	  selection event.
555*84e872a0SLloyd Pique	</para>
556*84e872a0SLloyd Pique      </section>
557*84e872a0SLloyd Pique      <section>
558*84e872a0SLloyd Pique	<title>Drag and Drop</title>
559*84e872a0SLloyd Pique	<para>
560*84e872a0SLloyd Pique	  A drag-and-drop operation is started using the
561*84e872a0SLloyd Pique	  <function>wl_data_device.start_drag</function> request. This
562*84e872a0SLloyd Pique	  requests causes a pointer grab that will generate enter, motion and
563*84e872a0SLloyd Pique	  leave events on the data device. A data source is supplied as
564*84e872a0SLloyd Pique	  argument to start_drag, and data offers associated with it are
565*84e872a0SLloyd Pique	  supplied to clients surfaces under the pointer in the
566*84e872a0SLloyd Pique	  <function>wl_data_device.enter</function> event. The data offer
567*84e872a0SLloyd Pique	  is introduced to the client prior to the enter event with the
568*84e872a0SLloyd Pique	  <function>wl_data_device.data_offer</function> event.
569*84e872a0SLloyd Pique	</para>
570*84e872a0SLloyd Pique	<para>
571*84e872a0SLloyd Pique	  Clients are expected to provide feedback to the data sending client
572*84e872a0SLloyd Pique	  by calling the <function>wl_data_offer.accept</function> request with
573*84e872a0SLloyd Pique	  a mime type it accepts. If none of the advertised mime types is
574*84e872a0SLloyd Pique	  supported by the receiving client, it should supply NULL to the
575*84e872a0SLloyd Pique	  accept request. The accept request causes the sending client to
576*84e872a0SLloyd Pique	  receive a <function>wl_data_source.target</function> event with the
577*84e872a0SLloyd Pique	  chosen mime type.
578*84e872a0SLloyd Pique	</para>
579*84e872a0SLloyd Pique	<para>
580*84e872a0SLloyd Pique	  When the drag ends, the receiving client receives a
581*84e872a0SLloyd Pique	  <function>wl_data_device.drop</function> event at which it is expected
582*84e872a0SLloyd Pique	  to transfer the data using the
583*84e872a0SLloyd Pique	  <function>wl_data_offer.receive</function> request.
584*84e872a0SLloyd Pique	</para>
585*84e872a0SLloyd Pique      </section>
586*84e872a0SLloyd Pique    </section>
587*84e872a0SLloyd Pique  </section>
588*84e872a0SLloyd Pique</chapter>
589