GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat: add default border delta to windows; improvemenets to floating window move
Lars Bergerd78901198080
diff --git a/packages/wm/src/common/events/handle_window_moved_or_resized.rs b/packages/wm/src/common/events/handle_window_moved_or_resized.rsindex 0301c240..71306285 100644--- a/packages/wm/src/common/events/handle_window_moved_or_resized.rs+++ b/packages/wm/src/common/events/handle_window_moved_or_resized.rs@@ -53,24 +53,15 @@ fn update_tiling_window(return Ok(());}- let monitor = window.monitor().context("No monitor.")?;-// Remove invisible borders from current placement to be able to compare// window width/height.- let new_placement = window.native().placement()?;- let adjusted_placement = Rect::from_ltrb(- new_placement.left- + window.border_delta().left.to_pixels(monitor.width()?),- new_placement.top- + window.border_delta().top.to_pixels(monitor.width()?),- new_placement.right- - window.border_delta().right.to_pixels(monitor.width()?),- new_placement.bottom- - window.border_delta().bottom.to_pixels(monitor.width()?),- );+ let new_placement = window+ .native()+ .placement()?+ .apply_delta(&window.border_delta());- let delta_width = adjusted_placement.width() - window.width()?;- let delta_height = adjusted_placement.height() - window.height()?;+ let delta_width = new_placement.width() - window.width()?;+ let delta_height = new_placement.height() - window.height()?;resize_window(window.clone().into(),diff --git a/packages/wm/src/common/rect.rs b/packages/wm/src/common/rect.rsindex eba2fedc..ba42a641 100644--- a/packages/wm/src/common/rect.rs+++ b/packages/wm/src/common/rect.rs@@ -1,4 +1,4 @@-use super::RectDelta;+use super::{Direction, RectDelta};#[derive(Debug, Clone)]pub struct Rect {@@ -65,6 +65,26 @@ impl Rect {)}+ pub fn translate_in_direction(+ &self,+ direction: &Direction,+ distance: i32,+ ) -> Rect {+ let (delta_x, delta_y) = match direction {+ Direction::Up => (0, -distance),+ Direction::Down => (0, distance),+ Direction::Left => (-distance, 0),+ Direction::Right => (distance, 0),+ };++ Self::from_xy(+ self.x() + delta_x,+ self.y() + delta_y,+ self.width(),+ self.height(),+ )+ }+pub fn center_point(&self) -> (i32, i32) {(self.left + (self.width() / 2),diff --git a/packages/wm/src/windows/commands/move_window_in_direction.rs b/packages/wm/src/windows/commands/move_window_in_direction.rsindex 9ef88bcf..13556a16 100644--- a/packages/wm/src/windows/commands/move_window_in_direction.rs+++ b/packages/wm/src/windows/commands/move_window_in_direction.rs@@ -1,7 +1,7 @@use anyhow::Context;use crate::{- common::{Direction, TilingDirection},+ common::{Direction, Rect, TilingDirection},containers::{commands::{flatten_split_container, move_container_within_tree,@@ -419,48 +419,39 @@ fn move_floating_window(// 3. If the window is on the monitor's edge, then move it to the next// monitor in the given direction.let monitor = window_to_move.monitor().context("No monitor.")?;+ let monitor_length = match direction {+ Direction::Up | Direction::Down => monitor.height()?,+ Direction::Left | Direction::Right => monitor.width()?,+ };- let placement = window_to_move.native().placement()?;-- let new_placement = match direction {- Direction::Up => {- let length = monitor.height()? - placement.height();- let multiplier = (length) as f32 / placement.height() as f32;- let dist = length as f32 / multiplier;-- placement.translate_to_coordinates(- placement.x(),- placement.y() + dist as i32,- )- }- Direction::Down => {- let length = monitor.height()? - placement.height();- let multiplier = (length) as f32 / placement.height() as f32;- let dist = length as f32 / multiplier;-- placement.translate_to_coordinates(- placement.x(),- placement.y() - dist as i32,- )- }- Direction::Left => {- let multiplier =- (monitor.width()? - placement.width()) / placement.width();- let dist = (monitor.width()? - placement.width()) / multiplier;+ let placement = window_to_move+ .floating_placement()+ .apply_delta(&window_to_move.border_delta());- placement- .translate_to_coordinates(placement.x() - dist, placement.y())- }- Direction::Right => {- let multiplier =- (monitor.width()? - placement.width()) / placement.width();- let dist = (monitor.width()? - placement.width()) / multiplier;+ let window_length = match direction {+ Direction::Up | Direction::Down => placement.height(),+ Direction::Left | Direction::Right => placement.width(),+ };- placement- .translate_to_coordinates(placement.x() + dist, placement.y())- }+ let length_delta = monitor_length - window_length;+ let length_percentage = window_length as f32 / monitor_length as f32;+ let window_multiplier = length_delta as f32 / window_length as f32;++ println!("Monitor: {}", monitor_length);+ println!("Length delta: {}", length_delta);+ println!("Length percentage: {}", length_percentage);+ println!("Window multiplier: {}", window_multiplier);++ let move_distance = match length_percentage {+ x if x >= 0.0 && x < 0.2 => length_delta / 5,+ x if x >= 0.2 && x < 0.4 => length_delta / 4,+ x if x >= 0.4 && x < 0.6 => length_delta / 3,+ x if x >= 0.6 => length_delta / 2,+ _ => 0,};+ let new_placement =+ placement.translate_in_direction(direction, move_distance);window_to_move.set_floating_placement(new_placement);state.containers_to_redraw.push(window_to_move.into());diff --git a/packages/wm/src/windows/non_tiling_window.rs b/packages/wm/src/windows/non_tiling_window.rsindex a6de0683..203c20d3 100644--- a/packages/wm/src/windows/non_tiling_window.rs+++ b/packages/wm/src/windows/non_tiling_window.rs@@ -58,11 +58,12 @@ impl NonTilingWindow {prev_state,insertion_target,display_state: DisplayState::Shown,+ // TODO: Pass border delta via the constructor.border_delta: RectDelta::new(+ LengthValue::new_px(7.),LengthValue::new_px(0.),- LengthValue::new_px(0.),- LengthValue::new_px(0.),- LengthValue::new_px(0.),+ LengthValue::new_px(7.),+ LengthValue::new_px(7.),),has_pending_dpi_adjustment: false,floating_placement,diff --git a/packages/wm/src/windows/tiling_window.rs b/packages/wm/src/windows/tiling_window.rsindex a0cd2383..a31ed0a4 100644--- a/packages/wm/src/windows/tiling_window.rs+++ b/packages/wm/src/windows/tiling_window.rs@@ -64,11 +64,12 @@ impl TilingWindow {state: WindowState::Tiling,prev_state,display_state: DisplayState::Shown,+ // TODO: Pass border delta via the constructor.border_delta: RectDelta::new(+ LengthValue::new_px(7.),LengthValue::new_px(0.),- LengthValue::new_px(0.),- LengthValue::new_px(0.),- LengthValue::new_px(0.),+ LengthValue::new_px(7.),+ LengthValue::new_px(7.),),has_pending_dpi_adjustment: false,floating_placement,