summaryrefslogtreecommitdiff
path: root/src/main.rs
blob: 2a4c4c2f417388f565cbcbe1e933f3fe4dbeee36 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#![allow(clippy::single_component_path_imports)]

#[macro_use]
extern crate anyhow;
#[macro_use]
extern crate log;

mod bar;
mod button_manager;
mod color;
mod config;
mod cursor;
mod i3bar_protocol;
mod ord_adaptor;
mod pointer_btn;
mod protocol;
mod shared_state;
mod state;
mod status_cmd;
mod text;
mod utils;
mod wm_info_provider;

use wayrs_client::connection::Connection;

use state::State;

#[tokio::main(flavor = "current_thread")]
async fn main() -> anyhow::Result<()> {
    env_logger::init();

    let mut conn = Connection::connect()?;
    let globals = conn.async_collect_initial_globals().await?;
    let mut state = State::new(&mut conn, &globals);
    conn.async_flush().await?;

    loop {
        tokio::select! {
            recv_events = conn.async_recv_events() => {
                recv_events?;
                conn.dispatch_events(&mut state);
                conn.async_flush().await?;
            }
            reat_res = state.status_cmd_read() => {
                if let Err(e) = reat_res.and_then(|_| state.status_cmd_notify_available(&mut conn)) {
                    if let Some(mut status_cmd) = state.shared_state.status_cmd.take() {
                        let _ = status_cmd.child.kill();
                    }
                    state.set_error(&mut conn, e.to_string());
                }
                conn.async_flush().await?;
            }
        }
    }
}