shell/tiling: Add option to toggle orientation

This commit is contained in:
Victoria Brekenfeld 2022-10-26 15:42:45 +02:00
parent 01b34aadd2
commit 0c47631d9b
5 changed files with 25 additions and 5 deletions

View file

@ -31,9 +31,7 @@
(modifiers: [Logo], key: "j"): Focus(Down), (modifiers: [Logo], key: "j"): Focus(Down),
(modifiers: [Logo], key: "k"): Focus(Up), (modifiers: [Logo], key: "k"): Focus(Up),
(modifiers: [Logo], key: "l"): Focus(Right), (modifiers: [Logo], key: "l"): Focus(Right),
//TODO: automatic orientation with Logo+o toggling (modifiers: [Logo], key: "o"): ToggleOrientation,
(modifiers: [Logo], key: "v"): Orientation(Vertical),
(modifiers: [Logo], key: "o"): Orientation(Horizontal),
(modifiers: [Logo], key: "y"): ToggleTiling, (modifiers: [Logo], key: "y"): ToggleTiling,
(modifiers: [Logo], key: "g"): ToggleWindowFloating, (modifiers: [Logo], key: "g"): ToggleWindowFloating,
(modifiers: [Logo, Shift], key: "f"): Fullscreen, (modifiers: [Logo, Shift], key: "f"): Fullscreen,

View file

@ -785,6 +785,7 @@ pub enum Action {
Workspace(u8), Workspace(u8),
MoveToWorkspace(u8), MoveToWorkspace(u8),
Focus(FocusDirection), Focus(FocusDirection),
ToggleOrientation,
Orientation(crate::shell::layout::Orientation), Orientation(crate::shell::layout::Orientation),
ToggleTiling, ToggleTiling,
ToggleWindowFloating, ToggleWindowFloating,

View file

@ -373,12 +373,22 @@ impl State {
workspace.fullscreen_toggle(&window, &current_output); workspace.fullscreen_toggle(&window, &current_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) => { Action::Orientation(orientation) => {
let output = seat.active_output(); let output = seat.active_output();
let workspace = self.common.shell.active_space_mut(&output); let workspace = self.common.shell.active_space_mut(&output);
let focus_stack = workspace.focus_stack.get(seat); let focus_stack = workspace.focus_stack.get(seat);
workspace.tiling_layer.update_orientation( workspace.tiling_layer.update_orientation(
orientation, Some(orientation),
&seat, &seat,
focus_stack.iter(), focus_stack.iter(),
); );

View file

@ -16,6 +16,16 @@ pub enum Orientation {
Vertical, 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! { lazy_static::lazy_static! {
static ref EXCEPTIONS_APPID: RegexSet = RegexSet::new(&[ static ref EXCEPTIONS_APPID: RegexSet = RegexSet::new(&[
r"Authy Desktop", r"Authy Desktop",

View file

@ -570,7 +570,7 @@ impl TilingLayout {
pub fn update_orientation<'a>( pub fn update_orientation<'a>(
&mut self, &mut self,
new_orientation: Orientation, new_orientation: Option<Orientation>,
seat: &Seat<State>, seat: &Seat<State>,
focus_stack: impl Iterator<Item = &'a CosmicMapped> + 'a, focus_stack: impl Iterator<Item = &'a CosmicMapped> + 'a,
) { ) {
@ -589,6 +589,7 @@ impl TilingLayout {
Orientation::Horizontal => last_geometry.size.h, Orientation::Horizontal => last_geometry.size.h,
Orientation::Vertical => last_geometry.size.w, Orientation::Vertical => last_geometry.size.w,
}; };
let new_orientation = new_orientation.unwrap_or(!*orientation);
let new_length = match new_orientation { let new_length = match new_orientation {
Orientation::Horizontal => last_geometry.size.h, Orientation::Horizontal => last_geometry.size.h,
Orientation::Vertical => last_geometry.size.w, Orientation::Vertical => last_geometry.size.w,