mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-07-08 14:05:10 +02:00
fix(wm): add layout edge index awareness
This commit builds onc3f135703eand1080159e68to add layout-specific edge index awareness to all default layouts. This is most useful for UltrawideVerticalStack and RightMostVerticalStack, which have a lot of edge cases due to the positioning of the 0th index changing with the number of containers on a workspace.
This commit is contained in:
@@ -35,6 +35,37 @@ pub enum DefaultLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl DefaultLayout {
|
impl DefaultLayout {
|
||||||
|
pub fn leftmost_index(&self, len: usize) -> usize {
|
||||||
|
match self {
|
||||||
|
Self::UltrawideVerticalStack | Self::RightMainVerticalStack => match len {
|
||||||
|
n if n > 1 => 1,
|
||||||
|
_ => 0,
|
||||||
|
},
|
||||||
|
DefaultLayout::BSP
|
||||||
|
| DefaultLayout::Columns
|
||||||
|
| DefaultLayout::Rows
|
||||||
|
| DefaultLayout::VerticalStack
|
||||||
|
| DefaultLayout::HorizontalStack
|
||||||
|
| DefaultLayout::Grid => 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn rightmost_index(&self, len: usize) -> usize {
|
||||||
|
match self {
|
||||||
|
DefaultLayout::BSP
|
||||||
|
| DefaultLayout::Columns
|
||||||
|
| DefaultLayout::Rows
|
||||||
|
| DefaultLayout::VerticalStack
|
||||||
|
| DefaultLayout::HorizontalStack
|
||||||
|
| DefaultLayout::Grid => len.saturating_sub(1),
|
||||||
|
DefaultLayout::UltrawideVerticalStack => match len {
|
||||||
|
2 => 0,
|
||||||
|
_ => len.saturating_sub(1),
|
||||||
|
},
|
||||||
|
DefaultLayout::RightMainVerticalStack => 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[allow(clippy::cast_precision_loss, clippy::only_used_in_recursion)]
|
#[allow(clippy::cast_precision_loss, clippy::only_used_in_recursion)]
|
||||||
pub fn resize(
|
pub fn resize(
|
||||||
|
|||||||
+48
-4
@@ -17,6 +17,8 @@ use crate::core::Rect;
|
|||||||
use crate::container::Container;
|
use crate::container::Container;
|
||||||
use crate::ring::Ring;
|
use crate::ring::Ring;
|
||||||
use crate::workspace::Workspace;
|
use crate::workspace::Workspace;
|
||||||
|
use crate::DefaultLayout;
|
||||||
|
use crate::Layout;
|
||||||
use crate::OperationDirection;
|
use crate::OperationDirection;
|
||||||
|
|
||||||
#[derive(
|
#[derive(
|
||||||
@@ -191,10 +193,52 @@ impl Monitor {
|
|||||||
Some(workspace) => workspace,
|
Some(workspace) => workspace,
|
||||||
};
|
};
|
||||||
|
|
||||||
if matches!(direction, Some(OperationDirection::Right)) {
|
match direction {
|
||||||
target_workspace.add_container_to_front(container);
|
Some(OperationDirection::Left) => match target_workspace.layout() {
|
||||||
} else {
|
Layout::Default(layout) => match layout {
|
||||||
target_workspace.add_container_to_back(container);
|
DefaultLayout::RightMainVerticalStack => {
|
||||||
|
target_workspace.add_container_to_front(container);
|
||||||
|
}
|
||||||
|
DefaultLayout::UltrawideVerticalStack => {
|
||||||
|
if target_workspace.containers().len() == 1 {
|
||||||
|
target_workspace.insert_container_at_idx(0, container);
|
||||||
|
} else {
|
||||||
|
target_workspace.add_container_to_back(container);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
target_workspace.add_container_to_back(container);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Layout::Custom(_) => {
|
||||||
|
target_workspace.add_container_to_back(container);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Some(OperationDirection::Right) => match target_workspace.layout() {
|
||||||
|
Layout::Default(layout) => {
|
||||||
|
let target_index = layout.leftmost_index(target_workspace.containers().len());
|
||||||
|
|
||||||
|
match layout {
|
||||||
|
DefaultLayout::RightMainVerticalStack
|
||||||
|
| DefaultLayout::UltrawideVerticalStack => {
|
||||||
|
if target_workspace.containers().len() == 1 {
|
||||||
|
target_workspace.add_container_to_back(container);
|
||||||
|
} else {
|
||||||
|
target_workspace.insert_container_at_idx(target_index, container);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
target_workspace.insert_container_at_idx(target_index, container);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Layout::Custom(_) => {
|
||||||
|
target_workspace.add_container_to_front(container);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
target_workspace.add_container_to_back(container);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if follow {
|
if follow {
|
||||||
|
|||||||
+100
-22
@@ -1293,14 +1293,28 @@ impl WindowManager {
|
|||||||
if let Ok(focused_workspace) = self.focused_workspace_mut() {
|
if let Ok(focused_workspace) = self.focused_workspace_mut() {
|
||||||
if focused_workspace.monocle_container().is_none() {
|
if focused_workspace.monocle_container().is_none() {
|
||||||
match direction {
|
match direction {
|
||||||
OperationDirection::Left => {
|
OperationDirection::Left => match focused_workspace.layout() {
|
||||||
focused_workspace.focus_container(
|
Layout::Default(layout) => {
|
||||||
focused_workspace.containers().len().saturating_sub(1),
|
let target_index =
|
||||||
);
|
layout.rightmost_index(focused_workspace.containers().len());
|
||||||
}
|
focused_workspace.focus_container(target_index);
|
||||||
OperationDirection::Right => {
|
}
|
||||||
focused_workspace.focus_container(0);
|
Layout::Custom(_) => {
|
||||||
}
|
focused_workspace.focus_container(
|
||||||
|
focused_workspace.containers().len().saturating_sub(1),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
OperationDirection::Right => match focused_workspace.layout() {
|
||||||
|
Layout::Default(layout) => {
|
||||||
|
let target_index =
|
||||||
|
layout.leftmost_index(focused_workspace.containers().len());
|
||||||
|
focused_workspace.focus_container(target_index);
|
||||||
|
}
|
||||||
|
Layout::Custom(_) => {
|
||||||
|
focused_workspace.focus_container(0);
|
||||||
|
}
|
||||||
|
},
|
||||||
_ => {}
|
_ => {}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -1331,14 +1345,28 @@ impl WindowManager {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
match direction {
|
match direction {
|
||||||
OperationDirection::Left => {
|
OperationDirection::Left => match focused_workspace.layout() {
|
||||||
focused_workspace.focus_container(
|
Layout::Default(layout) => {
|
||||||
focused_workspace.containers().len().saturating_sub(1),
|
let target_index = layout
|
||||||
);
|
.rightmost_index(focused_workspace.containers().len());
|
||||||
}
|
focused_workspace.focus_container(target_index);
|
||||||
OperationDirection::Right => {
|
}
|
||||||
focused_workspace.focus_container(0);
|
Layout::Custom(_) => {
|
||||||
}
|
focused_workspace.focus_container(
|
||||||
|
focused_workspace.containers().len().saturating_sub(1),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
OperationDirection::Right => match focused_workspace.layout() {
|
||||||
|
Layout::Default(layout) => {
|
||||||
|
let target_index =
|
||||||
|
layout.leftmost_index(focused_workspace.containers().len());
|
||||||
|
focused_workspace.focus_container(target_index);
|
||||||
|
}
|
||||||
|
Layout::Custom(_) => {
|
||||||
|
focused_workspace.focus_container(0);
|
||||||
|
}
|
||||||
|
},
|
||||||
_ => {}
|
_ => {}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -1460,15 +1488,65 @@ impl WindowManager {
|
|||||||
match direction {
|
match direction {
|
||||||
OperationDirection::Left => {
|
OperationDirection::Left => {
|
||||||
// insert the origin container into the focused workspace on the target monitor
|
// insert the origin container into the focused workspace on the target monitor
|
||||||
// at the back if we are moving across a boundary to the left (back = right side
|
// at the back (or rightmost position) if we are moving across a boundary to
|
||||||
// of the target)
|
// the left (back = right side of the target)
|
||||||
target_workspace.add_container_to_back(origin_container);
|
match target_workspace.layout() {
|
||||||
|
Layout::Default(layout) => match layout {
|
||||||
|
DefaultLayout::RightMainVerticalStack => {
|
||||||
|
target_workspace.add_container_to_front(origin_container);
|
||||||
|
}
|
||||||
|
DefaultLayout::UltrawideVerticalStack => {
|
||||||
|
if target_workspace.containers().len() == 1 {
|
||||||
|
target_workspace
|
||||||
|
.insert_container_at_idx(0, origin_container);
|
||||||
|
} else {
|
||||||
|
target_workspace
|
||||||
|
.add_container_to_back(origin_container);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
target_workspace.add_container_to_back(origin_container);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Layout::Custom(_) => {
|
||||||
|
target_workspace.add_container_to_back(origin_container);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
OperationDirection::Right => {
|
OperationDirection::Right => {
|
||||||
// insert the origin container into the focused workspace on the target monitor
|
// insert the origin container into the focused workspace on the target monitor
|
||||||
// at the front if we are moving across a boundary to the right (front = left side
|
// at the front (or leftmost position) if we are moving across a boundary to the
|
||||||
// of the target)
|
// right (front = left side of the target)
|
||||||
target_workspace.add_container_to_front(origin_container);
|
match target_workspace.layout() {
|
||||||
|
Layout::Default(layout) => {
|
||||||
|
let target_index =
|
||||||
|
layout.leftmost_index(target_workspace.containers().len());
|
||||||
|
|
||||||
|
match layout {
|
||||||
|
DefaultLayout::RightMainVerticalStack
|
||||||
|
| DefaultLayout::UltrawideVerticalStack => {
|
||||||
|
if target_workspace.containers().len() == 1 {
|
||||||
|
target_workspace
|
||||||
|
.add_container_to_back(origin_container);
|
||||||
|
} else {
|
||||||
|
target_workspace.insert_container_at_idx(
|
||||||
|
target_index,
|
||||||
|
origin_container,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
target_workspace.insert_container_at_idx(
|
||||||
|
target_index,
|
||||||
|
origin_container,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Layout::Custom(_) => {
|
||||||
|
target_workspace.add_container_to_front(origin_container);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
OperationDirection::Up | OperationDirection::Down => {
|
OperationDirection::Up | OperationDirection::Down => {
|
||||||
// insert the origin container into the focused workspace on the target monitor
|
// insert the origin container into the focused workspace on the target monitor
|
||||||
|
|||||||
@@ -668,6 +668,7 @@ impl Workspace {
|
|||||||
|
|
||||||
pub fn insert_container_at_idx(&mut self, idx: usize, container: Container) {
|
pub fn insert_container_at_idx(&mut self, idx: usize, container: Container) {
|
||||||
self.containers_mut().insert(idx, container);
|
self.containers_mut().insert(idx, container);
|
||||||
|
self.focus_container(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_container_by_idx(&mut self, idx: usize) -> Option<Container> {
|
pub fn remove_container_by_idx(&mut self, idx: usize) -> Option<Container> {
|
||||||
|
|||||||
Reference in New Issue
Block a user