hello_wayland/
main.rs

1use {
2    crate::common::protocols::wayland::{wl_callback::WlCallback, wl_display::WlDisplay},
3    wl_client::{Libwayland, proxy},
4};
5
6#[path = "../common/mod.rs"]
7mod common;
8
9fn main() {
10    // Load the `libwayland-client.so` dynamic library.
11    let lib = Libwayland::open().unwrap();
12    // Connect to the default display determined by the `WAYLAND_DISPLAY` env var.
13    let con = lib.connect_to_default_display().unwrap();
14    // Create a new event queue with the name `hello-wayland`. This name will show up
15    // when debugging applications with `WAYLAND_DEBUG=1`.
16    let queue = con.create_queue(c"hello-wayland");
17    // Get a reference to the `wl_display` singleton. This type was generated with the
18    // `wl-client-builder` crate.
19    let display: WlDisplay = queue.display();
20    // Create a `wl_callback` object. The compositor will immediately respond with a
21    // `wl_callback.done` event.
22    let sync = display.sync();
23    // Set the event handler of the proxy.
24    proxy::set_event_handler(
25        &sync,
26        // When only handling a single event, the following functional form can be used.
27        // In general, and when handling more than one event, the event handler trait must
28        // be implemented. In this case, `WlCallbackEventHandler`.
29        WlCallback::on_done(|_, _| println!("Hello wayland!")),
30    );
31    // Perform a roundtrip to ensure that the `done` event has been dispatched.
32    queue.dispatch_roundtrip_blocking().unwrap();
33}