GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat: partially implement floating move in direction
Lars Berger01ca0f40c57f
diff --git a/packages/wm/src/common/commands/sync_native_focus.rs b/packages/wm/src/common/commands/sync_native_focus.rsindex 646cc8c5..6df386a6 100644--- a/packages/wm/src/common/commands/sync_native_focus.rs+++ b/packages/wm/src/common/commands/sync_native_focus.rs@@ -27,7 +27,8 @@ pub fn sync_native_focus(state: &mut WmState) -> anyhow::Result<()> {}// TODO: Change z-index of workspace windows that match the focused- // container's state.+ // container's state. Make sure not to decrease z-index for floating+ // windows that are always on top.state.emit_event(WmEvent::FocusChanged {focused_container: focused_container,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 3cc66b7f..0301c240 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@@ -57,7 +57,7 @@ fn update_tiling_window(// Remove invisible borders from current placement to be able to compare// window width/height.- let new_placement = window.native().placement();+ let new_placement = window.native().placement()?;let adjusted_placement = Rect::from_ltrb(new_placement.left+ window.border_delta().left.to_pixels(monitor.width()?),@@ -92,7 +92,7 @@ fn update_floating_window(state: &mut WmState,) -> anyhow::Result<()> {// Update state with new location of the floating window.- let new_placement = window.native().placement();+ let new_placement = window.native().placement()?;window.set_floating_placement(new_placement);// Change floating window's parent workspace if moved out of its bounds.diff --git a/packages/wm/src/common/platform/native_window.rs b/packages/wm/src/common/platform/native_window.rsindex 944195de..f2e1b838 100644--- a/packages/wm/src/common/platform/native_window.rs+++ b/packages/wm/src/common/platform/native_window.rs@@ -244,11 +244,17 @@ impl NativeWindow {Ok(())}- pub fn placement(&self) -> Rect {+ pub fn placement(&self) -> anyhow::Result<Rect> {let mut placement = WINDOWPLACEMENT::default();- let _ = unsafe { GetWindowPlacement(self.handle, &mut placement) };- let rect = placement.rcNormalPosition;- Rect::from_ltrb(rect.left, rect.top, rect.right, rect.bottom)+ unsafe { GetWindowPlacement(self.handle, &mut placement) }?;++ let normal_pos = placement.rcNormalPosition;+ Ok(Rect::from_ltrb(+ normal_pos.left,+ normal_pos.top,+ normal_pos.right,+ normal_pos.bottom,+ ))}fn has_window_style(&self, style: WINDOW_STYLE) -> bool {diff --git a/packages/wm/src/common/rect.rs b/packages/wm/src/common/rect.rsindex 7e7667f5..eba2fedc 100644--- a/packages/wm/src/common/rect.rs+++ b/packages/wm/src/common/rect.rs@@ -53,11 +53,11 @@ impl Rect {self.bottom - self.top}- pub fn translate_to_coordinates(&mut self, x: i32, y: i32) -> Self {+ pub fn translate_to_coordinates(&self, x: i32, y: i32) -> Self {Self::from_xy(x, y, self.width(), self.height())}- pub fn translate_to_center(&mut self, outer_rect: &Rect) -> Self {+ pub fn translate_to_center(&self, outer_rect: &Rect) -> Self {Self::translate_to_coordinates(self,outer_rect.left + (outer_rect.width() / 2) - (self.width() / 2),diff --git a/packages/wm/src/windows/commands/manage_window.rs b/packages/wm/src/windows/commands/manage_window.rsindex f8ad78a3..6de4fc43 100644--- a/packages/wm/src/windows/commands/manage_window.rs+++ b/packages/wm/src/windows/commands/manage_window.rs@@ -95,10 +95,10 @@ fn create_window(== target_workspace.id()&& !config.value.window_state_defaults.floating.centered{- native_window.placement()+ native_window.placement()?} else {native_window- .placement()+ .placement()?.translate_to_center(&target_workspace.to_rect()?)};diff --git a/packages/wm/src/windows/commands/move_window_in_direction.rs b/packages/wm/src/windows/commands/move_window_in_direction.rsindex b64dba25..9ef88bcf 100644--- a/packages/wm/src/windows/commands/move_window_in_direction.rs+++ b/packages/wm/src/windows/commands/move_window_in_direction.rs@@ -412,5 +412,58 @@ fn move_floating_window(direction: &Direction,state: &mut WmState,) -> anyhow::Result<()> {- todo!()+ // 1. Move the window X% if within the bounds of the monitor's working+ // area.+ // 2. If the window is within 2% of the monitor's edge, then snap it to+ // the edge.+ // 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 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;++ 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;++ placement+ .translate_to_coordinates(placement.x() + dist, placement.y())+ }+ };++ window_to_move.set_floating_placement(new_placement);++ state.containers_to_redraw.push(window_to_move.into());++ Ok(())}