configurations things
This commit is contained in:
Generated
+1
@@ -529,6 +529,7 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"iced",
|
"iced",
|
||||||
|
"iced_layershell",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"toml",
|
"toml",
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ path = "src/lib.rs"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
iced = { workspace = true }
|
iced = { workspace = true }
|
||||||
|
iced_layershell = { workspace = true }
|
||||||
toml = { workspace = true }
|
toml = { workspace = true }
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
chrono = { workspace = true }
|
chrono = { workspace = true }
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use toml::Table;
|
use toml::Table;
|
||||||
|
|
||||||
|
use crate::display::Display;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct BarbarConfig {
|
pub struct BarbarConfig {
|
||||||
pub monitor: Option<String>,
|
#[serde(default)]
|
||||||
|
pub display: Display,
|
||||||
pub ups: Option<i32>, // Updates per second
|
pub ups: Option<i32>, // Updates per second
|
||||||
pub order: ModuleOrder,
|
pub order: ModuleOrder,
|
||||||
pub modules: Option<Table>, // 'clock': [clock settings]
|
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.
|
//! so it must stay acyclic and pure.
|
||||||
|
|
||||||
mod config;
|
mod config;
|
||||||
|
mod display;
|
||||||
mod effect;
|
mod effect;
|
||||||
mod messages;
|
mod messages;
|
||||||
mod module;
|
mod module;
|
||||||
@@ -12,6 +13,7 @@ mod service;
|
|||||||
mod wire;
|
mod wire;
|
||||||
|
|
||||||
pub use config::{BarbarConfig, Modules};
|
pub use config::{BarbarConfig, Modules};
|
||||||
|
pub use display::Display;
|
||||||
pub use effect::ModuleEffect;
|
pub use effect::ModuleEffect;
|
||||||
pub use messages::*;
|
pub use messages::*;
|
||||||
pub use module::BarModule;
|
pub use module::BarModule;
|
||||||
|
|||||||
@@ -13,6 +13,10 @@ pub(crate) struct Bar {
|
|||||||
pub(crate) modules: BTreeMap<&'static str, Box<dyn BarModule>>,
|
pub(crate) modules: BTreeMap<&'static str, Box<dyn BarModule>>,
|
||||||
/// Left, Middle, Right ; Module Order
|
/// Left, Middle, Right ; Module Order
|
||||||
pub(crate) order: (Vec<Modules>, Vec<Modules>, Vec<Modules>),
|
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.
|
/// Surface id of the open popup.
|
||||||
pub(crate) popup_id: Option<window::Id>,
|
pub(crate) popup_id: Option<window::Id>,
|
||||||
/// Fan-out routing table: module id -> services it wants.
|
/// Fan-out routing table: module id -> services it wants.
|
||||||
@@ -26,6 +30,8 @@ impl Bar {
|
|||||||
pub(crate) fn new(
|
pub(crate) fn new(
|
||||||
modules_config_table: &Table,
|
modules_config_table: &Table,
|
||||||
modules_order: (Vec<Modules>, Vec<Modules>, Vec<Modules>),
|
modules_order: (Vec<Modules>, Vec<Modules>, Vec<Modules>),
|
||||||
|
padding: f32,
|
||||||
|
spacing: f32,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
// Registry owns construction: adding a module never edits this file.
|
// Registry owns construction: adding a module never edits this file.
|
||||||
let modules: BTreeMap<&'static str, Box<dyn BarModule>> =
|
let modules: BTreeMap<&'static str, Box<dyn BarModule>> =
|
||||||
@@ -53,6 +59,8 @@ impl Bar {
|
|||||||
active_popup: None,
|
active_popup: None,
|
||||||
modules,
|
modules,
|
||||||
order: modules_order,
|
order: modules_order,
|
||||||
|
padding,
|
||||||
|
spacing,
|
||||||
popup_id: None,
|
popup_id: None,
|
||||||
routes,
|
routes,
|
||||||
inputs,
|
inputs,
|
||||||
|
|||||||
+7
-22
@@ -10,8 +10,6 @@ use std::io::Read;
|
|||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use common::BarbarConfig;
|
use common::BarbarConfig;
|
||||||
use iced_layershell::daemon;
|
use iced_layershell::daemon;
|
||||||
use iced_layershell::reexport::Anchor;
|
|
||||||
use iced_layershell::settings::{LayerShellSettings, Settings, StartMode};
|
|
||||||
|
|
||||||
mod app;
|
mod app;
|
||||||
mod args;
|
mod args;
|
||||||
@@ -24,9 +22,6 @@ mod view;
|
|||||||
pub(crate) use app::Bar;
|
pub(crate) use app::Bar;
|
||||||
pub(crate) use msg::{Message, Msg};
|
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
|
/// Default log filter per build profile. Debug builds log barbar's own crates
|
||||||
/// at `debug` while dependency noise (iced_layershell/sctk/cosmic_text/wgpu…)
|
/// at `debug` while dependency noise (iced_layershell/sctk/cosmic_text/wgpu…)
|
||||||
/// stays at `warn`; release builds log `warn` and above. `RUST_LOG` overrides.
|
/// stays at `warn`; release builds log `warn` and above. `RUST_LOG` overrides.
|
||||||
@@ -56,14 +51,12 @@ fn main() -> Result<(), iced_layershell::Error> {
|
|||||||
return Ok(());
|
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 modules = config.modules.clone().unwrap_or_default();
|
||||||
let order = config.order;
|
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(
|
daemon(
|
||||||
move || {
|
move || {
|
||||||
@@ -74,6 +67,8 @@ fn main() -> Result<(), iced_layershell::Error> {
|
|||||||
order.middle.clone(),
|
order.middle.clone(),
|
||||||
order.right.clone(),
|
order.right.clone(),
|
||||||
),
|
),
|
||||||
|
padding,
|
||||||
|
spacing,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
subscription::namespace,
|
subscription::namespace,
|
||||||
@@ -82,16 +77,6 @@ fn main() -> Result<(), iced_layershell::Error> {
|
|||||||
)
|
)
|
||||||
.style(view::style)
|
.style(view::style)
|
||||||
.subscription(subscription::gather_subscriptions)
|
.subscription(subscription::gather_subscriptions)
|
||||||
.settings(Settings {
|
.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()
|
|
||||||
})
|
|
||||||
.run()
|
.run()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ fn bar_view(bar: &Bar) -> Element<'_, Message> {
|
|||||||
.map(|w| Message::Event(Msg::Wire(w)))
|
.map(|w| Message::Event(Msg::Wire(w)))
|
||||||
})
|
})
|
||||||
.collect::<Vec<Element<Message>>>())
|
.collect::<Vec<Element<Message>>>())
|
||||||
.spacing(8)
|
.spacing(bar.spacing)
|
||||||
.align_y(Alignment::Center);
|
.align_y(Alignment::Center);
|
||||||
|
|
||||||
let middle = row(bar
|
let middle = row(bar
|
||||||
@@ -49,7 +49,7 @@ fn bar_view(bar: &Bar) -> Element<'_, Message> {
|
|||||||
.map(|w| Message::Event(Msg::Wire(w)))
|
.map(|w| Message::Event(Msg::Wire(w)))
|
||||||
})
|
})
|
||||||
.collect::<Vec<Element<Message>>>())
|
.collect::<Vec<Element<Message>>>())
|
||||||
.spacing(8)
|
.spacing(bar.spacing)
|
||||||
.align_y(Alignment::Center);
|
.align_y(Alignment::Center);
|
||||||
let right = row(bar
|
let right = row(bar
|
||||||
.order
|
.order
|
||||||
@@ -63,7 +63,7 @@ fn bar_view(bar: &Bar) -> Element<'_, Message> {
|
|||||||
.map(|w| Message::Event(Msg::Wire(w)))
|
.map(|w| Message::Event(Msg::Wire(w)))
|
||||||
})
|
})
|
||||||
.collect::<Vec<Element<Message>>>())
|
.collect::<Vec<Element<Message>>>())
|
||||||
.spacing(8)
|
.spacing(bar.spacing)
|
||||||
.align_y(Alignment::Center);
|
.align_y(Alignment::Center);
|
||||||
|
|
||||||
let row = row![
|
let row = row![
|
||||||
@@ -77,7 +77,7 @@ fn bar_view(bar: &Bar) -> Element<'_, Message> {
|
|||||||
.align_y(Alignment::Center);
|
.align_y(Alignment::Center);
|
||||||
|
|
||||||
container(row)
|
container(row)
|
||||||
.padding(8)
|
.padding([0.0, bar.padding])
|
||||||
.width(Length::Fill)
|
.width(Length::Fill)
|
||||||
.height(Length::Fill)
|
.height(Length::Fill)
|
||||||
.align_y(Alignment::Center)
|
.align_y(Alignment::Center)
|
||||||
|
|||||||
@@ -1,4 +1,16 @@
|
|||||||
|
[display]
|
||||||
|
# Output to pin the bar to; omit to follow the active output.
|
||||||
monitor = "DP-2"
|
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]
|
[order]
|
||||||
left = ["workspaces", "weather"]
|
left = ["workspaces", "weather"]
|
||||||
|
|||||||
Reference in New Issue
Block a user