mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-08-27 14:13:59 +02:00
feat(wm): add initial_window_placement_rules for workspace-level
Adds a new initial_window_placement_rules workspace configuration option that allows users to control where new tiled windows are inserted in the container list. Supports placement by named strategy (Primary, Secondary, BeforeFocused, AfterFocused, Last), fixed container index, or per-application matching rules with OR/AND logic.
This commit is contained in:
@@ -67,6 +67,38 @@ impl CustomLayout {
|
||||
None
|
||||
}
|
||||
|
||||
/// Returns the container index of the primary container in the custom layout.
|
||||
///
|
||||
/// This converts the column index of the `Column::Primary` variant to a container index.
|
||||
#[must_use]
|
||||
pub fn primary_container_index(&self) -> Option<usize> {
|
||||
self.primary_idx()
|
||||
.map(|col_idx| self.first_container_idx(col_idx))
|
||||
}
|
||||
|
||||
/// Returns the container index of the secondary container in the custom layout.
|
||||
///
|
||||
/// This finds the `Column::Secondary` variant and converts its column index to a container index.
|
||||
/// Returns `None` if there is no secondary column or if there are not enough containers.
|
||||
#[must_use]
|
||||
pub fn secondary_container_index(&self, container_count: usize) -> Option<usize> {
|
||||
if container_count < 2 {
|
||||
return None;
|
||||
}
|
||||
|
||||
for (i, column) in self.iter().enumerate() {
|
||||
if let Column::Secondary(_) = column {
|
||||
let idx = self.first_container_idx(i);
|
||||
if idx < container_count {
|
||||
return Some(idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: if no secondary column, return index 1 if it exists
|
||||
if container_count >= 2 { Some(1) } else { None }
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn primary_width_percentage(&self) -> Option<f32> {
|
||||
for column in self.iter() {
|
||||
|
||||
@@ -301,6 +301,27 @@ impl DefaultLayout {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the container index of the primary (largest) pane for this layout.
|
||||
///
|
||||
/// For all default layouts, the primary container is always at index 0.
|
||||
#[must_use]
|
||||
pub fn primary_index(&self) -> usize {
|
||||
0
|
||||
}
|
||||
|
||||
/// Returns the container index of the secondary pane for this layout,
|
||||
/// if there are enough containers. Returns `None` if there are fewer than 2 containers.
|
||||
///
|
||||
/// For all default layouts, the secondary container is at index 1.
|
||||
/// - **BSP**: the second-largest split area
|
||||
/// - **UltrawideVerticalStack**: the left (secondary) column
|
||||
/// - **VerticalStack / HorizontalStack / RightMainVerticalStack**: the first container in the stack area
|
||||
/// - **Columns / Rows / Grid / Scrolling**: simply the second container
|
||||
#[must_use]
|
||||
pub fn secondary_index(&self, container_count: usize) -> Option<usize> {
|
||||
if container_count >= 2 { Some(1) } else { None }
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
#[allow(clippy::cast_precision_loss, clippy::only_used_in_recursion)]
|
||||
pub fn resize(
|
||||
|
||||
@@ -33,4 +33,25 @@ impl Layout {
|
||||
Layout::Custom(layout) => Box::new(layout.clone()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the container index of the primary (largest) pane for this layout.
|
||||
#[must_use]
|
||||
pub fn primary_index(&self) -> usize {
|
||||
match self {
|
||||
Layout::Default(layout) => layout.primary_index(),
|
||||
#[cfg(feature = "win32")]
|
||||
Layout::Custom(layout) => layout.primary_container_index().unwrap_or(0),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the container index of the secondary pane for this layout,
|
||||
/// if there are enough containers.
|
||||
#[must_use]
|
||||
pub fn secondary_index(&self, container_count: usize) -> Option<usize> {
|
||||
match self {
|
||||
Layout::Default(layout) => layout.secondary_index(container_count),
|
||||
#[cfg(feature = "win32")]
|
||||
Layout::Custom(layout) => layout.secondary_container_index(container_count),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user