Skip to content

GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.

feat: implement ignore command

Lars Bergerea7b891ae92f
diff --git a/packages/wm/src/app_command.rs b/packages/wm/src/app_command.rs
index a7ae998f..0e17c992 100644
--- a/packages/wm/src/app_command.rs
+++ b/packages/wm/src/app_command.rs
@@ -22,8 +22,8 @@ use crate::{
user_config::{FloatingStateConfig, FullscreenStateConfig, UserConfig},
windows::{
commands::{
- move_window_in_direction, move_window_to_workspace, resize_window,
- update_window_state,
+ ignore_window, move_window_in_direction, move_window_to_workspace,
+ resize_window, update_window_state,
},
traits::WindowGetters,
WindowState,
@@ -307,7 +307,12 @@ impl InvokeCommand {
Ok(())
}
- InvokeCommand::Ignore => todo!(),
+ InvokeCommand::Ignore => {
+ match subject_container.as_window_container() {
+ Ok(window) => ignore_window(window, state),
+ _ => Ok(()),
+ }
+ }
InvokeCommand::Move(args) => {
match subject_container.as_window_container() {
Ok(window) => {
diff --git a/packages/wm/src/common/memo.rs b/packages/wm/src/common/memo.rs
index f85b4833..2f25acaf 100644
--- a/packages/wm/src/common/memo.rs
+++ b/packages/wm/src/common/memo.rs
@@ -2,7 +2,7 @@ use std::sync::{Arc, Mutex};
/// A thread-safe type that provides lazy initialization and caching of a
/// value.
-#[derive(Debug)]
+#[derive(Debug, Clone)]
pub struct Memo<T>
where
T: Clone,
diff --git a/packages/wm/src/common/platform/native_window.rs b/packages/wm/src/common/platform/native_window.rs
index d5d64916..edfa2865 100644
--- a/packages/wm/src/common/platform/native_window.rs
+++ b/packages/wm/src/common/platform/native_window.rs
@@ -37,7 +37,7 @@ use crate::{
windows::WindowState,
};
-#[derive(Debug)]
+#[derive(Debug, Clone)]
pub struct NativeWindow {
pub handle: isize,
title: Memo<String>,
@@ -546,12 +546,6 @@ impl PartialEq for NativeWindow {
impl Eq for NativeWindow {}
-impl Default for NativeWindow {
- fn default() -> Self {
- Self::new(0)
- }
-}
-
pub fn available_windows() -> anyhow::Result<Vec<NativeWindow>> {
available_window_handles()?
.into_iter()
diff --git a/packages/wm/src/windows/commands/ignore_window.rs b/packages/wm/src/windows/commands/ignore_window.rs
new file mode 100644
index 00000000..ea28d95c
--- /dev/null
+++ b/packages/wm/src/windows/commands/ignore_window.rs
@@ -0,0 +1,44 @@
+use anyhow::Context;
+
+use crate::{
+ containers::{
+ commands::{detach_container, flatten_child_split_containers},
+ traits::CommonGetters,
+ WindowContainer,
+ },
+ windows::{traits::WindowGetters, WindowState},
+ wm_state::WmState,
+};
+
+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.clone())?;
+ }
+
+ // 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
+ .containers_to_redraw
+ .extend(ancestor_to_redraw.tiling_children().map(Into::into));
+ }
+
+ Ok(())
+}
diff --git a/packages/wm/src/windows/commands/mod.rs b/packages/wm/src/windows/commands/mod.rs
index ee2eee35..c789fe2a 100644
--- a/packages/wm/src/windows/commands/mod.rs
+++ b/packages/wm/src/windows/commands/mod.rs
@@ -1,3 +1,4 @@
+mod ignore_window;
mod manage_window;
mod move_window_in_direction;
mod move_window_to_workspace;
@@ -5,6 +6,7 @@ mod resize_window;
mod unmanage_window;
mod update_window_state;
+pub use ignore_window::*;
pub use manage_window::*;
pub use move_window_in_direction::*;
pub use move_window_to_workspace::*;
diff --git a/packages/wm/src/windows/non_tiling_window.rs b/packages/wm/src/windows/non_tiling_window.rs
index ebde3e31..d32d77a0 100644
--- a/packages/wm/src/windows/non_tiling_window.rs
+++ b/packages/wm/src/windows/non_tiling_window.rs
@@ -72,11 +72,9 @@ impl NonTilingWindow {
}
pub fn to_tiling(&self, inner_gap: LengthValue) -> TilingWindow {
- let native = std::mem::take(&mut self.0.borrow_mut().native);
-
TilingWindow::new(
Some(self.id()),
- native,
+ self.native().clone(),
Some(self.state()),
self.border_delta(),
self.floating_placement(),
diff --git a/packages/wm/src/windows/tiling_window.rs b/packages/wm/src/windows/tiling_window.rs
index 016cfe9c..2cbcf8d6 100644
--- a/packages/wm/src/windows/tiling_window.rs
+++ b/packages/wm/src/windows/tiling_window.rs
@@ -81,11 +81,9 @@ impl TilingWindow {
state: WindowState,
insertion_target: Option<(Container, usize)>,
) -> NonTilingWindow {
- let native = std::mem::take(&mut self.0.borrow_mut().native);
-
NonTilingWindow::new(
Some(self.id()),
- native,
+ self.native().clone(),
state,
Some(WindowState::Tiling),
self.border_delta(),
diff --git a/packages/wm/src/wm_state.rs b/packages/wm/src/wm_state.rs
index 7c0ec3cf..d5aa6e6b 100644
--- a/packages/wm/src/wm_state.rs
+++ b/packages/wm/src/wm_state.rs
@@ -48,6 +48,10 @@ pub struct WmState {
/// Configs of currently enabled binding modes.
pub binding_modes: Vec<BindingModeConfig>,
+ /// Windows that the WM should ignore. Windows can be added via the
+ /// `ignore` command.
+ pub ignored_windows: Vec<NativeWindow>,
+
/// Whether the initial state has been populated.
has_initialized: bool,
@@ -80,6 +84,7 @@ impl WmState {
recent_workspace_name: None,
unmanaged_or_minimized_timestamp: None,
binding_modes: Vec::new(),
+ ignored_windows: Vec::new(),
has_initialized: false,
event_tx,
}