From cc67cd25e9068983dad376d4439c25cb9eca910d Mon Sep 17 00:00:00 2001 From: Doloro1978 Date: Sun, 13 Sep 2026 18:32:37 +0100 Subject: [PATCH] configurations things --- Cargo.lock | 1 + crates/common/Cargo.toml | 1 + crates/common/src/config.rs | 5 ++- crates/common/src/display.rs | 83 ++++++++++++++++++++++++++++++++++++ crates/common/src/lib.rs | 2 + crates/core/src/app.rs | 8 ++++ crates/core/src/main.rs | 29 +++---------- crates/core/src/view.rs | 8 ++-- test.toml | 12 ++++++ 9 files changed, 122 insertions(+), 27 deletions(-) create mode 100644 crates/common/src/display.rs diff --git a/Cargo.lock b/Cargo.lock index 810b51f..d32f426 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -529,6 +529,7 @@ version = "0.1.0" dependencies = [ "chrono", "iced", + "iced_layershell", "serde", "serde_json", "toml", diff --git a/crates/common/Cargo.toml b/crates/common/Cargo.toml index 1bdb6b7..d61b119 100644 --- a/crates/common/Cargo.toml +++ b/crates/common/Cargo.toml @@ -9,6 +9,7 @@ path = "src/lib.rs" [dependencies] iced = { workspace = true } +iced_layershell = { workspace = true } toml = { workspace = true } serde = { workspace = true } chrono = { workspace = true } diff --git a/crates/common/src/config.rs b/crates/common/src/config.rs index e3627b8..b1e72e0 100644 --- a/crates/common/src/config.rs +++ b/crates/common/src/config.rs @@ -1,9 +1,12 @@ use serde::{Deserialize, Serialize}; use toml::Table; +use crate::display::Display; + #[derive(Serialize, Deserialize)] pub struct BarbarConfig { - pub monitor: Option, + #[serde(default)] + pub display: Display, pub ups: Option, // Updates per second pub order: ModuleOrder, pub modules: Option, // 'clock': [clock settings] diff --git a/crates/common/src/display.rs b/crates/common/src/display.rs new file mode 100644 index 0000000..9d71ad0 --- /dev/null +++ b/crates/common/src/display.rs @@ -0,0 +1,83 @@ +//! `[display]` config section, converted into `iced_layershell` settings. +//! +//! Keeps the bar surface's geometry and renderer flags in one place, so `core` +//! only reads config and hands the result straight to the daemon. + +use iced::Pixels; +use iced_layershell::reexport::{Anchor, KeyboardInteractivity}; +use iced_layershell::settings::{LayerShellSettings, Settings, StartMode}; +use serde::{Deserialize, Serialize}; + +/// Bar height in logical px when `[display].height` is omitted. +const DEFAULT_HEIGHT: u32 = 36; +/// Default text size in logical px. +const DEFAULT_TEXT_SIZE: f32 = 16.0; +/// Default horizontal padding between the bar edge and its content, logical px. +const DEFAULT_PADDING: f32 = 8.0; +/// Default gap between modules in the bar, logical px. +const DEFAULT_SPACING: f32 = 8.0; + +/// Parsed `[display]` table. +#[derive(Deserialize, Serialize, Clone, Debug)] +#[serde(default)] +pub struct Display { + /// Output to pin the bar to; `None` follows the active output. + pub monitor: Option, + /// Bar height in logical px; the same strip is reserved exclusively. + pub height: u32, + /// MSAA for triangle primitives (Canvas/meshes). Quads — borders, + /// rounded rectangles — are already anti-aliased analytically, so this + /// does not change them. + pub antialiasing: bool, + /// Default text size in logical px. + pub default_text_size: f32, + /// Left/right padding between the bar edge and its content, logical px. + pub padding: f32, + /// Gap between modules in the bar, logical px. + pub spacing: f32, +} + +impl Default for Display { + fn default() -> Self { + Self { + monitor: None, + height: DEFAULT_HEIGHT, + antialiasing: false, + default_text_size: DEFAULT_TEXT_SIZE, + padding: DEFAULT_PADDING, + spacing: DEFAULT_SPACING, + } + } +} + +impl Display { + /// Output the bar starts on. + pub fn start_mode(&self) -> StartMode { + match &self.monitor { + Some(name) => StartMode::TargetScreen(name.clone()), + None => StartMode::Active, + } + } + + /// Bar surface placement: full width, top, reserved strip of `height`. + pub fn layer_settings(&self) -> LayerShellSettings { + LayerShellSettings { + size: Some((0, self.height)), + exclusive_zone: self.height as i32, + anchor: Anchor::Top | Anchor::Left | Anchor::Right, + start_mode: self.start_mode(), + keyboard_interactivity: KeyboardInteractivity::None, + ..Default::default() + } + } + + /// Full daemon settings: layer-shell placement plus iced renderer flags. + pub fn settings(&self) -> Settings { + Settings { + layer_settings: self.layer_settings(), + default_text_size: Pixels(self.default_text_size), + antialiasing: self.antialiasing, + ..Default::default() + } + } +} diff --git a/crates/common/src/lib.rs b/crates/common/src/lib.rs index 4e2cbe4..b371d9d 100644 --- a/crates/common/src/lib.rs +++ b/crates/common/src/lib.rs @@ -5,6 +5,7 @@ //! so it must stay acyclic and pure. mod config; +mod display; mod effect; mod messages; mod module; @@ -12,6 +13,7 @@ mod service; mod wire; pub use config::{BarbarConfig, Modules}; +pub use display::Display; pub use effect::ModuleEffect; pub use messages::*; pub use module::BarModule; diff --git a/crates/core/src/app.rs b/crates/core/src/app.rs index cc2b84e..bcfd24b 100644 --- a/crates/core/src/app.rs +++ b/crates/core/src/app.rs @@ -13,6 +13,10 @@ pub(crate) struct Bar { pub(crate) modules: BTreeMap<&'static str, Box>, /// Left, Middle, Right ; Module Order pub(crate) order: (Vec, Vec, Vec), + /// Left/right padding between the bar edge and its content. + pub(crate) padding: f32, + /// Gap between modules in the bar. + pub(crate) spacing: f32, /// Surface id of the open popup. pub(crate) popup_id: Option, /// Fan-out routing table: module id -> services it wants. @@ -26,6 +30,8 @@ impl Bar { pub(crate) fn new( modules_config_table: &Table, modules_order: (Vec, Vec, Vec), + padding: f32, + spacing: f32, ) -> Self { // Registry owns construction: adding a module never edits this file. let modules: BTreeMap<&'static str, Box> = @@ -53,6 +59,8 @@ impl Bar { active_popup: None, modules, order: modules_order, + padding, + spacing, popup_id: None, routes, inputs, diff --git a/crates/core/src/main.rs b/crates/core/src/main.rs index a237a1c..4c4cb6e 100644 --- a/crates/core/src/main.rs +++ b/crates/core/src/main.rs @@ -10,8 +10,6 @@ use std::io::Read; use clap::Parser; use common::BarbarConfig; use iced_layershell::daemon; -use iced_layershell::reexport::Anchor; -use iced_layershell::settings::{LayerShellSettings, Settings, StartMode}; mod app; mod args; @@ -24,9 +22,6 @@ mod view; pub(crate) use app::Bar; pub(crate) use msg::{Message, Msg}; -/// Height of the bar in logical pixels. -const BAR_HEIGHT: u32 = 36; - /// Default log filter per build profile. Debug builds log barbar's own crates /// at `debug` while dependency noise (iced_layershell/sctk/cosmic_text/wgpu…) /// stays at `warn`; release builds log `warn` and above. `RUST_LOG` overrides. @@ -56,14 +51,12 @@ fn main() -> Result<(), iced_layershell::Error> { return Ok(()); } - let start_mode = match &config.monitor { - Some(x) => StartMode::TargetScreen(x.clone()), - None => StartMode::Active, - }; - let modules = config.modules.clone().unwrap_or_default(); let order = config.order; - tracing::info!(monitor = ?config.monitor, "starting barbar daemon"); + let disp = config.display; + tracing::info!(monitor = ?disp.monitor, "starting barbar daemon"); + let (padding, spacing) = (disp.padding, disp.spacing); + let settings = disp.settings(); daemon( move || { @@ -74,6 +67,8 @@ fn main() -> Result<(), iced_layershell::Error> { order.middle.clone(), order.right.clone(), ), + padding, + spacing, ) }, subscription::namespace, @@ -82,16 +77,6 @@ fn main() -> Result<(), iced_layershell::Error> { ) .style(view::style) .subscription(subscription::gather_subscriptions) - .settings(Settings { - layer_settings: LayerShellSettings { - size: Some((0, BAR_HEIGHT)), - exclusive_zone: BAR_HEIGHT as i32, - anchor: Anchor::Top | Anchor::Left | Anchor::Right, - start_mode, - keyboard_interactivity: iced_layershell::reexport::KeyboardInteractivity::None, - ..Default::default() - }, - ..Default::default() - }) + .settings(settings) .run() } diff --git a/crates/core/src/view.rs b/crates/core/src/view.rs index 60f17a0..b418a9c 100644 --- a/crates/core/src/view.rs +++ b/crates/core/src/view.rs @@ -34,7 +34,7 @@ fn bar_view(bar: &Bar) -> Element<'_, Message> { .map(|w| Message::Event(Msg::Wire(w))) }) .collect::>>()) - .spacing(8) + .spacing(bar.spacing) .align_y(Alignment::Center); let middle = row(bar @@ -49,7 +49,7 @@ fn bar_view(bar: &Bar) -> Element<'_, Message> { .map(|w| Message::Event(Msg::Wire(w))) }) .collect::>>()) - .spacing(8) + .spacing(bar.spacing) .align_y(Alignment::Center); let right = row(bar .order @@ -63,7 +63,7 @@ fn bar_view(bar: &Bar) -> Element<'_, Message> { .map(|w| Message::Event(Msg::Wire(w))) }) .collect::>>()) - .spacing(8) + .spacing(bar.spacing) .align_y(Alignment::Center); let row = row![ @@ -77,7 +77,7 @@ fn bar_view(bar: &Bar) -> Element<'_, Message> { .align_y(Alignment::Center); container(row) - .padding(8) + .padding([0.0, bar.padding]) .width(Length::Fill) .height(Length::Fill) .align_y(Alignment::Center) diff --git a/test.toml b/test.toml index 2590424..221ec22 100644 --- a/test.toml +++ b/test.toml @@ -1,4 +1,16 @@ +[display] +# Output to pin the bar to; omit to follow the active output. monitor = "DP-2" +# Bar height in logical px (default 36); reserved exclusively. +height = 24 +# MSAA for triangle primitives (does not affect quad borders). +antialiasing = true +# Default text size in logical px (default 16). +default_text_size = 14.0 +# Left/right padding between the bar edge and its content, logical px. +padding = 4.0 +# Gap between modules in the bar, logical px. +spacing = 8.0 [order] left = ["workspaces", "weather"]