diff --git a/Cargo.lock b/Cargo.lock index 790cdc6e0..7d3e9b964 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -26,6 +26,18 @@ dependencies = [ "memchr", ] +[[package]] +name = "ambassador" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b27ba24e4d8a188489d5a03c7fabc167a60809a383cdb4d15feb37479cd2a48" +dependencies = [ + "itertools", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "anstream" version = "0.6.14" @@ -428,6 +440,12 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f25c0e292a7ca6d6498557ff1df68f32c99850012b6ea401cf8daf771f22ff53" +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + [[package]] name = "embed-resource" version = "2.4.2" @@ -454,18 +472,6 @@ dependencies = [ "syn 2.0.67", ] -[[package]] -name = "enum_dispatch" -version = "0.3.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa18ce2bc66555b3218614519ac839ddb759a7d6720732f979ef8d13be147ecd" -dependencies = [ - "once_cell", - "proc-macro2", - "quote", - "syn 2.0.67", -] - [[package]] name = "equivalent" version = "1.0.1" @@ -916,6 +922,15 @@ version = "1.70.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.11" @@ -1571,6 +1586,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ "proc-macro2", + "quote", "unicode-ident", ] @@ -2258,10 +2274,10 @@ dependencies = [ name = "wm" version = "0.0.0" dependencies = [ + "ambassador", "anyhow", "clap", "enum-as-inner", - "enum_dispatch", "futures-util", "home", "regex", diff --git a/packages/wm/Cargo.toml b/packages/wm/Cargo.toml index c38ca084a..1ed4b3bb1 100644 --- a/packages/wm/Cargo.toml +++ b/packages/wm/Cargo.toml @@ -24,7 +24,7 @@ tauri-winres = { workspace = true } [dependencies] anyhow = { workspace = true } clap = { version = "4", features = ["derive"] } -enum_dispatch = "0.3" +ambassador = "0.4.1" enum-as-inner = "0.6" futures-util = "0.3" home = "0.5" diff --git a/packages/wm/src/containers/container.rs b/packages/wm/src/containers/container.rs index fbb373e53..75d0776b9 100644 --- a/packages/wm/src/containers/container.rs +++ b/packages/wm/src/containers/container.rs @@ -1,16 +1,31 @@ +use std::{ + cell::{Ref, RefMut}, + collections::VecDeque, +}; + +use ambassador::Delegate; use enum_as_inner::EnumAsInner; -use enum_dispatch::enum_dispatch; +use uuid::Uuid; -use super::{traits::CommonGetters, RootContainer, SplitContainer}; +use super::{RootContainer, SplitContainer}; use crate::{ + common::{ + platform::NativeWindow, Direction, DisplayState, LengthValue, Rect, + RectDelta, TilingDirection, + }, + containers::{traits::*, ContainerDto}, monitors::Monitor, - windows::{NonTilingWindow, TilingWindow}, + user_config::{UserConfig, WindowRuleConfig}, + windows::{ + traits::*, ActiveDrag, NonTilingWindow, TilingWindow, WindowState, + }, workspaces::Workspace, }; /// A container of any type. -#[derive(Clone, Debug, EnumAsInner)] -#[enum_dispatch(CommonGetters, PositionGetters)] +#[derive(Clone, Debug, EnumAsInner, Delegate)] // <------- +#[delegate(CommonGetters)] +#[delegate(PositionGetters)] pub enum Container { Root(RootContainer), Monitor(Monitor), @@ -20,6 +35,21 @@ pub enum Container { NonTilingWindow(NonTilingWindow), } +impl From for Container{ + fn from(value: SplitContainer) -> Self { + Container::Split(value) + } +} +impl From for Container { + fn from(value: Workspace) -> Self { + Container::Workspace(value) + } +} +impl From for Container{ + fn from(value: RootContainer) -> Self { + Container::Root(value) + } +} impl From for Container { fn from(tiling_container: TilingContainer) -> Self { match tiling_container { @@ -59,13 +89,27 @@ impl Eq for Container {} /// * `CommonGetters` /// * `PositionGetters` /// * `TilingSizeGetters` -#[derive(Clone, Debug, EnumAsInner)] -#[enum_dispatch(CommonGetters, PositionGetters, TilingSizeGetters)] +#[derive(Clone, Debug, EnumAsInner, Delegate)] +#[delegate(CommonGetters)] +#[delegate(PositionGetters)] +#[delegate(TilingSizeGetters)] pub enum TilingContainer { Split(SplitContainer), TilingWindow(TilingWindow), } +impl From for TilingContainer{ + fn from(value: SplitContainer) -> Self { + TilingContainer::Split(value) + } +} + +impl From for TilingContainer{ + fn from(value: TilingWindow) -> Self { + TilingContainer::TilingWindow(value) + } +} + impl TryFrom for TilingContainer { type Error = &'static str; @@ -90,13 +134,44 @@ impl Eq for TilingContainer {} /// * `CommonGetters` /// * `PositionGetters` /// * `WindowGetters` -#[derive(Clone, Debug, EnumAsInner)] -#[enum_dispatch(CommonGetters, PositionGetters, WindowGetters)] +#[derive(Clone, Debug, EnumAsInner, Delegate)] +#[delegate(CommonGetters)] +#[delegate(PositionGetters)] +#[delegate(WindowGetters)] pub enum WindowContainer { TilingWindow(TilingWindow), NonTilingWindow(NonTilingWindow), } +impl From for WindowContainer{ + fn from(value: TilingWindow) -> Self { + WindowContainer::TilingWindow(value) + } +} + +impl From for WindowContainer{ + fn from(value: NonTilingWindow) -> Self { + WindowContainer::NonTilingWindow(value) + } +} +impl From for Container { + fn from(value: NonTilingWindow) -> Self { + Container::NonTilingWindow(value) + } +} + +impl From for Container { + fn from(value: Monitor) -> Self { + Container::Monitor(value) + } +} + +impl From for Container{ + fn from(value: TilingWindow) -> Self { + Container::TilingWindow(value) + } +} + impl TryFrom for WindowContainer { type Error = &'static str; @@ -136,13 +211,27 @@ impl Eq for WindowContainer {} /// * `CommonGetters` /// * `PositionGetters` /// * `TilingDirectionGetters` -#[derive(Clone, Debug, EnumAsInner)] -#[enum_dispatch(CommonGetters, PositionGetters, TilingDirectionGetters)] +#[derive(Clone, Debug, EnumAsInner, Delegate)] +#[delegate(CommonGetters)] +#[delegate(PositionGetters)] +#[delegate(TilingDirectionGetters)] pub enum DirectionContainer { Workspace(Workspace), Split(SplitContainer), } +impl From for DirectionContainer{ + fn from(value: SplitContainer) -> Self { + DirectionContainer::Split(value) + } +} + +impl From for DirectionContainer { + fn from(value: Workspace) -> Self { + DirectionContainer::Workspace(value) + } +} + impl TryFrom for DirectionContainer { type Error = &'static str; diff --git a/packages/wm/src/containers/traits/common_getters.rs b/packages/wm/src/containers/traits/common_getters.rs index 3bfe6861e..57a662c15 100644 --- a/packages/wm/src/containers/traits/common_getters.rs +++ b/packages/wm/src/containers/traits/common_getters.rs @@ -2,8 +2,7 @@ use std::{ cell::{Ref, RefMut}, collections::VecDeque, }; - -use enum_dispatch::enum_dispatch; +use ambassador::delegatable_trait; use uuid::Uuid; use crate::{ @@ -16,7 +15,7 @@ use crate::{ workspaces::Workspace, }; -#[enum_dispatch] +#[delegatable_trait] pub trait CommonGetters { /// A unique identifier for the container. fn id(&self) -> Uuid; diff --git a/packages/wm/src/containers/traits/position_getters.rs b/packages/wm/src/containers/traits/position_getters.rs index 456999834..0ed6e12f2 100644 --- a/packages/wm/src/containers/traits/position_getters.rs +++ b/packages/wm/src/containers/traits/position_getters.rs @@ -1,4 +1,4 @@ -use enum_dispatch::enum_dispatch; +use ambassador::delegatable_trait; use crate::{ common::Rect, @@ -7,7 +7,7 @@ use crate::{ }, }; -#[enum_dispatch] +#[delegatable_trait] pub trait PositionGetters { fn to_rect(&self) -> anyhow::Result; } diff --git a/packages/wm/src/containers/traits/tiling_direction_getters.rs b/packages/wm/src/containers/traits/tiling_direction_getters.rs index a53867c8f..d02333392 100644 --- a/packages/wm/src/containers/traits/tiling_direction_getters.rs +++ b/packages/wm/src/containers/traits/tiling_direction_getters.rs @@ -1,5 +1,4 @@ -use enum_dispatch::enum_dispatch; - +use ambassador::delegatable_trait; use super::CommonGetters; use crate::{ common::{Direction, TilingDirection}, @@ -7,7 +6,7 @@ use crate::{ windows::TilingWindow, }; -#[enum_dispatch] +#[delegatable_trait] pub trait TilingDirectionGetters: CommonGetters { fn tiling_direction(&self) -> TilingDirection; diff --git a/packages/wm/src/containers/traits/tiling_size_getters.rs b/packages/wm/src/containers/traits/tiling_size_getters.rs index 13efb0dcb..0caf56fd3 100644 --- a/packages/wm/src/containers/traits/tiling_size_getters.rs +++ b/packages/wm/src/containers/traits/tiling_size_getters.rs @@ -1,5 +1,5 @@ +use ambassador::delegatable_trait; use anyhow::Context; -use enum_dispatch::enum_dispatch; use super::{CommonGetters, TilingDirectionGetters}; use crate::{ @@ -7,7 +7,7 @@ use crate::{ containers::{Container, DirectionContainer, TilingContainer}, }; -#[enum_dispatch] +#[delegatable_trait] pub trait TilingSizeGetters: CommonGetters { fn tiling_size(&self) -> f32; diff --git a/packages/wm/src/windows/traits/window_getters.rs b/packages/wm/src/windows/traits/window_getters.rs index c86c4761d..bdaeac9f3 100644 --- a/packages/wm/src/windows/traits/window_getters.rs +++ b/packages/wm/src/windows/traits/window_getters.rs @@ -1,7 +1,5 @@ use std::cell::Ref; - -use enum_dispatch::enum_dispatch; - +use ambassador::delegatable_trait; use crate::{ common::{ platform::NativeWindow, DisplayState, LengthValue, Rect, RectDelta, @@ -11,7 +9,7 @@ use crate::{ windows::{active_drag::ActiveDrag, WindowState}, }; -#[enum_dispatch] +#[delegatable_trait] pub trait WindowGetters { fn state(&self) -> WindowState;