configurations things
This commit is contained in:
@@ -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 }
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use toml::Table;
|
||||
|
||||
use crate::display::Display;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct BarbarConfig {
|
||||
pub monitor: Option<String>,
|
||||
#[serde(default)]
|
||||
pub display: Display,
|
||||
pub ups: Option<i32>, // Updates per second
|
||||
pub order: ModuleOrder,
|
||||
pub modules: Option<Table>, // 'clock': [clock settings]
|
||||
|
||||
@@ -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<String>,
|
||||
/// 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()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -13,6 +13,10 @@ pub(crate) struct Bar {
|
||||
pub(crate) modules: BTreeMap<&'static str, Box<dyn BarModule>>,
|
||||
/// Left, Middle, Right ; Module Order
|
||||
pub(crate) order: (Vec<Modules>, Vec<Modules>, Vec<Modules>),
|
||||
/// 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<window::Id>,
|
||||
/// 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<Modules>, Vec<Modules>, Vec<Modules>),
|
||||
padding: f32,
|
||||
spacing: f32,
|
||||
) -> Self {
|
||||
// Registry owns construction: adding a module never edits this file.
|
||||
let modules: BTreeMap<&'static str, Box<dyn BarModule>> =
|
||||
@@ -53,6 +59,8 @@ impl Bar {
|
||||
active_popup: None,
|
||||
modules,
|
||||
order: modules_order,
|
||||
padding,
|
||||
spacing,
|
||||
popup_id: None,
|
||||
routes,
|
||||
inputs,
|
||||
|
||||
+7
-22
@@ -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()
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ fn bar_view(bar: &Bar) -> Element<'_, Message> {
|
||||
.map(|w| Message::Event(Msg::Wire(w)))
|
||||
})
|
||||
.collect::<Vec<Element<Message>>>())
|
||||
.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::<Vec<Element<Message>>>())
|
||||
.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::<Vec<Element<Message>>>())
|
||||
.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)
|
||||
|
||||
Reference in New Issue
Block a user