Skip to content

Commit

Permalink
fix(stackbar): avoid drops from variable updates
Browse files Browse the repository at this point in the history
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
  • Loading branch information
LGUG2Z committed Apr 29, 2024
1 parent 95990d6 commit 611fa34
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
33 changes: 20 additions & 13 deletions komorebi/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,26 +159,33 @@ impl Container {
}

pub fn set_stackbar_mode(&mut self, mode: StackbarMode) {
self.stackbar = match mode {
StackbarMode::Always => Stackbar::create().ok(),
StackbarMode::Never => 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() {
Stackbar::create().ok()
} else {
None
self.stackbar = Stackbar::create().ok();
}

if self.windows().len() == 1 && self.stackbar.is_some() {
self.stackbar = None;
}
}
};
}
}

pub fn renew_stackbar(&mut self) {
match &self.stackbar {
None => {}
Some(stackbar) => {
if !WindowsApi::is_window(stackbar.hwnd()) {
self.stackbar = Stackbar::create().ok()
}
if let Some(stackbar) = &self.stackbar {
if !WindowsApi::is_window(stackbar.hwnd()) {
self.stackbar = Stackbar::create().ok()
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions komorebi/src/stackbar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand All @@ -87,6 +88,7 @@ impl Clone for Stackbar {
}
}
}

impl Stackbar {
unsafe extern "system" fn window_proc(
hwnd: HWND,
Expand Down

0 comments on commit 611fa34

Please sign in to comment.