mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-03-18 07:23:57 +01:00
fix(operation_direction): adjust for layout flips
If the BSP layout was flipped on the X or Y axis (or both), OperationDirection commands would not adjust their directions accordingly and prevent the user from focusing, moving etc in a valid direction on the flipped layout. This commit addresses that bug by ensuring that we always try to apply any axis adjustments to an OperationDirection before calling the is_valid or new_idx functions.
This commit is contained in:
@@ -5,6 +5,7 @@ use strum::Display;
|
||||
use strum::EnumString;
|
||||
|
||||
use crate::Layout;
|
||||
use crate::LayoutFlip;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Serialize, Deserialize, Display, EnumString)]
|
||||
#[strum(serialize_all = "snake_case")]
|
||||
@@ -29,8 +30,50 @@ impl OperationDirection {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_valid(&self, layout: Layout, idx: usize, len: usize) -> bool {
|
||||
match self {
|
||||
fn flip_direction(
|
||||
direction: &OperationDirection,
|
||||
layout_flip: Option<LayoutFlip>,
|
||||
) -> OperationDirection {
|
||||
if let Some(flip) = layout_flip {
|
||||
match direction {
|
||||
OperationDirection::Left => match flip {
|
||||
LayoutFlip::Horizontal | LayoutFlip::HorizontalAndVertical => {
|
||||
OperationDirection::Right
|
||||
}
|
||||
_ => *direction,
|
||||
},
|
||||
OperationDirection::Right => match flip {
|
||||
LayoutFlip::Horizontal | LayoutFlip::HorizontalAndVertical => {
|
||||
OperationDirection::Left
|
||||
}
|
||||
_ => *direction,
|
||||
},
|
||||
OperationDirection::Up => match flip {
|
||||
LayoutFlip::Vertical | LayoutFlip::HorizontalAndVertical => {
|
||||
OperationDirection::Down
|
||||
}
|
||||
_ => *direction,
|
||||
},
|
||||
OperationDirection::Down => match flip {
|
||||
LayoutFlip::Vertical | LayoutFlip::HorizontalAndVertical => {
|
||||
OperationDirection::Up
|
||||
}
|
||||
_ => *direction,
|
||||
},
|
||||
}
|
||||
} else {
|
||||
*direction
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_valid(
|
||||
&self,
|
||||
layout: Layout,
|
||||
layout_flip: Option<LayoutFlip>,
|
||||
idx: usize,
|
||||
len: usize,
|
||||
) -> bool {
|
||||
match OperationDirection::flip_direction(self, layout_flip) {
|
||||
OperationDirection::Up => match layout {
|
||||
Layout::BSP => len > 2 && idx != 0 && idx != 1,
|
||||
Layout::Columns => false,
|
||||
@@ -54,8 +97,8 @@ impl OperationDirection {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_idx(&self, layout: Layout, idx: usize) -> usize {
|
||||
match self {
|
||||
pub fn new_idx(&self, layout: Layout, layout_flip: Option<LayoutFlip>, idx: usize) -> usize {
|
||||
match OperationDirection::flip_direction(self, layout_flip) {
|
||||
OperationDirection::Up => match layout {
|
||||
Layout::BSP => {
|
||||
if idx % 2 == 0 {
|
||||
|
||||
@@ -204,6 +204,7 @@ impl WindowManager {
|
||||
|
||||
let is_valid = direction.is_valid(
|
||||
workspace.layout(),
|
||||
workspace.layout_flip(),
|
||||
workspace.focused_container_idx(),
|
||||
workspace.containers_mut().len(),
|
||||
);
|
||||
|
||||
@@ -273,11 +273,16 @@ impl Workspace {
|
||||
|
||||
pub fn new_idx_for_direction(&self, direction: OperationDirection) -> Option<usize> {
|
||||
if direction.is_valid(
|
||||
self.layout,
|
||||
self.layout(),
|
||||
self.layout_flip(),
|
||||
self.focused_container_idx(),
|
||||
self.containers().len(),
|
||||
) {
|
||||
Option::from(direction.new_idx(self.layout, self.containers.focused_idx()))
|
||||
Option::from(direction.new_idx(
|
||||
self.layout(),
|
||||
self.layout_flip(),
|
||||
self.containers.focused_idx(),
|
||||
))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user