Skip to content

Commit

Permalink
feat(cli): fixups for cycle-layout cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
LGUG2Z committed Oct 8, 2023
1 parent 1a2cad6 commit bbdcd35
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 19 deletions.
14 changes: 13 additions & 1 deletion komorebi-core/src/default_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl DefaultLayout {
}

#[must_use]
pub const fn cycle(self) -> Self {
pub const fn cycle_next(self) -> Self {
match self {
Self::BSP => Self::Columns,
Self::Columns => Self::Rows,
Expand All @@ -138,4 +138,16 @@ impl DefaultLayout {
Self::UltrawideVerticalStack => Self::BSP,
}
}

#[must_use]
pub const fn cycle_previous(self) -> Self {
match self {
Self::BSP => Self::UltrawideVerticalStack,
Self::UltrawideVerticalStack => Self::HorizontalStack,
Self::HorizontalStack => Self::VerticalStack,
Self::VerticalStack => Self::Rows,
Self::Rows => Self::Columns,
Self::Columns => Self::BSP,
}
}
}
2 changes: 1 addition & 1 deletion komorebi-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub enum SocketMessage {
AdjustContainerPadding(Sizing, i32),
AdjustWorkspacePadding(Sizing, i32),
ChangeLayout(DefaultLayout),
CycleLayout(),
CycleLayout(CycleDirection),
ChangeLayoutCustom(PathBuf),
FlipLayout(Axis),
// Monitor and Workspace Commands
Expand Down
2 changes: 1 addition & 1 deletion komorebi/src/process_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ impl WindowManager {
SocketMessage::Retile => self.retile_all(false)?,
SocketMessage::FlipLayout(layout_flip) => self.flip_layout(layout_flip)?,
SocketMessage::ChangeLayout(layout) => self.change_workspace_layout_default(layout)?,
SocketMessage::CycleLayout() => self.cycle_layout()?,
SocketMessage::CycleLayout(direction) => self.cycle_layout(direction)?,
SocketMessage::ChangeLayoutCustom(ref path) => {
self.change_workspace_custom_layout(path.clone())?;
}
Expand Down
23 changes: 13 additions & 10 deletions komorebi/src/window_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1706,22 +1706,25 @@ impl WindowManager {
}

#[tracing::instrument(skip(self))]
pub fn cycle_layout(&mut self) -> Result<()> {
pub fn cycle_layout(&mut self, direction: CycleDirection) -> Result<()> {
tracing::info!("cycling layout");

let workspace = self.focused_workspace_mut()?;
let current_layout = workspace.layout()?;
let current_layout = workspace.layout();

match current_layout {
// For cycling, only Default Layout is supported
DefaultLayout => {
let new_layout = current_layout.cycle();
tracing::info!("Next layout for cycling: {:?}", new_layout);
current_layout.set_layout(new_layout);
}
CustomLayout => {
tracing::info!("Current layout is custom, skipping cycling");
Layout::Default(current) => {
let new_layout = match direction {
CycleDirection::Previous => current.cycle_previous(),
CycleDirection::Next => current.cycle_next(),
};

tracing::info!("next layout: {new_layout}");
workspace.set_layout(Layout::Default(new_layout));
}
Layout::Custom(_) => {}
}

self.update_focused_workspace(self.mouse_follows_focus)
}

Expand Down
4 changes: 2 additions & 2 deletions komorebic.lib.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ ChangeLayout(default_layout) {
RunWait("komorebic.exe change-layout " default_layout, , "Hide")
}

CycleLayout() {
RunWait("komorebic.exe cycle-layout " , , "Hide")
CycleLayout(operation_direction) {
RunWait("komorebic.exe cycle-layout " operation_direction, , "Hide")
}

LoadCustomLayout(path) {
Expand Down
8 changes: 4 additions & 4 deletions komorebic/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ gen_enum_subcommand_args! {
CycleStack: CycleDirection,
FlipLayout: Axis,
ChangeLayout: DefaultLayout,
CycleLayout: CycleLayout,
CycleLayout: CycleDirection,
WatchConfiguration: BooleanState,
MouseFollowsFocus: BooleanState,
Query: StateQuery,
Expand Down Expand Up @@ -855,7 +855,7 @@ enum SubCommand {
ChangeLayout(ChangeLayout),
// Cycle between available layouts
#[clap(arg_required_else_help = false)]
CycleLayout(),
CycleLayout(CycleLayout),
/// Load a custom layout from file for the focused workspace
#[clap(arg_required_else_help = true)]
LoadCustomLayout(LoadCustomLayout),
Expand Down Expand Up @@ -1614,8 +1614,8 @@ Stop-Process -Name:whkd -ErrorAction SilentlyContinue
SubCommand::ChangeLayout(arg) => {
send_message(&SocketMessage::ChangeLayout(arg.default_layout).as_bytes()?)?;
}
SubCommand::CycleLayout() => {
send_message(&SocketMessage::CycleLayout().as_bytes()?)?;
SubCommand::CycleLayout(arg) => {
send_message(&SocketMessage::CycleLayout(arg.cycle_direction).as_bytes()?)?;
}
SubCommand::LoadCustomLayout(arg) => {
send_message(
Expand Down

0 comments on commit bbdcd35

Please sign in to comment.