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;
|
||||
|
||||
Reference in New Issue
Block a user