diff --git a/src/client.rs b/src/client.rs index 1b1597b..8d67792 100644 --- a/src/client.rs +++ b/src/client.rs @@ -54,11 +54,11 @@ pub fn exec_swayr_cmd(cmd: &SwayrCommand) { } } -fn focus_window_by_id(id: &ipc::Id) { +fn focus_window_by_id(id: ipc::Id) { util::swaymsg(&[format!("[con_id={}]", id).as_str(), "focus"]); } -fn quit_window_by_id(id: &ipc::Id) { +fn quit_window_by_id(id: ipc::Id) { util::swaymsg(&[format!("[con_id={}]", id).as_str(), "kill"]); } @@ -67,7 +67,7 @@ pub fn switch_window() { let windows = con::get_windows(&root); if let Some(window) = con::select_window("Switch to window", &windows) { - focus_window_by_id(&window.get_id()) + focus_window_by_id(window.get_id()) } } @@ -94,7 +94,7 @@ pub fn switch_workspace_or_window() { con::WsOrWin::Ws { ws } => { util::swaymsg(&["workspace", "number", ws.get_name()]); } - con::WsOrWin::Win { win } => focus_window_by_id(&win.get_id()), + con::WsOrWin::Win { win } => focus_window_by_id(win.get_id()), } } } diff --git a/src/con.rs b/src/con.rs index c01f071..aac3efc 100644 --- a/src/con.rs +++ b/src/con.rs @@ -39,8 +39,8 @@ pub struct Window<'a> { } impl Window<'_> { - pub fn get_id(&self) -> &ipc::Id { - &self.node.id + pub fn get_id(&self) -> ipc::Id { + self.node.id } pub fn get_app_name(&self) -> &str { @@ -288,8 +288,8 @@ impl Workspace<'_> { self.node.name.as_ref().unwrap() } - pub fn get_id(&self) -> &ipc::Id { - &self.node.id + pub fn get_id(&self) -> ipc::Id { + self.node.id } pub fn is_scratchpad(&self) -> bool { diff --git a/src/demon.rs b/src/demon.rs index b460006..8910397 100644 --- a/src/demon.rs +++ b/src/demon.rs @@ -53,10 +53,10 @@ fn update_last_focus_time( } fn remove_con_props( - id: &ipc::Id, + id: ipc::Id, con_props: Arc>>, ) { - con_props.write().unwrap().remove(id); + con_props.write().unwrap().remove(&id); } fn handle_con_event( @@ -72,7 +72,7 @@ fn handle_con_event( update_last_focus_time(container.id, con_props) } ipc::WindowEventType::Close => { - remove_con_props(&container.id, con_props) + remove_con_props(container.id, con_props) } _ => handled = false, }, @@ -82,12 +82,17 @@ fn handle_con_event( old: _, } => match change { ipc::WorkspaceEventType::Init | ipc::WorkspaceEventType::Focus => { - println!("WsEv"); - update_last_focus_time(current.id, con_props) - } - ipc::WorkspaceEventType::Empty => { - remove_con_props(¤t.id, con_props) + update_last_focus_time( + current + .expect("No current in Init or Focus workspace event") + .id, + con_props, + ) } + ipc::WorkspaceEventType::Empty => remove_con_props( + current.expect("No current in Empty workspace event").id, + con_props, + ), _ => handled = false, }, } diff --git a/src/ipc.rs b/src/ipc.rs index 7948f59..ae8c547 100644 --- a/src/ipc.rs +++ b/src/ipc.rs @@ -229,8 +229,9 @@ pub enum ConEvent { }, WorkspaceEvent { change: WorkspaceEventType, - current: Box, - // If the old was empty, it'll be killed => "old": null + // On a reload event, current and old are both null. + current: Option>, + // If the old was empty, it'll be killed => "old": null. old: Option>, }, }