GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat: change `update_window_state` to not always redraw
Lars Berger978d9f215c99
diff --git a/packages/wm/src/app_command.rs b/packages/wm/src/app_command.rsindex 5fd0d1a6..ede4fb12 100644--- a/packages/wm/src/app_command.rs+++ b/packages/wm/src/app_command.rs@@ -17,8 +17,8 @@ use crate::{user_config::{FloatingStateConfig, FullscreenStateConfig, UserConfig},windows::{commands::{- move_window_in_direction, resize_window, toggle_window_state,- update_window_state, move_window_to_workspace+ move_window_in_direction, move_window_to_workspace, resize_window,+ toggle_window_state, update_window_state,},traits::WindowGetters,WindowState,@@ -235,11 +235,16 @@ impl InvokeCommand {match subject_container.as_window_container() {Ok(window) => {if let Some(direction) = &args.direction {- move_window_in_direction(window.clone(), direction, state, config)?;+ move_window_in_direction(+ window.clone(),+ direction,+ state,+ config,+ )?;};-+if let Some(workspace) = &args.workspace {- move_window_to_workspace(window, workspace, state, config)?;+ move_window_to_workspace(window, workspace, state, config)?;}Ok(())@@ -283,7 +288,7 @@ impl InvokeCommand {&config.value.window_state_defaults.floating;update_window_state(- window,+ window.clone(),WindowState::Floating(FloatingStateConfig {centered: centered.unwrap_or(floating_defaults.centered),show_on_top: show_on_top@@ -291,7 +296,10 @@ impl InvokeCommand {}),state,config,- )+ )?;++ state.containers_to_redraw.push(window.into());+ Ok(())}_ => Ok(()),},@@ -305,7 +313,7 @@ impl InvokeCommand {&config.value.window_state_defaults.fullscreen;update_window_state(- window,+ window.clone(),WindowState::Fullscreen(FullscreenStateConfig {maximized: maximized.unwrap_or(fullscreen_defaults.maximized),@@ -316,18 +324,26 @@ impl InvokeCommand {}),state,config,- )+ )?;++ state.containers_to_redraw.push(window.into());+ Ok(())}_ => Ok(()),},InvokeCommand::SetMinimized => {match subject_container.as_window_container() {- Ok(window) => update_window_state(- window,- WindowState::Minimized,- state,- config,- ),+ Ok(window) => {+ update_window_state(+ window.clone(),+ WindowState::Minimized,+ state,+ config,+ )?;++ state.containers_to_redraw.push(window.into());+ Ok(())+ }_ => Ok(()),}}diff --git a/packages/wm/src/containers/commands/detach_container.rs b/packages/wm/src/containers/commands/detach_container.rsindex befaf1c8..afa92926 100644--- a/packages/wm/src/containers/commands/detach_container.rs+++ b/packages/wm/src/containers/commands/detach_container.rs@@ -1,8 +1,10 @@+use std::collections::VecDeque;+use anyhow::Context;use crate::containers::{traits::{CommonGetters, TilingSizeGetters},- Container, TilingContainer,+ Container,};use super::flatten_split_container;@@ -29,27 +31,22 @@ pub fn detach_container(child_to_remove: Container) -> anyhow::Result<()> {.retain(|id| *id != child_to_remove.id());*child_to_remove.borrow_parent_mut() = None;+ *child_to_remove.borrow_children_mut() = VecDeque::new();// Resize the siblings if it is a tiling container.if let Ok(child_to_remove) = child_to_remove.as_tiling_container() {- resize_sibling_containers(child_to_remove, parent)?;+ resize_sibling_containers(parent, child_to_remove.tiling_size())?;}Ok(())}fn resize_sibling_containers(- child_to_remove: TilingContainer,parent: Container,+ tiling_size: f32,) -> anyhow::Result<()> {- let tiling_siblings = parent- .children()- .into_iter()- .filter_map(|c| c.as_tiling_container().ok())- .collect::<Vec<_>>();-- let tiling_size_increment =- child_to_remove.tiling_size() / tiling_siblings.len() as f32;+ let tiling_siblings = parent.tiling_children().collect::<Vec<_>>();+ let tiling_size_increment = tiling_size / tiling_siblings.len() as f32;// Adjust size of the siblings based on the freed up space.for sibling in &tiling_siblings {diff --git a/packages/wm/src/containers/commands/flatten_split_container.rs b/packages/wm/src/containers/commands/flatten_split_container.rsindex 259b15ba..2fdcf492 100644--- a/packages/wm/src/containers/commands/flatten_split_container.rs+++ b/packages/wm/src/containers/commands/flatten_split_container.rs@@ -1,3 +1,5 @@+use std::collections::VecDeque;+use anyhow::Context;use crate::containers::{@@ -66,6 +68,7 @@ pub fn flatten_split_container(.retain(|id| *id != split_container.id());*split_container.borrow_parent_mut() = None;+ *split_container.borrow_children_mut() = VecDeque::new();Ok(())}diff --git a/packages/wm/src/windows/commands/toggle_window_state.rs b/packages/wm/src/windows/commands/toggle_window_state.rsindex 93604019..64352dd5 100644--- a/packages/wm/src/windows/commands/toggle_window_state.rs+++ b/packages/wm/src/windows/commands/toggle_window_state.rs@@ -7,6 +7,10 @@ use crate::{use super::update_window_state;+/// Toggles the state of a window between its previous state if the window+/// has one, or tiling if it does not.+///+/// Always adds the window for redraw.pub fn toggle_window_state(window: WindowContainer,window_state: WindowState,@@ -23,11 +27,21 @@ pub fn toggle_window_state(// a previous state, the window is updated to be tiling.match window.prev_state() {Some(prev_state) => {- update_window_state(window, prev_state, state, config)- }- None if window.state() != WindowState::Tiling => {- update_window_state(window, WindowState::Tiling, state, config)+ update_window_state(window.clone(), prev_state, state, config)}+ None if window.state() != WindowState::Tiling => update_window_state(+ window.clone(),+ WindowState::Tiling,+ state,+ config,+ ),None => Ok(()),- }+ }?;++ // The `update_window_state` call will already add the window for redraw+ // on tiling <-> non-tiling state changes. However, on toggle, we always+ // want to add the window for redraw.+ state.containers_to_redraw.push(window.into());++ Ok(())}diff --git a/packages/wm/src/windows/commands/update_window_state.rs b/packages/wm/src/windows/commands/update_window_state.rsindex 93c387df..dd6fbc84 100644--- a/packages/wm/src/windows/commands/update_window_state.rs+++ b/packages/wm/src/windows/commands/update_window_state.rs@@ -14,6 +14,11 @@ use crate::{wm_state::WmState,};+/// Updates the state of a window.+///+/// Adds the window for redraw if the window's state changes between+/// tiling and non-tiling. Does not add the window for redraw if the+/// window stays in a non-tiling state.pub fn update_window_state(window: WindowContainer,window_state: WindowState,@@ -30,6 +35,7 @@ pub fn update_window_state(}}+/// Updates the state of a window to be `WindowState::Tiling`.fn set_tiling(window: WindowContainer,state: &mut WmState,@@ -73,12 +79,16 @@ fn set_tiling(state,)?;- state.add_container_to_redraw(target_parent);+ state+ .containers_to_redraw+ .extend(target_parent.tiling_children().map(Into::into))}Ok(())}+/// Updates the state of a window to be either `WindowState::Floating`,+/// `WindowState::Fullscreen`, or `WindowState::Minimized`.fn set_non_tiling(window: WindowContainer,window_state: WindowState,@@ -87,7 +97,6 @@ fn set_non_tiling(match window {WindowContainer::NonTilingWindow(window) => {window.set_state(window_state);- state.add_container_to_redraw(window.into());}WindowContainer::TilingWindow(window) => {let parent = window.parent().context("No parent")?;@@ -124,8 +133,9 @@ fn set_non_tiling(}}- // TODO: Only redraw tiling descendants of the workspace.- state.add_container_to_redraw(workspace.into());+ state+ .containers_to_redraw+ .extend(workspace.tiling_children().map(Into::into))}}