mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-06-12 21:44:27 +02: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 strum::EnumString;
|
||||||
|
|
||||||
use crate::Layout;
|
use crate::Layout;
|
||||||
|
use crate::LayoutFlip;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Serialize, Deserialize, Display, EnumString)]
|
#[derive(Clone, Copy, Debug, Serialize, Deserialize, Display, EnumString)]
|
||||||
#[strum(serialize_all = "snake_case")]
|
#[strum(serialize_all = "snake_case")]
|
||||||
@@ -29,8 +30,50 @@ impl OperationDirection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_valid(&self, layout: Layout, idx: usize, len: usize) -> bool {
|
fn flip_direction(
|
||||||
match self {
|
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 {
|
OperationDirection::Up => match layout {
|
||||||
Layout::BSP => len > 2 && idx != 0 && idx != 1,
|
Layout::BSP => len > 2 && idx != 0 && idx != 1,
|
||||||
Layout::Columns => false,
|
Layout::Columns => false,
|
||||||
@@ -54,8 +97,8 @@ impl OperationDirection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_idx(&self, layout: Layout, idx: usize) -> usize {
|
pub fn new_idx(&self, layout: Layout, layout_flip: Option<LayoutFlip>, idx: usize) -> usize {
|
||||||
match self {
|
match OperationDirection::flip_direction(self, layout_flip) {
|
||||||
OperationDirection::Up => match layout {
|
OperationDirection::Up => match layout {
|
||||||
Layout::BSP => {
|
Layout::BSP => {
|
||||||
if idx % 2 == 0 {
|
if idx % 2 == 0 {
|
||||||
|
|||||||
@@ -204,6 +204,7 @@ impl WindowManager {
|
|||||||
|
|
||||||
let is_valid = direction.is_valid(
|
let is_valid = direction.is_valid(
|
||||||
workspace.layout(),
|
workspace.layout(),
|
||||||
|
workspace.layout_flip(),
|
||||||
workspace.focused_container_idx(),
|
workspace.focused_container_idx(),
|
||||||
workspace.containers_mut().len(),
|
workspace.containers_mut().len(),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -273,11 +273,16 @@ impl Workspace {
|
|||||||
|
|
||||||
pub fn new_idx_for_direction(&self, direction: OperationDirection) -> Option<usize> {
|
pub fn new_idx_for_direction(&self, direction: OperationDirection) -> Option<usize> {
|
||||||
if direction.is_valid(
|
if direction.is_valid(
|
||||||
self.layout,
|
self.layout(),
|
||||||
|
self.layout_flip(),
|
||||||
self.focused_container_idx(),
|
self.focused_container_idx(),
|
||||||
self.containers().len(),
|
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 {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user