diff --git a/Cargo.lock b/Cargo.lock index 60b056bc..6d193c4e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3448,6 +3448,7 @@ dependencies = [ "eframe", "egui-phosphor", "image 0.25.10", + "komorebi-config", "komorebi-protocol", "lazy_static", "reqwest", diff --git a/crates/komorebi-bar-core/Cargo.toml b/crates/komorebi-bar-core/Cargo.toml index 2bd0d5af..f40abaa2 100644 --- a/crates/komorebi-bar-core/Cargo.toml +++ b/crates/komorebi-bar-core/Cargo.toml @@ -11,6 +11,7 @@ eframe = { workspace = true } egui-phosphor = { git = "https://github.com/amPerl/egui-phosphor", rev = "d13688738478ecd12b426e3e74c59d6577a85b59" } lazy_static = { workspace = true } image = "0.25" +komorebi-config = { path = "../komorebi-config", default-features = false } reqwest = { version = "0.12", features = ["blocking"] } komorebi-protocol = { path = "../komorebi-protocol", default-features = false } serde = { workspace = true } @@ -24,4 +25,4 @@ schemars = { workspace = true, optional = true } [features] default = ["schemars"] -schemars = ["dep:schemars"] +schemars = ["dep:schemars", "komorebi-config/schemars", "komorebi-protocol/schemars"] diff --git a/crates/komorebi-bar-core/src/widgets/mod.rs b/crates/komorebi-bar-core/src/widgets/mod.rs index ad975407..cda332df 100644 --- a/crates/komorebi-bar-core/src/widgets/mod.rs +++ b/crates/komorebi-bar-core/src/widgets/mod.rs @@ -4,6 +4,7 @@ pub mod cpu; pub mod date; pub mod icons; pub mod memory; +pub mod platform_config; pub mod storage; pub mod time; pub mod update; diff --git a/crates/komorebi-bar-core/src/widgets/platform_config.rs b/crates/komorebi-bar-core/src/widgets/platform_config.rs new file mode 100644 index 00000000..746fc7db --- /dev/null +++ b/crates/komorebi-bar-core/src/widgets/platform_config.rs @@ -0,0 +1,131 @@ +//! The configuration types of the widgets only the Windows bar runs (keyboard, media, system +//! tray). They are data without any platform code, so that `WidgetConfig` can name every widget +//! and the schema is one union that each platform's view prunes (see `schema`). + +use crate::config::LabelPrefix; +use crate::config::MediaDisplayFormat; +use komorebi_config::matching::MatchingStrategy; +use serde::Deserialize; +use serde::Serialize; + +#[derive(Copy, Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] +/// Keyboard widget configuration +pub struct KeyboardConfig { + /// Enable the Input widget + pub enable: bool, + /// Data refresh interval + #[cfg_attr(feature = "schemars", schemars(extend("default" = 10)))] + pub data_refresh_interval: Option, + /// Display label prefix + pub label_prefix: Option, +} + +#[derive(Copy, Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] +/// Media widget configuration +pub struct MediaConfig { + /// Enable the Media widget + pub enable: bool, + /// Display format of the media widget (defaults to IconAndText) + pub display: Option, +} + +#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, PartialEq)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] +/// Position of the overflow toggle button +pub enum OverflowTogglePosition { + /// Toggle button appears on the left side (before visible icons) + Left, + /// Toggle button appears on the right side (after visible icons) + #[default] + Right, +} + +#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] +/// Where to place a systray button (refresh, info, shortcuts, etc.) +pub enum ButtonPosition { + /// Show in the main visible area + Visible, + /// Show in the overflow/hidden section + Overflow, +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] +#[serde(untagged)] +/// A field value with an optional matching strategy. +/// +/// A plain string uses exact (case-insensitive) matching. +/// An object with `value` and `matching_strategy` uses the specified strategy. +pub enum FieldMatch { + /// Exact case-insensitive match + Exact(String), + /// Match using a specific strategy + WithStrategy { + /// The value to match against + value: String, + /// How to match (Equals, StartsWith, EndsWith, Contains, Regex, etc.) + matching_strategy: MatchingStrategy, + }, +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] +#[serde(untagged)] +/// Rule for matching a systray icon to hide +/// +/// A plain string matches the exe name (backward compatible). +/// An object with optional `exe`, `tooltip`, and/or `guid` fields +/// uses AND logic: all specified fields must match. +/// Each field can be a plain string (exact match) or an object with +/// `value` and `matching_strategy` for advanced matching. +pub enum HiddenIconRule { + /// Match by exe name (case-insensitive, exact) + Exe(String), + /// Match by one or more properties (all specified fields must match) + Match { + /// Exe name to match + exe: Option, + /// Tooltip text to match + tooltip: Option, + /// Icon GUID to match (most stable identifier across restarts) + guid: Option, + }, +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] +/// System tray widget configuration +pub struct SystrayConfig { + /// Enable the System Tray widget + pub enable: bool, + /// A list of rules for icons to hide from the system tray + /// + /// Each entry can be a plain string (matches exe name, case-insensitive) + /// or an object with optional `exe`, `tooltip`, and/or `guid` fields + /// (all specified fields must match, AND logic, case-insensitive). + /// + /// Run komorebi-bar with RUST_LOG=info to see the properties of all + /// systray icons in the log output. + pub hidden_icons: Option>, + /// Position of the overflow toggle button (default: Right) + pub overflow_toggle_position: Option, + /// Show an info button that opens a floating panel listing all systray icons + /// with their exe, tooltip, and GUID. Set to "Visible" to show it in the main + /// area, or "Overflow" to show it in the hidden/overflow section. + pub info_button: Option, + /// Interval in seconds to automatically check for and remove stale icons + /// whose owning process has exited. Clamped between 30 and 600 seconds. + /// Defaults to 60. Set to 0 to disable. + pub stale_icons_check_interval: Option, + /// Show a refresh button that manually triggers stale icon cleanup. + /// Set to "Visible" to show it in the main area, or "Overflow" to + /// show it in the hidden/overflow section. + pub refresh_button: Option, + /// Show a button that toggles komorebi-shortcuts (kills the process if + /// running, starts it otherwise). Set to "Visible" to show it in the main + /// area, or "Overflow" to show it in the hidden/overflow section. + pub shortcuts_button: Option, +} diff --git a/komorebi-bar/src/widgets/keyboard.rs b/komorebi-bar/src/widgets/keyboard.rs index 5fe6d0a7..ee27da88 100644 --- a/komorebi-bar/src/widgets/keyboard.rs +++ b/komorebi-bar/src/widgets/keyboard.rs @@ -1,4 +1,5 @@ use crate::config::LabelPrefix; +pub use komorebi_bar_core::widgets::platform_config::KeyboardConfig; use crate::render::RenderConfig; use crate::widgets::widget::BarWidget; use color_eyre::eyre; @@ -9,8 +10,6 @@ use eframe::egui::TextFormat; use eframe::egui::Ui; use eframe::egui::WidgetText; use eframe::egui::text::LayoutJob; -use serde::Deserialize; -use serde::Serialize; use std::sync::Arc; use std::time::Duration; use std::time::Instant; @@ -23,19 +22,6 @@ use windows::Win32::UI::WindowsAndMessaging::GetWindowThreadProcessId; const ERROR_TEXT: &str = "Error"; -#[derive(Copy, Clone, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// Keyboard widget configuration -pub struct KeyboardConfig { - /// Enable the Input widget - pub enable: bool, - /// Data refresh interval - #[cfg_attr(feature = "schemars", schemars(extend("default" = 10)))] - pub data_refresh_interval: Option, - /// Display label prefix - pub label_prefix: Option, -} - impl From for Keyboard { fn from(value: KeyboardConfig) -> Self { let data_refresh_interval = value.data_refresh_interval.unwrap_or(10); diff --git a/komorebi-bar/src/widgets/media.rs b/komorebi-bar/src/widgets/media.rs index e0155fe0..5c371b61 100644 --- a/komorebi-bar/src/widgets/media.rs +++ b/komorebi-bar/src/widgets/media.rs @@ -1,6 +1,7 @@ use crate::MAX_LABEL_WIDTH; use crate::bar::Alignment; use crate::config::MediaDisplayFormat; +pub use komorebi_bar_core::widgets::platform_config::MediaConfig; use crate::render::RenderConfig; use crate::selected_frame::SelectableFrame; use crate::ui::CustomUi; @@ -12,22 +13,10 @@ use eframe::egui::TextFormat; use eframe::egui::Ui; use eframe::egui::Vec2; use eframe::egui::text::LayoutJob; -use serde::Deserialize; -use serde::Serialize; use std::sync::atomic::Ordering; use windows::Media::Control::GlobalSystemMediaTransportControlsSessionManager; use windows::Media::Control::GlobalSystemMediaTransportControlsSessionPlaybackStatus; -#[derive(Copy, Clone, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// Media widget configuration -pub struct MediaConfig { - /// Enable the Media widget - pub enable: bool, - /// Display format of the media widget (defaults to IconAndText) - pub display: Option, -} - impl From for Media { fn from(value: MediaConfig) -> Self { Self::new( diff --git a/komorebi-bar/src/widgets/systray.rs b/komorebi-bar/src/widgets/systray.rs index 5d6f6367..230f2a5c 100644 --- a/komorebi-bar/src/widgets/systray.rs +++ b/komorebi-bar/src/widgets/systray.rs @@ -26,10 +26,13 @@ use eframe::egui::ViewportId; use eframe::egui::Window as EguiWindow; use egui_extras::Column; use egui_extras::TableBuilder; +pub use komorebi_bar_core::widgets::platform_config::ButtonPosition; +pub use komorebi_bar_core::widgets::platform_config::FieldMatch; +pub use komorebi_bar_core::widgets::platform_config::HiddenIconRule; +pub use komorebi_bar_core::widgets::platform_config::OverflowTogglePosition; +pub use komorebi_bar_core::widgets::platform_config::SystrayConfig; use komorebi_client::MatchingStrategy; use parking_lot::Mutex; -use serde::Deserialize; -use serde::Serialize; use std::collections::HashMap; use std::sync::Arc; use std::sync::LazyLock; @@ -61,105 +64,6 @@ static SHOW_HIDDEN_ICONS: AtomicBool = AtomicBool::new(false); /// Whether the systray info panel is currently shown static SHOW_SYSTRAY_INFO: AtomicBool = AtomicBool::new(false); -#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, PartialEq)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// Position of the overflow toggle button -pub enum OverflowTogglePosition { - /// Toggle button appears on the left side (before visible icons) - Left, - /// Toggle button appears on the right side (after visible icons) - #[default] - Right, -} - -#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// Where to place a systray button (refresh, info, shortcuts, etc.) -pub enum ButtonPosition { - /// Show in the main visible area - Visible, - /// Show in the overflow/hidden section - Overflow, -} - -#[derive(Clone, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -#[serde(untagged)] -/// A field value with an optional matching strategy. -/// -/// A plain string uses exact (case-insensitive) matching. -/// An object with `value` and `matching_strategy` uses the specified strategy. -pub enum FieldMatch { - /// Exact case-insensitive match - Exact(String), - /// Match using a specific strategy - WithStrategy { - /// The value to match against - value: String, - /// How to match (Equals, StartsWith, EndsWith, Contains, Regex, etc.) - matching_strategy: MatchingStrategy, - }, -} - -#[derive(Clone, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -#[serde(untagged)] -/// Rule for matching a systray icon to hide -/// -/// A plain string matches the exe name (backward compatible). -/// An object with optional `exe`, `tooltip`, and/or `guid` fields -/// uses AND logic: all specified fields must match. -/// Each field can be a plain string (exact match) or an object with -/// `value` and `matching_strategy` for advanced matching. -pub enum HiddenIconRule { - /// Match by exe name (case-insensitive, exact) - Exe(String), - /// Match by one or more properties (all specified fields must match) - Match { - /// Exe name to match - exe: Option, - /// Tooltip text to match - tooltip: Option, - /// Icon GUID to match (most stable identifier across restarts) - guid: Option, - }, -} - -#[derive(Clone, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// System tray widget configuration -pub struct SystrayConfig { - /// Enable the System Tray widget - pub enable: bool, - /// A list of rules for icons to hide from the system tray - /// - /// Each entry can be a plain string (matches exe name, case-insensitive) - /// or an object with optional `exe`, `tooltip`, and/or `guid` fields - /// (all specified fields must match, AND logic, case-insensitive). - /// - /// Run komorebi-bar with RUST_LOG=info to see the properties of all - /// systray icons in the log output. - pub hidden_icons: Option>, - /// Position of the overflow toggle button (default: Right) - pub overflow_toggle_position: Option, - /// Show an info button that opens a floating panel listing all systray icons - /// with their exe, tooltip, and GUID. Set to "Visible" to show it in the main - /// area, or "Overflow" to show it in the hidden/overflow section. - pub info_button: Option, - /// Interval in seconds to automatically check for and remove stale icons - /// whose owning process has exited. Clamped between 30 and 600 seconds. - /// Defaults to 60. Set to 0 to disable. - pub stale_icons_check_interval: Option, - /// Show a refresh button that manually triggers stale icon cleanup. - /// Set to "Visible" to show it in the main area, or "Overflow" to - /// show it in the hidden/overflow section. - pub refresh_button: Option, - /// Show a button that toggles komorebi-shortcuts (kills the process if - /// running, starts it otherwise). Set to "Visible" to show it in the main - /// area, or "Overflow" to show it in the hidden/overflow section. - pub shortcuts_button: Option, -} - /// Command sent from UI to background thread #[derive(Debug)] enum SystrayCommand { diff --git a/komorebi-for-mac/Cargo.lock b/komorebi-for-mac/Cargo.lock index d069566f..707642c1 100644 --- a/komorebi-for-mac/Cargo.lock +++ b/komorebi-for-mac/Cargo.lock @@ -3256,6 +3256,7 @@ dependencies = [ "eframe", "egui-phosphor", "image 0.25.10", + "komorebi-config", "komorebi-protocol", "lazy_static", "reqwest",