Skip to content

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

fix: tiling windows are resized consistently

Lars Berger2a6a14a97c70
diff --git a/packages/wm/src/windows/commands/resize_window.rs b/packages/wm/src/windows/commands/resize_window.rs
index afe3cb91..d94aba4a 100644
--- a/packages/wm/src/windows/commands/resize_window.rs
+++ b/packages/wm/src/windows/commands/resize_window.rs
@@ -1,3 +1,5 @@
+use anyhow::Context;
+
use crate::{
common::LengthValue,
containers::{
@@ -15,6 +17,8 @@ pub fn resize_window(
height_delta: Option<LengthValue>,
state: &mut WmState,
) -> anyhow::Result<()> {
+ let monitor = window.monitor().context("No monitor")?;
+ let monitor_rect = monitor.to_rect()?;
let window_rect = window.to_rect()?;
let target_width = match width_delta {
@@ -22,14 +26,19 @@ pub fn resize_window(
let parent_width = match window.as_tiling_container() {
Ok(tiling_window) => tiling_window
.container_to_resize(true)?
- .map(|container| container.as_container()),
- _ => Some(window.clone().into()),
- }
- .and_then(|container| container.parent())
- .and_then(|parent| parent.width().ok());
+ .and_then(|container| container.parent())
+ .and_then(|parent| parent.width().ok())
+ .map(|parent_width| {
+ parent_width
+ - tiling_window.inner_gap().to_pixels(monitor_rect.width())
+ * tiling_window.tiling_siblings().count() as i32
+ }),
+ _ => window.parent().and_then(|parent| parent.width().ok()),
+ };
parent_width.map(|parent_width| {
- window_rect.width() + delta.to_pixels(parent_width)
+ let delta_px = delta.to_pixels(parent_width);
+ window_rect.width() + delta_px
})
}
_ => None,
@@ -40,14 +49,19 @@ pub fn resize_window(
let parent_height = match window.as_tiling_container() {
Ok(tiling_window) => tiling_window
.container_to_resize(false)?
- .map(|container| container.as_container()),
- _ => Some(window.clone().into()),
- }
- .and_then(|container| container.parent())
- .and_then(|parent| parent.height().ok());
+ .and_then(|container| container.parent())
+ .and_then(|parent| parent.height().ok())
+ .map(|parent_height| {
+ parent_height
+ - tiling_window.inner_gap().to_pixels(monitor_rect.height())
+ * tiling_window.tiling_siblings().count() as i32
+ }),
+ _ => window.parent().and_then(|parent| parent.height().ok()),
+ };
parent_height.map(|parent_height| {
- window_rect.height() + delta.to_pixels(parent_height)
+ let delta_px = delta.to_pixels(parent_height);
+ window_rect.height() + delta_px
})
}
_ => None,
diff --git a/packages/wm/src/windows/commands/set_window_size.rs b/packages/wm/src/windows/commands/set_window_size.rs
index a9fb31fa..f65cc105 100644
--- a/packages/wm/src/windows/commands/set_window_size.rs
+++ b/packages/wm/src/windows/commands/set_window_size.rs
@@ -66,6 +66,9 @@ fn set_tiling_window_length(
is_width_resize: bool,
state: &mut WmState,
) -> anyhow::Result<()> {
+ let monitor = window.monitor().context("No monitor")?;
+ let monitor_rect = monitor.to_rect()?;
+
// When resizing a tiling window, the container to resize can actually be
// an ancestor split container.
let container_to_resize = window.container_to_resize(is_width_resize)?;
@@ -73,9 +76,17 @@ fn set_tiling_window_length(
if let Some(container_to_resize) = container_to_resize {
let parent = container_to_resize.parent().context("No parent.")?;
let parent_length = match is_width_resize {
- true => parent.width(),
- false => parent.height(),
- }?;
+ true => {
+ parent.width()?
+ - window.inner_gap().to_pixels(monitor_rect.width())
+ * window.tiling_siblings().count() as i32
+ }
+ false => {
+ parent.height()?
+ - window.inner_gap().to_pixels(monitor_rect.height())
+ * window.tiling_siblings().count() as i32
+ }
+ };
// Convert the target length to a tiling size.
let tiling_size = target_length.to_percent(parent_length);