diff --git a/Cargo.lock b/Cargo.lock index 9ed11bcf..558bc96d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1968,7 +1968,7 @@ dependencies = [ "palette", "rand 0.7.3", "serde", - "serde_yaml", + "serde_yaml 0.8.26", "shell-words", "shellexpand", "toml", @@ -3009,6 +3009,7 @@ dependencies = [ "dispatch2", "ed25519-dalek", "hotwatch", + "komorebi-layouts", "komorebi-themes", "lazy_static", "nanoid", @@ -3087,10 +3088,26 @@ dependencies = [ "serde_json_lenient", ] +[[package]] +name = "komorebi-layouts" +version = "0.1.40" +source = "git+https://github.com/LGUG2Z/komorebi?rev=b4f00fbc1257ab858aa4f45c06a8d3f176aee9a0#b4f00fbc1257ab858aa4f45c06a8d3f176aee9a0" +dependencies = [ + "clap", + "color-eyre", + "objc2-core-foundation", + "schemars 1.2.1", + "serde", + "serde_json_lenient", + "serde_yaml 0.9.34+deprecated", + "strum", + "tracing", +] + [[package]] name = "komorebi-themes" version = "0.1.40" -source = "git+https://github.com/LGUG2Z/komorebi?rev=0758c7d9008a8e174ac35f469e53fd8fddd6b672#0758c7d9008a8e174ac35f469e53fd8fddd6b672" +source = "git+https://github.com/LGUG2Z/komorebi?rev=b4f00fbc1257ab858aa4f45c06a8d3f176aee9a0#b4f00fbc1257ab858aa4f45c06a8d3f176aee9a0" dependencies = [ "base16-egui-themes", "catppuccin-egui", @@ -5455,6 +5472,19 @@ dependencies = [ "yaml-rust", ] +[[package]] +name = "serde_yaml" +version = "0.9.34+deprecated" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" +dependencies = [ + "indexmap 2.13.0", + "itoa", + "ryu", + "serde", + "unsafe-libyaml", +] + [[package]] name = "servo-fontconfig" version = "0.5.1" @@ -6327,6 +6357,12 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" +[[package]] +name = "unsafe-libyaml" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" + [[package]] name = "untrusted" version = "0.9.0" diff --git a/Cargo.toml b/Cargo.toml index eece35e2..27c86b52 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,11 @@ members = [ version = "0.1.0" [workspace.dependencies] -komorebi-themes = { git = "https://github.com/LGUG2Z/komorebi", rev = "0758c7d9008a8e174ac35f469e53fd8fddd6b672" } +komorebi-themes = { git = "https://github.com/LGUG2Z/komorebi", rev = "b4f00fbc1257ab858aa4f45c06a8d3f176aee9a0" } +komorebi-layouts = { git = "https://github.com/LGUG2Z/komorebi", rev = "b4f00fbc1257ab858aa4f45c06a8d3f176aee9a0", features = [ + "darwin", + "schemars", +] } chrono = "0.4" chrono-tz = "0.10" diff --git a/deny.toml b/deny.toml index 0be4ca3f..2081ceb5 100644 --- a/deny.toml +++ b/deny.toml @@ -47,6 +47,11 @@ crate = "komorebi-client" expression = "LicenseRef-Komorebi-2.0" license-files = [] +[[licenses.clarify]] +crate = "komorebi-layouts" +expression = "LicenseRef-Komorebi-2.0" +license-files = [] + [[licenses.clarify]] crate = "komorebic" expression = "LicenseRef-Komorebi-2.0" diff --git a/komorebi-client/src/lib.rs b/komorebi-client/src/lib.rs index 653d4814..907cb2b1 100644 --- a/komorebi-client/src/lib.rs +++ b/komorebi-client/src/lib.rs @@ -4,23 +4,23 @@ pub use komorebi::NotificationEvent; pub use komorebi::animation::AnimationPrefix; pub use komorebi::container::Container; pub use komorebi::core::ApplicationIdentifier; +pub use komorebi::core::Axis; +pub use komorebi::core::CycleDirection; +pub use komorebi::core::DefaultLayout; +pub use komorebi::core::Layout; pub use komorebi::core::MoveBehaviour; pub use komorebi::core::OperationBehaviour; +pub use komorebi::core::OperationDirection; +pub use komorebi::core::Rect; pub use komorebi::core::Sizing; pub use komorebi::core::SocketMessage; pub use komorebi::core::StateQuery; pub use komorebi::core::SubscribeOptions; pub use komorebi::core::WindowKind; pub use komorebi::core::animation::AnimationStyle; -pub use komorebi::core::arrangement::Axis; pub use komorebi::core::asc::ApplicationSpecificConfiguration; -pub use komorebi::core::cycle_direction::CycleDirection; -pub use komorebi::core::default_layout::DefaultLayout; -pub use komorebi::core::layout::Layout; -pub use komorebi::core::operation_direction::OperationDirection; pub use komorebi::core::pathext::PathExt; pub use komorebi::core::pathext::replace_env_in_path; -pub use komorebi::core::rect::Rect; pub use komorebi::monitor_reconciliator::MonitorNotification; pub use komorebi::splash; pub use komorebi::state::State; diff --git a/komorebi/Cargo.toml b/komorebi/Cargo.toml index 52302f69..b19192b0 100644 --- a/komorebi/Cargo.toml +++ b/komorebi/Cargo.toml @@ -6,6 +6,7 @@ edition = "2024" [dependencies] komorebi-themes = { workspace = true } +komorebi-layouts = { workspace = true } quickxml_to_serde = { git = "https://github.com/LGUG2Z/quickxml_to_serde.git", version = "0.6.1" } version = { path = "../version" } diff --git a/komorebi/src/animation/lerp.rs b/komorebi/src/animation/lerp.rs index 10cb0c2b..2ee9e15d 100644 --- a/komorebi/src/animation/lerp.rs +++ b/komorebi/src/animation/lerp.rs @@ -1,5 +1,5 @@ +use crate::core::Rect; use crate::core::animation::AnimationStyle; -use crate::core::rect::Rect; use super::style::apply_ease_func; diff --git a/komorebi/src/border_manager/border.rs b/komorebi/src/border_manager/border.rs index d8f12271..2a61ae50 100644 --- a/komorebi/src/border_manager/border.rs +++ b/komorebi/src/border_manager/border.rs @@ -10,8 +10,8 @@ use crate::border_manager::BORDER_OFFSET_ADJUSTMENT; use crate::border_manager::BORDER_WIDTH; use crate::border_manager::ns_window::NsWindow; use crate::border_manager::window_kind_colour; +use crate::core::Rect; use crate::core::WindowKind; -use crate::core::rect::Rect; use crate::core_graphics::CoreGraphicsApi; use crate::macos_api::MacosApi; use color_eyre::eyre; diff --git a/komorebi/src/core/arrangement.rs b/komorebi/src/core/arrangement.rs deleted file mode 100644 index f69b9cb3..00000000 --- a/komorebi/src/core/arrangement.rs +++ /dev/null @@ -1,1166 +0,0 @@ -use crate::core::default_layout::DefaultLayout; -use crate::core::default_layout::LayoutOptions; -use crate::core::rect::Rect; -use clap::ValueEnum; -use serde::Deserialize; -use serde::Serialize; -use std::num::NonZeroUsize; -use strum::Display; -use strum::EnumString; - -pub trait Arrangement { - #[allow(clippy::too_many_arguments)] - fn calculate( - &self, - area: &Rect, - len: NonZeroUsize, - container_padding: Option, - layout_flip: Option, - resize_dimensions: &[Option], - focused_idx: usize, - layout_options: Option, - latest_layout: &[Rect], - ) -> Vec; -} - -impl Arrangement for DefaultLayout { - #[allow(clippy::too_many_lines, clippy::cognitive_complexity)] - fn calculate( - &self, - area: &Rect, - len: NonZeroUsize, - container_padding: Option, - layout_flip: Option, - resize_dimensions: &[Option], - focused_idx: usize, - layout_options: Option, - latest_layout: &[Rect], - ) -> Vec { - let len = usize::from(len); - let mut dimensions = match self { - Self::Scrolling => { - let column_count = layout_options - .and_then(|o| o.scrolling.map(|s| s.columns)) - .unwrap_or(3); - - let column_width = area.right / column_count.min(len) as i32; - let mut layouts = Vec::with_capacity(len); - - match len { - // treat < 3 windows the same as the columns layout - len if len < 3 => { - layouts = columns(area, len); - - let adjustment = calculate_columns_adjustment(resize_dimensions); - layouts.iter_mut().zip(adjustment.iter()).for_each( - |(layout, adjustment)| { - layout.top += adjustment.top; - layout.bottom += adjustment.bottom; - layout.left += adjustment.left; - layout.right += adjustment.right; - }, - ); - - if matches!( - layout_flip, - Some(Axis::Horizontal | Axis::HorizontalAndVertical) - ) && let 2.. = len - { - columns_reverse(&mut layouts); - } - } - // treat >= column_count as scrolling - len => { - let visible_columns = area.right / column_width; - let keep_centered = layout_options - .and_then(|o| { - o.scrolling - .map(|s| s.center_focused_column.unwrap_or_default()) - }) - .unwrap_or(false); - - let first_visible: isize = if focused_idx == 0 { - // if focused idx is 0, we are at the beginning of the scrolling strip - 0 - } else { - let previous_first_visible = if latest_layout.is_empty() { - 0 - } else { - // previous first_visible based on the left position of the first visible window - let left_edge = area.left; - latest_layout - .iter() - .position(|rect| rect.left >= left_edge) - .unwrap_or(0) as isize - }; - - let focused_idx = focused_idx as isize; - - // if center_focused_column is enabled, and we have an odd number of visible columns, - // center the focused window column - if keep_centered && visible_columns % 2 == 1 { - let center_offset = visible_columns as isize / 2; - (focused_idx - center_offset).max(0).min( - (len as isize) - .saturating_sub(visible_columns as isize) - .max(0), - ) - } else { - if focused_idx < previous_first_visible { - // focused window is off the left edge, we need to scroll left - focused_idx - } else if focused_idx - >= previous_first_visible + visible_columns as isize - { - // focused window is off the right edge, we need to scroll right - // and make sure it's the last visible window - (focused_idx + 1 - visible_columns as isize).max(0) - } else { - // focused window is already visible, we don't need to scroll - previous_first_visible - } - .min( - (len as isize) - .saturating_sub(visible_columns as isize) - .max(0), - ) - } - }; - - for i in 0..len { - let position = (i as isize) - first_visible; - let left = area.left + (position as i32 * column_width); - - layouts.push(Rect { - left, - top: area.top, - right: column_width, - bottom: area.bottom, - }); - } - - let adjustment = calculate_scrolling_adjustment(resize_dimensions); - layouts.iter_mut().zip(adjustment.iter()).for_each( - |(layout, adjustment)| { - layout.top += adjustment.top; - layout.bottom += adjustment.bottom; - layout.left += adjustment.left; - layout.right += adjustment.right; - }, - ); - } - } - - layouts - } - Self::BSP => recursive_fibonacci( - 0, - len, - area, - layout_flip, - calculate_resize_adjustments(resize_dimensions), - ), - Self::Columns => { - let mut layouts = columns(area, len); - - let adjustment = calculate_columns_adjustment(resize_dimensions); - layouts - .iter_mut() - .zip(adjustment.iter()) - .for_each(|(layout, adjustment)| { - layout.top += adjustment.top; - layout.bottom += adjustment.bottom; - layout.left += adjustment.left; - layout.right += adjustment.right; - }); - - if matches!( - layout_flip, - Some(Axis::Horizontal | Axis::HorizontalAndVertical) - ) && let 2.. = len - { - columns_reverse(&mut layouts); - } - - layouts - } - Self::Rows => { - let mut layouts = rows(area, len); - - let adjustment = calculate_rows_adjustment(resize_dimensions); - layouts - .iter_mut() - .zip(adjustment.iter()) - .for_each(|(layout, adjustment)| { - layout.top += adjustment.top; - layout.bottom += adjustment.bottom; - layout.left += adjustment.left; - layout.right += adjustment.right; - }); - - if matches!( - layout_flip, - Some(Axis::Vertical | Axis::HorizontalAndVertical) - ) && let 2.. = len - { - rows_reverse(&mut layouts); - } - - layouts - } - Self::VerticalStack => { - let mut layouts: Vec = vec![]; - - let primary_right = match len { - 1 => area.right, - _ => area.right / 2, - }; - - let main_left = area.left; - let stack_left = area.left + primary_right; - - if len >= 1 { - layouts.push(Rect { - left: main_left, - top: area.top, - right: primary_right, - bottom: area.bottom, - }); - - if len > 1 { - layouts.append(&mut rows( - &Rect { - left: stack_left, - top: area.top, - right: area.right - primary_right, - bottom: area.bottom, - }, - len - 1, - )); - } - } - - let adjustment = calculate_vertical_stack_adjustment(resize_dimensions); - layouts - .iter_mut() - .zip(adjustment.iter()) - .for_each(|(layout, adjustment)| { - layout.top += adjustment.top; - layout.bottom += adjustment.bottom; - layout.left += adjustment.left; - layout.right += adjustment.right; - }); - - if matches!( - layout_flip, - Some(Axis::Horizontal | Axis::HorizontalAndVertical) - ) && let 2.. = len - { - let (primary, rest) = layouts.split_at_mut(1); - let primary = &mut primary[0]; - - for rect in rest.iter_mut() { - rect.left = primary.left; - } - primary.left = rest[0].left + rest[0].right; - } - - if matches!( - layout_flip, - Some(Axis::Vertical | Axis::HorizontalAndVertical) - ) && let 3.. = len - { - rows_reverse(&mut layouts[1..]); - } - - layouts - } - Self::RightMainVerticalStack => { - // Shamelessly borrowed from LeftWM: https://github.com/leftwm/leftwm/commit/f673851745295ae7584a102535566f559d96a941 - let mut layouts: Vec = vec![]; - - let primary_width = match len { - 1 => area.right, - _ => area.right / 2, - }; - - let primary_left = match len { - 1 => 0, - _ => area.right - primary_width, - }; - - if len >= 1 { - layouts.push(Rect { - left: area.left + primary_left, - top: area.top, - right: primary_width, - bottom: area.bottom, - }); - - if len > 1 { - layouts.append(&mut rows( - &Rect { - left: area.left, - top: area.top, - right: primary_left, - bottom: area.bottom, - }, - len - 1, - )); - } - } - - let adjustment = calculate_right_vertical_stack_adjustment(resize_dimensions); - layouts - .iter_mut() - .zip(adjustment.iter()) - .for_each(|(layout, adjustment)| { - layout.top += adjustment.top; - layout.bottom += adjustment.bottom; - layout.left += adjustment.left; - layout.right += adjustment.right; - }); - - if matches!( - layout_flip, - Some(Axis::Horizontal | Axis::HorizontalAndVertical) - ) && let 2.. = len - { - let (primary, rest) = layouts.split_at_mut(1); - let primary = &mut primary[0]; - - primary.left = rest[0].left; - for rect in rest.iter_mut() { - rect.left = primary.left + primary.right; - } - } - - if matches!( - layout_flip, - Some(Axis::Vertical | Axis::HorizontalAndVertical) - ) && let 3.. = len - { - rows_reverse(&mut layouts[1..]); - } - - layouts - } - Self::HorizontalStack => { - let mut layouts: Vec = vec![]; - - let bottom = match len { - 1 => area.bottom, - _ => area.bottom / 2, - }; - - let main_top = area.top; - let stack_top = area.top + bottom; - - if len >= 1 { - layouts.push(Rect { - left: area.left, - top: main_top, - right: area.right, - bottom, - }); - - if len > 1 { - layouts.append(&mut columns( - &Rect { - left: area.left, - top: stack_top, - right: area.right, - bottom: area.bottom - bottom, - }, - len - 1, - )); - } - } - - let adjustment = calculate_horizontal_stack_adjustment(resize_dimensions); - layouts - .iter_mut() - .zip(adjustment.iter()) - .for_each(|(layout, adjustment)| { - layout.top += adjustment.top; - layout.bottom += adjustment.bottom; - layout.left += adjustment.left; - layout.right += adjustment.right; - }); - - if matches!( - layout_flip, - Some(Axis::Vertical | Axis::HorizontalAndVertical) - ) && let 2.. = len - { - let (primary, rest) = layouts.split_at_mut(1); - let primary = &mut primary[0]; - - for rect in rest.iter_mut() { - rect.top = primary.top; - } - primary.top = rest[0].top + rest[0].bottom; - } - - if matches!( - layout_flip, - Some(Axis::Horizontal | Axis::HorizontalAndVertical) - ) && let 3.. = len - { - columns_reverse(&mut layouts[1..]); - } - - layouts - } - Self::UltrawideVerticalStack => { - let mut layouts: Vec = vec![]; - - let primary_right = match len { - 1 => area.right, - _ => area.right / 2, - }; - - let secondary_right = match len { - 1 => 0, - 2 => area.right - primary_right, - _ => (area.right - primary_right) / 2, - }; - - let (primary_left, secondary_left, stack_left) = match len { - 1 => (area.left, 0, 0), - 2 => { - let primary = area.left + secondary_right; - let secondary = area.left; - - (primary, secondary, 0) - } - _ => { - let primary = area.left + secondary_right; - let secondary = area.left; - let stack = area.left + primary_right + secondary_right; - - (primary, secondary, stack) - } - }; - - if len >= 1 { - layouts.push(Rect { - left: primary_left, - top: area.top, - right: primary_right, - bottom: area.bottom, - }); - - if len >= 2 { - layouts.push(Rect { - left: secondary_left, - top: area.top, - right: secondary_right, - bottom: area.bottom, - }); - - if len > 2 { - layouts.append(&mut rows( - &Rect { - left: stack_left, - top: area.top, - right: secondary_right, - bottom: area.bottom, - }, - len - 2, - )); - } - } - } - - let adjustment = calculate_ultrawide_adjustment(resize_dimensions); - layouts - .iter_mut() - .zip(adjustment.iter()) - .for_each(|(layout, adjustment)| { - layout.top += adjustment.top; - layout.bottom += adjustment.bottom; - layout.left += adjustment.left; - layout.right += adjustment.right; - }); - - if matches!( - layout_flip, - Some(Axis::Horizontal | Axis::HorizontalAndVertical) - ) { - match len { - 2 => { - let (primary, secondary) = layouts.split_at_mut(1); - let primary = &mut primary[0]; - let secondary = &mut secondary[0]; - - primary.left = secondary.left; - secondary.left = primary.left + primary.right; - } - 3.. => { - let (primary, rest) = layouts.split_at_mut(1); - let (secondary, tertiary) = rest.split_at_mut(1); - let primary = &mut primary[0]; - let secondary = &mut secondary[0]; - - for rect in tertiary.iter_mut() { - rect.left = secondary.left; - } - primary.left = tertiary[0].left + tertiary[0].right; - secondary.left = primary.left + primary.right; - } - _ => {} - } - } - - if matches!( - layout_flip, - Some(Axis::Vertical | Axis::HorizontalAndVertical) - ) && let 4.. = len - { - rows_reverse(&mut layouts[2..]); - } - - layouts - } - #[allow( - clippy::cast_precision_loss, - clippy::cast_possible_truncation, - clippy::cast_possible_wrap - )] - Self::Grid => { - // Shamelessly lifted from LeftWM - // https://github.com/leftwm/leftwm/blob/18675067b8450e520ef75db2ebbb0d973aa1199e/leftwm-core/src/layouts/grid_horizontal.rs - let mut layouts: Vec = vec![]; - layouts.resize(len, Rect::default()); - - let len = len as i32; - - let row_constraint = layout_options.and_then(|o| o.grid.map(|g| g.rows)); - - let num_cols = if let Some(rows) = row_constraint { - ((len as f32) / (rows as f32)).ceil() as i32 - } else { - (len as f32).sqrt().ceil() as i32 - }; - - let mut iter = layouts.iter_mut().enumerate().peekable(); - - for col in 0..num_cols { - let iter_peek = iter.peek().map(|x| x.0).unwrap_or_default() as i32; - let remaining_windows = len - iter_peek; - let remaining_columns = num_cols - col; - - let num_rows_in_this_col = if let Some(rows) = row_constraint { - (remaining_windows / remaining_columns).min(rows as i32) - } else { - remaining_windows / remaining_columns - }; - - let win_height = area.bottom / num_rows_in_this_col; - let win_width = area.right / num_cols; - - for row in 0..num_rows_in_this_col { - if let Some((_idx, win)) = iter.next() { - let mut left = area.left + win_width * col; - let mut top = area.top + win_height * row; - - match layout_flip { - Some(Axis::Horizontal) => { - left = area.right - win_width * (col + 1) + area.left; - } - Some(Axis::Vertical) => { - top = area.bottom - win_height * (row + 1) + area.top; - } - Some(Axis::HorizontalAndVertical) => { - left = area.right - win_width * (col + 1) + area.left; - top = area.bottom - win_height * (row + 1) + area.top; - } - None => {} // No flip - } - - win.bottom = win_height; - win.right = win_width; - win.left = left; - win.top = top; - } - } - } - - layouts - } - }; - - dimensions - .iter_mut() - .for_each(|l| l.add_padding(container_padding.unwrap_or_default())); - - dimensions - } -} - -#[derive(Clone, Copy, Debug, Serialize, Deserialize, Display, EnumString, ValueEnum, PartialEq)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// An axis on which to perform an operation -pub enum Axis { - /// Horizontal axis - Horizontal, - /// Vertical axis - Vertical, - /// Both horizontal and vertical axes - HorizontalAndVertical, -} - -#[must_use] -fn columns(area: &Rect, len: usize) -> Vec { - #[allow(clippy::cast_possible_wrap, clippy::cast_possible_truncation)] - let right = area.right / len as i32; - let mut left = 0; - - let mut layouts: Vec = vec![]; - for _ in 0..len { - layouts.push(Rect { - left: area.left + left, - top: area.top, - right, - bottom: area.bottom, - }); - - left += right; - } - - layouts -} - -#[must_use] -fn rows(area: &Rect, len: usize) -> Vec { - #[allow(clippy::cast_possible_wrap, clippy::cast_possible_truncation)] - let bottom = area.bottom / len as i32; - let mut top = 0; - - let mut layouts: Vec = vec![]; - for _ in 0..len { - layouts.push(Rect { - left: area.left, - top: area.top + top, - right: area.right, - bottom, - }); - - top += bottom; - } - - layouts -} - -fn columns_reverse(columns: &mut [Rect]) { - let len = columns.len(); - columns[len - 1].left = columns[0].left; - for i in (0..len - 1).rev() { - columns[i].left = columns[i + 1].left + columns[i + 1].right; - } -} - -fn rows_reverse(rows: &mut [Rect]) { - let len = rows.len(); - rows[len - 1].top = rows[0].top; - for i in (0..len - 1).rev() { - rows[i].top = rows[i + 1].top + rows[i + 1].bottom; - } -} - -fn calculate_resize_adjustments(resize_dimensions: &[Option]) -> Vec> { - let mut resize_adjustments = resize_dimensions.to_vec(); - - // This needs to be aware of layout flips - for (i, opt) in resize_dimensions.iter().enumerate() { - if let Some(resize_ref) = opt - && i > 0 - { - if resize_ref.left != 0 { - #[allow(clippy::if_not_else)] - let range = if i == 1 { - 0..1 - } else if i & 1 != 0 { - i - 1..i - } else { - i - 2..i - }; - - for n in range { - let should_adjust = n % 2 == 0; - if should_adjust { - if let Some(Some(adjacent_resize)) = resize_adjustments.get_mut(n) { - adjacent_resize.right += resize_ref.left; - } else { - resize_adjustments[n] = Option::from(Rect { - left: 0, - top: 0, - right: resize_ref.left, - bottom: 0, - }); - } - } - } - - if let Some(rr) = resize_adjustments[i].as_mut() { - rr.left = 0; - } - } - - if resize_ref.top != 0 { - let range = if i == 1 { - 0..1 - } else if i & 1 == 0 { - i - 1..i - } else { - i - 2..i - }; - - for n in range { - let should_adjust = n % 2 != 0; - if should_adjust { - if let Some(Some(adjacent_resize)) = resize_adjustments.get_mut(n) { - adjacent_resize.bottom += resize_ref.top; - } else { - resize_adjustments[n] = Option::from(Rect { - left: 0, - top: 0, - right: 0, - bottom: resize_ref.top, - }); - } - } - } - - if let Some(Some(resize)) = resize_adjustments.get_mut(i) { - resize.top = 0; - } - } - } - } - - let cleaned_resize_adjustments: Vec<_> = resize_adjustments - .iter() - .map(|adjustment| match adjustment { - None => None, - Some(rect) if rect.eq(&Rect::default()) => None, - Some(_) => *adjustment, - }) - .collect(); - - cleaned_resize_adjustments -} - -#[allow(clippy::only_used_in_recursion)] -fn recursive_fibonacci( - idx: usize, - count: usize, - area: &Rect, - layout_flip: Option, - resize_adjustments: Vec>, -) -> Vec { - let mut a = *area; - - let resized = if let Some(Some(r)) = resize_adjustments.get(idx) { - a.left += r.left; - a.top += r.top; - a.right += r.right; - a.bottom += r.bottom; - a - } else { - *area - }; - - let half_width = area.right / 2; - let half_height = area.bottom / 2; - let half_resized_width = resized.right / 2; - let half_resized_height = resized.bottom / 2; - - let (main_x, alt_x, alt_y, main_y); - - if let Some(flip) = layout_flip { - match flip { - Axis::Horizontal => { - main_x = resized.left + half_width + (half_width - half_resized_width); - alt_x = resized.left; - - alt_y = resized.top + half_resized_height; - main_y = resized.top; - } - Axis::Vertical => { - main_y = resized.top + half_height + (half_height - half_resized_height); - alt_y = resized.top; - - main_x = resized.left; - alt_x = resized.left + half_resized_width; - } - Axis::HorizontalAndVertical => { - main_x = resized.left + half_width + (half_width - half_resized_width); - alt_x = resized.left; - main_y = resized.top + half_height + (half_height - half_resized_height); - alt_y = resized.top; - } - } - } else { - main_x = resized.left; - alt_x = resized.left + half_resized_width; - main_y = resized.top; - alt_y = resized.top + half_resized_height; - } - - #[allow(clippy::if_not_else)] - if count == 0 { - vec![] - } else if count == 1 { - vec![Rect { - left: resized.left, - top: resized.top, - right: resized.right, - bottom: resized.bottom, - }] - } else if !idx.is_multiple_of(2) { - let mut res = vec![Rect { - left: resized.left, - top: main_y, - right: resized.right, - bottom: half_resized_height, - }]; - res.append(&mut recursive_fibonacci( - idx + 1, - count - 1, - &Rect { - left: area.left, - top: alt_y, - right: area.right, - bottom: area.bottom - half_resized_height, - }, - layout_flip, - resize_adjustments, - )); - res - } else { - let mut res = vec![Rect { - left: main_x, - top: resized.top, - right: half_resized_width, - bottom: resized.bottom, - }]; - res.append(&mut recursive_fibonacci( - idx + 1, - count - 1, - &Rect { - left: alt_x, - top: area.top, - right: area.right - half_resized_width, - bottom: area.bottom, - }, - layout_flip, - resize_adjustments, - )); - res - } -} - -fn calculate_columns_adjustment(resize_dimensions: &[Option]) -> Vec { - let len = resize_dimensions.len(); - let mut result = vec![Rect::default(); len]; - match len { - 0 | 1 => (), - _ => { - for (i, rect) in resize_dimensions.iter().enumerate() { - if let Some(rect) = rect { - if i != 0 { - resize_right(&mut result[i - 1], rect.left); - resize_left(&mut result[i], rect.left); - } - - if i != len - 1 { - resize_right(&mut result[i], rect.right); - resize_left(&mut result[i + 1], rect.right); - } - } - } - } - }; - - result -} - -fn calculate_rows_adjustment(resize_dimensions: &[Option]) -> Vec { - let len = resize_dimensions.len(); - let mut result = vec![Rect::default(); len]; - match len { - 0 | 1 => (), - _ => { - for (i, rect) in resize_dimensions.iter().enumerate() { - if let Some(rect) = rect { - if i != 0 { - resize_bottom(&mut result[i - 1], rect.top); - resize_top(&mut result[i], rect.top); - } - - if i != len - 1 { - resize_bottom(&mut result[i], rect.bottom); - resize_top(&mut result[i + 1], rect.bottom); - } - } - } - } - }; - - result -} - -fn calculate_vertical_stack_adjustment(resize_dimensions: &[Option]) -> Vec { - let len = resize_dimensions.len(); - let mut result = vec![Rect::default(); len]; - match len { - // One container can't be resized - 0 | 1 => (), - _ => { - let (master, stack) = result.split_at_mut(1); - let primary = &mut master[0]; - - if let Some(resize) = resize_dimensions[0] { - resize_right(primary, resize.right); - for s in &mut *stack { - resize_left(s, resize.right); - } - } - - // Handle stack on the right - for (i, rect) in resize_dimensions[1..].iter().enumerate() { - if let Some(rect) = rect { - resize_right(primary, rect.left); - stack - .iter_mut() - .for_each(|vertical_element| resize_left(vertical_element, rect.left)); - - // Containers in stack except first can be resized up displacing container - // above them - if i != 0 { - resize_bottom(&mut stack[i - 1], rect.top); - resize_top(&mut stack[i], rect.top); - } - - // Containers in stack except last can be resized down displacing container - // below them - if i != stack.len() - 1 { - resize_bottom(&mut stack[i], rect.bottom); - resize_top(&mut stack[i + 1], rect.bottom); - } - } - } - } - }; - - result -} - -fn calculate_right_vertical_stack_adjustment(resize_dimensions: &[Option]) -> Vec { - let len = resize_dimensions.len(); - let mut result = vec![Rect::default(); len]; - match len { - // One container can't be resized - 0 | 1 => (), - _ => { - let (master, stack) = result.split_at_mut(1); - let primary = &mut master[0]; - - if let Some(resize) = resize_dimensions[0] { - resize_left(primary, resize.left); - for s in &mut *stack { - resize_right(s, resize.left); - } - } - - // Handle stack on the left - for (i, rect) in resize_dimensions[1..].iter().enumerate() { - if let Some(rect) = rect { - resize_left(primary, rect.right); - stack - .iter_mut() - .for_each(|vertical_element| resize_right(vertical_element, rect.right)); - - // Containers in stack except first can be resized up displacing container - // above them - if i != 0 { - resize_bottom(&mut stack[i - 1], rect.top); - resize_top(&mut stack[i], rect.top); - } - - // Containers in stack except last can be resized down displacing container - // below them - if i != stack.len() - 1 { - resize_bottom(&mut stack[i], rect.bottom); - resize_top(&mut stack[i + 1], rect.bottom); - } - } - } - } - }; - - result -} - -fn calculate_horizontal_stack_adjustment(resize_dimensions: &[Option]) -> Vec { - let len = resize_dimensions.len(); - let mut result = vec![Rect::default(); len]; - match len { - 0 | 1 => (), - _ => { - let (primary, rest) = result.split_at_mut(1); - let primary = &mut primary[0]; - if let Some(resize_primary) = resize_dimensions[0] { - resize_bottom(primary, resize_primary.bottom); - - for horizontal_element in &mut *rest { - resize_top(horizontal_element, resize_primary.bottom); - } - } - - for (i, rect) in resize_dimensions[1..].iter().enumerate() { - if let Some(rect) = rect { - resize_bottom(primary, rect.top); - rest.iter_mut() - .for_each(|vertical_element| resize_top(vertical_element, rect.top)); - - if i != 0 { - resize_right(&mut rest[i - 1], rect.left); - resize_left(&mut rest[i], rect.left); - } - - if i != rest.len() - 1 { - resize_right(&mut rest[i], rect.right); - resize_left(&mut rest[i + 1], rect.right); - } - } - } - } - }; - - result -} - -fn calculate_ultrawide_adjustment(resize_dimensions: &[Option]) -> Vec { - let len = resize_dimensions.len(); - let mut result = vec![Rect::default(); len]; - match len { - // One container can't be resized - 0 | 1 => (), - 2 => { - let (primary, secondary) = result.split_at_mut(1); - let primary = &mut primary[0]; - let secondary = &mut secondary[0]; - // With two containers on screen container 0 is on the right - if let Some(resize_primary) = resize_dimensions[0] { - resize_left(primary, resize_primary.left); - resize_right(secondary, resize_primary.left); - } - - if let Some(resize_secondary) = resize_dimensions[1] { - resize_left(primary, resize_secondary.right); - resize_right(secondary, resize_secondary.right); - } - } - _ => { - let (primary, rest) = result.split_at_mut(1); - let (secondary, tertiary) = rest.split_at_mut(1); - let primary = &mut primary[0]; - let secondary = &mut secondary[0]; - // With three or more containers container 0 is in the center - if let Some(resize_primary) = resize_dimensions[0] { - resize_left(primary, resize_primary.left); - resize_right(primary, resize_primary.right); - - resize_right(secondary, resize_primary.left); - - for vertical_element in &mut *tertiary { - resize_left(vertical_element, resize_primary.right); - } - } - - // Container 1 is on the left - if let Some(resize_secondary) = resize_dimensions[1] { - resize_left(primary, resize_secondary.right); - resize_right(secondary, resize_secondary.right); - } - - // Handle stack on the right - for (i, rect) in resize_dimensions[2..].iter().enumerate() { - if let Some(rect) = rect { - resize_right(primary, rect.left); - tertiary - .iter_mut() - .for_each(|vertical_element| resize_left(vertical_element, rect.left)); - - // Containers in stack except first can be resized up displacing container - // above them - if i != 0 { - resize_bottom(&mut tertiary[i - 1], rect.top); - resize_top(&mut tertiary[i], rect.top); - } - - // Containers in stack except last can be resized down displacing container - // below them - if i != tertiary.len() - 1 { - resize_bottom(&mut tertiary[i], rect.bottom); - resize_top(&mut tertiary[i + 1], rect.bottom); - } - } - } - } - }; - - result -} - -fn calculate_scrolling_adjustment(resize_dimensions: &[Option]) -> Vec { - let len = resize_dimensions.len(); - let mut result = vec![Rect::default(); len]; - - if len <= 1 { - return result; - } - - for (i, rect) in resize_dimensions.iter().enumerate() { - if let Some(rect) = rect { - let is_leftmost = i == 0; - let is_rightmost = i == len - 1; - - resize_left(&mut result[i], rect.left); - resize_right(&mut result[i], rect.right); - resize_top(&mut result[i], rect.top); - resize_bottom(&mut result[i], rect.bottom); - - if !is_leftmost && rect.left != 0 { - resize_right(&mut result[i - 1], rect.left); - } - - if !is_rightmost && rect.right != 0 { - resize_left(&mut result[i + 1], rect.right); - } - } - } - - result -} - -fn resize_left(rect: &mut Rect, resize: i32) { - rect.left += resize / 2; - rect.right += -resize / 2; -} - -fn resize_right(rect: &mut Rect, resize: i32) { - rect.right += resize / 2; -} - -fn resize_top(rect: &mut Rect, resize: i32) { - rect.top += resize / 2; - rect.bottom += -resize / 2; -} - -fn resize_bottom(rect: &mut Rect, resize: i32) { - rect.bottom += resize / 2; -} diff --git a/komorebi/src/core/cycle_direction.rs b/komorebi/src/core/cycle_direction.rs deleted file mode 100644 index e75dec60..00000000 --- a/komorebi/src/core/cycle_direction.rs +++ /dev/null @@ -1,36 +0,0 @@ -use std::num::NonZeroUsize; - -use clap::ValueEnum; -use serde::Deserialize; -use serde::Serialize; -use strum::Display; -use strum::EnumString; - -#[derive(Clone, Copy, Debug, Serialize, Deserialize, Display, EnumString, ValueEnum)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -pub enum CycleDirection { - Previous, - Next, -} - -impl CycleDirection { - #[must_use] - pub const fn next_idx(&self, idx: usize, len: NonZeroUsize) -> usize { - match self { - Self::Previous => { - if idx == 0 { - len.get() - 1 - } else { - idx - 1 - } - } - Self::Next => { - if idx == len.get() - 1 { - 0 - } else { - idx + 1 - } - } - } - } -} diff --git a/komorebi/src/core/default_layout.rs b/komorebi/src/core/default_layout.rs deleted file mode 100644 index 3e789381..00000000 --- a/komorebi/src/core/default_layout.rs +++ /dev/null @@ -1,309 +0,0 @@ -use crate::core::Sizing; -use crate::core::operation_direction::OperationDirection; -use crate::core::rect::Rect; -use clap::ValueEnum; -use serde::Deserialize; -use serde::Serialize; -use strum::Display; -use strum::EnumString; - -#[derive( - Clone, Copy, Debug, Serialize, Deserialize, Eq, PartialEq, Display, EnumString, ValueEnum, -)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema), schemars(extend("default" = Self::BSP)))] -/// A predefined komorebi layout -pub enum DefaultLayout { - /// BSP Layout - /// - /// ``` - /// +-------+-----+ - /// | | | - /// | +--+--+ - /// | | |--| - /// +-------+--+--+ - /// ``` - BSP, - /// Columns Layout - /// - /// ``` - /// +--+--+--+--+ - /// | | | | | - /// | | | | | - /// | | | | | - /// +--+--+--+--+ - /// ``` - Columns, - /// Rows Layout - /// - /// ``` - /// +-----------+ - /// |-----------| - /// |-----------| - /// |-----------| - /// +-----------+ - /// ``` - Rows, - /// Vertical Stack Layout - /// - /// ``` - /// +-------+-----+ - /// | | | - /// | +-----+ - /// | | | - /// +-------+-----+ - /// ``` - VerticalStack, - /// Horizontal Stack Layout - /// - /// ``` - /// +------+------+ - /// | | - /// |------+------+ - /// | | | - /// +------+------+ - /// ``` - HorizontalStack, - /// Ultrawide Vertical Stack Layout - /// - /// ``` - /// +-----+-----------+-----+ - /// | | | | - /// | | +-----+ - /// | | | | - /// | | +-----+ - /// | | | | - /// +-----+-----------+-----+ - /// ``` - UltrawideVerticalStack, - /// Grid Layout - /// - /// ``` - /// +-----+-----+ +---+---+---+ +---+---+---+ +---+---+---+ - ///| | | | | | | | | | | | | | | - ///| | | | | | | | | | | | | +---+ - ///+-----+-----+ | +---+---+ +---+---+---+ +---+---| | - ///| | | | | | | | | | | | | +---+ - ///| | | | | | | | | | | | | | | - ///+-----+-----+ +---+---+---+ +---+---+---+ +---+---+---+ - /// 4 windows 5 windows 6 windows 7 windows - ///``` - Grid, - /// Right Main Vertical Stack Layout - /// - /// ``` - /// +-----+-------+ - /// | | | - /// +-----+ | - /// | | | - /// +-----+-------+ - /// ``` - RightMainVerticalStack, - /// Scrolling Layout - /// - /// ``` - /// +--+--+--+--+--+--+ - /// | | | | - /// | | | | - /// | | | | - /// +--+--+--+--+--+--+ - /// ``` - Scrolling, - // NOTE: If any new layout is added, please make sure to register the same in `DefaultLayout::cycle` -} - -#[derive(Clone, Copy, Debug, Serialize, Deserialize, Eq, PartialEq)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// Options for specific layouts -pub struct LayoutOptions { - /// Options related to the Scrolling layout - pub scrolling: Option, - /// Options related to the Grid layout - pub grid: Option, -} - -#[derive(Clone, Copy, Debug, Serialize, Deserialize, Eq, PartialEq)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// Options for the Scrolling layout -pub struct ScrollingLayoutOptions { - /// Desired number of visible columns (default: 3) - pub columns: usize, - /// With an odd number of visible columns, keep the focused window column centered - pub center_focused_column: Option, -} - -#[derive(Clone, Copy, Debug, Serialize, Deserialize, Eq, PartialEq)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// Options for the Grid layout -pub struct GridLayoutOptions { - /// Maximum number of rows per grid column - pub rows: usize, -} - -impl DefaultLayout { - pub fn leftmost_index(&self, len: usize) -> usize { - match self { - Self::UltrawideVerticalStack | Self::RightMainVerticalStack => match len { - n if n > 1 => 1, - _ => 0, - }, - Self::Scrolling => 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, - DefaultLayout::Scrolling => len.saturating_sub(1), - } - } - - #[must_use] - #[allow(clippy::cast_precision_loss, clippy::only_used_in_recursion)] - pub fn resize( - &self, - unaltered: &Rect, - resize: &Option, - edge: OperationDirection, - sizing: Sizing, - delta: i32, - ) -> Option { - if !matches!( - self, - Self::BSP - | Self::Columns - | Self::Rows - | Self::VerticalStack - | Self::RightMainVerticalStack - | Self::HorizontalStack - | Self::UltrawideVerticalStack - | Self::Scrolling - ) { - return None; - }; - - let mut r = resize.unwrap_or_default(); - - let resize_delta = delta; - - match edge { - OperationDirection::Left => match sizing { - Sizing::Increase => { - // Some final checks to make sure the user can't infinitely resize to - // the point of pushing other windows out of bounds - - // Note: These checks cannot take into account the changes made to the - // edges of adjacent windows at operation time, so it is still possible - // to push windows out of bounds by maxing out an Increase Left on a - // Window with index 1, and then maxing out a Decrease Right on a Window - // with index 0. I don't think it's worth trying to defensively program - // against this; if people end up in this situation they are better off - // just hitting the retile command - let diff = ((r.left + -resize_delta) as f32).abs(); - if diff < unaltered.right as f32 { - r.left += -resize_delta; - } - } - Sizing::Decrease => { - let diff = ((r.left - -resize_delta) as f32).abs(); - if diff < unaltered.right as f32 { - r.left -= -resize_delta; - } - } - }, - OperationDirection::Up => match sizing { - Sizing::Increase => { - let diff = ((r.top + resize_delta) as f32).abs(); - if diff < unaltered.bottom as f32 { - r.top += -resize_delta; - } - } - Sizing::Decrease => { - let diff = ((r.top - resize_delta) as f32).abs(); - if diff < unaltered.bottom as f32 { - r.top -= -resize_delta; - } - } - }, - OperationDirection::Right => match sizing { - Sizing::Increase => { - let diff = ((r.right + resize_delta) as f32).abs(); - if diff < unaltered.right as f32 { - r.right += resize_delta; - } - } - Sizing::Decrease => { - let diff = ((r.right - resize_delta) as f32).abs(); - if diff < unaltered.right as f32 { - r.right -= resize_delta; - } - } - }, - OperationDirection::Down => match sizing { - Sizing::Increase => { - let diff = ((r.bottom + resize_delta) as f32).abs(); - if diff < unaltered.bottom as f32 { - r.bottom += resize_delta; - } - } - Sizing::Decrease => { - let diff = ((r.bottom - resize_delta) as f32).abs(); - if diff < unaltered.bottom as f32 { - r.bottom -= resize_delta; - } - } - }, - }; - - if r.eq(&Rect::default()) { - None - } else { - Option::from(r) - } - } - - #[must_use] - pub const fn cycle_next(self) -> Self { - match self { - Self::BSP => Self::Columns, - Self::Columns => Self::Rows, - Self::Rows => Self::VerticalStack, - Self::VerticalStack => Self::HorizontalStack, - Self::HorizontalStack => Self::UltrawideVerticalStack, - Self::UltrawideVerticalStack => Self::Grid, - Self::Grid => Self::RightMainVerticalStack, - Self::RightMainVerticalStack => Self::Scrolling, - Self::Scrolling => Self::BSP, - } - } - - #[must_use] - pub const fn cycle_previous(self) -> Self { - match self { - Self::Scrolling => Self::RightMainVerticalStack, - Self::RightMainVerticalStack => Self::Grid, - Self::Grid => Self::UltrawideVerticalStack, - Self::UltrawideVerticalStack => Self::HorizontalStack, - Self::HorizontalStack => Self::VerticalStack, - Self::VerticalStack => Self::Rows, - Self::Rows => Self::Columns, - Self::Columns => Self::BSP, - Self::BSP => Self::RightMainVerticalStack, - } - } -} diff --git a/komorebi/src/core/direction.rs b/komorebi/src/core/direction.rs deleted file mode 100644 index 39560cc9..00000000 --- a/komorebi/src/core/direction.rs +++ /dev/null @@ -1,397 +0,0 @@ -use crate::core::default_layout::DefaultLayout; -use crate::core::default_layout::LayoutOptions; -use crate::core::operation_direction::OperationDirection; - -pub trait Direction { - fn index_in_direction( - &self, - op_direction: OperationDirection, - idx: usize, - count: usize, - layout_options: Option, - ) -> Option; - - fn is_valid_direction( - &self, - op_direction: OperationDirection, - idx: usize, - count: usize, - layout_options: Option, - ) -> bool; - fn up_index( - &self, - op_direction: Option, - idx: usize, - count: Option, - layout_options: Option, - ) -> usize; - fn down_index( - &self, - op_direction: Option, - idx: usize, - count: Option, - layout_options: Option, - ) -> usize; - fn left_index( - &self, - op_direction: Option, - idx: usize, - count: Option, - layout_options: Option, - ) -> usize; - fn right_index( - &self, - op_direction: Option, - idx: usize, - count: Option, - layout_options: Option, - ) -> usize; -} - -impl Direction for DefaultLayout { - fn index_in_direction( - &self, - op_direction: OperationDirection, - idx: usize, - count: usize, - layout_options: Option, - ) -> Option { - match op_direction { - OperationDirection::Left => { - if self.is_valid_direction(op_direction, idx, count, layout_options) { - Option::from(self.left_index( - Some(op_direction), - idx, - Some(count), - layout_options, - )) - } else { - None - } - } - OperationDirection::Right => { - if self.is_valid_direction(op_direction, idx, count, layout_options) { - Option::from(self.right_index( - Some(op_direction), - idx, - Some(count), - layout_options, - )) - } else { - None - } - } - OperationDirection::Up => { - if self.is_valid_direction(op_direction, idx, count, layout_options) { - Option::from(self.up_index( - Some(op_direction), - idx, - Some(count), - layout_options, - )) - } else { - None - } - } - OperationDirection::Down => { - if self.is_valid_direction(op_direction, idx, count, layout_options) { - Option::from(self.down_index( - Some(op_direction), - idx, - Some(count), - layout_options, - )) - } else { - None - } - } - } - } - - fn is_valid_direction( - &self, - op_direction: OperationDirection, - idx: usize, - count: usize, - layout_options: Option, - ) -> bool { - if count < 2 { - return false; - } - - match op_direction { - OperationDirection::Up => match self { - Self::BSP => idx != 0 && idx != 1, - Self::Columns => false, - Self::Rows | Self::HorizontalStack => idx != 0, - Self::VerticalStack | Self::RightMainVerticalStack => idx != 0 && idx != 1, - Self::UltrawideVerticalStack => idx > 2, - Self::Grid => !is_grid_edge(op_direction, idx, count, layout_options), - Self::Scrolling => false, - }, - OperationDirection::Down => match self { - Self::BSP => idx != count - 1 && !idx.is_multiple_of(2), - Self::Columns => false, - Self::Rows => idx != count - 1, - Self::VerticalStack | Self::RightMainVerticalStack => idx != 0 && idx != count - 1, - Self::HorizontalStack => idx == 0, - Self::UltrawideVerticalStack => idx > 1 && idx != count - 1, - Self::Grid => !is_grid_edge(op_direction, idx, count, layout_options), - Self::Scrolling => false, - }, - OperationDirection::Left => match self { - Self::BSP => idx != 0, - Self::Columns | Self::VerticalStack => idx != 0, - Self::RightMainVerticalStack => idx == 0, - Self::Rows => false, - Self::HorizontalStack => idx != 0 && idx != 1, - Self::UltrawideVerticalStack => idx != 1, - Self::Grid => !is_grid_edge(op_direction, idx, count, layout_options), - Self::Scrolling => idx != 0, - }, - OperationDirection::Right => match self { - Self::BSP => idx.is_multiple_of(2) && idx != count - 1, - Self::Columns => idx != count - 1, - Self::Rows => false, - Self::VerticalStack => idx == 0, - Self::RightMainVerticalStack => idx != 0, - Self::HorizontalStack => idx != 0 && idx != count - 1, - Self::UltrawideVerticalStack => match count { - 2 => idx != 0, - _ => idx < 2, - }, - Self::Grid => !is_grid_edge(op_direction, idx, count, layout_options), - Self::Scrolling => idx != count - 1, - }, - } - } - - fn up_index( - &self, - op_direction: Option, - idx: usize, - count: Option, - layout_options: Option, - ) -> usize { - match self { - Self::BSP => { - if idx.is_multiple_of(2) { - idx - 1 - } else { - idx - 2 - } - } - Self::Columns => unreachable!(), - Self::Rows - | Self::VerticalStack - | Self::UltrawideVerticalStack - | Self::RightMainVerticalStack => idx - 1, - Self::HorizontalStack => 0, - Self::Grid => grid_neighbor(op_direction, idx, count, layout_options), - Self::Scrolling => unreachable!(), - } - } - - fn down_index( - &self, - op_direction: Option, - idx: usize, - count: Option, - layout_options: Option, - ) -> usize { - match self { - Self::BSP - | Self::Rows - | Self::VerticalStack - | Self::UltrawideVerticalStack - | Self::RightMainVerticalStack => idx + 1, - Self::Columns => unreachable!(), - Self::HorizontalStack => 1, - Self::Grid => grid_neighbor(op_direction, idx, count, layout_options), - Self::Scrolling => unreachable!(), - } - } - - fn left_index( - &self, - op_direction: Option, - idx: usize, - count: Option, - layout_options: Option, - ) -> usize { - match self { - Self::BSP => { - if idx.is_multiple_of(2) { - idx - 2 - } else { - idx - 1 - } - } - Self::Columns | Self::HorizontalStack => idx - 1, - Self::Rows => unreachable!(), - Self::VerticalStack => 0, - Self::RightMainVerticalStack => 1, - Self::UltrawideVerticalStack => match idx { - 0 => 1, - 1 => unreachable!(), - _ => 0, - }, - Self::Grid => grid_neighbor(op_direction, idx, count, layout_options), - Self::Scrolling => idx - 1, - } - } - - fn right_index( - &self, - op_direction: Option, - idx: usize, - count: Option, - layout_options: Option, - ) -> usize { - match self { - Self::BSP | Self::Columns | Self::HorizontalStack => idx + 1, - Self::Rows => unreachable!(), - Self::VerticalStack => 1, - Self::RightMainVerticalStack => 0, - Self::UltrawideVerticalStack => match idx { - 1 => 0, - 0 => 2, - _ => unreachable!(), - }, - Self::Grid => grid_neighbor(op_direction, idx, count, layout_options), - Self::Scrolling => idx + 1, - } - } -} - -struct GridItem { - state: GridItemState, - row: usize, - num_rows: usize, - touching_edges: GridTouchingEdges, -} - -enum GridItemState { - Valid, - Invalid, -} - -#[allow(clippy::struct_excessive_bools)] -struct GridTouchingEdges { - left: bool, - right: bool, - up: bool, - down: bool, -} - -#[allow( - clippy::cast_possible_truncation, - clippy::cast_precision_loss, - clippy::cast_sign_loss -)] -fn get_grid_item(idx: usize, count: usize, layout_options: Option) -> GridItem { - let row_constraint = layout_options.and_then(|o| o.grid.map(|g| g.rows)); - let num_cols = if let Some(rows) = row_constraint { - ((count as f32) / (rows as f32)).ceil() as i32 - } else { - (count as f32).sqrt().ceil() as i32 - }; - - let mut iter = 0; - - for col in 0..num_cols { - let remaining_windows = (count - iter) as i32; - let remaining_columns = num_cols - col; - - let num_rows_in_this_col = if let Some(rows) = row_constraint { - (remaining_windows / remaining_columns).min(rows as i32) - } else { - remaining_windows / remaining_columns - }; - - for row in 0..num_rows_in_this_col { - if iter == idx { - return GridItem { - state: GridItemState::Valid, - row: (row + 1) as usize, - num_rows: num_rows_in_this_col as usize, - touching_edges: GridTouchingEdges { - left: col == 0, - right: col == num_cols - 1, - up: row == 0, - down: row == num_rows_in_this_col - 1, - }, - }; - } - - iter += 1; - } - } - - GridItem { - state: GridItemState::Invalid, - row: 0, - num_rows: 0, - touching_edges: GridTouchingEdges { - left: true, - right: true, - up: true, - down: true, - }, - } -} - -fn is_grid_edge( - op_direction: OperationDirection, - idx: usize, - count: usize, - layout_options: Option, -) -> bool { - let item = get_grid_item(idx, count, layout_options); - - match item.state { - GridItemState::Invalid => false, - GridItemState::Valid => match op_direction { - OperationDirection::Left => item.touching_edges.left, - OperationDirection::Right => item.touching_edges.right, - OperationDirection::Up => item.touching_edges.up, - OperationDirection::Down => item.touching_edges.down, - }, - } -} - -fn grid_neighbor( - op_direction: Option, - idx: usize, - count: Option, - layout_options: Option, -) -> usize { - let Some(op_direction) = op_direction else { - return 0; - }; - - let Some(count) = count else { - return 0; - }; - - let item = get_grid_item(idx, count, layout_options); - - match op_direction { - OperationDirection::Left => { - let item_from_prev_col = get_grid_item(idx - item.row, count, layout_options); - - if item.touching_edges.up && item.num_rows != item_from_prev_col.num_rows { - return idx - (item.num_rows - 1); - } - - if item.num_rows != item_from_prev_col.num_rows && !item.touching_edges.down { - return idx - (item.num_rows - 1); - } - - idx - item.num_rows - } - OperationDirection::Right => idx + item.num_rows, - OperationDirection::Up => idx - 1, - OperationDirection::Down => idx + 1, - } -} diff --git a/komorebi/src/core/layout.rs b/komorebi/src/core/layout.rs deleted file mode 100644 index adf67773..00000000 --- a/komorebi/src/core/layout.rs +++ /dev/null @@ -1,29 +0,0 @@ -use crate::core::arrangement::Arrangement; -use crate::core::default_layout::DefaultLayout; -use crate::core::direction::Direction; -use serde::Deserialize; -use serde::Serialize; - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// A komorebi layout -pub enum Layout { - /// A predefined komorebi layout - Default(DefaultLayout), -} - -impl Layout { - #[must_use] - pub fn as_boxed_direction(&self) -> Box { - match self { - Layout::Default(layout) => Box::new(*layout), - } - } - - #[must_use] - pub fn as_boxed_arrangement(&self) -> Box { - match self { - Layout::Default(layout) => Box::new(*layout), - } - } -} diff --git a/komorebi/src/core/mod.rs b/komorebi/src/core/mod.rs index 83facad3..ef3d0ff9 100644 --- a/komorebi/src/core/mod.rs +++ b/komorebi/src/core/mod.rs @@ -1,11 +1,6 @@ use crate::animation::AnimationPrefix; use crate::core::animation::AnimationStyle; -use crate::core::arrangement::Axis; -use crate::core::cycle_direction::CycleDirection; -use crate::core::default_layout::DefaultLayout; -use crate::core::operation_direction::OperationDirection; use crate::core::pathext::ResolvedPathBuf; -use crate::core::rect::Rect; use clap::ValueEnum; use color_eyre::eyre; use komorebi_themes::KomorebiTheme; @@ -17,17 +12,31 @@ use std::str::FromStr; use strum::Display; use strum::EnumString; +// Re-export types from komorebi-layouts +pub use komorebi_layouts::Arrangement; +pub use komorebi_layouts::Axis; +pub use komorebi_layouts::CycleDirection; +pub use komorebi_layouts::DEFAULT_RATIO; +pub use komorebi_layouts::DEFAULT_SECONDARY_RATIO; +pub use komorebi_layouts::DefaultLayout; +pub use komorebi_layouts::Direction; +pub use komorebi_layouts::GridLayoutOptions; +pub use komorebi_layouts::Layout; +pub use komorebi_layouts::LayoutOptions; +pub use komorebi_layouts::MAX_RATIO; +pub use komorebi_layouts::MAX_RATIOS; +pub use komorebi_layouts::MIN_RATIO; +pub use komorebi_layouts::OperationDirection; +pub use komorebi_layouts::Rect; +pub use komorebi_layouts::ScrollingLayoutOptions; +pub use komorebi_layouts::Sizing; + +// Keep local modules that aren't in komorebi-layouts pub mod animation; -pub mod arrangement; pub mod asc; pub mod config_generation; -pub mod cycle_direction; -pub mod default_layout; -pub mod direction; -pub mod layout; -pub mod operation_direction; pub mod pathext; -pub mod rect; +pub mod rect_ext; #[derive( Clone, Copy, Debug, Default, PartialEq, Serialize, Deserialize, Display, EnumString, ValueEnum, @@ -42,29 +51,6 @@ pub enum OperationBehaviour { NoOp, } -#[derive(Clone, Copy, Debug, Serialize, Deserialize, Display, EnumString, ValueEnum)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -pub enum Sizing { - Increase, - Decrease, -} - -impl Sizing { - #[must_use] - pub const fn adjust_by(&self, value: i32, adjustment: i32) -> i32 { - match self { - Self::Increase => value + adjustment, - Self::Decrease => { - if value > 0 && value - adjustment >= 0 { - value - adjustment - } else { - value - } - } - } - } -} - #[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, PartialEq)] pub struct WindowManagementBehaviour { /// The current WindowContainerBehaviour to be used diff --git a/komorebi/src/core/operation_direction.rs b/komorebi/src/core/operation_direction.rs deleted file mode 100644 index f29ca763..00000000 --- a/komorebi/src/core/operation_direction.rs +++ /dev/null @@ -1,61 +0,0 @@ -use crate::core::arrangement::Axis; -use crate::core::default_layout::LayoutOptions; -use crate::core::direction::Direction; -use clap::ValueEnum; -use serde::Deserialize; -use serde::Serialize; -use std::num::NonZeroUsize; - -#[derive(Clone, Copy, Debug, Serialize, Deserialize, ValueEnum)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -pub enum OperationDirection { - Left, - Right, - Up, - Down, -} - -impl OperationDirection { - #[must_use] - pub const fn opposite(self) -> Self { - match self { - Self::Left => Self::Right, - Self::Right => Self::Left, - Self::Up => Self::Down, - Self::Down => Self::Up, - } - } - - fn flip(self, layout_flip: Option) -> Self { - layout_flip.map_or(self, |flip| match self { - Self::Left => match flip { - Axis::Horizontal | Axis::HorizontalAndVertical => Self::Right, - Axis::Vertical => self, - }, - Self::Right => match flip { - Axis::Horizontal | Axis::HorizontalAndVertical => Self::Left, - Axis::Vertical => self, - }, - Self::Up => match flip { - Axis::Vertical | Axis::HorizontalAndVertical => Self::Down, - Axis::Horizontal => self, - }, - Self::Down => match flip { - Axis::Vertical | Axis::HorizontalAndVertical => Self::Up, - Axis::Horizontal => self, - }, - }) - } - - #[must_use] - pub fn destination( - self, - layout: &dyn Direction, - layout_flip: Option, - idx: usize, - len: NonZeroUsize, - layout_options: Option, - ) -> Option { - layout.index_in_direction(self.flip(layout_flip), idx, len.get(), layout_options) - } -} diff --git a/komorebi/src/core/rect.rs b/komorebi/src/core/rect.rs deleted file mode 100644 index 62525601..00000000 --- a/komorebi/src/core/rect.rs +++ /dev/null @@ -1,126 +0,0 @@ -use crate::core_graphics::CoreGraphicsApi; -use crate::window::WindowBounds; -use objc2_core_foundation::CGFloat; -use objc2_core_foundation::CGPoint; -use objc2_core_foundation::CGRect; -use objc2_core_foundation::CGSize; -use serde::Deserialize; -use serde::Serialize; - -#[derive(Debug, Default, Copy, Clone, Serialize, Deserialize, PartialEq)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// Rectangle dimensions -pub struct Rect { - /// Left point of the rectangle - pub left: i32, - /// Top point of the rectangle - pub top: i32, - /// Width of the recentangle (from the left point) - pub right: i32, - /// Height of the rectangle (from the top point) - pub bottom: i32, -} - -impl From for Rect { - fn from(value: CGSize) -> Self { - Self { - left: 0, - top: 0, - right: value.width as i32, - bottom: value.height as i32, - } - } -} - -impl From for Rect { - fn from(value: CGRect) -> Self { - Self { - left: value.origin.x as i32, - top: value.origin.y as i32, - right: value.size.width as i32, - bottom: value.size.height as i32, - } - } -} - -impl From<&Rect> for CGRect { - fn from(value: &Rect) -> Self { - Self { - origin: CGPoint { - x: value.left as CGFloat, - y: value.top as CGFloat, - }, - size: CGSize { - width: value.right as CGFloat, - height: value.bottom as CGFloat, - }, - } - } -} - -impl From for Rect { - fn from(value: WindowBounds) -> Self { - Self { - left: value.x as i32, - top: value.y as i32, - right: value.width as i32, - bottom: value.height as i32, - } - } -} - -impl Rect { - pub fn contains(&self, other: &Rect) -> bool { - CoreGraphicsApi::contains_rect(other.into(), self.into()) - } - - pub fn percentage_within_horizontal_bounds(&self, other: &Rect) -> f64 { - let overlap_left = self.left.max(other.left); - let overlap_right = (self.left + self.right).min(other.left + other.right); - - let overlap_width = overlap_right - overlap_left; - - if overlap_width <= 0 { - 0.0 - } else { - (overlap_width as f64) / (other.right as f64) * 100.0 - } - } - - /// Decrease the size of self by the padding amount. - pub fn add_padding(&mut self, padding: T) - where - T: Into>, - { - if let Some(padding) = padding.into() { - self.left += padding; - self.top += padding; - self.right -= padding * 2; - self.bottom -= padding * 2; - } - } - - /// Increase the size of self by the margin amount. - pub fn add_margin(&mut self, margin: i32) { - self.left -= margin; - self.top -= margin; - self.right += margin * 2; - self.bottom += margin * 2; - } - - pub fn left_padding(&mut self, padding: i32) { - self.left += padding; - } - - pub fn right_padding(&mut self, padding: i32) { - self.right -= padding; - } - - #[must_use] - pub const fn contains_point(&self, point: (i32, i32)) -> bool { - point.0 >= self.left - && point.0 <= self.left + self.right - && point.1 >= self.top - && point.1 <= self.top + self.bottom - } -} diff --git a/komorebi/src/macos_api.rs b/komorebi/src/macos_api.rs index a9b38c52..e36cd10e 100644 --- a/komorebi/src/macos_api.rs +++ b/komorebi/src/macos_api.rs @@ -10,7 +10,8 @@ use crate::accessibility::error::AccessibilityError; use crate::application::Application; use crate::cf_array_as; use crate::container::Container; -use crate::core::rect::Rect; +use crate::core::Rect; +use crate::core::rect_ext::RectExt; use crate::core_graphics::CoreGraphicsApi; use crate::ioreg::IoReg; use crate::monitor::Monitor; diff --git a/komorebi/src/monitor.rs b/komorebi/src/monitor.rs index 8d3e8270..338aefd8 100644 --- a/komorebi/src/monitor.rs +++ b/komorebi/src/monitor.rs @@ -1,12 +1,12 @@ use crate::DEFAULT_CONTAINER_PADDING; use crate::DEFAULT_WORKSPACE_PADDING; use crate::container::Container; +use crate::core::DefaultLayout; use crate::core::FloatingLayerBehaviour; +use crate::core::Layout; +use crate::core::OperationDirection; +use crate::core::Rect; use crate::core::WindowHidingPosition; -use crate::core::default_layout::DefaultLayout; -use crate::core::layout::Layout; -use crate::core::operation_direction::OperationDirection; -use crate::core::rect::Rect; use crate::macos_api::MacosApi; use crate::ring::Ring; use crate::static_config::Wallpaper; diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index d999a99d..3d4d9943 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -21,21 +21,21 @@ use crate::application::Application; use crate::border_manager; use crate::cf_array_as; use crate::core::ApplicationIdentifier; +use crate::core::Axis; +use crate::core::Layout; +use crate::core::LayoutOptions; use crate::core::MoveBehaviour; +use crate::core::OperationDirection; +use crate::core::Rect; +use crate::core::ScrollingLayoutOptions; use crate::core::SocketMessage; use crate::core::StateQuery; use crate::core::WindowContainerBehaviour; use crate::core::WindowKind; -use crate::core::arrangement::Axis; use crate::core::config_generation::IdWithIdentifier; use crate::core::config_generation::MatchingRule; use crate::core::config_generation::MatchingStrategy; use crate::core::config_generation::WorkspaceMatchingRule; -use crate::core::default_layout::LayoutOptions; -use crate::core::default_layout::ScrollingLayoutOptions; -use crate::core::layout::Layout; -use crate::core::operation_direction::OperationDirection; -use crate::core::rect::Rect; use crate::core_graphics::CoreGraphicsApi; use crate::current_space_id; use crate::macos_api::MacosApi; @@ -1513,6 +1513,8 @@ impl WindowManager { center_focused_column: Default::default(), }), grid: None, + column_ratios: None, + row_ratios: None, }, }; @@ -1871,7 +1873,7 @@ pub fn read_commands_uds( mod tests { use crate::SocketMessage; use crate::WindowManagerEvent; - use crate::core::rect::Rect; + use crate::core::Rect; use crate::monitor; use crate::window_manager::WindowManager; use crossbeam_channel::Receiver; diff --git a/komorebi/src/process_event.rs b/komorebi/src/process_event.rs index 3b321105..14a233f6 100644 --- a/komorebi/src/process_event.rs +++ b/komorebi/src/process_event.rs @@ -11,14 +11,14 @@ use crate::accessibility::error::AccessibilityApiError; use crate::accessibility::error::AccessibilityError; use crate::accessibility::notification_constants::AccessibilityNotification; use crate::border_manager; +use crate::core::DefaultLayout; +use crate::core::Layout; +use crate::core::OperationDirection; +use crate::core::Rect; use crate::core::Sizing; use crate::core::WindowContainerBehaviour; use crate::core::WindowHidingPosition; use crate::core::config_generation::MatchingRule; -use crate::core::default_layout::DefaultLayout; -use crate::core::layout::Layout; -use crate::core::operation_direction::OperationDirection; -use crate::core::rect::Rect; use crate::current_space_id; use crate::macos_api::MacosApi; use crate::notify_subscribers; diff --git a/komorebi/src/state.rs b/komorebi/src/state.rs index 81d12019..6c71081e 100644 --- a/komorebi/src/state.rs +++ b/komorebi/src/state.rs @@ -6,10 +6,10 @@ use crate::MANAGE_IDENTIFIERS; use crate::WORKSPACE_MATCHING_RULES; use crate::core::MoveBehaviour; use crate::core::OperationBehaviour; +use crate::core::Rect; use crate::core::WindowContainerBehaviour; use crate::core::config_generation::MatchingRule; use crate::core::config_generation::WorkspaceMatchingRule; -use crate::core::rect::Rect; use crate::monitor::Monitor; use crate::ring::Ring; use crate::window_manager::WindowManager; diff --git a/komorebi/src/static_config.rs b/komorebi/src/static_config.rs index 7e6ed17e..bc7e1482 100644 --- a/komorebi/src/static_config.rs +++ b/komorebi/src/static_config.rs @@ -24,27 +24,27 @@ use crate::animation::DEFAULT_ANIMATION_FPS; use crate::animation::PerAnimationPrefixConfig; use crate::border_manager; use crate::core::ApplicationIdentifier; +use crate::core::Axis; use crate::core::CrossBoundaryBehaviour; +use crate::core::DefaultLayout; use crate::core::FloatingLayerBehaviour; +use crate::core::Layout; +use crate::core::LayoutOptions; use crate::core::MoveBehaviour; use crate::core::OperationBehaviour; use crate::core::Placement; +use crate::core::Rect; use crate::core::SocketMessage; use crate::core::WindowContainerBehaviour; use crate::core::WindowHidingPosition; use crate::core::WindowManagementBehaviour; use crate::core::animation::AnimationStyle; -use crate::core::arrangement::Axis; use crate::core::asc::ApplicationSpecificConfiguration; use crate::core::asc::AscApplicationRulesOrSchema; use crate::core::config_generation::MatchingRule; use crate::core::config_generation::MatchingStrategy; use crate::core::config_generation::WorkspaceMatchingRule; -use crate::core::default_layout::DefaultLayout; -use crate::core::default_layout::LayoutOptions; -use crate::core::layout::Layout; use crate::core::pathext::ResolvedPathBuf; -use crate::core::rect::Rect; use crate::current_space_id; use crate::monitor; use crate::monitor::Monitor; diff --git a/komorebi/src/window.rs b/komorebi/src/window.rs index 48bd0f70..4569d8de 100644 --- a/komorebi/src/window.rs +++ b/komorebi/src/window.rs @@ -46,12 +46,12 @@ use crate::animation::prefix::new_animation_key; use crate::application::Application; use crate::cf_dictionary_value; use crate::core::ApplicationIdentifier; +use crate::core::Rect; use crate::core::WindowHidingPosition; use crate::core::animation::AnimationStyle; use crate::core::config_generation::IdWithIdentifier; use crate::core::config_generation::MatchingRule; use crate::core::config_generation::MatchingStrategy; -use crate::core::rect::Rect; use crate::core_graphics::CoreGraphicsApi; use crate::hidden_frame_bottom_left; use crate::hidden_frame_bottom_right; diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index 00c03171..da9e1007 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -9,22 +9,22 @@ use crate::accessibility::AccessibilityApi; use crate::application::Application; use crate::border_manager; use crate::container::Container; +use crate::core::Arrangement; +use crate::core::Axis; use crate::core::CrossBoundaryBehaviour; +use crate::core::CycleDirection; +use crate::core::DefaultLayout; +use crate::core::Layout; use crate::core::MoveBehaviour; use crate::core::OperationBehaviour; +use crate::core::OperationDirection; use crate::core::Placement; +use crate::core::Rect; use crate::core::Sizing; use crate::core::WindowContainerBehaviour; use crate::core::WindowHidingPosition; use crate::core::WindowManagementBehaviour; -use crate::core::arrangement::Arrangement; -use crate::core::arrangement::Axis; use crate::core::config_generation::MatchingRule; -use crate::core::cycle_direction::CycleDirection; -use crate::core::default_layout::DefaultLayout; -use crate::core::layout::Layout; -use crate::core::operation_direction::OperationDirection; -use crate::core::rect::Rect; use crate::current_space_id; use crate::lockable_sequence::Lockable; use crate::macos_api::MacosApi; diff --git a/komorebi/src/workspace.rs b/komorebi/src/workspace.rs index 7eafabb0..9a8c9cbc 100644 --- a/komorebi/src/workspace.rs +++ b/komorebi/src/workspace.rs @@ -1,16 +1,16 @@ use crate::DATA_DIR; use crate::container::Container; +use crate::core::Axis; +use crate::core::CycleDirection; +use crate::core::DefaultLayout; use crate::core::FloatingLayerBehaviour; +use crate::core::Layout; +use crate::core::LayoutOptions; +use crate::core::OperationDirection; +use crate::core::Rect; use crate::core::SocketMessage; use crate::core::WindowContainerBehaviour; use crate::core::WindowHidingPosition; -use crate::core::arrangement::Axis; -use crate::core::cycle_direction::CycleDirection; -use crate::core::default_layout::DefaultLayout; -use crate::core::default_layout::LayoutOptions; -use crate::core::layout::Layout; -use crate::core::operation_direction::OperationDirection; -use crate::core::rect::Rect; use crate::lockable_sequence::LockableSequence; use crate::macos_api::MacosApi; use crate::ring::Ring; diff --git a/nix/komorebi-bar-options.nix b/nix/komorebi-bar-options.nix index 07c09c14..253e04dd 100644 --- a/nix/komorebi-bar-options.nix +++ b/nix/komorebi-bar-options.nix @@ -965,17 +965,6 @@ in ] ); }; - auto_select_text = lib.mkOption { - type = ( - lib.types.nullOr ( - lib.types.oneOf [ - (lib.types.nullOr catppuccinValue) - (lib.types.nullOr base16Value) - ] - ) - ); - default = null; - }; colours = lib.mkOption { type = ( lib.types.nullOr ( @@ -1051,6 +1040,17 @@ in ); default = null; }; + auto_select_fill = lib.mkOption { + type = ( + lib.types.nullOr ( + lib.types.oneOf [ + (lib.types.nullOr catppuccinValue) + (lib.types.nullOr base16Value) + ] + ) + ); + default = null; + }; accent = lib.mkOption { type = ( lib.types.nullOr ( @@ -1348,7 +1348,7 @@ in ); default = null; }; - auto_select_fill = lib.mkOption { + auto_select_text = lib.mkOption { type = ( lib.types.nullOr ( lib.types.oneOf [ diff --git a/nix/komorebi-options.nix b/nix/komorebi-options.nix index 23163b79..511d43f3 100644 --- a/nix/komorebi-options.nix +++ b/nix/komorebi-options.nix @@ -647,6 +647,11 @@ in lib.types.nullOr ( lib.types.submodule { options = { + column_ratios = lib.mkOption { + type = (lib.types.nullOr (lib.types.listOf (lib.types.nullOr lib.types.number))); + default = null; + description = "Column width ratios (up to MAX_RATIOS values between 0.1 and 0.9)\n\n- Used by Columns layout: ratios for each column width\n- Used by Grid layout: ratios for column widths\n- Used by BSP, VerticalStack, RightMainVerticalStack: column_ratios[0] as primary split ratio\n- Used by HorizontalStack: column_ratios[0] as primary split ratio (top area height)\n- Used by UltrawideVerticalStack: column_ratios[0] as center ratio, column_ratios[1] as left ratio\n\nColumns without a ratio share remaining space equally.\nExample: `[0.3, 0.4, 0.3]` for 30%-40%-30% columns"; + }; grid = lib.mkOption { type = ( lib.types.nullOr ( @@ -663,6 +668,11 @@ in default = null; description = "Options related to the Grid layout"; }; + row_ratios = lib.mkOption { + type = (lib.types.nullOr (lib.types.listOf (lib.types.nullOr lib.types.number))); + default = null; + description = "Row height ratios (up to MAX_RATIOS values between 0.1 and 0.9)\n\n- Used by Rows layout: ratios for each row height\n- Used by Grid layout: ratios for row heights\n\nRows without a ratio share remaining space equally.\nExample: `[0.5, 0.5]` for 50%-50% rows"; + }; scrolling = lib.mkOption { type = ( lib.types.nullOr ( @@ -789,7 +799,29 @@ in ); default = null; }; - bar_accent = lib.mkOption { + stack_border = lib.mkOption { + type = ( + lib.types.nullOr ( + lib.types.oneOf [ + (lib.types.nullOr catppuccinValue) + (lib.types.nullOr base16Value) + ] + ) + ); + default = null; + }; + single_border = lib.mkOption { + type = ( + lib.types.nullOr ( + lib.types.oneOf [ + (lib.types.nullOr catppuccinValue) + (lib.types.nullOr base16Value) + ] + ) + ); + default = null; + }; + unfocused_border = lib.mkOption { type = ( lib.types.nullOr ( lib.types.oneOf [ @@ -1097,39 +1129,6 @@ in ); default = null; }; - stack_border = lib.mkOption { - type = ( - lib.types.nullOr ( - lib.types.oneOf [ - (lib.types.nullOr catppuccinValue) - (lib.types.nullOr base16Value) - ] - ) - ); - default = null; - }; - monocle_border = lib.mkOption { - type = ( - lib.types.nullOr ( - lib.types.oneOf [ - (lib.types.nullOr catppuccinValue) - (lib.types.nullOr base16Value) - ] - ) - ); - default = null; - }; - single_border = lib.mkOption { - type = ( - lib.types.nullOr ( - lib.types.oneOf [ - (lib.types.nullOr catppuccinValue) - (lib.types.nullOr base16Value) - ] - ) - ); - default = null; - }; colours = lib.mkOption { type = ( lib.types.nullOr ( @@ -1205,7 +1204,18 @@ in ); default = null; }; - unfocused_border = lib.mkOption { + bar_accent = lib.mkOption { + type = ( + lib.types.nullOr ( + lib.types.oneOf [ + (lib.types.nullOr catppuccinValue) + (lib.types.nullOr base16Value) + ] + ) + ); + default = null; + }; + monocle_border = lib.mkOption { type = ( lib.types.nullOr ( lib.types.oneOf [ diff --git a/schema.bar.json b/schema.bar.json index 97478101..2fe4fff6 100644 --- a/schema.bar.json +++ b/schema.bar.json @@ -2196,50 +2196,49 @@ }, "DefaultLayout": { "description": "A predefined komorebi layout", - "default": "BSP", "oneOf": [ { - "description": "BSP Layout\n\n```\n+-------+-----+\n| | |\n| +--+--+\n| | |--|\n+-------+--+--+\n```", + "description": "BSP Layout\n\n```text\n+-------+-----+\n| | |\n| +--+--+\n| | |--|\n+-------+--+--+\n```", "type": "string", "const": "BSP" }, { - "description": "Columns Layout\n\n```\n+--+--+--+--+\n| | | | |\n| | | | |\n| | | | |\n+--+--+--+--+\n```", + "description": "Columns Layout\n\n```text\n+--+--+--+--+\n| | | | |\n| | | | |\n| | | | |\n+--+--+--+--+\n```", "type": "string", "const": "Columns" }, { - "description": "Rows Layout\n\n```\n+-----------+\n|-----------|\n|-----------|\n|-----------|\n+-----------+\n```", + "description": "Rows Layout\n\n```text\n+-----------+\n|-----------|\n|-----------|\n|-----------|\n+-----------+\n```", "type": "string", "const": "Rows" }, { - "description": "Vertical Stack Layout\n\n```\n+-------+-----+\n| | |\n| +-----+\n| | |\n+-------+-----+\n```", + "description": "Vertical Stack Layout\n\n```text\n+-------+-----+\n| | |\n| +-----+\n| | |\n+-------+-----+\n```", "type": "string", "const": "VerticalStack" }, { - "description": "Horizontal Stack Layout\n\n```\n+------+------+\n| |\n|------+------+\n| | |\n+------+------+\n```", + "description": "Horizontal Stack Layout\n\n```text\n+------+------+\n| |\n|------+------+\n| | |\n+------+------+\n```", "type": "string", "const": "HorizontalStack" }, { - "description": "Ultrawide Vertical Stack Layout\n\n```\n+-----+-----------+-----+\n| | | |\n| | +-----+\n| | | |\n| | +-----+\n| | | |\n+-----+-----------+-----+\n```", + "description": "Ultrawide Vertical Stack Layout\n\n```text\n+-----+-----------+-----+\n| | | |\n| | +-----+\n| | | |\n| | +-----+\n| | | |\n+-----+-----------+-----+\n```", "type": "string", "const": "UltrawideVerticalStack" }, { - "description": "Grid Layout\n\n```\n+-----+-----+ +---+---+---+ +---+---+---+ +---+---+---+\n| | | | | | | | | | | | | | |\n| | | | | | | | | | | | | +---+\n+-----+-----+ | +---+---+ +---+---+---+ +---+---| |\n| | | | | | | | | | | | | +---+\n| | | | | | | | | | | | | | |\n+-----+-----+ +---+---+---+ +---+---+---+ +---+---+---+\n 4 windows 5 windows 6 windows 7 windows\n```", + "description": "Grid Layout\n\n```text\n+-----+-----+ +---+---+---+ +---+---+---+ +---+---+---+\n| | | | | | | | | | | | | | |\n| | | | | | | | | | | | | +---+\n+-----+-----+ | +---+---+ +---+---+---+ +---+---| |\n| | | | | | | | | | | | | +---+\n| | | | | | | | | | | | | | |\n+-----+-----+ +---+---+---+ +---+---+---+ +---+---+---+\n 4 windows 5 windows 6 windows 7 windows\n```", "type": "string", "const": "Grid" }, { - "description": "Right Main Vertical Stack Layout\n\n```\n+-----+-------+\n| | |\n+-----+ |\n| | |\n+-----+-------+\n```", + "description": "Right Main Vertical Stack Layout\n\n```text\n+-----+-------+\n| | |\n+-----+ |\n| | |\n+-----+-------+\n```", "type": "string", "const": "RightMainVerticalStack" }, { - "description": "Scrolling Layout\n\n```\n+--+--+--+--+--+--+\n| | | |\n| | | |\n| | | |\n+--+--+--+--+--+--+\n```", + "description": "Scrolling Layout\n\n```text\n+--+--+--+--+--+--+\n| | | |\n| | | |\n| | | |\n+--+--+--+--+--+--+\n```", "type": "string", "const": "Scrolling" } diff --git a/schema.json b/schema.json index d09c9656..c1543f63 100644 --- a/schema.json +++ b/schema.json @@ -640,7 +640,7 @@ ] }, "Axis": { - "description": "An axis on which to perform an operation", + "description": "Axis on which to perform an operation", "oneOf": [ { "description": "Horizontal axis", @@ -2444,50 +2444,49 @@ }, "DefaultLayout": { "description": "A predefined komorebi layout", - "default": "BSP", "oneOf": [ { - "description": "BSP Layout\n\n```\n+-------+-----+\n| | |\n| +--+--+\n| | |--|\n+-------+--+--+\n```", + "description": "BSP Layout\n\n```text\n+-------+-----+\n| | |\n| +--+--+\n| | |--|\n+-------+--+--+\n```", "type": "string", "const": "BSP" }, { - "description": "Columns Layout\n\n```\n+--+--+--+--+\n| | | | |\n| | | | |\n| | | | |\n+--+--+--+--+\n```", + "description": "Columns Layout\n\n```text\n+--+--+--+--+\n| | | | |\n| | | | |\n| | | | |\n+--+--+--+--+\n```", "type": "string", "const": "Columns" }, { - "description": "Rows Layout\n\n```\n+-----------+\n|-----------|\n|-----------|\n|-----------|\n+-----------+\n```", + "description": "Rows Layout\n\n```text\n+-----------+\n|-----------|\n|-----------|\n|-----------|\n+-----------+\n```", "type": "string", "const": "Rows" }, { - "description": "Vertical Stack Layout\n\n```\n+-------+-----+\n| | |\n| +-----+\n| | |\n+-------+-----+\n```", + "description": "Vertical Stack Layout\n\n```text\n+-------+-----+\n| | |\n| +-----+\n| | |\n+-------+-----+\n```", "type": "string", "const": "VerticalStack" }, { - "description": "Horizontal Stack Layout\n\n```\n+------+------+\n| |\n|------+------+\n| | |\n+------+------+\n```", + "description": "Horizontal Stack Layout\n\n```text\n+------+------+\n| |\n|------+------+\n| | |\n+------+------+\n```", "type": "string", "const": "HorizontalStack" }, { - "description": "Ultrawide Vertical Stack Layout\n\n```\n+-----+-----------+-----+\n| | | |\n| | +-----+\n| | | |\n| | +-----+\n| | | |\n+-----+-----------+-----+\n```", + "description": "Ultrawide Vertical Stack Layout\n\n```text\n+-----+-----------+-----+\n| | | |\n| | +-----+\n| | | |\n| | +-----+\n| | | |\n+-----+-----------+-----+\n```", "type": "string", "const": "UltrawideVerticalStack" }, { - "description": "Grid Layout\n\n```\n+-----+-----+ +---+---+---+ +---+---+---+ +---+---+---+\n| | | | | | | | | | | | | | |\n| | | | | | | | | | | | | +---+\n+-----+-----+ | +---+---+ +---+---+---+ +---+---| |\n| | | | | | | | | | | | | +---+\n| | | | | | | | | | | | | | |\n+-----+-----+ +---+---+---+ +---+---+---+ +---+---+---+\n 4 windows 5 windows 6 windows 7 windows\n```", + "description": "Grid Layout\n\n```text\n+-----+-----+ +---+---+---+ +---+---+---+ +---+---+---+\n| | | | | | | | | | | | | | |\n| | | | | | | | | | | | | +---+\n+-----+-----+ | +---+---+ +---+---+---+ +---+---| |\n| | | | | | | | | | | | | +---+\n| | | | | | | | | | | | | | |\n+-----+-----+ +---+---+---+ +---+---+---+ +---+---+---+\n 4 windows 5 windows 6 windows 7 windows\n```", "type": "string", "const": "Grid" }, { - "description": "Right Main Vertical Stack Layout\n\n```\n+-----+-------+\n| | |\n+-----+ |\n| | |\n+-----+-------+\n```", + "description": "Right Main Vertical Stack Layout\n\n```text\n+-----+-------+\n| | |\n+-----+ |\n| | |\n+-----+-------+\n```", "type": "string", "const": "RightMainVerticalStack" }, { - "description": "Scrolling Layout\n\n```\n+--+--+--+--+--+--+\n| | | |\n| | | |\n| | | |\n+--+--+--+--+--+--+\n```", + "description": "Scrolling Layout\n\n```text\n+--+--+--+--+--+--+\n| | | |\n| | | |\n| | | |\n+--+--+--+--+--+--+\n```", "type": "string", "const": "Scrolling" } @@ -2902,6 +2901,23 @@ "description": "Options for specific layouts", "type": "object", "properties": { + "column_ratios": { + "description": "Column width ratios (up to MAX_RATIOS values between 0.1 and 0.9)\n\n- Used by Columns layout: ratios for each column width\n- Used by Grid layout: ratios for column widths\n- Used by BSP, VerticalStack, RightMainVerticalStack: column_ratios[0] as primary split ratio\n- Used by HorizontalStack: column_ratios[0] as primary split ratio (top area height)\n- Used by UltrawideVerticalStack: column_ratios[0] as center ratio, column_ratios[1] as left ratio\n\nColumns without a ratio share remaining space equally.\nExample: `[0.3, 0.4, 0.3]` for 30%-40%-30% columns", + "type": [ + "array", + "null" + ], + "default": null, + "items": { + "type": [ + "number", + "null" + ], + "format": "float" + }, + "maxItems": 5, + "minItems": 5 + }, "grid": { "description": "Options related to the Grid layout", "anyOf": [ @@ -2913,6 +2929,23 @@ } ] }, + "row_ratios": { + "description": "Row height ratios (up to MAX_RATIOS values between 0.1 and 0.9)\n\n- Used by Rows layout: ratios for each row height\n- Used by Grid layout: ratios for row heights\n\nRows without a ratio share remaining space equally.\nExample: `[0.5, 0.5]` for 50%-50% rows", + "type": [ + "array", + "null" + ], + "default": null, + "items": { + "type": [ + "number", + "null" + ], + "format": "float" + }, + "maxItems": 5, + "minItems": 5 + }, "scrolling": { "description": "Options related to the Scrolling layout", "anyOf": [