From b8c0799ffc4afa6ecf09f4bd3f1e622887d43303 Mon Sep 17 00:00:00 2001 From: Tassilo Horn Date: Sun, 24 Jan 2021 17:55:00 +0100 Subject: [PATCH] Don't get into a restart loop if swaymsg monitor process exited --- src/demon.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/demon.rs b/src/demon.rs index 8910397..796e0db 100644 --- a/src/demon.rs +++ b/src/demon.rs @@ -13,7 +13,7 @@ use std::time::{SystemTime, UNIX_EPOCH}; pub fn monitor_con_events( con_props: Arc>>, ) { - let child = proc::Command::new("swaymsg") + let mut child = proc::Command::new("swaymsg") .arg("--monitor") .arg("--raw") .arg("-t") @@ -22,7 +22,7 @@ pub fn monitor_con_events( .stdout(proc::Stdio::piped()) .spawn() .expect("Failed to subscribe to window events"); - let stdout: proc::ChildStdout = child.stdout.unwrap(); + let stdout = child.stdout.take().unwrap(); let reader = std::io::BufReader::new(stdout); let deserializer = Deserializer::from_reader(reader); for res in deserializer.into_iter::() { @@ -31,8 +31,19 @@ pub fn monitor_con_events( Err(err) => eprintln!("Error handling window event:\n{:?}", err), } } - eprintln!("Stopped monitoring con events. Restarting..."); - monitor_con_events(con_props); + + match child.try_wait() { + Ok(exit_code) => match exit_code { + None => { + eprintln!("Stopped monitoring con events. Restarting..."); + monitor_con_events(con_props) + } + Some(exit_code) => { + println!("Swaymsg exited with code {}. Exiting.", exit_code) + } + }, + Err(err) => println!("Swaymsg errored with {}. Exiting.", err), + } } fn update_last_focus_time(