From e6d41406c09ff3037e255936ba7a3df4828842ec Mon Sep 17 00:00:00 2001 From: DreamMaoMao <2523610504@qq.com> Date: Tue, 22 Oct 2024 16:26:48 +0800 Subject: [PATCH] fix: the --centered parameter does not take effect --- packages/wm/src/app_command.rs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/packages/wm/src/app_command.rs b/packages/wm/src/app_command.rs index f124c9208..4f3234df9 100644 --- a/packages/wm/src/app_command.rs +++ b/packages/wm/src/app_command.rs @@ -5,6 +5,7 @@ use clap::{error::KindFormatter, Args, Parser, ValueEnum}; use serde::{Deserialize, Deserializer, Serialize}; use tracing::{warn, Level}; use uuid::Uuid; +use crate::containers::traits::PositionGetters; use crate::{ common::{ @@ -446,10 +447,21 @@ impl InvokeCommand { let floating_defaults = &config.value.window_behavior.state_defaults.floating; + let is_centered = centered.unwrap_or(floating_defaults.centered); + + if is_centered { + let workspace = window.workspace().context("no workspace find.")?; + window.set_floating_placement( + window + .floating_placement() + .translate_to_center(&workspace.to_rect()?), + ); + } + update_window_state( window.clone(), WindowState::Floating(FloatingStateConfig { - centered: centered.unwrap_or(floating_defaults.centered), + centered: is_centered, shown_on_top: shown_on_top .unwrap_or(floating_defaults.shown_on_top), }), @@ -552,8 +564,19 @@ impl InvokeCommand { let floating_defaults = &config.value.window_behavior.state_defaults.floating; + let is_centered = centered.unwrap_or(floating_defaults.centered); + + if is_centered { + let workspace = window.workspace().context("no workspace find.")?; + window.set_floating_placement( + window + .floating_placement() + .translate_to_center(&workspace.to_rect()?), + ); + } + let target_state = WindowState::Floating(FloatingStateConfig { - centered: centered.unwrap_or(floating_defaults.centered), + centered: is_centered, shown_on_top: shown_on_top .unwrap_or(floating_defaults.shown_on_top), });