Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add command set-tiling-direction [vertical|horizontal] #702

Merged
merged 2 commits into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -225,6 +227,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 @@ -573,6 +579,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)
}
}