From 33ac10483636bcd1e8db3d0038f4ffc7d3a03abf Mon Sep 17 00:00:00 2001 From: Tassilo Horn Date: Sun, 17 Jan 2021 09:49:57 +0100 Subject: [PATCH] Move event handler to separate module --- src/bin/swayrd.rs | 35 +++++++++-------------------------- src/lib.rs | 1 + 2 files changed, 10 insertions(+), 26 deletions(-) diff --git a/src/bin/swayrd.rs b/src/bin/swayrd.rs index bc5bb0a..ad15e32 100644 --- a/src/bin/swayrd.rs +++ b/src/bin/swayrd.rs @@ -1,41 +1,24 @@ extern crate serde; extern crate serde_json; -use serde_json::Deserializer; use std::collections::HashMap; -use std::process as proc; use std::sync::Arc; use std::sync::RwLock; use std::thread; +use swayr::demon; use swayr::ipc; fn main() { let win_props: Arc>> = Arc::new(RwLock::new(HashMap::new())); + let win_props_for_ev_handler = win_props.clone(); - let subscriber_handle = thread::spawn(|| { - let child = proc::Command::new("swaymsg") - .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::(); - for res in stream { - match res { - Ok(win_ev) => println!( - "WindowEvent {:?} for node {:?}", - win_ev.change, win_ev.container.id - ), - Err(err) => panic!("{:?}", err), - } - } - }); + let subscriber_handle = + thread::spawn(|| demon::monitor_window_events(win_props_for_ev_handler)); - subscriber_handle.join(); + let subscriber_result = subscriber_handle.join(); + match subscriber_result { + Ok(()) => println!("Subscriber thread shut down cleanly."), + Err(err) => panic!(err), + } } diff --git a/src/lib.rs b/src/lib.rs index 71ce250..646d3dc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,2 +1,3 @@ pub mod con; +pub mod demon; pub mod ipc;