refactor(bar-core): move the config types of the Keyboard, Media and Systray widgets into the core

KeyboardConfig, MediaConfig, SystrayConfig, OverflowTogglePosition,
ButtonPosition, FieldMatch and HiddenIconRule (pure data: serde and schemars
derives, no platform code) move from the Windows widget files to
crates/komorebi-bar-core/src/widgets/platform_config.rs, so that the next
revision can give WidgetConfig a variant for every widget. The Windows
widget files re-export them (`pub use`), so no other file changes; the
runtime halves (Win32, systray_util) stay in komorebi-bar. The core gains the
komorebi-config dependency (for MatchingStrategy; the schemars feature now
forwards to komorebi-config and komorebi-protocol); one line in each
Cargo.lock. Nothing on macOS refers to the types yet, so the macOS schema
cannot change. The schema harness (out of tree) no longer slices systray.rs
by line number.

Verified: schema harness macOS and Windows byte-identical (3,774 / 9,091
lines); native bar-core tests 3+5; Windows clippy -D warnings --locked
clean; macOS fake-CC check --locked 0 errors. Not run: the bars.
This commit is contained in:
LGUG2Z committed 2026-10-31 10:42:45 -07:00
1 parent a290449763
commit e1820d9bbe
8 files changed
+143 -129

No files matched your search

Generated
+1
View File
@@ -3448,6 +3448,7 @@ dependencies = [
"eframe",
"egui-phosphor",
"image 0.25.10",
"komorebi-config",
"komorebi-protocol",
"lazy_static",
"reqwest",
+2 -1
View File
@@ -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"]
@@ -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;
@@ -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<u64>,
/// Display label prefix
pub label_prefix: Option<LabelPrefix>,
}
#[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<MediaDisplayFormat>,
}
#[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<FieldMatch>,
/// Tooltip text to match
tooltip: Option<FieldMatch>,
/// Icon GUID to match (most stable identifier across restarts)
guid: Option<FieldMatch>,
},
}
#[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<Vec<HiddenIconRule>>,
/// Position of the overflow toggle button (default: Right)
pub overflow_toggle_position: Option<OverflowTogglePosition>,
/// 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<ButtonPosition>,
/// 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<u64>,
/// 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<ButtonPosition>,
/// 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<ButtonPosition>,
}
+1 -15
View File
@@ -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<u64>,
/// Display label prefix
pub label_prefix: Option<LabelPrefix>,
}
impl From<KeyboardConfig> for Keyboard {
fn from(value: KeyboardConfig) -> Self {
let data_refresh_interval = value.data_refresh_interval.unwrap_or(10);
+1 -12
View File
@@ -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<MediaDisplayFormat>,
}
impl From<MediaConfig> for Media {
fn from(value: MediaConfig) -> Self {
Self::new(
+5 -101
View File
@@ -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<FieldMatch>,
/// Tooltip text to match
tooltip: Option<FieldMatch>,
/// Icon GUID to match (most stable identifier across restarts)
guid: Option<FieldMatch>,
},
}
#[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<Vec<HiddenIconRule>>,
/// Position of the overflow toggle button (default: Right)
pub overflow_toggle_position: Option<OverflowTogglePosition>,
/// 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<ButtonPosition>,
/// 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<u64>,
/// 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<ButtonPosition>,
/// 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<ButtonPosition>,
}
/// Command sent from UI to background thread
#[derive(Debug)]
enum SystrayCommand {
+1
View File
@@ -3256,6 +3256,7 @@ dependencies = [
"eframe",
"egui-phosphor",
"image 0.25.10",
"komorebi-config",
"komorebi-protocol",
"lazy_static",
"reqwest",