Skip to content

Commit

Permalink
fix(wm): enforce valid hwnd check for border fns
Browse files Browse the repository at this point in the history
This commit ensures that the active window border has non-zero HWND
before attempting to either hide it or set the border position. This is
required as the border is only initialized when a komorebic command is
received, meaning that the default value of 0 will never change if a
user decides to use komorebi without the active window border.

Most notably this commit fixes an issue where users who did not have the
active window border enabled would not be able to move away from an
empty workspace using a komorebic command.

fix #217
  • Loading branch information
LGUG2Z committed Aug 27, 2022
1 parent 5a0ba4c commit 5d094f6
Showing 1 changed file with 29 additions and 21 deletions.
50 changes: 29 additions & 21 deletions komorebi/src/border.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ impl Border {
}

pub fn hide(self) -> Result<()> {
WindowsApi::hide_border_window(self.hwnd())
if self.hwnd == 0 {
Ok(())
} else {
WindowsApi::hide_border_window(self.hwnd())
}
}

pub fn set_position(
Expand All @@ -96,29 +100,33 @@ impl Border {
invisible_borders: &Rect,
activate: bool,
) -> Result<()> {
let mut should_expand_border = false;

let mut rect = WindowsApi::window_rect(window.hwnd())?;
rect.top -= invisible_borders.bottom;
rect.bottom += invisible_borders.bottom;

let border_overflows = BORDER_OVERFLOW_IDENTIFIERS.lock();
if border_overflows.contains(&window.title()?)
|| border_overflows.contains(&window.exe()?)
|| border_overflows.contains(&window.class()?)
{
should_expand_border = true;
}
if self.hwnd == 0 {
Ok(())
} else {
let mut should_expand_border = false;

if should_expand_border {
rect.left -= invisible_borders.left;
rect.top -= invisible_borders.top;
rect.right += invisible_borders.right;
let mut rect = WindowsApi::window_rect(window.hwnd())?;
rect.top -= invisible_borders.bottom;
rect.bottom += invisible_borders.bottom;
}

*BORDER_RECT.lock() = rect;
let border_overflows = BORDER_OVERFLOW_IDENTIFIERS.lock();
if border_overflows.contains(&window.title()?)
|| border_overflows.contains(&window.exe()?)
|| border_overflows.contains(&window.class()?)
{
should_expand_border = true;
}

if should_expand_border {
rect.left -= invisible_borders.left;
rect.top -= invisible_borders.top;
rect.right += invisible_borders.right;
rect.bottom += invisible_borders.bottom;
}

WindowsApi::position_border_window(self.hwnd(), &rect, activate)
*BORDER_RECT.lock() = rect;

WindowsApi::position_border_window(self.hwnd(), &rect, activate)
}
}
}

0 comments on commit 5d094f6

Please sign in to comment.