fix(stackbar): avoid drops from variable updates

This commit ensures that when we call methods to change
Container.stackbar we are not unintentionally invoking a Drop which
kills a stackbar window that already exists.

Checks have been added to make sure that we not change the value of the
stackbar variable if it is already an Option::Some.

re #746 re #792
This commit is contained in:
LGUG2Z
2024-04-29 13:52:00 -07:00
parent 95990d682b
commit 611fa34567
2 changed files with 25 additions and 16 deletions

View File

@@ -159,27 +159,34 @@ impl Container {
}
pub fn set_stackbar_mode(&mut self, mode: StackbarMode) {
self.stackbar = match mode {
StackbarMode::Always => Stackbar::create().ok(),
StackbarMode::Never => None,
StackbarMode::OnStack => {
if self.windows().len() > 1 && self.stackbar().is_none() {
Stackbar::create().ok()
} else {
None
match mode {
StackbarMode::Always => {
if self.stackbar.is_none() {
self.stackbar = Stackbar::create().ok();
}
}
};
}
StackbarMode::Never => {
if self.stackbar.is_some() {
self.stackbar = None
}
}
StackbarMode::OnStack => {
if self.windows().len() > 1 && self.stackbar().is_none() {
self.stackbar = Stackbar::create().ok();
}
pub fn renew_stackbar(&mut self) {
match &self.stackbar {
None => {}
Some(stackbar) => {
if !WindowsApi::is_window(stackbar.hwnd()) {
self.stackbar = Stackbar::create().ok()
if self.windows().len() == 1 && self.stackbar.is_some() {
self.stackbar = None;
}
}
}
}
pub fn renew_stackbar(&mut self) {
if let Some(stackbar) = &self.stackbar {
if !WindowsApi::is_window(stackbar.hwnd()) {
self.stackbar = Stackbar::create().ok()
}
}
}
}

View File

@@ -74,6 +74,7 @@ pub struct Stackbar {
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());
}
}
@@ -87,6 +88,7 @@ impl Clone for Stackbar {
}
}
}
impl Stackbar {
unsafe extern "system" fn window_proc(
hwnd: HWND,