|
|
@ -14,34 +14,48 @@ use std::time::{SystemTime, UNIX_EPOCH}; |
|
|
|
use swayipc as s; |
|
|
|
use swayipc as s; |
|
|
|
use swayipc::reply as r; |
|
|
|
use swayipc::reply as r; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn connect_and_subscribe() -> s::Fallible<s::EventIterator> { |
|
|
|
|
|
|
|
s::Connection::new()? |
|
|
|
|
|
|
|
.subscribe(&[s::EventType::Window, s::EventType::Workspace]) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn monitor_sway_events( |
|
|
|
pub fn monitor_sway_events( |
|
|
|
extra_props: Arc<RwLock<HashMap<i64, ipc::ExtraProps>>>, |
|
|
|
extra_props: Arc<RwLock<HashMap<i64, ipc::ExtraProps>>>, |
|
|
|
) { |
|
|
|
) { |
|
|
|
'reset: loop { |
|
|
|
'reset: loop { |
|
|
|
println!("Connecting to sway for subscribing to events..."); |
|
|
|
println!("Connecting to sway for subscribing to events..."); |
|
|
|
let iter = s::Connection::new() |
|
|
|
match connect_and_subscribe() { |
|
|
|
.expect("Could not connect!") |
|
|
|
Err(err) => { |
|
|
|
.subscribe(&[s::EventType::Window, s::EventType::Workspace]) |
|
|
|
eprintln!("Could not connect and subscribe: {}", err); |
|
|
|
.expect("Could not subscribe to window and workspace events."); |
|
|
|
std::thread::sleep(std::time::Duration::from_secs(3)); |
|
|
|
|
|
|
|
break 'reset; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Ok(iter) => { |
|
|
|
for ev_result in iter { |
|
|
|
for ev_result in iter { |
|
|
|
let handled; |
|
|
|
let handled; |
|
|
|
match ev_result { |
|
|
|
match ev_result { |
|
|
|
Ok(ev) => match ev { |
|
|
|
Ok(ev) => match ev { |
|
|
|
r::Event::Window(win_ev) => { |
|
|
|
r::Event::Window(win_ev) => { |
|
|
|
let extra_props_clone = extra_props.clone(); |
|
|
|
let extra_props_clone = extra_props.clone(); |
|
|
|
handled = |
|
|
|
handled = handle_window_event( |
|
|
|
handle_window_event(win_ev, extra_props_clone); |
|
|
|
win_ev, |
|
|
|
|
|
|
|
extra_props_clone, |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
r::Event::Workspace(ws_ev) => { |
|
|
|
r::Event::Workspace(ws_ev) => { |
|
|
|
let extra_props_clone = extra_props.clone(); |
|
|
|
let extra_props_clone = extra_props.clone(); |
|
|
|
handled = |
|
|
|
handled = handle_workspace_event( |
|
|
|
handle_workspace_event(ws_ev, extra_props_clone); |
|
|
|
ws_ev, |
|
|
|
|
|
|
|
extra_props_clone, |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
_ => handled = false, |
|
|
|
_ => handled = false, |
|
|
|
}, |
|
|
|
}, |
|
|
|
Err(e) => { |
|
|
|
Err(e) => { |
|
|
|
eprintln!("Error while receiving events: {}", e); |
|
|
|
eprintln!("Error while receiving events: {}", e); |
|
|
|
|
|
|
|
std::thread::sleep(std::time::Duration::from_secs( |
|
|
|
|
|
|
|
3, |
|
|
|
|
|
|
|
)); |
|
|
|
eprintln!("Resetting!"); |
|
|
|
eprintln!("Resetting!"); |
|
|
|
break 'reset; |
|
|
|
break 'reset; |
|
|
|
} |
|
|
|
} |
|
|
@ -54,6 +68,8 @@ pub fn monitor_sway_events( |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn handle_window_event( |
|
|
|
fn handle_window_event( |
|
|
|