2018-10-28 21:14:05 -05:00

227 lines
18 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="API documentation for the Rust `wayland_client` crate."><meta name="keywords" content="rust, rustlang, rust-lang, wayland_client"><title>wayland_client - Rust</title><link rel="stylesheet" type="text/css" href="../normalize.css"><link rel="stylesheet" type="text/css" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../dark.css"><link rel="stylesheet" type="text/css" href="../light.css" id="themeStyle"><script src="../storage.js"></script></head><body class="rustdoc mod"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">&#9776;</div><p class='location'>Crate wayland_client</p><div class="sidebar-elems"><div class="block items"><ul><li><a href="#modules">Modules</a></li><li><a href="#macros">Macros</a></li><li><a href="#structs">Structs</a></li><li><a href="#enums">Enums</a></li></ul></div><p class='location'></p><script>window.sidebarCurrent = {name: 'wayland_client', ty: 'mod', relpath: '../'};</script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!"><img src="../brush.svg" width="18" alt="Pick another theme!"></button><div id="theme-choices"></div></div><script src="../theme.js"></script><nav class="sub"><form class="search-form js-only"><div class="search-container"><input class="search-input" name="search" autocomplete="off" placeholder="Click or press S to search, ? for more options…" type="search"><a id="settings-menu" href="../settings.html"><img src="../wheel.svg" width="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class='fqn'><span class='in-band'>Crate <a class="mod" href=''>wayland_client</a></span><span class='out-of-band'><span id='render-detail'><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class='inner'>&#x2212;</span>]</a></span><a class='srclink' href='../src/wayland_client/lib.rs.html#1-189' title='goto source code'>[src]</a></span></h1><div class='docblock'><p>Client-side Wayland connector</p>
<h2 id="overview" class="section-header"><a href="#overview">Overview</a></h2>
<p>This crate provides the interfaces and machinery to safely create
client applications for the wayland protocol. It is a rust wrapper
around the <code>libwayland-client.so</code> C library.</p>
<p>The wayland protocol revolves around the creation of various objects
and the exchange of messages associated to these objects. The initial
object is always the <code>Display</code>, that you get at initialization of the
connection, exposed by this crate as <code>Display::connect_to_env()</code>.</p>
<h2 id="protocol-and-messages-handling-model" class="section-header"><a href="#protocol-and-messages-handling-model">Protocol and messages handling model</a></h2>
<p>The protocol being bi-directional, you can send and receive messages.
Sending messages is done via methods of <code>Proxy&lt;_&gt;</code> objects, receiving
and handling them is done by providing implementations.</p>
<h3 id="proxies" class="section-header"><a href="#proxies">Proxies</a></h3>
<p>Wayland protocol objects are represented in this crate by <code>Proxy&lt;I&gt;</code>
objects, where <code>I</code> is a type representing the interface of the considered
object. And object's interface (think &quot;class&quot; in an object-oriented context)
defines which messages it can send and receive.</p>
<p>These proxies are used to send messages to the server (in the wayland context,
these are called &quot;requests&quot;). To do so, you need to import the appropriate
extension trait adding these methods. For example, to use a <code>Proxy&lt;WlSurface&gt;</code>,
you need to import <code>protocol::wl_surface::RequestsTrait</code> from this crate.
It is also possible to directly use the <code>Proxy::&lt;I&gt;::send(..)</code> method, but
this should only be done carefully: using it improperly can mess the protocol
state and cause protocol errors, which are fatal to the connection (the server
will kill you).</p>
<p>There is not a 1 to 1 mapping between <code>Proxy&lt;I&gt;</code> instances and protocol
objects. Rather, you can think of <code>Proxy&lt;I&gt;</code> as an <code>Rc</code>-like handle to a
wayland object. Multiple instances of it can exist referring to the same
protocol object.</p>
<p>Similarly, the lifetimes of the protocol objects and the <code>Proxy&lt;I&gt;</code> are
not tighly tied. As protocol objects are created and destroyed by protocol
messages, it can happen that an object gets destroyed while one or more
<code>Proxy&lt;I&gt;</code> still refers to it. In such case, these proxies will be disabled
and their <code>alive()</code> method will start to return <code>false</code>. Trying to send messages
with them will also fail.</p>
<h3 id="implementations-1" class="section-header"><a href="#implementations-1">Implementations</a></h3>
<p>To receive and process messages from the server to you (in wayland context they are
called &quot;events&quot;), you need to provide an <code>Implementation</code> for each wayland object
created in the protocol session. Whenever a new protocol object is created, you will
receive a <code>NewProxy&lt;I&gt;</code> object. Providing an implementation via its <code>implement()</code> method
will turn it into a regular <code>Proxy&lt;I&gt;</code> object.</p>
<p><strong>All objects must be implemented</strong>, even if it is an implementation doing nothing.
Failure to do so (by dropping the <code>NewProxy&lt;I&gt;</code> for example) can cause future fatal
errors if the server tries to send an event to this object.</p>
<p>An implementation is just a struct implementing the <code>Implementation&lt;Proxy&lt;I&gt;, I::Event&gt;</code>
trait, where <code>I</code> is the interface of the considered object:</p>
<pre class="rust rust-example-rendered">
<span class="comment">// Example implementation for the wl_surface interface</span>
<span class="kw">use</span> <span class="ident">wayland_client</span>::<span class="ident">Proxy</span>;
<span class="kw">use</span> <span class="ident">wayland_client</span>::<span class="ident">protocol</span>::<span class="ident">wl_surface</span>;
<span class="kw">use</span> <span class="ident">wayland_client</span>::<span class="ident">commons</span>::<span class="ident">Implementation</span>;
<span class="kw">struct</span> <span class="ident">MyImpl</span> {
<span class="comment">// ...</span>
}
<span class="kw">impl</span> <span class="ident">Implementation</span><span class="op">&lt;</span><span class="ident">Proxy</span><span class="op">&lt;</span><span class="ident">wl_surface</span>::<span class="ident">WlSurface</span><span class="op">&gt;</span>, <span class="ident">wl_surface</span>::<span class="ident">Event</span><span class="op">&gt;</span> <span class="kw">for</span> <span class="ident">MyImpl</span> {
<span class="kw">fn</span> <span class="ident">receive</span>(<span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="self">self</span>, <span class="ident">msg</span>: <span class="ident">wl_surface</span>::<span class="ident">Event</span>, <span class="ident">proxy</span>: <span class="ident">Proxy</span><span class="op">&lt;</span><span class="ident">wl_surface</span>::<span class="ident">WlSurface</span><span class="op">&gt;</span>) {
<span class="comment">// process the message...</span>
}
}</pre>
<p>The trait is also automatically implemented for <code>FnMut(I::Event, Proxy&lt;I&gt;)</code> closures,
so you can use them for simplicity if a full struct would be too cumbersome.</p>
<h2 id="event-queues" class="section-header"><a href="#event-queues">Event Queues</a></h2>
<p>The wayland client machinnery provides the possibility to have one or more event queues
handling the processing of received messages. All wayland objects are associated to an
event queue, which controls when its events are dispatched.</p>
<p>Events received from the server are stored in an internal buffer, and processed (by calling
the appropriate implementations) when the associated event queue is dispatched.</p>
<p>A default event queue is created at the same time as the initial <code>Display</code>, and by default
whenever a wayland object is created, it inherits the queue of its parent (the object that sent
or receive the message that created the new object). It means that if you only plan to use the
default event queue, you don't need to worry about assigning objects to their queues.</p>
<p>See the documentation of <code>EventQueue</code> for details about dispatching and integrating the event
queue into the event loop of your application. See the <code>Proxy::make_wrapper()</code> method for
details about assigning objects to event queues.</p>
<h2 id="dynamic-linking-with-libwayland-clientso" class="section-header"><a href="#dynamic-linking-with-libwayland-clientso">Dynamic linking with <code>libwayland-client.so</code></a></h2>
<p>If you need to gracefully handle the case of a system on which wayland is not installed (by
fallbacking to X11 for example), you can do so by activating the <code>dlopen</code> cargo feature.</p>
<p>When this is done, the library will be loaded a runtime rather than directly linked. And trying
to create a <code>Display</code> on a system that does not have this library will return a <code>NoWaylandLib</code>
error.</p>
<h2 id="auxiliary-libraries" class="section-header"><a href="#auxiliary-libraries">Auxiliary libraries</a></h2>
<p>Two auxiliary libraries are also available behind cargo features:</p>
<ul>
<li>the <code>cursor</code> feature will try to load <code>libwayland-cursor.so</code>, a library helping with loading
system themed cursor textures, to integrate your app in the system theme.</li>
<li>the <code>egl</code> feature will try to load <code>libwayland-egl.so</code>, a library allowing the creation of
OpenGL surface from wayland surfaces.</li>
</ul>
<p>Both of them will also be loaded at runtime if the <code>dlopen</code> feature was provided. See their
respective submodules for details about their use.</p>
</div><h2 id='modules' class='section-header'><a href="#modules">Modules</a></h2>
<table>
<tr class=' module-item'>
<td><a class="mod" href="commons/index.html"
title='mod wayland_client::commons'>commons</a></td>
<td class='docblock-short'>
<p>Re-export of wayland-commons</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="mod" href="cursor/index.html"
title='mod wayland_client::cursor'>cursor</a></td>
<td class='docblock-short'>
<p>Cursor utilities</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="mod" href="egl/index.html"
title='mod wayland_client::egl'>egl</a></td>
<td class='docblock-short'>
<p>EGL utilities</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="mod" href="protocol/index.html"
title='mod wayland_client::protocol'>protocol</a></td>
<td class='docblock-short'>
<p>Generated interfaces for the core wayland protocol</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="mod" href="sys/index.html"
title='mod wayland_client::sys'>sys</a></td>
<td class='docblock-short'>
<p>C-associated types</p>
</td>
</tr></table><h2 id='macros' class='section-header'><a href="#macros">Macros</a></h2>
<table>
<tr class=' module-item'>
<td><a class="macro" href="macro.global_filter.html"
title='macro wayland_client::global_filter'>global_filter</a></td>
<td class='docblock-short'>
<p>Convenience macro to create a <code>GlobalManager</code> callback</p>
</td>
</tr></table><h2 id='structs' class='section-header'><a href="#structs">Structs</a></h2>
<table>
<tr class=' module-item'>
<td><a class="struct" href="struct.Display.html"
title='struct wayland_client::Display'>Display</a></td>
<td class='docblock-short'>
<p>A connection to a wayland server</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="struct" href="struct.EventQueue.html"
title='struct wayland_client::EventQueue'>EventQueue</a></td>
<td class='docblock-short'>
<p>An event queue for protocol messages</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="struct" href="struct.GlobalManager.html"
title='struct wayland_client::GlobalManager'>GlobalManager</a></td>
<td class='docblock-short'>
<p>An utility to manage global objects</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="struct" href="struct.NewProxy.html"
title='struct wayland_client::NewProxy'>NewProxy</a></td>
<td class='docblock-short'>
<p>A newly-created proxy that needs implementation</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="struct" href="struct.Proxy.html"
title='struct wayland_client::Proxy'>Proxy</a></td>
<td class='docblock-short'>
<p>An handle to a wayland proxy</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="struct" href="struct.QueueToken.html"
title='struct wayland_client::QueueToken'>QueueToken</a></td>
<td class='docblock-short'>
<p>A token representing this event queue</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="struct" href="struct.ReadEventsGuard.html"
title='struct wayland_client::ReadEventsGuard'>ReadEventsGuard</a></td>
<td class='docblock-short'>
<p>A guard over a read intention.</p>
</td>
</tr></table><h2 id='enums' class='section-header'><a href="#enums">Enums</a></h2>
<table>
<tr class=' module-item'>
<td><a class="enum" href="enum.ConnectError.html"
title='enum wayland_client::ConnectError'>ConnectError</a></td>
<td class='docblock-short'>
<p>Enum representing the possible reasons why connecting to the wayland server failed</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="enum" href="enum.GlobalError.html"
title='enum wayland_client::GlobalError'>GlobalError</a></td>
<td class='docblock-short'>
<p>An error that occured trying to bind a global</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="enum" href="enum.GlobalEvent.html"
title='enum wayland_client::GlobalEvent'>GlobalEvent</a></td>
<td class='docblock-short'>
<p>Event provided to the user callback of GlobalManager</p>
</td>
</tr></table></section><section id="search" class="content hidden"></section><section class="footer"></section><aside id="help" class="hidden"><div><h1 class="hidden">Help</h1><div class="shortcuts"><h2>Keyboard Shortcuts</h2><dl><dt><kbd>?</kbd></dt><dd>Show this help dialog</dd><dt><kbd>S</kbd></dt><dd>Focus the search field</dd><dt><kbd></kbd></dt><dd>Move up in search results</dd><dt><kbd></kbd></dt><dd>Move down in search results</dd><dt><kbd></kbd></dt><dd>Switch tab</dd><dt><kbd>&#9166;</kbd></dt><dd>Go to active search result</dd><dt><kbd>+</kbd></dt><dd>Expand all sections</dd><dt><kbd>-</kbd></dt><dd>Collapse all sections</dd></dl></div><div class="infos"><h2>Search Tricks</h2><p>Prefix searches with a type followed by a colon (e.g. <code>fn:</code>) to restrict the search to a given type.</p><p>Accepted types are: <code>fn</code>, <code>mod</code>, <code>struct</code>, <code>enum</code>, <code>trait</code>, <code>type</code>, <code>macro</code>, and <code>const</code>.</p><p>Search functions by type signature (e.g. <code>vec -> usize</code> or <code>* -> vec</code>)</p><p>Search multiple things at once by splitting your query with comma (e.g. <code>str,u8</code> or <code>String,struct:Vec,test</code>)</p></div></div></aside><script>window.rootPath = "../";window.currentCrate = "wayland_client";</script><script src="../aliases.js"></script><script src="../main.js"></script><script defer src="../search-index.js"></script></body></html>