input_method/
input_method.rs

1use std::time::Duration;
2use tokio::{sync::{mpsc, oneshot}, time::sleep};
3use wayland_protocols_async::zwp_input_method_v2::handler::InputMethodHandler;
4
5#[tokio::main]
6async fn main() {
7    // create mpsc channel for interacting with the input_method handler
8    let (input_method_msg_tx, mut input_method_msg_rx) = mpsc::channel(128);
9
10    // create mpsc channel for receiving events from the input_method handler
11    let (input_method_event_tx, mut input_method_event_rx) = mpsc::channel(128);
12    
13    // create the handler instance
14    let mut input_method_handler = InputMethodHandler::new(input_method_event_tx);
15
16
17    // start the input_method handler
18    let input_method_t = tokio::spawn(async move {
19        let _ = input_method_handler.run(input_method_msg_rx).await;
20    });
21
22    // receive all input_method events
23    let input_method_event_t = tokio::spawn(async move {
24        loop {
25            let msg = input_method_event_rx.recv().await;
26            if msg.is_none() {
27                continue;
28            }
29            println!("received input_method_event event={:?}", msg);
30        }
31    });
32
33    let _ = input_method_t.await.unwrap();
34    let _ = input_method_event_t.await.unwrap();
35}