GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
use anyhow::Context;
use wm_common::WindowState;
use crate::{
commands::container::{
detach_container, flatten_child_split_containers,
},
models::WindowContainer,
traits::{CommonGetters, WindowGetters},
wm_state::WmState,
};
#[allow(clippy::needless_pass_by_value)]
pub fn ignore_window(
window: WindowContainer,
state: &mut WmState,
) -> anyhow::Result<()> {
// Create iterator of parent, grandparent, and great-grandparent.
let ancestors = window.ancestors().take(3).collect::<Vec<_>>();
state.ignored_windows.push(window.native().clone());
detach_container(window.clone().into())?;
// After detaching the container, flatten any redundant split containers.
// For example, in the layout V[1 H[2]] where container 1 is detached to
// become V[H[2]], this will then need to be flattened to V[2].
for ancestor in ancestors.iter().rev() {
flatten_child_split_containers(ancestor)?;
}
// Sibling containers need to be redrawn if the window was tiling.
if window.state() == WindowState::Tiling {
let ancestor_to_redraw = ancestors
.into_iter()
.find(|ancestor| !ancestor.is_detached())
.context("No ancestor to redraw.")?;
state
.pending_sync
.queue_containers_to_redraw(ancestor_to_redraw.tiling_children());
}
Ok(())
}