feat(wm): implement layout cycling and flipping

Another lift and shift from komorebi to add support for the CycleLayout
and FlipLayout SocketMessage variants. Trying to get through all of the
main workspace-related interactive commands.
This commit is contained in:
LGUG2Z committed 2025-09-19 09:49:27 -07:00
1 parent c91520c531
commit 4fc401cca8
5 files changed
+87 -1

No files matched your search

+5 -1
View File
@@ -4,8 +4,12 @@ use crate::core::rect::Rect;
use clap::ValueEnum;
use serde::Deserialize;
use serde::Serialize;
use strum::Display;
use strum::EnumString;
#[derive(Clone, Copy, Debug, Serialize, Deserialize, Eq, PartialEq, ValueEnum)]
#[derive(
Clone, Copy, Debug, Serialize, Deserialize, Eq, PartialEq, Display, EnumString, ValueEnum,
)]
pub enum DefaultLayout {
BSP,
Columns,
+2
View File
@@ -120,6 +120,8 @@ pub enum SocketMessage {
CycleStack(CycleDirection),
UnstackWindow,
ChangeLayout(DefaultLayout),
CycleLayout(CycleDirection),
FlipLayout(Axis),
TogglePause,
ToggleMonocle,
ToggleFloat,
+2
View File
@@ -98,7 +98,9 @@ impl WindowManager {
SocketMessage::CycleStack(direction) => {
self.cycle_container_window_in_direction(direction)?;
}
SocketMessage::FlipLayout(layout_flip) => self.flip_layout(layout_flip)?,
SocketMessage::ChangeLayout(layout) => self.change_workspace_layout_default(layout)?,
SocketMessage::CycleLayout(direction) => self.cycle_layout(direction)?,
SocketMessage::TogglePause => {
if self.is_paused {
tracing::info!("resuming");
+64
View File
@@ -1169,4 +1169,68 @@ impl WindowManager {
workspace.focus_container(target_idx);
self.update_focused_workspace(self.mouse_follows_focus, true)
}
#[tracing::instrument(skip(self))]
pub fn flip_layout(&mut self, layout_flip: Axis) -> eyre::Result<()> {
let workspace = self.focused_workspace_mut()?;
tracing::info!("flipping layout");
#[allow(clippy::match_same_arms)]
match workspace.layout_flip {
None => {
workspace.layout_flip = Option::from(layout_flip);
}
Some(current_layout_flip) => {
match current_layout_flip {
Axis::Horizontal => match layout_flip {
Axis::Horizontal => workspace.layout_flip = None,
Axis::Vertical => {
workspace.layout_flip = Option::from(Axis::HorizontalAndVertical)
}
Axis::HorizontalAndVertical => {
workspace.layout_flip = Option::from(Axis::HorizontalAndVertical)
}
},
Axis::Vertical => match layout_flip {
Axis::Horizontal => {
workspace.layout_flip = Option::from(Axis::HorizontalAndVertical)
}
Axis::Vertical => workspace.layout_flip = None,
Axis::HorizontalAndVertical => {
workspace.layout_flip = Option::from(Axis::HorizontalAndVertical)
}
},
Axis::HorizontalAndVertical => match layout_flip {
Axis::Horizontal => workspace.layout_flip = Option::from(Axis::Vertical),
Axis::Vertical => workspace.layout_flip = Option::from(Axis::Horizontal),
Axis::HorizontalAndVertical => workspace.layout_flip = None,
},
};
}
}
self.update_focused_workspace(false, false)
}
#[tracing::instrument(skip(self))]
pub fn cycle_layout(&mut self, direction: CycleDirection) -> eyre::Result<()> {
tracing::info!("cycling layout");
let workspace = self.focused_workspace_mut()?;
match workspace.layout {
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.layout = Layout::Default(new_layout);
}
}
self.update_focused_workspace(self.mouse_follows_focus, false)
}
}
+14
View File
@@ -56,7 +56,9 @@ macro_rules! gen_enum_subcommand_args {
gen_enum_subcommand_args! {
Focus: OperationDirection,
Move: OperationDirection,
FlipLayout: Axis,
ChangeLayout: DefaultLayout,
CycleLayout: CycleDirection,
Stack: OperationDirection,
CycleStack: CycleDirection,
PromoteWindow: OperationDirection,
@@ -138,6 +140,12 @@ enum SubCommand {
/// Set the layout on the focused workspace
#[clap(arg_required_else_help = true)]
ChangeLayout(ChangeLayout),
/// Cycle between available layouts
#[clap(arg_required_else_help = true)]
CycleLayout(CycleLayout),
/// Flip the layout on the focused workspace
#[clap(arg_required_else_help = true)]
FlipLayout(FlipLayout),
/// Promote the focused window to the top of the tree
Promote,
/// Promote the user focus to the top of the tree
@@ -173,6 +181,12 @@ fn main() -> eyre::Result<()> {
SubCommand::ChangeLayout(arg) => {
send_message(&SocketMessage::ChangeLayout(arg.default_layout))?;
}
SubCommand::CycleLayout(arg) => {
send_message(&SocketMessage::CycleLayout(arg.cycle_direction))?;
}
SubCommand::FlipLayout(arg) => {
send_message(&SocketMessage::FlipLayout(arg.axis))?;
}
SubCommand::Stack(arg) => {
send_message(&SocketMessage::StackWindow(arg.operation_direction))?;
}