1use crate::common::protocols::wayland::wl_callback::WlCallback;
2use crate::common::protocols::wayland::wl_display::WlDisplay;
3use mio::Interest;
4use mio::Token;
5use mio::unix::SourceFd;
6use std::os::fd::AsRawFd;
7use wl_client::Libwayland;
8use wl_client::Queue;
9use wl_client::proxy;
10
11#[path = "../common/mod.rs"]
12mod common;
13
14fn main() {
15 let lib = Libwayland::open().unwrap();
16 let con = lib.connect_to_default_display().unwrap();
17 let queue = con.create_local_queue(c"poll-integration");
18
19 let watcher = queue.create_watcher().unwrap();
22 let token = Token(0);
23
24 create_sync(&queue, 1);
25
26 let mut events = mio::Events::with_capacity(2);
27 let mut poll = mio::Poll::new().unwrap();
28 poll.registry()
29 .register(
30 &mut SourceFd(&watcher.as_raw_fd()),
31 token,
32 Interest::READABLE,
33 )
34 .unwrap();
35
36 loop {
37 con.flush().unwrap();
39 poll.poll(&mut events, None).unwrap();
40 for event in events.iter() {
41 if event.token() == token {
42 queue.dispatch_pending().unwrap();
43 watcher.reset().unwrap();
45 }
46 }
47 events.clear();
48 }
49}
50
51fn create_sync(queue: &Queue, n: u64) {
52 let sync = queue.display::<WlDisplay>().sync();
53 proxy::set_event_handler(
54 &sync.clone(),
55 WlCallback::on_done(move |_, _| {
56 println!("done! ({n})");
57 proxy::destroy(&sync);
58 create_sync(proxy::queue(&sync), n + 1);
59 }),
60 );
61}