Move event handler to separate module

timeout_old
Tassilo Horn 4 years ago
parent 131051a69f
commit 33ac104836
  1. 35
      src/bin/swayrd.rs
  2. 1
      src/lib.rs

@ -1,41 +1,24 @@
extern crate serde; extern crate serde;
extern crate serde_json; extern crate serde_json;
use serde_json::Deserializer;
use std::collections::HashMap; use std::collections::HashMap;
use std::process as proc;
use std::sync::Arc; use std::sync::Arc;
use std::sync::RwLock; use std::sync::RwLock;
use std::thread; use std::thread;
use swayr::demon;
use swayr::ipc; use swayr::ipc;
fn main() { fn main() {
let win_props: Arc<RwLock<HashMap<ipc::Id, ipc::WindowProps>>> = let win_props: Arc<RwLock<HashMap<ipc::Id, ipc::WindowProps>>> =
Arc::new(RwLock::new(HashMap::new())); Arc::new(RwLock::new(HashMap::new()));
let win_props_for_ev_handler = win_props.clone();
let subscriber_handle = thread::spawn(|| { let subscriber_handle =
let child = proc::Command::new("swaymsg") thread::spawn(|| demon::monitor_window_events(win_props_for_ev_handler));
.arg("--monitor")
.arg("--raw")
.arg("-t")
.arg("subscribe")
.arg("[\"window\"]")
.stdout(proc::Stdio::piped())
.spawn()
.expect("Failed to subscribe to window events");
let stdout: std::process::ChildStdout = child.stdout.unwrap();
// TODO: Before the WindowEvents, there's one Reply. How to read that?
let stream = Deserializer::from_reader(stdout).into_iter::<ipc::WindowEvent>();
for res in stream {
match res {
Ok(win_ev) => println!(
"WindowEvent {:?} for node {:?}",
win_ev.change, win_ev.container.id
),
Err(err) => panic!("{:?}", err),
}
}
});
subscriber_handle.join(); let subscriber_result = subscriber_handle.join();
match subscriber_result {
Ok(()) => println!("Subscriber thread shut down cleanly."),
Err(err) => panic!(err),
}
} }

@ -1,2 +1,3 @@
pub mod con; pub mod con;
pub mod demon;
pub mod ipc; pub mod ipc;

Loading…
Cancel
Save