Fix ConEvent deserialization issue

In a workspace Reload event, both current and old workspace are actually null.
timeout_old
Tassilo Horn 4 years ago
parent 47d47f47f5
commit dcfe4ccc99
  1. 8
      src/client.rs
  2. 8
      src/con.rs
  3. 23
      src/demon.rs
  4. 5
      src/ipc.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()),
}
}
}

@ -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 {

@ -53,10 +53,10 @@ fn update_last_focus_time(
}
fn remove_con_props(
id: &ipc::Id,
id: ipc::Id,
con_props: Arc<RwLock<HashMap<ipc::Id, ipc::ConProps>>>,
) {
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(&current.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,
},
}

@ -229,8 +229,9 @@ pub enum ConEvent {
},
WorkspaceEvent {
change: WorkspaceEventType,
current: Box<Node>,
// If the old was empty, it'll be killed => "old": null
// On a reload event, current and old are both null.
current: Option<Box<Node>>,
// If the old was empty, it'll be killed => "old": null.
old: Option<Box<Node>>,
},
}

Loading…
Cancel
Save