diff --git a/packages/wm/src/app_command.rs b/packages/wm/src/app_command.rs index f124c920..0df89bca 100644 --- a/packages/wm/src/app_command.rs +++ b/packages/wm/src/app_command.rs @@ -18,7 +18,7 @@ use crate::{ commands::{ focus_in_direction, set_tiling_direction, toggle_tiling_direction, }, - traits::CommonGetters, + traits::{CommonGetters, PositionGetters}, Container, }, monitors::commands::focus_monitor, @@ -195,6 +195,12 @@ pub enum InvokeCommand { #[clap(long, default_missing_value = "true", require_equals = true, num_args = 0..=1)] centered: Option, + + #[clap(long, require_equals = true)] + width: Option, + + #[clap(long, require_equals = true)] + height: Option, }, SetFullscreen { #[clap(long, default_missing_value = "true", require_equals = true, num_args = 0..=1)] @@ -441,11 +447,32 @@ impl InvokeCommand { InvokeCommand::SetFloating { centered, shown_on_top, + width, + height, } => match subject_container.as_window_container() { Ok(window) => { let floating_defaults = &config.value.window_behavior.state_defaults.floating; + let is_centered = centered.unwrap_or(floating_defaults.centered); + let mut floating_placement = window.floating_placement().clone(); + + if let (Some(width), Some(height)) = (width, height) { + floating_placement.right = floating_placement.left + width; + floating_placement.bottom = floating_placement.top + height; + } + + if is_centered { + let workspace = + window.workspace().context("no workspace find.")?; + window.set_floating_placement( + floating_placement + .translate_to_center(&workspace.to_rect()?), + ) + } else if width.is_some() && height.is_some() { + window.set_floating_placement(floating_placement); + } + update_window_state( window.clone(), WindowState::Floating(FloatingStateConfig { diff --git a/packages/wm/src/user_config.rs b/packages/wm/src/user_config.rs index 3a156f60..f23c6607 100644 --- a/packages/wm/src/user_config.rs +++ b/packages/wm/src/user_config.rs @@ -118,6 +118,8 @@ impl UserConfig { commands: vec![InvokeCommand::SetFloating { centered: Some(floating_defaults.centered), shown_on_top: Some(floating_defaults.shown_on_top), + width: None, + height: None, }], match_window: vec![ WindowMatchConfig {