diff --git a/packages/wm/src/app_command.rs b/packages/wm/src/app_command.rs index c83dceabc..49211d5f8 100644 --- a/packages/wm/src/app_command.rs +++ b/packages/wm/src/app_command.rs @@ -12,20 +12,20 @@ use crate::{ commands::{ cycle_focus, disable_binding_mode, enable_binding_mode, reload_config, shell_exec, - }, Direction, LengthValue, Rect, RectDelta, TilingDirection + }, Direction, LengthValue, RectDelta, TilingDirection }, containers::{ commands::{ focus_in_direction, set_tiling_direction, toggle_tiling_direction, }, - traits::{CommonGetters, PositionGetters}, + traits::{CommonGetters}, Container, }, monitors::commands::focus_monitor, user_config::{FloatingStateConfig, FullscreenStateConfig, UserConfig}, windows::{ commands::{ - ignore_window, move_window_in_direction, move_window_to_workspace, resize_window, set_window_position, set_window_size, update_window_state + ignore_window, move_window_in_direction, move_window_to_workspace, resize_window, set_floating_placement_position, set_floating_placement_size, set_window_position, set_window_size, update_window_state }, traits::WindowGetters, WindowState, @@ -475,22 +475,22 @@ impl InvokeCommand { &config.value.window_behavior.state_defaults.floating; let is_centered = centered.unwrap_or(floating_defaults.centered); - + if width.is_some() || height.is_some() { - set_window_size(window.clone(), + set_floating_placement_size( + window.clone(), width.clone(), - height.clone(), - state)?; + height.clone())?; } - + if is_centered || x_pos.is_some() || y_pos.is_some() { - set_window_position( + set_floating_placement_position( window.clone(), is_centered, x_pos.clone(), - y_pos.clone(), state)?; + y_pos.clone())?; } - + update_window_state( window.clone(), WindowState::Floating(FloatingStateConfig { diff --git a/packages/wm/src/windows/commands/set_window_position.rs b/packages/wm/src/windows/commands/set_window_position.rs index b5ef00421..b01a10603 100644 --- a/packages/wm/src/windows/commands/set_window_position.rs +++ b/packages/wm/src/windows/commands/set_window_position.rs @@ -46,7 +46,29 @@ fn set_floating_window_position( target_y_pos: Option, state: &mut WmState, ) -> anyhow::Result<()> { - let window_rect = window.to_rect()?; + let window_container = window.as_window_container()?; + + set_floating_placement_position( + window_container, + centered, + target_x_pos, + target_y_pos)?; + + state + .pending_sync + .containers_to_redraw + .push(window.clone().into()); + + Ok(()) +} + +pub fn set_floating_placement_position( + window: WindowContainer, + centered: bool, + target_x_pos: Option, + target_y_pos: Option, +) -> anyhow::Result<()> { + let window_rect = window.floating_placement(); match centered { true => { @@ -55,7 +77,8 @@ fn set_floating_window_position( window.set_floating_placement( window_rect .translate_to_center(&workspace.to_rect()?), - ) + ); + Ok(()) }, false => { let monitor = window.monitor().context("No monitor")?; @@ -75,13 +98,7 @@ fn set_floating_window_position( window.floating_placement().width(), window.floating_placement().height(), )); + Ok(()) } } - - state - .pending_sync - .containers_to_redraw - .push(window.clone().into()); - - Ok(()) } diff --git a/packages/wm/src/windows/commands/set_window_size.rs b/packages/wm/src/windows/commands/set_window_size.rs index 64893b4a9..806ffcf9a 100644 --- a/packages/wm/src/windows/commands/set_window_size.rs +++ b/packages/wm/src/windows/commands/set_window_size.rs @@ -8,7 +8,7 @@ use crate::{ WindowContainer, }, windows::{ - traits::WindowGetters, NonTilingWindow, TilingWindow, WindowState, + traits::WindowGetters, NonTilingWindow, TilingWindow, WindowState }, wm_state::WmState, }; @@ -108,6 +108,26 @@ fn set_floating_window_size( target_width: Option, target_height: Option, state: &mut WmState, +) -> anyhow::Result<()> { + let window_container = window.as_window_container()?; + + set_floating_placement_size( + window_container, + target_width, + target_height)?; + + state + .pending_sync + .containers_to_redraw + .push(window.clone().into()); + + Ok(()) +} + +pub fn set_floating_placement_size( + window: WindowContainer, + target_width: Option, + target_height: Option, ) -> anyhow::Result<()> { let monitor = window.monitor().context("No monitor")?; let monitor_rect = monitor.to_rect()?; @@ -154,10 +174,5 @@ fn set_floating_window_size( new_height, )); - state - .pending_sync - .containers_to_redraw - .push(window.clone().into()); - Ok(()) -} +} \ No newline at end of file