Skip to content

Commit

Permalink
feat: add set-tiling-direction <vertical|horizontal> command (#702)
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasWischeropp authored Sep 1, 2024
1 parent d548c7d commit ee86fbf
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
18 changes: 16 additions & 2 deletions packages/wm/src/app_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ use crate::{
cycle_focus, disable_binding_mode, enable_binding_mode,
reload_config, shell_exec,
},
Direction, LengthValue, RectDelta,
Direction, LengthValue, RectDelta, TilingDirection,
},
containers::{
commands::{focus_in_direction, toggle_tiling_direction},
commands::{
focus_in_direction, set_tiling_direction, toggle_tiling_direction,
},
traits::CommonGetters,
Container,
},
Expand Down Expand Up @@ -226,6 +228,10 @@ pub enum InvokeCommand {
ToggleMinimized,
ToggleTiling,
ToggleTilingDirection,
SetTilingDirection {
#[clap(required = true)]
tiling_direction: TilingDirection,
},
WmCycleFocus {
#[clap(long, default_value_t = false)]
omit_fullscreen: bool,
Expand Down Expand Up @@ -578,6 +584,14 @@ impl InvokeCommand {
InvokeCommand::ToggleTilingDirection => {
toggle_tiling_direction(subject_container, state, config)
}
InvokeCommand::SetTilingDirection { tiling_direction } => {
set_tiling_direction(
subject_container,
state,
config,
tiling_direction.clone(),
)
}
InvokeCommand::WmCycleFocus {
omit_fullscreen,
omit_minimized,
Expand Down
17 changes: 17 additions & 0 deletions packages/wm/src/containers/commands/toggle_tiling_direction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use anyhow::Context;

use super::{flatten_split_container, wrap_in_split_container};
use crate::{
common::TilingDirection,
containers::{
traits::{CommonGetters, TilingDirectionGetters},
Container, DirectionContainer, SplitContainer,
Expand Down Expand Up @@ -82,3 +83,19 @@ fn toggle_window_direction(

Ok(split_container.into())
}

pub fn set_tiling_direction(
container: Container,
state: &mut WmState,
config: &UserConfig,
tiling_direction: TilingDirection,
) -> anyhow::Result<()> {
let direction_container = container
.direction_container()
.context("No direction container.")?;

match direction_container.tiling_direction() == tiling_direction {
true => Ok(()),
false => toggle_tiling_direction(container, state, config)
}
}

1 comment on commit ee86fbf

@ParasiteDelta
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet! I'll integrate this once there's a formalized release.

Please sign in to comment.