Add toggle-window-width by-id action

This commit is contained in:
Ivan Molodetskikh
2024-12-30 09:05:35 +03:00
parent 8409107a5b
commit a7c57f4faf
6 changed files with 87 additions and 0 deletions
+31
View File
@@ -2607,6 +2607,29 @@ impl<W: LayoutElement> Layout<W> {
monitor.toggle_width();
}
pub fn toggle_window_width(&mut self, window: Option<&W::Id>) {
if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move {
if window.is_none() || window == Some(move_.tile.window().id()) {
return;
}
}
let workspace = if let Some(window) = window {
Some(
self.workspaces_mut()
.find(|ws| ws.has_window(window))
.unwrap(),
)
} else {
self.active_workspace_mut()
};
let Some(workspace) = workspace else {
return;
};
workspace.toggle_window_width(window);
}
pub fn toggle_window_height(&mut self, window: Option<&W::Id>) {
if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move {
if window.is_none() || window == Some(move_.tile.window().id()) {
@@ -4474,6 +4497,10 @@ mod tests {
},
MoveColumnToOutput(#[proptest(strategy = "1..=5usize")] usize),
SwitchPresetColumnWidth,
SwitchPresetWindowWidth {
#[proptest(strategy = "proptest::option::of(1..=5usize)")]
id: Option<usize>,
},
SwitchPresetWindowHeight {
#[proptest(strategy = "proptest::option::of(1..=5usize)")]
id: Option<usize>,
@@ -5009,6 +5036,10 @@ mod tests {
Op::MoveWorkspaceDown => layout.move_workspace_down(),
Op::MoveWorkspaceUp => layout.move_workspace_up(),
Op::SwitchPresetColumnWidth => layout.toggle_width(),
Op::SwitchPresetWindowWidth { id } => {
let id = id.filter(|id| layout.has_window(id));
layout.toggle_window_width(id.as_ref());
}
Op::SwitchPresetWindowHeight { id } => {
let id = id.filter(|id| layout.has_window(id));
layout.toggle_window_height(id.as_ref());