diff --git a/Cargo.lock b/Cargo.lock index d3fae2a5..63db4d98 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3134,6 +3134,7 @@ dependencies = [ "dirs 6.0.0", "ed25519-dalek", "hotwatch", + "komorebi-layouts", "komorebi-themes", "lazy_static", "miow", @@ -3231,6 +3232,21 @@ dependencies = [ "windows-core 0.62.2", ] +[[package]] +name = "komorebi-layouts" +version = "0.1.40" +dependencies = [ + "clap", + "color-eyre", + "schemars 1.2.1", + "serde", + "serde_json_lenient", + "serde_yaml 0.9.34+deprecated", + "strum", + "tracing", + "windows 0.62.2", +] + [[package]] name = "komorebi-shortcuts" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index e71a4fba..f15c82b0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,7 @@ members = [ "komorebi", "komorebi-client", "komorebi-gui", + "komorebi-layouts", "komorebic", "komorebic-no-console", "komorebi-bar", diff --git a/komorebi-layouts/Cargo.toml b/komorebi-layouts/Cargo.toml new file mode 100644 index 00000000..c6858df4 --- /dev/null +++ b/komorebi-layouts/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "komorebi-layouts" +version = "0.1.40" +edition = "2024" + +[dependencies] +clap = { workspace = true } +color-eyre = { workspace = true } +serde = { workspace = true } +serde_json = { workspace = true } +serde_yaml = { workspace = true } +strum = { workspace = true } +tracing = { workspace = true } + +# Optional dependencies +schemars = { workspace = true, optional = true } +windows = { workspace = true, optional = true } + +[features] +schemars = ["dep:schemars"] +win32 = ["dep:windows"] diff --git a/komorebi/src/core/arrangement.rs b/komorebi-layouts/src/arrangement.rs similarity index 100% rename from komorebi/src/core/arrangement.rs rename to komorebi-layouts/src/arrangement.rs diff --git a/komorebi/src/core/custom_layout.rs b/komorebi-layouts/src/custom_layout.rs similarity index 100% rename from komorebi/src/core/custom_layout.rs rename to komorebi-layouts/src/custom_layout.rs diff --git a/komorebi/src/core/cycle_direction.rs b/komorebi-layouts/src/cycle_direction.rs similarity index 100% rename from komorebi/src/core/cycle_direction.rs rename to komorebi-layouts/src/cycle_direction.rs diff --git a/komorebi/src/core/default_layout.rs b/komorebi-layouts/src/default_layout.rs similarity index 100% rename from komorebi/src/core/default_layout.rs rename to komorebi-layouts/src/default_layout.rs diff --git a/komorebi/src/core/direction.rs b/komorebi-layouts/src/direction.rs similarity index 100% rename from komorebi/src/core/direction.rs rename to komorebi-layouts/src/direction.rs diff --git a/komorebi/src/core/layout.rs b/komorebi-layouts/src/layout.rs similarity index 100% rename from komorebi/src/core/layout.rs rename to komorebi-layouts/src/layout.rs diff --git a/komorebi-layouts/src/lib.rs b/komorebi-layouts/src/lib.rs new file mode 100644 index 00000000..d2368c1e --- /dev/null +++ b/komorebi-layouts/src/lib.rs @@ -0,0 +1,28 @@ +#![warn(clippy::all)] +#![allow(clippy::missing_errors_doc, clippy::use_self, clippy::doc_markdown)] + +//! Layout system for the komorebi window manager. +//! +//! This crate provides the core layout algorithms and types for arranging windows +//! in various configurations. It includes optional Windows-specific functionality +//! behind the `win32` feature flag. + +pub mod arrangement; +pub mod custom_layout; +pub mod cycle_direction; +pub mod default_layout; +pub mod direction; +pub mod layout; +pub mod operation_direction; +pub mod rect; +pub mod sizing; + +pub use arrangement::*; +pub use custom_layout::*; +pub use cycle_direction::*; +pub use default_layout::*; +pub use direction::*; +pub use layout::*; +pub use operation_direction::*; +pub use rect::*; +pub use sizing::*; diff --git a/komorebi/src/core/operation_direction.rs b/komorebi-layouts/src/operation_direction.rs similarity index 100% rename from komorebi/src/core/operation_direction.rs rename to komorebi-layouts/src/operation_direction.rs diff --git a/komorebi/src/core/rect.rs b/komorebi-layouts/src/rect.rs similarity index 96% rename from komorebi/src/core/rect.rs rename to komorebi-layouts/src/rect.rs index fb12109f..33e0279c 100644 --- a/komorebi/src/core/rect.rs +++ b/komorebi-layouts/src/rect.rs @@ -1,5 +1,7 @@ use serde::Deserialize; use serde::Serialize; + +#[cfg(feature = "win32")] use windows::Win32::Foundation::RECT; #[derive(Debug, Default, Clone, Copy, Serialize, Deserialize, Eq, PartialEq)] @@ -16,6 +18,7 @@ pub struct Rect { pub bottom: i32, } +#[cfg(feature = "win32")] impl From for Rect { fn from(rect: RECT) -> Self { Self { @@ -27,6 +30,7 @@ impl From for Rect { } } +#[cfg(feature = "win32")] impl From for RECT { fn from(rect: Rect) -> Self { Self { @@ -96,6 +100,7 @@ impl Rect { } } + #[cfg(feature = "win32")] #[must_use] pub const fn rect(&self) -> RECT { RECT { diff --git a/komorebi-layouts/src/sizing.rs b/komorebi-layouts/src/sizing.rs new file mode 100644 index 00000000..cd2e1fd0 --- /dev/null +++ b/komorebi-layouts/src/sizing.rs @@ -0,0 +1,31 @@ +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))] +/// Sizing +pub enum Sizing { + /// Increase + Increase, + /// Decrease + 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 + } + } + } + } +} diff --git a/komorebi/Cargo.toml b/komorebi/Cargo.toml index 60cdb059..7102f3d8 100644 --- a/komorebi/Cargo.toml +++ b/komorebi/Cargo.toml @@ -8,6 +8,7 @@ edition = "2024" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +komorebi-layouts = { path = "../komorebi-layouts", features = ["win32"] } komorebi-themes = { path = "../komorebi-themes" } base64 = "0.22" @@ -63,4 +64,4 @@ uuid = { version = "1", features = ["v4"] } [features] default = ["schemars"] deadlock_detection = ["parking_lot/deadlock_detection"] -schemars = ["dep:schemars"] +schemars = ["dep:schemars", "komorebi-layouts/schemars"] diff --git a/komorebi/src/core/mod.rs b/komorebi/src/core/mod.rs index 4193e347..364bcd4c 100644 --- a/komorebi/src/core/mod.rs +++ b/komorebi/src/core/mod.rs @@ -15,37 +15,42 @@ use strum::EnumString; use crate::KomorebiTheme; use crate::animation::prefix::AnimationPrefix; + +// Re-export everything from komorebi-layouts +pub use komorebi_layouts::Arrangement; +pub use komorebi_layouts::Axis; +pub use komorebi_layouts::Column; +pub use komorebi_layouts::ColumnSplit; +pub use komorebi_layouts::ColumnSplitWithCapacity; +pub use komorebi_layouts::ColumnWidth; +pub use komorebi_layouts::CustomLayout; +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; + +// Local modules and exports pub use animation::AnimationStyle; -pub use arrangement::Arrangement; -pub use arrangement::Axis; -pub use custom_layout::Column; -pub use custom_layout::ColumnSplit; -pub use custom_layout::ColumnSplitWithCapacity; -pub use custom_layout::ColumnWidth; -pub use custom_layout::CustomLayout; -pub use cycle_direction::CycleDirection; -pub use default_layout::*; -pub use direction::Direction; -pub use layout::Layout; -pub use operation_direction::OperationDirection; pub use pathext::PathExt; pub use pathext::ResolvedPathBuf; pub use pathext::replace_env_in_path; pub use pathext::resolve_option_hashmap_usize_path; -pub use rect::Rect; pub mod animation; -pub mod arrangement; pub mod asc; pub mod config_generation; -pub mod custom_layout; -pub mod cycle_direction; -pub mod default_layout; -pub mod direction; -pub mod layout; -pub mod operation_direction; pub mod pathext; -pub mod rect; // serde_as must be before derive #[serde_with::serde_as] @@ -545,32 +550,6 @@ pub enum OperationBehaviour { NoOp, } -#[derive(Clone, Copy, Debug, Serialize, Deserialize, Display, EnumString, ValueEnum)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// Sizing -pub enum Sizing { - /// Increase - Increase, - /// Decrease - 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, Display, EnumString, ValueEnum, PartialEq, )] diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index a0bd4aa4..136c048f 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -60,9 +60,11 @@ use crate::core::Axis; use crate::core::BorderImplementation; use crate::core::FocusFollowsMouseImplementation; 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::Sizing; use crate::core::SocketMessage; use crate::core::StateQuery; @@ -72,8 +74,6 @@ use crate::core::config_generation::IdWithIdentifier; use crate::core::config_generation::MatchingRule; use crate::core::config_generation::MatchingStrategy; use crate::current_virtual_desktop; -use crate::default_layout::LayoutOptions; -use crate::default_layout::ScrollingLayoutOptions; use crate::monitor::MonitorInformation; use crate::notify_subscribers; use crate::stackbar_manager; diff --git a/komorebi/src/static_config.rs b/komorebi/src/static_config.rs index e1627492..8a30bdae 100644 --- a/komorebi/src/static_config.rs +++ b/komorebi/src/static_config.rs @@ -53,6 +53,7 @@ use crate::core::DefaultLayout; use crate::core::FocusFollowsMouseImplementation; use crate::core::HidingBehaviour; use crate::core::Layout; +use crate::core::LayoutOptions; use crate::core::MoveBehaviour; use crate::core::OperationBehaviour; use crate::core::Rect; @@ -67,7 +68,6 @@ use crate::core::config_generation::ApplicationOptions; use crate::core::config_generation::MatchingRule; use crate::core::config_generation::MatchingStrategy; use crate::current_virtual_desktop; -use crate::default_layout::LayoutOptions; use crate::monitor; use crate::monitor::Monitor; use crate::monitor_reconciliator; diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index 5559cf13..e85a7849 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -28,6 +28,7 @@ use crate::animation::AnimationEngine; use crate::core::Arrangement; use crate::core::Axis; use crate::core::BorderImplementation; +use crate::core::CustomLayout; use crate::core::CycleDirection; use crate::core::DefaultLayout; use crate::core::FocusFollowsMouseImplementation; @@ -40,7 +41,6 @@ use crate::core::Sizing; use crate::core::WindowContainerBehaviour; use crate::core::WindowManagementBehaviour; use crate::core::config_generation::MatchingRule; -use crate::core::custom_layout::CustomLayout; use crate::CrossBoundaryBehaviour; use crate::DATA_DIR; diff --git a/komorebi/src/workspace.rs b/komorebi/src/workspace.rs index b9e4d5be..0fda4704 100644 --- a/komorebi/src/workspace.rs +++ b/komorebi/src/workspace.rs @@ -25,9 +25,9 @@ use crate::core::CustomLayout; use crate::core::CycleDirection; use crate::core::DefaultLayout; use crate::core::Layout; +use crate::core::LayoutOptions; use crate::core::OperationDirection; use crate::core::Rect; -use crate::default_layout::LayoutOptions; use crate::lockable_sequence::LockableSequence; use crate::ring::Ring; use crate::should_act;