From aa3b47fbad55c2347513671a43e46a2008c03caf Mon Sep 17 00:00:00 2001 From: Skia Date: Mon, 27 Nov 2023 11:12:31 +0100 Subject: [PATCH] get_current_*: don't use outdated cache is these functions Fixes https://gitlab.com/hyask/swaysome/-/issues/18 Thanks a lot @mahieujeremy for reporting that and providing a fix so quickly! --- src/main.rs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0ce2e14..a70143b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -263,14 +263,18 @@ impl SwaySome { } fn get_current_output_index(&self) -> usize { - match self.outputs.iter().position(|x| x.focused) { + // Do not use `self.outputs`, as the information here could be outdated, especially the `focused` attribute + let outputs = self.get_outputs(); + match outputs.iter().position(|x| x.focused) { Some(i) => i, None => panic!("WTF! No focused output???"), } } fn get_current_output_name(&self) -> String { - let focused_output_index = match self.outputs.iter().find(|x| x.focused) { + // Do not use `self.outputs`, as the information here could be outdated, especially the `focused` attribute + let outputs = self.get_outputs(); + let focused_output_index = match outputs.iter().find(|x| x.focused) { Some(i) => i.name.as_str(), None => panic!("WTF! No focused output???"), }; @@ -279,17 +283,12 @@ impl SwaySome { } fn get_current_workspace_index(&self) -> usize { - self.workspaces + // Do not use `self.outputs`, as the information here could be outdated, especially the `focused` attribute + let outputs = self.get_outputs(); + // Do not use `self.workspaces`, as the information here could be outdated, especially the `visible` attribute + self.get_workspaces() .iter() - .find(|w| { - w.visible - && self - .outputs - .iter() - .find(|o| o.name == w.output) - .unwrap() - .focused - }) + .find(|w| w.visible && outputs.iter().find(|o| o.name == w.output).unwrap().focused) .unwrap() .num }