Restart connection & subscription on error

timeout_old
Tassilo Horn 4 years ago
parent dd52f6d8c3
commit f14d70a4f0
  1. 12
      src/demon.rs

@ -17,6 +17,8 @@ use swayipc::reply as r;
pub fn monitor_sway_events(
extra_props: Arc<RwLock<HashMap<i64, ipc::ExtraProps>>>,
) {
'reset: loop {
println!("Connecting to sway for subscribing to events...");
let iter = s::Connection::new()
.expect("Could not connect!")
.subscribe(&[s::EventType::Window, s::EventType::Workspace])
@ -28,17 +30,20 @@ pub fn monitor_sway_events(
Ok(ev) => match ev {
r::Event::Window(win_ev) => {
let extra_props_clone = extra_props.clone();
handled = handle_window_event(win_ev, extra_props_clone);
handled =
handle_window_event(win_ev, extra_props_clone);
}
r::Event::Workspace(ws_ev) => {
let extra_props_clone = extra_props.clone();
handled = handle_workspace_event(ws_ev, extra_props_clone);
handled =
handle_workspace_event(ws_ev, extra_props_clone);
}
_ => handled = false,
},
Err(e) => {
eprintln!("Error while receiving events: {}", e);
handled = false;
eprintln!("Resetting!");
break 'reset;
}
}
if handled {
@ -49,6 +54,7 @@ pub fn monitor_sway_events(
}
}
}
}
fn handle_window_event(
ev: Box<r::WindowEvent>,

Loading…
Cancel
Save