diff --git a/Cargo.lock b/Cargo.lock index 6d193c4e..67dbf613 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3445,10 +3445,12 @@ version = "0.1.42" dependencies = [ "chrono", "chrono-tz", + "color-eyre", "eframe", "egui-phosphor", "image 0.25.10", "komorebi-config", + "komorebi-layouts", "komorebi-protocol", "lazy_static", "reqwest", diff --git a/crates/komorebi-bar-core/Cargo.toml b/crates/komorebi-bar-core/Cargo.toml index f40abaa2..d5ad8e6e 100644 --- a/crates/komorebi-bar-core/Cargo.toml +++ b/crates/komorebi-bar-core/Cargo.toml @@ -13,8 +13,10 @@ lazy_static = { workspace = true } image = "0.25" komorebi-config = { path = "../komorebi-config", default-features = false } reqwest = { version = "0.12", features = ["blocking"] } +komorebi-layouts = { path = "../../komorebi-layouts" } komorebi-protocol = { path = "../komorebi-protocol", default-features = false } serde = { workspace = true } +color-eyre = { workspace = true } serde_json = { workspace = true, features = ["preserve_order"] } starship-battery = "0.11" sysinfo = { workspace = true } @@ -25,4 +27,4 @@ schemars = { workspace = true, optional = true } [features] default = ["schemars"] -schemars = ["dep:schemars", "komorebi-config/schemars", "komorebi-protocol/schemars"] +schemars = ["dep:schemars", "komorebi-config/schemars", "komorebi-layouts/schemars", "komorebi-protocol/schemars"] diff --git a/crates/komorebi-bar-core/src/widgets/komorebi_config.rs b/crates/komorebi-bar-core/src/widgets/komorebi_config.rs new file mode 100644 index 00000000..ab75ca74 --- /dev/null +++ b/crates/komorebi-bar-core/src/widgets/komorebi_config.rs @@ -0,0 +1,158 @@ +//! The configuration of the komorebi widgets (workspaces, layout, focused container, ...) and +//! the layout kind the layout widget shows: data only, shared by both bars. + +use crate::config::DisplayFormat; +use crate::config::WorkspacesDisplayFormat; +use color_eyre::eyre; +use serde::Deserialize; +use serde::Deserializer; +use serde::Serialize; +use serde::de::Error; +use serde_json::from_str; +use std::collections::BTreeMap; +use std::fmt::Display; +use std::fmt::Formatter; + +#[derive(Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] +/// Komorebi widget configuration +pub struct KomorebiConfig { + /// Configure the Workspaces widget + pub workspaces: Option, + /// Configure the Layout widget + pub layout: Option, + /// Configure the Workspace Layer widget + pub workspace_layer: Option, + /// Configure the Focused Container widget + #[serde(alias = "focused_window")] + pub focused_container: Option, + /// Configure the Locked Container widget + pub locked_container: Option, + /// Configure the Configuration Switcher widget + pub configuration_switcher: Option, +} + +#[derive(Copy, Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] +/// Komorebi widget workspaces configuration +pub struct KomorebiWorkspacesConfig { + /// Enable the Komorebi Workspaces widget + pub enable: bool, + /// Hide workspaces without any windows + pub hide_empty_workspaces: bool, + /// Display format of the workspace + pub display: Option, +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] +/// Komorebi widget layout configuration +pub struct KomorebiLayoutConfig { + /// Enable the Komorebi Layout widget + pub enable: bool, + /// List of layout options + pub options: Option>, + /// Display format of the current layout + pub display: Option, +} + +#[derive(Copy, Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] +/// Komorebi widget workspace layer configuration +pub struct KomorebiWorkspaceLayerConfig { + /// Enable the Komorebi Workspace Layer widget + pub enable: bool, + /// Display format of the current layer + pub display: Option, + /// Show the widget event if the layer is Tiling + pub show_when_tiling: Option, +} + +#[derive(Copy, Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] +/// Komorebi widget focused container configuration +pub struct KomorebiFocusedContainerConfig { + /// Enable the Komorebi Focused Container widget + pub enable: bool, + /// DEPRECATED: use `display` instead (Show the icon of the currently focused container) + #[deprecated(note = "Use `display` instead")] + pub show_icon: Option, + /// Display format of the currently focused container + pub display: Option, +} + +#[derive(Copy, Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] +/// Komorebi widget locked container configuration +pub struct KomorebiLockedContainerConfig { + /// Enable the Komorebi Locked Container widget + pub enable: bool, + /// Display format of the current locked state + pub display: Option, + /// Show the widget event if the layer is unlocked + pub show_when_unlocked: Option, +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] +/// Komorebi widget configuration switcher configuration +pub struct KomorebiConfigurationSwitcherConfig { + /// Enable the Komorebi Configurations widget + pub enable: bool, + /// A map of display friendly name => path to configuration.json + pub configurations: BTreeMap, +} + +#[derive(Copy, Clone, Debug, Serialize, PartialEq)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] +#[serde(untagged)] +/// Komorebi layout kind +pub enum KomorebiLayout { + /// Predefined layout + #[cfg_attr(feature = "schemars", schemars(title = "Default"))] + Default(komorebi_layouts::DefaultLayout), + /// Monocle mode + Monocle, + /// Floating layer + Floating, + /// Paused + Paused, + /// Custom layout + Custom, +} + +impl<'de> Deserialize<'de> for KomorebiLayout { + fn deserialize(deserializer: D) -> eyre::Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + + // Attempt to deserialize the string as a DefaultLayout + if let Ok(default_layout) = from_str::(&format!("\"{s}\"")) + { + return Ok(KomorebiLayout::Default(default_layout)); + } + + // Handle other cases + match s.as_str() { + "Monocle" => Ok(KomorebiLayout::Monocle), + "Floating" => Ok(KomorebiLayout::Floating), + "Paused" => Ok(KomorebiLayout::Paused), + "Custom" => Ok(KomorebiLayout::Custom), + _ => Err(Error::custom(format!("Invalid layout: {s}"))), + } + } +} + +impl Display for KomorebiLayout { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + match self { + KomorebiLayout::Default(layout) => write!(f, "{layout}"), + KomorebiLayout::Monocle => write!(f, "Monocle"), + KomorebiLayout::Floating => write!(f, "Floating"), + KomorebiLayout::Paused => write!(f, "Paused"), + KomorebiLayout::Custom => write!(f, "Custom"), + } + } +} diff --git a/crates/komorebi-bar-core/src/widgets/mod.rs b/crates/komorebi-bar-core/src/widgets/mod.rs index cda332df..1e786dae 100644 --- a/crates/komorebi-bar-core/src/widgets/mod.rs +++ b/crates/komorebi-bar-core/src/widgets/mod.rs @@ -3,6 +3,7 @@ pub mod battery; pub mod cpu; pub mod date; pub mod icons; +pub mod komorebi_config; pub mod memory; pub mod platform_config; pub mod storage; diff --git a/komorebi-bar/src/widgets/komorebi.rs b/komorebi-bar/src/widgets/komorebi.rs index a9a3a1f1..1dba3200 100644 --- a/komorebi-bar/src/widgets/komorebi.rs +++ b/komorebi-bar/src/widgets/komorebi.rs @@ -7,7 +7,7 @@ use crate::config::WorkspacesDisplayFormat; use crate::render::RenderConfig; use crate::selected_frame::SelectableFrame; use crate::ui::CustomUi; -use crate::widgets::komorebi_layout::KomorebiLayout; +use crate::widgets::komorebi_layout::KomorebiLayoutExt; use crate::widgets::widget::BarWidget; use eframe::egui::Align; use eframe::egui::Color32; @@ -28,6 +28,14 @@ use eframe::egui::Ui; use eframe::egui::Vec2; use eframe::egui::text::LayoutJob; use eframe::egui::vec2; +pub use komorebi_bar_core::widgets::komorebi_config::KomorebiConfig; +pub use komorebi_bar_core::widgets::komorebi_config::KomorebiConfigurationSwitcherConfig; +pub use komorebi_bar_core::widgets::komorebi_config::KomorebiFocusedContainerConfig; +pub use komorebi_bar_core::widgets::komorebi_config::KomorebiLayout; +pub use komorebi_bar_core::widgets::komorebi_config::KomorebiLayoutConfig; +pub use komorebi_bar_core::widgets::komorebi_config::KomorebiLockedContainerConfig; +pub use komorebi_bar_core::widgets::komorebi_config::KomorebiWorkspaceLayerConfig; +pub use komorebi_bar_core::widgets::komorebi_config::KomorebiWorkspacesConfig; use komorebi_client::Container; use komorebi_client::PathExt; use komorebi_client::Rect; @@ -37,106 +45,13 @@ use komorebi_client::State; use komorebi_client::Window; use komorebi_client::Workspace; use komorebi_client::WorkspaceLayer; -use serde::Deserialize; -use serde::Serialize; use std::cell::RefCell; -use std::collections::BTreeMap; use std::collections::HashMap; use std::io::Result as IoResult; use std::path::Path; use std::rc::Rc; use std::sync::atomic::Ordering; -#[derive(Clone, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// Komorebi widget configuration -pub struct KomorebiConfig { - /// Configure the Workspaces widget - pub workspaces: Option, - /// Configure the Layout widget - pub layout: Option, - /// Configure the Workspace Layer widget - pub workspace_layer: Option, - /// Configure the Focused Container widget - #[serde(alias = "focused_window")] - pub focused_container: Option, - /// Configure the Locked Container widget - pub locked_container: Option, - /// Configure the Configuration Switcher widget - pub configuration_switcher: Option, -} - -#[derive(Copy, Clone, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// Komorebi widget workspaces configuration -pub struct KomorebiWorkspacesConfig { - /// Enable the Komorebi Workspaces widget - pub enable: bool, - /// Hide workspaces without any windows - pub hide_empty_workspaces: bool, - /// Display format of the workspace - pub display: Option, -} - -#[derive(Clone, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// Komorebi widget layout configuration -pub struct KomorebiLayoutConfig { - /// Enable the Komorebi Layout widget - pub enable: bool, - /// List of layout options - pub options: Option>, - /// Display format of the current layout - pub display: Option, -} - -#[derive(Copy, Clone, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// Komorebi widget workspace layer configuration -pub struct KomorebiWorkspaceLayerConfig { - /// Enable the Komorebi Workspace Layer widget - pub enable: bool, - /// Display format of the current layer - pub display: Option, - /// Show the widget event if the layer is Tiling - pub show_when_tiling: Option, -} - -#[derive(Copy, Clone, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// Komorebi widget focused container configuration -pub struct KomorebiFocusedContainerConfig { - /// Enable the Komorebi Focused Container widget - pub enable: bool, - /// DEPRECATED: use `display` instead (Show the icon of the currently focused container) - #[deprecated(note = "Use `display` instead")] - pub show_icon: Option, - /// Display format of the currently focused container - pub display: Option, -} - -#[derive(Copy, Clone, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// Komorebi widget locked container configuration -pub struct KomorebiLockedContainerConfig { - /// Enable the Komorebi Locked Container widget - pub enable: bool, - /// Display format of the current locked state - pub display: Option, - /// Show the widget event if the layer is unlocked - pub show_when_unlocked: Option, -} - -#[derive(Clone, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// Komorebi widget configuration switcher configuration -pub struct KomorebiConfigurationSwitcherConfig { - /// Enable the Komorebi Configurations widget - pub enable: bool, - /// A map of display friendly name => path to configuration.json - pub configurations: BTreeMap, -} - impl From<&KomorebiConfig> for Komorebi { fn from(cfg: &KomorebiConfig) -> Self { let configuration_switcher = cfg.configuration_switcher.clone().map(|mut cs| { diff --git a/komorebi-bar/src/widgets/komorebi_layout.rs b/komorebi-bar/src/widgets/komorebi_layout.rs index 5c35246c..04d09d06 100644 --- a/komorebi-bar/src/widgets/komorebi_layout.rs +++ b/komorebi-bar/src/widgets/komorebi_layout.rs @@ -2,7 +2,6 @@ use crate::config::DisplayFormat; use crate::render::RenderConfig; use crate::selected_frame::SelectableFrame; use crate::widgets::komorebi::KomorebiLayoutConfig; -use color_eyre::eyre; use eframe::egui::Context; use eframe::egui::CornerRadius; use eframe::egui::FontId; @@ -14,70 +13,31 @@ use eframe::egui::StrokeKind; use eframe::egui::Ui; use eframe::egui::Vec2; use eframe::egui::vec2; +pub use komorebi_bar_core::widgets::komorebi_config::KomorebiLayout; use komorebi_client::SocketMessage; -use serde::Deserialize; -use serde::Deserializer; -use serde::Serialize; -use serde::de::Error; -use serde_json::from_str; -use std::fmt::Display; -use std::fmt::Formatter; -#[derive(Copy, Clone, Debug, Serialize, PartialEq)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -#[serde(untagged)] -/// Komorebi layout kind -pub enum KomorebiLayout { - /// Predefined layout - #[cfg_attr(feature = "schemars", schemars(title = "Default"))] - Default(komorebi_client::DefaultLayout), - /// Monocle mode - Monocle, - /// Floating layer - Floating, - /// Paused - Paused, - /// Custom layout - Custom, +/// What the layout widget does with a layout kind (the kind itself lives in the core). +pub trait KomorebiLayoutExt { + fn is_default(&mut self) -> bool; + fn on_click( + &mut self, + show_options: &bool, + monitor_idx: usize, + workspace_idx: Option, + ) -> bool; + fn on_click_option(&mut self, monitor_idx: usize, workspace_idx: Option); + fn show_icon(&mut self, is_selected: bool, font_id: FontId, ctx: &Context, ui: &mut Ui); + fn show( + &mut self, + ctx: &Context, + ui: &mut Ui, + render_config: &mut RenderConfig, + layout_config: &KomorebiLayoutConfig, + workspace_idx: Option, + ); } -impl<'de> Deserialize<'de> for KomorebiLayout { - fn deserialize(deserializer: D) -> eyre::Result - where - D: Deserializer<'de>, - { - let s: String = String::deserialize(deserializer)?; - - // Attempt to deserialize the string as a DefaultLayout - if let Ok(default_layout) = from_str::(&format!("\"{s}\"")) - { - return Ok(KomorebiLayout::Default(default_layout)); - } - - // Handle other cases - match s.as_str() { - "Monocle" => Ok(KomorebiLayout::Monocle), - "Floating" => Ok(KomorebiLayout::Floating), - "Paused" => Ok(KomorebiLayout::Paused), - "Custom" => Ok(KomorebiLayout::Custom), - _ => Err(Error::custom(format!("Invalid layout: {s}"))), - } - } -} - -impl Display for KomorebiLayout { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - match self { - KomorebiLayout::Default(layout) => write!(f, "{layout}"), - KomorebiLayout::Monocle => write!(f, "Monocle"), - KomorebiLayout::Floating => write!(f, "Floating"), - KomorebiLayout::Paused => write!(f, "Paused"), - KomorebiLayout::Custom => write!(f, "Custom"), - } - } -} - -impl KomorebiLayout { +impl KomorebiLayoutExt for KomorebiLayout { fn is_default(&mut self) -> bool { matches!(self, KomorebiLayout::Default(_)) } @@ -242,7 +202,7 @@ impl KomorebiLayout { } } - pub fn show( + fn show( &mut self, ctx: &Context, ui: &mut Ui, diff --git a/komorebi-for-mac/Cargo.lock b/komorebi-for-mac/Cargo.lock index 707642c1..1155f517 100644 --- a/komorebi-for-mac/Cargo.lock +++ b/komorebi-for-mac/Cargo.lock @@ -3253,10 +3253,12 @@ version = "0.1.42" dependencies = [ "chrono", "chrono-tz", + "color-eyre", "eframe", "egui-phosphor", "image 0.25.10", "komorebi-config", + "komorebi-layouts", "komorebi-protocol", "lazy_static", "reqwest", diff --git a/komorebi-for-mac/komorebi-bar/src/widgets/komorebi.rs b/komorebi-for-mac/komorebi-bar/src/widgets/komorebi.rs index 170c9c78..6ad709ae 100644 --- a/komorebi-for-mac/komorebi-bar/src/widgets/komorebi.rs +++ b/komorebi-for-mac/komorebi-bar/src/widgets/komorebi.rs @@ -7,7 +7,15 @@ use crate::config::WorkspacesDisplayFormat; use crate::render::RenderConfig; use crate::selected_frame::SelectableFrame; use crate::ui::CustomUi; -use crate::widgets::komorebi_layout::KomorebiLayout; +pub use komorebi_bar_core::widgets::komorebi_config::KomorebiConfig; +pub use komorebi_bar_core::widgets::komorebi_config::KomorebiConfigurationSwitcherConfig; +pub use komorebi_bar_core::widgets::komorebi_config::KomorebiFocusedContainerConfig; +pub use komorebi_bar_core::widgets::komorebi_config::KomorebiLayoutConfig; +pub use komorebi_bar_core::widgets::komorebi_config::KomorebiLockedContainerConfig; +pub use komorebi_bar_core::widgets::komorebi_config::KomorebiWorkspaceLayerConfig; +pub use komorebi_bar_core::widgets::komorebi_config::KomorebiWorkspacesConfig; +pub use komorebi_bar_core::widgets::komorebi_config::KomorebiLayout; +use crate::widgets::komorebi_layout::KomorebiLayoutExt; use crate::widgets::widget::BarWidget; use eframe::egui::Align; use eframe::egui::Color32; @@ -40,10 +48,7 @@ use komorebi_client::State; use komorebi_client::Window; use komorebi_client::Workspace; use komorebi_client::WorkspaceLayer; -use serde::Deserialize; -use serde::Serialize; use std::cell::RefCell; -use std::collections::BTreeMap; use std::collections::HashMap; use std::fs::File; use std::io::BufReader; @@ -52,96 +57,6 @@ use std::path::Path; use std::rc::Rc; use std::sync::atomic::Ordering; -#[derive(Clone, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// Komorebi widget configuration -pub struct KomorebiConfig { - /// Configure the Workspaces widget - pub workspaces: Option, - /// Configure the Layout widget - pub layout: Option, - /// Configure the Workspace Layer widget - pub workspace_layer: Option, - /// Configure the Focused Container widget - #[serde(alias = "focused_window")] - pub focused_container: Option, - /// Configure the Locked Container widget - pub locked_container: Option, - /// Configure the Configuration Switcher widget - pub configuration_switcher: Option, -} - -#[derive(Copy, Clone, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// Komorebi widget workspaces configuration -pub struct KomorebiWorkspacesConfig { - /// Enable the Komorebi Workspaces widget - pub enable: bool, - /// Hide workspaces without any windows - pub hide_empty_workspaces: bool, - /// Display format of the workspace - pub display: Option, -} - -#[derive(Clone, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// Komorebi widget layout configuration -pub struct KomorebiLayoutConfig { - /// Enable the Komorebi Layout widget - pub enable: bool, - /// List of layout options - pub options: Option>, - /// Display format of the current layout - pub display: Option, -} - -#[derive(Copy, Clone, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// Komorebi widget workspace layer configuration -pub struct KomorebiWorkspaceLayerConfig { - /// Enable the Komorebi Workspace Layer widget - pub enable: bool, - /// Display format of the current layer - pub display: Option, - /// Show the widget event if the layer is Tiling - pub show_when_tiling: Option, -} - -#[derive(Copy, Clone, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// Komorebi widget focused container configuration -pub struct KomorebiFocusedContainerConfig { - /// Enable the Komorebi Focused Container widget - pub enable: bool, - /// DEPRECATED: use `display` instead (Show the icon of the currently focused container) - #[deprecated(note = "Use `display` instead")] - pub show_icon: Option, - /// Display format of the currently focused container - pub display: Option, -} - -#[derive(Copy, Clone, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// Komorebi widget locked container configuration -pub struct KomorebiLockedContainerConfig { - /// Enable the Komorebi Locked Container widget - pub enable: bool, - /// Display format of the current locked state - pub display: Option, - /// Show the widget event if the layer is unlocked - pub show_when_unlocked: Option, -} - -#[derive(Clone, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// Komorebi widget configuration switcher configuration -pub struct KomorebiConfigurationSwitcherConfig { - /// Enable the Komorebi Configurations widget - pub enable: bool, - /// A map of display friendly name => path to configuration.json - pub configurations: BTreeMap, -} - impl From<&KomorebiConfig> for Komorebi { fn from(cfg: &KomorebiConfig) -> Self { let configuration_switcher = cfg.configuration_switcher.clone().map(|mut cs| { diff --git a/komorebi-for-mac/komorebi-bar/src/widgets/komorebi_layout.rs b/komorebi-for-mac/komorebi-bar/src/widgets/komorebi_layout.rs index 5c35246c..5c51684b 100644 --- a/komorebi-for-mac/komorebi-bar/src/widgets/komorebi_layout.rs +++ b/komorebi-for-mac/komorebi-bar/src/widgets/komorebi_layout.rs @@ -2,7 +2,7 @@ use crate::config::DisplayFormat; use crate::render::RenderConfig; use crate::selected_frame::SelectableFrame; use crate::widgets::komorebi::KomorebiLayoutConfig; -use color_eyre::eyre; +pub use komorebi_bar_core::widgets::komorebi_config::KomorebiLayout; use eframe::egui::Context; use eframe::egui::CornerRadius; use eframe::egui::FontId; @@ -15,69 +15,29 @@ use eframe::egui::Ui; use eframe::egui::Vec2; use eframe::egui::vec2; use komorebi_client::SocketMessage; -use serde::Deserialize; -use serde::Deserializer; -use serde::Serialize; -use serde::de::Error; -use serde_json::from_str; -use std::fmt::Display; -use std::fmt::Formatter; -#[derive(Copy, Clone, Debug, Serialize, PartialEq)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -#[serde(untagged)] -/// Komorebi layout kind -pub enum KomorebiLayout { - /// Predefined layout - #[cfg_attr(feature = "schemars", schemars(title = "Default"))] - Default(komorebi_client::DefaultLayout), - /// Monocle mode - Monocle, - /// Floating layer - Floating, - /// Paused - Paused, - /// Custom layout - Custom, +/// What the layout widget does with a layout kind (the kind itself lives in the core). +pub trait KomorebiLayoutExt { + fn is_default(&mut self) -> bool; + fn on_click( + &mut self, + show_options: &bool, + monitor_idx: usize, + workspace_idx: Option, + ) -> bool; + fn on_click_option(&mut self, monitor_idx: usize, workspace_idx: Option); + fn show_icon(&mut self, is_selected: bool, font_id: FontId, ctx: &Context, ui: &mut Ui); + fn show( + &mut self, + ctx: &Context, + ui: &mut Ui, + render_config: &mut RenderConfig, + layout_config: &KomorebiLayoutConfig, + workspace_idx: Option, + ); } -impl<'de> Deserialize<'de> for KomorebiLayout { - fn deserialize(deserializer: D) -> eyre::Result - where - D: Deserializer<'de>, - { - let s: String = String::deserialize(deserializer)?; - - // Attempt to deserialize the string as a DefaultLayout - if let Ok(default_layout) = from_str::(&format!("\"{s}\"")) - { - return Ok(KomorebiLayout::Default(default_layout)); - } - - // Handle other cases - match s.as_str() { - "Monocle" => Ok(KomorebiLayout::Monocle), - "Floating" => Ok(KomorebiLayout::Floating), - "Paused" => Ok(KomorebiLayout::Paused), - "Custom" => Ok(KomorebiLayout::Custom), - _ => Err(Error::custom(format!("Invalid layout: {s}"))), - } - } -} - -impl Display for KomorebiLayout { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - match self { - KomorebiLayout::Default(layout) => write!(f, "{layout}"), - KomorebiLayout::Monocle => write!(f, "Monocle"), - KomorebiLayout::Floating => write!(f, "Floating"), - KomorebiLayout::Paused => write!(f, "Paused"), - KomorebiLayout::Custom => write!(f, "Custom"), - } - } -} - -impl KomorebiLayout { +impl KomorebiLayoutExt for KomorebiLayout { fn is_default(&mut self) -> bool { matches!(self, KomorebiLayout::Default(_)) } @@ -242,7 +202,7 @@ impl KomorebiLayout { } } - pub fn show( + fn show( &mut self, ctx: &Context, ui: &mut Ui,