Skip to content

Commit

Permalink
fix(wm): clean stale floating windows from state
Browse files Browse the repository at this point in the history
Floating windows that were minimised or destroyed remained in the
Workspace state because the call to workspace.remove_window() was only
checking containers for a matching hwnd.

This commit ensures that floating windows are checked before other
window containers and removes the window from the Workspace state if
necessary.

This commit also adds steam.exe to the MULTI_WINDOW_EXES list to ensure
the expected behaviour when responding to an ObjectHide event.
  • Loading branch information
LGUG2Z committed Aug 6, 2021
1 parent bebf2f7 commit 88d6eee
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
3 changes: 2 additions & 1 deletion komorebi/src/main.rs
Expand Up @@ -47,7 +47,8 @@ lazy_static! {
"firefox.exe".to_string(),
"chrome.exe".to_string(),
"idea64.exe".to_string(),
"ApplicationFrameHost.exe".to_string()
"ApplicationFrameHost.exe".to_string(),
"steam.exe".to_string()
]));
}

Expand Down
2 changes: 1 addition & 1 deletion komorebi/src/process_command.rs
Expand Up @@ -123,7 +123,7 @@ impl WindowManager {
self.focus_workspace(workspace_idx)?;
}
SocketMessage::Stop => {
tracing::error!(
tracing::info!(
"received stop command, restoring all hidden windows and terminating process"
);
self.restore_all_windows();
Expand Down
21 changes: 20 additions & 1 deletion komorebi/src/workspace.rs
Expand Up @@ -108,17 +108,31 @@ impl Workspace {

pub fn reap_orphans(&mut self) -> Result<(usize, usize)> {
let mut hwnds = vec![];
let mut floating_hwnds = vec![];

for window in self.visible_windows_mut().into_iter().flatten() {
if !window.is_window() {
hwnds.push(window.hwnd);
}
}

for window in self.floating_windows() {
if !window.is_window() {
floating_hwnds.push(window.hwnd);
}
}

for hwnd in &hwnds {
tracing::debug!("reaping hwnd: {}", hwnd);
self.remove_window(*hwnd)?;
}

for hwnd in &floating_hwnds {
tracing::debug!("reaping floating hwnd: {}", hwnd);
self.floating_windows_mut()
.retain(|w| !floating_hwnds.contains(&w.hwnd));
}

let mut container_ids = vec![];
for container in self.containers() {
if container.windows().is_empty() {
Expand All @@ -129,7 +143,7 @@ impl Workspace {
self.containers_mut()
.retain(|c| !container_ids.contains(c.id()));

Ok((hwnds.len(), container_ids.len()))
Ok((hwnds.len() + floating_hwnds.len(), container_ids.len()))
}

pub fn focus_container_by_window(&mut self, hwnd: isize) -> Result<()> {
Expand Down Expand Up @@ -209,6 +223,11 @@ impl Workspace {
}

pub fn remove_window(&mut self, hwnd: isize) -> Result<()> {
if self.floating_windows().iter().any(|w| w.hwnd == hwnd) {
self.floating_windows_mut().retain(|w| w.hwnd != hwnd);
return Ok(());
}

let container_idx = self
.container_idx_for_window(hwnd)
.context("there is no window")?;
Expand Down

0 comments on commit 88d6eee

Please sign in to comment.