From 0c47631d9bf70e9f3857fc20a8c6416c4777a1f7 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Wed, 26 Oct 2022 15:42:45 +0200 Subject: [PATCH] shell/tiling: Add option to toggle orientation --- config.ron | 4 +--- src/config/mod.rs | 1 + src/input/mod.rs | 12 +++++++++++- src/shell/layout/mod.rs | 10 ++++++++++ src/shell/layout/tiling/mod.rs | 3 ++- 5 files changed, 25 insertions(+), 5 deletions(-) diff --git a/config.ron b/config.ron index f8a583c0..35a1f651 100644 --- a/config.ron +++ b/config.ron @@ -31,9 +31,7 @@ (modifiers: [Logo], key: "j"): Focus(Down), (modifiers: [Logo], key: "k"): Focus(Up), (modifiers: [Logo], key: "l"): Focus(Right), -//TODO: automatic orientation with Logo+o toggling - (modifiers: [Logo], key: "v"): Orientation(Vertical), - (modifiers: [Logo], key: "o"): Orientation(Horizontal), + (modifiers: [Logo], key: "o"): ToggleOrientation, (modifiers: [Logo], key: "y"): ToggleTiling, (modifiers: [Logo], key: "g"): ToggleWindowFloating, (modifiers: [Logo, Shift], key: "f"): Fullscreen, diff --git a/src/config/mod.rs b/src/config/mod.rs index 401e24e8..07bbe179 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -785,6 +785,7 @@ pub enum Action { Workspace(u8), MoveToWorkspace(u8), Focus(FocusDirection), + ToggleOrientation, Orientation(crate::shell::layout::Orientation), ToggleTiling, ToggleWindowFloating, diff --git a/src/input/mod.rs b/src/input/mod.rs index 23410731..e76f7539 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -373,12 +373,22 @@ impl State { workspace.fullscreen_toggle(&window, ¤t_output); } } + Action::ToggleOrientation => { + let output = seat.active_output(); + let workspace = self.common.shell.active_space_mut(&output); + let focus_stack = workspace.focus_stack.get(seat); + workspace.tiling_layer.update_orientation( + None, + &seat, + focus_stack.iter(), + ); + } Action::Orientation(orientation) => { let output = seat.active_output(); let workspace = self.common.shell.active_space_mut(&output); let focus_stack = workspace.focus_stack.get(seat); workspace.tiling_layer.update_orientation( - orientation, + Some(orientation), &seat, focus_stack.iter(), ); diff --git a/src/shell/layout/mod.rs b/src/shell/layout/mod.rs index 24353c66..83083d9f 100644 --- a/src/shell/layout/mod.rs +++ b/src/shell/layout/mod.rs @@ -16,6 +16,16 @@ pub enum Orientation { Vertical, } +impl std::ops::Not for Orientation { + type Output = Self; + fn not(self) -> Self::Output { + match self { + Orientation::Horizontal => Orientation::Vertical, + Orientation::Vertical => Orientation::Horizontal, + } + } +} + lazy_static::lazy_static! { static ref EXCEPTIONS_APPID: RegexSet = RegexSet::new(&[ r"Authy Desktop", diff --git a/src/shell/layout/tiling/mod.rs b/src/shell/layout/tiling/mod.rs index a0cbad7a..b655e2e5 100644 --- a/src/shell/layout/tiling/mod.rs +++ b/src/shell/layout/tiling/mod.rs @@ -570,7 +570,7 @@ impl TilingLayout { pub fn update_orientation<'a>( &mut self, - new_orientation: Orientation, + new_orientation: Option, seat: &Seat, focus_stack: impl Iterator + 'a, ) { @@ -589,6 +589,7 @@ impl TilingLayout { Orientation::Horizontal => last_geometry.size.h, Orientation::Vertical => last_geometry.size.w, }; + let new_orientation = new_orientation.unwrap_or(!*orientation); let new_length = match new_orientation { Orientation::Horizontal => last_geometry.size.h, Orientation::Vertical => last_geometry.size.w,