Skip to content

Commit

Permalink
feat: allow set windows size in set-floating command
Browse files Browse the repository at this point in the history
  • Loading branch information
DreamMaoMao committed Oct 30, 2024
1 parent 940bb4c commit cf8205e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
29 changes: 28 additions & 1 deletion packages/wm/src/app_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -195,6 +195,12 @@ pub enum InvokeCommand {

#[clap(long, default_missing_value = "true", require_equals = true, num_args = 0..=1)]
centered: Option<bool>,

#[clap(long, require_equals = true)]
width: Option<i32>,

#[clap(long, require_equals = true)]
height: Option<i32>,
},
SetFullscreen {
#[clap(long, default_missing_value = "true", require_equals = true, num_args = 0..=1)]
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions packages/wm/src/user_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit cf8205e

Please sign in to comment.