diff --git a/komorebi/src/container.rs b/komorebi/src/container.rs index 74d780e9..6dbd2c16 100644 --- a/komorebi/src/container.rs +++ b/komorebi/src/container.rs @@ -18,6 +18,7 @@ pub struct Container { #[getset(get = "pub")] id: String, windows: Ring, + #[serde(skip)] #[getset(get = "pub", get_mut = "pub")] stackbar: Option, } @@ -124,7 +125,10 @@ impl Container { let window = self.windows_mut().remove(idx); if matches!(*STACKBAR_MODE.lock(), StackbarMode::OnStack) && self.windows().len() <= 1 { - self.stackbar = None; + if let Some(stackbar) = &self.stackbar { + let _ = WindowsApi::close_window(stackbar.hwnd()); + self.stackbar = None; + } } if idx != 0 { @@ -166,17 +170,22 @@ impl Container { } } StackbarMode::Never => { - if self.stackbar.is_some() { - self.stackbar = None + if let Some(stackbar) = &self.stackbar { + let _ = WindowsApi::close_window(stackbar.hwnd()); } + + self.stackbar = None } StackbarMode::OnStack => { if self.windows().len() > 1 && self.stackbar().is_none() { self.stackbar = Stackbar::create().ok(); } - if self.windows().len() == 1 && self.stackbar.is_some() { - self.stackbar = None; + if let Some(stackbar) = &self.stackbar { + if self.windows().len() == 1 { + let _ = WindowsApi::close_window(stackbar.hwnd()); + self.stackbar = None; + } } } } diff --git a/komorebi/src/stackbar.rs b/komorebi/src/stackbar.rs index bca18500..c60f3265 100644 --- a/komorebi/src/stackbar.rs +++ b/komorebi/src/stackbar.rs @@ -64,29 +64,9 @@ use crate::STACKBAR_UNFOCUSED_TEXT_COLOUR; use crate::TRANSPARENCY_COLOUR; use crate::WINDOWS_BY_BAR_HWNDS; -#[derive(Debug, Default, Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)] pub struct Stackbar { pub(crate) hwnd: isize, - #[serde(skip)] - pub is_cloned: bool, -} - -impl Drop for Stackbar { - fn drop(&mut self) { - if !self.is_cloned { - tracing::debug!("dropping and calling close_window on stackbar"); - let _ = WindowsApi::close_window(self.hwnd()); - } - } -} - -impl Clone for Stackbar { - fn clone(&self) -> Self { - Self { - hwnd: self.hwnd, - is_cloned: true, - } - } } impl Stackbar { @@ -193,7 +173,6 @@ impl Stackbar { Ok(Self { hwnd: hwnd_receiver.recv()?.0, - ..Default::default() }) }