pub struct Libwayland { /* private fields */ }Expand description
A reference to the libwayland-client.so dynamic library.
You can obtain a reference by calling Self::open.
Implementations§
Source§impl Libwayland
impl Libwayland
Sourcepub fn connect_to_default_display(&'static self) -> Result<Connection>
pub fn connect_to_default_display(&'static self) -> Result<Connection>
Connects to the default display.
The default display is usually identified by the WAYLAND_DISPLAY environment
variable but falls back to wayland-0 if the environment variable is not set.
§Example
let lib = Libwayland::open().unwrap();
let _con = lib.connect_to_default_display().unwrap();Examples found in repository?
More examples
10async fn main() {
11 let lib = Libwayland::open().unwrap();
12 let con = lib.connect_to_default_display().unwrap();
13 let queue = con.create_local_queue(c"async-wait");
14
15 create_sync(&queue, 1);
16
17 loop {
18 queue.wait_for_events().await.unwrap();
19 queue.dispatch_pending().unwrap();
20 }
21}26fn main() {
27 let lib = Libwayland::open().unwrap();
28 let con = lib.connect_to_default_display().unwrap();
29 let queue = con.create_local_queue(c"keyboard-events");
30 let singletons = get_singletons(&queue.display());
31 let simple_window = simple_window::prepare(singletons);
32
33 let wl_registry = queue.display::<WlDisplay>().get_registry();
34 proxy::set_event_handler_local(
35 &wl_registry,
36 RegistryEventHandler {
37 wl_registry: wl_registry.clone(),
38 seats: Default::default(),
39 },
40 );
41
42 while !simple_window.exit.get() {
43 queue.dispatch_blocking().unwrap();
44 }
45}11async fn main() {
12 let lib = Libwayland::open().unwrap();
13 let con = lib.connect_to_default_display().unwrap();
14 let queue = con.create_local_queue(c"async-roundtrip");
15 let registry = queue.display::<WlDisplay>().get_registry();
16 let num_globals = Cell::new(0);
17 queue
18 .dispatch_scope_async(async |scope| {
19 scope.set_event_handler_local(
20 ®istry,
21 WlRegistry::on_global(|_, _, _, _| {
22 num_globals.set(num_globals.get() + 1);
23 }),
24 );
25 // This function can be used to perform an async roundtrip. It is
26 // compatible with any async runtime. This example also demonstrates
27 // that this works in combination with scoped event handlers.
28 queue.dispatch_roundtrip_async().await.unwrap();
29 })
30 .await;
31 println!("number of globals: {}", num_globals.get());
32}Sourcepub fn connect_to_named_display(
&'static self,
display: &CStr,
) -> Result<Connection>
pub fn connect_to_named_display( &'static self, display: &CStr, ) -> Result<Connection>
Connects to a display with a given name.
The name of the display should usually be of the form wayland-N or it should be
the absolute path of a display socket.
§Example
let lib = Libwayland::open().unwrap();
let _con = lib.connect_to_named_display(c"wayland-1").unwrap();Sourcepub fn connect_to_fd(&'static self, fd: OwnedFd) -> Result<Connection>
pub fn connect_to_fd(&'static self, fd: OwnedFd) -> Result<Connection>
Consumes an existing socket connected to a wayland compositor.
Unlike Libwayland::connect_to_default_display, this function does not perform
any blocking IO.
Sourcepub unsafe fn wrap_owned_pointer(
&'static self,
wl_display: NonNull<wl_display>,
) -> Result<Connection>
pub unsafe fn wrap_owned_pointer( &'static self, wl_display: NonNull<wl_display>, ) -> Result<Connection>
Takes ownership of an existing wl_display.
If the display is owned when the last clone of the Connection is dropped, the
display will be destroyed. All proxies and queues created from the Connection
will contain a clone of the connection to keep the connection alive.
For proxies and queues that already exist at the time this function is called, you must manage the lifetime requirements manually.
§Safety
wl_displaymust be valid and must stay valid for the lifetime of this object and its clones.- The display file descriptor must be open and owned by the
wl_display. - If the display is owned by the time the connection is dropped, all proxies and queues created from this object must have been destroyed before then.
§Example
let lib = Libwayland::open().unwrap();
let wl_display = {
let con = lib.connect_to_default_display().unwrap();
con.take_ownership().unwrap()
};
// SAFETY: We took the display from a freshly created Connection so it is valid
// and has no queues or proxies attached.
let _con = unsafe { lib.wrap_owned_pointer(wl_display) };Sourcepub unsafe fn wrap_borrowed_pointer(
&'static self,
wl_display: NonNull<wl_display>,
) -> Result<Connection>
pub unsafe fn wrap_borrowed_pointer( &'static self, wl_display: NonNull<wl_display>, ) -> Result<Connection>
Borrows an existing wl_display.
§Safety
wl_displaymust be valid and must stay valid for the lifetime of this object and its clones.- The display file descriptor must be open and owned by the
wl_display.
§Example
let lib = Libwayland::open().unwrap();
let con = lib.connect_to_default_display().unwrap();
let wl_display = con.wl_display();
{
// SAFETY: - We took the display from a freshly created Connection so it is valid.
// - We drop the connection before dropping the outer connection that
// owns the wl_display.
let _con = unsafe { lib.wrap_borrowed_pointer(wl_display) };
}Source§impl Libwayland
impl Libwayland
Sourcepub fn open() -> Result<&'static Self>
pub fn open() -> Result<&'static Self>
Obtains a reference to libwayland-client.so.
Examples found in repository?
More examples
10async fn main() {
11 let lib = Libwayland::open().unwrap();
12 let con = lib.connect_to_default_display().unwrap();
13 let queue = con.create_local_queue(c"async-wait");
14
15 create_sync(&queue, 1);
16
17 loop {
18 queue.wait_for_events().await.unwrap();
19 queue.dispatch_pending().unwrap();
20 }
21}26fn main() {
27 let lib = Libwayland::open().unwrap();
28 let con = lib.connect_to_default_display().unwrap();
29 let queue = con.create_local_queue(c"keyboard-events");
30 let singletons = get_singletons(&queue.display());
31 let simple_window = simple_window::prepare(singletons);
32
33 let wl_registry = queue.display::<WlDisplay>().get_registry();
34 proxy::set_event_handler_local(
35 &wl_registry,
36 RegistryEventHandler {
37 wl_registry: wl_registry.clone(),
38 seats: Default::default(),
39 },
40 );
41
42 while !simple_window.exit.get() {
43 queue.dispatch_blocking().unwrap();
44 }
45}11async fn main() {
12 let lib = Libwayland::open().unwrap();
13 let con = lib.connect_to_default_display().unwrap();
14 let queue = con.create_local_queue(c"async-roundtrip");
15 let registry = queue.display::<WlDisplay>().get_registry();
16 let num_globals = Cell::new(0);
17 queue
18 .dispatch_scope_async(async |scope| {
19 scope.set_event_handler_local(
20 ®istry,
21 WlRegistry::on_global(|_, _, _, _| {
22 num_globals.set(num_globals.get() + 1);
23 }),
24 );
25 // This function can be used to perform an async roundtrip. It is
26 // compatible with any async runtime. This example also demonstrates
27 // that this works in combination with scoped event handlers.
28 queue.dispatch_roundtrip_async().await.unwrap();
29 })
30 .await;
31 println!("number of globals: {}", num_globals.get());
32}