From 539c80cda9fab613a47b6ed20559241cf9a05173 Mon Sep 17 00:00:00 2001 From: Doloro1978 Date: Sat, 12 Sep 2026 12:24:36 +0100 Subject: [PATCH] fucking something i forgot --- Cargo.lock | 151 +++++++++++++++--- Cargo.toml | 4 +- crates/common/Cargo.toml | 1 + crates/common/src/config.rs | 10 ++ crates/common/src/lib.rs | 2 + crates/core/Cargo.toml | 2 + crates/core/src/args.rs | 10 ++ crates/core/src/main.rs | 23 ++- crates/modules/Cargo.toml | 6 +- crates/modules/clock/Cargo.toml | 15 -- crates/modules/clock/src/lib.rs | 7 - .../{clock/src/module.rs => src/clock.rs} | 41 +++-- crates/modules/src/lib.rs | 11 +- crates/services/Cargo.toml | 3 +- crates/services/datetime/Cargo.toml | 14 -- crates/services/datetime/src/kind.rs | 28 ---- crates/services/datetime/src/lib.rs | 11 -- .../src/ticker.rs => src/datetime.rs} | 35 +++- crates/services/src/lib.rs | 10 +- test.toml | 4 + 20 files changed, 260 insertions(+), 128 deletions(-) create mode 100644 crates/common/src/config.rs create mode 100644 crates/core/src/args.rs delete mode 100644 crates/modules/clock/Cargo.toml delete mode 100644 crates/modules/clock/src/lib.rs rename crates/modules/{clock/src/module.rs => src/clock.rs} (77%) delete mode 100644 crates/services/datetime/Cargo.toml delete mode 100644 crates/services/datetime/src/kind.rs delete mode 100644 crates/services/datetime/src/lib.rs rename crates/services/{datetime/src/ticker.rs => src/datetime.rs} (69%) create mode 100644 test.toml diff --git a/Cargo.lock b/Cargo.lock index 58286d2..88c72d6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -65,6 +65,56 @@ dependencies = [ "libc", ] +[[package]] +name = "anstream" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "824a212faf96e9acacdbd09febd34438f8f711fb84e09a8916013cd7815ca28d" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000" + +[[package]] +name = "anstyle-parse" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52ce7f38b242319f7cabaa6813055467063ecdc9d355bbb4ce0c68908cd8130e" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" +dependencies = [ + "anstyle", + "once_cell_polyfill", + "windows-sys 0.61.2", +] + [[package]] name = "arrayref" version = "0.3.9" @@ -270,6 +320,46 @@ dependencies = [ "windows-link", ] +[[package]] +name = "clap" +version = "4.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "473c7e07f409a8d772161724aa8db6a765a2532a70f9667eeb7b49d3d02fbdca" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b48fea5a88e9ae728a2dcbedbfc0e730f7d60da42e1cb049a83c9fb8b789889" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d012d2b9d65aca7f18f4d9878a045bc17899bba951561ba5ec3c2ba1eed9a061" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 3.0.5", +] + +[[package]] +name = "clap_lex" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8d4a3bb8b1e0c1050499d1815f5ab16d04f0959b233085fb31653fbfc9d98f9" + [[package]] name = "clipboard-win" version = "5.4.1" @@ -320,6 +410,12 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "colorchoice" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570" + [[package]] name = "combine" version = "4.6.8" @@ -335,6 +431,7 @@ name = "common" version = "0.1.0" dependencies = [ "iced", + "serde", "toml", ] @@ -352,12 +449,14 @@ name = "core" version = "0.1.0" dependencies = [ "chrono", + "clap", "common", "iced", "iced_layershell", "modules", "services", "tokio", + "toml", ] [[package]] @@ -1014,6 +1113,12 @@ version = "0.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "hermit-abi" version = "0.5.3" @@ -1418,6 +1523,12 @@ dependencies = [ "hashbrown 0.17.1", ] +[[package]] +name = "is_terminal_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" + [[package]] name = "jni" version = "0.22.4" @@ -1713,23 +1824,16 @@ dependencies = [ "paste", ] -[[package]] -name = "module-clock" -version = "0.1.0" -dependencies = [ - "common", - "iced", - "service-datetime", - "thiserror 2.0.20", - "toml", -] - [[package]] name = "modules" version = "0.1.0" dependencies = [ "common", - "module-clock", + "iced", + "serde", + "services", + "thiserror 2.0.20", + "toml", ] [[package]] @@ -2105,6 +2209,12 @@ version = "1.21.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" +[[package]] +name = "once_cell_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" + [[package]] name = "orbclient" version = "0.3.55" @@ -2539,7 +2649,7 @@ dependencies = [ ] [[package]] -name = "service-datetime" +name = "services" version = "0.1.0" dependencies = [ "chrono", @@ -2548,15 +2658,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "services" -version = "0.1.0" -dependencies = [ - "common", - "iced", - "service-datetime", -] - [[package]] name = "shlex" version = "2.0.1" @@ -3104,6 +3205,12 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + [[package]] name = "version_check" version = "0.9.5" diff --git a/Cargo.toml b/Cargo.toml index 8ffcda8..e04d428 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = ["crates/core", "crates/common", "crates/modules", "crates/modules/clock", "crates/services", "crates/services/datetime"] +members = ["crates/core", "crates/common", "crates/modules", "crates/services"] resolver = "2" [workspace.package] @@ -14,7 +14,7 @@ chrono = "0.4" toml = "1.1" serde = { version = "1", features = ["derive"] } thiserror = "2" -clap = { version = "4.5", features = ["derive"] } +clap = { version = "4.6.6", features = ["derive", "help"] } # Optimize all dependencies even in dev builds; workspace members keep dev # defaults (opt-level 0) and release settings under --release. diff --git a/crates/common/Cargo.toml b/crates/common/Cargo.toml index 69d140c..874ad22 100644 --- a/crates/common/Cargo.toml +++ b/crates/common/Cargo.toml @@ -10,3 +10,4 @@ path = "src/lib.rs" [dependencies] iced = { workspace = true } toml = { workspace = true } +serde = { workspace = true } diff --git a/crates/common/src/config.rs b/crates/common/src/config.rs new file mode 100644 index 0000000..9307580 --- /dev/null +++ b/crates/common/src/config.rs @@ -0,0 +1,10 @@ +use serde::{Deserialize, Serialize}; +use toml::Table; + +#[derive(Serialize, Deserialize)] +pub struct BarbarConfig { + pub monitor: Option, + pub ups: Option, // Updates per second + pub modules: Option, // 'clock': [clock settings] + pub services: Option
, // 'clockticker': [clockticker settings] +} diff --git a/crates/common/src/lib.rs b/crates/common/src/lib.rs index a82781f..ff8dcbb 100644 --- a/crates/common/src/lib.rs +++ b/crates/common/src/lib.rs @@ -4,10 +4,12 @@ //! layer-shell effects). `common` is the hub every other crate depends on, //! so it must stay acyclic and pure. +mod config; mod effect; mod module; mod service; +pub use config::BarbarConfig; pub use effect::ModuleEffect; pub use module::{BarModule, ModuleMsg}; pub use service::{Service, ServiceEvent}; diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index b771611..ea15583 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -12,6 +12,8 @@ iced = { workspace = true } iced_layershell = { workspace = true } tokio = { workspace = true } chrono = { workspace = true } +clap = {workspace = true} +toml = {workspace =true} # Modules + services modules = { path = "../modules" } services = { path = "../services" } diff --git a/crates/core/src/args.rs b/crates/core/src/args.rs new file mode 100644 index 0000000..b82ae59 --- /dev/null +++ b/crates/core/src/args.rs @@ -0,0 +1,10 @@ +use clap::Parser; +use std::path::PathBuf; + +#[derive(Parser)] +pub struct Args { + #[arg(short, long)] + pub config: PathBuf, + // #[arg(long)] + // demo: bool, +} diff --git a/crates/core/src/main.rs b/crates/core/src/main.rs index f322206..c9e5fd2 100644 --- a/crates/core/src/main.rs +++ b/crates/core/src/main.rs @@ -4,11 +4,17 @@ //! `wlr-layer-shell`. Optional first CLI arg = target output name. //! Clicking a module's button spawns a LayerShell popup anchored to it. +use std::fs::File; +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; mod msg; mod popup; mod subscription; @@ -22,8 +28,21 @@ pub(crate) use msg::{Message, Msg}; const BAR_HEIGHT: u32 = 36; fn main() -> Result<(), iced_layershell::Error> { - let start_mode = match std::env::args().nth(1) { - Some(output) => StartMode::TargetScreen(output), + let args = args::Args::parse(); + + let config_handle = File::open(args.config); + let config: BarbarConfig; + if let Ok(mut config_file) = config_handle { + let mut string = String::new(); + config_file.read_to_string(&mut string).unwrap(); + config = toml::from_str(&string).unwrap(); + } else { + println!("cant open config file"); + return Ok(()); + } + + let start_mode = match config.monitor { + Some(x) => StartMode::TargetScreen(x), None => StartMode::Active, }; diff --git a/crates/modules/Cargo.toml b/crates/modules/Cargo.toml index dffa7c1..7f0cfd2 100644 --- a/crates/modules/Cargo.toml +++ b/crates/modules/Cargo.toml @@ -9,4 +9,8 @@ path = "src/lib.rs" [dependencies] common = { path = "../common" } -module_clock = { package = "module-clock", path = "clock" } +services = { path = "../services" } +iced = { workspace = true } +thiserror = { workspace = true } +toml = { workspace = true } +serde = {workspace = true} diff --git a/crates/modules/clock/Cargo.toml b/crates/modules/clock/Cargo.toml deleted file mode 100644 index 4c960af..0000000 --- a/crates/modules/clock/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "module-clock" -version.workspace = true -edition.workspace = true - -[lib] -name = "module_clock" -path = "src/lib.rs" - -[dependencies] -common = { path = "../../common" } -service_datetime = { package = "service-datetime", path = "../../services/datetime" } -iced = { workspace = true } -thiserror = { workspace = true } -toml = { workspace = true } diff --git a/crates/modules/clock/src/lib.rs b/crates/modules/clock/src/lib.rs deleted file mode 100644 index a14201f..0000000 --- a/crates/modules/clock/src/lib.rs +++ /dev/null @@ -1,7 +0,0 @@ -//! Clock module: subscribes to second ticks, renders the time in the bar. -//! Left-click toggles the seconds suffix; right-click opens a popup with -//! the current time in large text. - -mod module; - -pub use module::{Clock, ClockError, ClockMsg}; diff --git a/crates/modules/clock/src/module.rs b/crates/modules/src/clock.rs similarity index 77% rename from crates/modules/clock/src/module.rs rename to crates/modules/src/clock.rs index 74ef411..8227d4b 100644 --- a/crates/modules/clock/src/module.rs +++ b/crates/modules/src/clock.rs @@ -1,8 +1,14 @@ +//! Clock module: subscribes to second ticks, renders the time in the bar. +//! Left-click toggles the seconds suffix; right-click opens a popup with +//! the current time in large text. + use iced::widget::{container, mouse_area, text}; use iced::{Element, Task}; use common::{BarModule, ModuleEffect, ModuleMsg, Service}; -use service_datetime::{ClockKind, ClockPayload}; +use serde::Deserialize; +use services::datetime::{ClockKind, ClockPayload}; +use toml::Table; /// Big-text popup size (logical px). const POPUP_W: u32 = 360; @@ -30,11 +36,21 @@ pub struct Clock { show_seconds: bool, } +#[derive(Deserialize, Default)] +struct ClockConfig { + #[serde(default)] + format: bool, +} + impl Clock { - pub fn new() -> Self { - Self { - value: "--:--:--".to_string(), - show_seconds: true, + pub fn new(config: Option
) -> Self { + let module_config = config_clock(config); + match module_config { + Some(x) => Self { + value: "--:--:--".to_string(), + show_seconds: { x.format }, + }, + None => Self::default(), } } @@ -54,10 +70,15 @@ impl Clock { impl Default for Clock { fn default() -> Self { - Self::new() + Self::new(None) } } +fn config_clock(table: Option
) -> Option { + let clock = table?.get("clock")?.clone(); + clock.try_into().ok() +} + impl BarModule for Clock { fn id(&self) -> &'static str { "clock" @@ -105,12 +126,4 @@ impl BarModule for Clock { fn popup_size(&self) -> Option<(u32, u32)> { Some((POPUP_W, POPUP_H)) } - fn config(&mut self, config: toml::Table) -> Result<(), Box> { - if let toml::Value::Boolean(e) = config["format"] { - if e { - self.show_seconds = true; - }; - } - Ok(()) - } } diff --git a/crates/modules/src/lib.rs b/crates/modules/src/lib.rs index 26d93f6..8ee5a01 100644 --- a/crates/modules/src/lib.rs +++ b/crates/modules/src/lib.rs @@ -1,10 +1,13 @@ //! Bar module registry: constructs every enabled module. Adding a module is -//! a new crate under `crates/modules/` plus one entry in `all()` — core -//! never changes. +//! a new file under `src/` plus one entry in `all()` — core never changes. +mod clock; + +pub use clock::{Clock, ClockError, ClockMsg}; use common::BarModule; +use toml::Table; /// One instance of every enabled module, ready to insert by `id()`. -pub fn all() -> Vec> { - vec![Box::new(module_clock::Clock::new())] +pub fn all(module_config: Table) -> Vec> { + vec![Box::new(clock::Clock::new(Some(module_config)))] } diff --git a/crates/services/Cargo.toml b/crates/services/Cargo.toml index 5ab13d6..1cb6fe9 100644 --- a/crates/services/Cargo.toml +++ b/crates/services/Cargo.toml @@ -9,5 +9,6 @@ path = "src/lib.rs" [dependencies] common = { path = "../common" } -service_datetime = { package = "service-datetime", path = "datetime" } iced = { workspace = true } +tokio = { workspace = true } +chrono = { workspace = true } diff --git a/crates/services/datetime/Cargo.toml b/crates/services/datetime/Cargo.toml deleted file mode 100644 index 0aedec3..0000000 --- a/crates/services/datetime/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "service-datetime" -version.workspace = true -edition.workspace = true - -[lib] -name = "service_datetime" -path = "src/lib.rs" - -[dependencies] -common = { path = "../../common" } -iced = { workspace = true } -tokio = { workspace = true } -chrono = { workspace = true } diff --git a/crates/services/datetime/src/kind.rs b/crates/services/datetime/src/kind.rs deleted file mode 100644 index 06f3359..0000000 --- a/crates/services/datetime/src/kind.rs +++ /dev/null @@ -1,28 +0,0 @@ -use common::Service; - -/// Route-key namespace owned by this service; keys are `"clock."`. -pub const NAMESPACE: &str = "clock."; - -/// What a clock subscription wants: the tick interval and payload selector. -#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] -pub enum ClockKind { - Mins, - Seconds, -} - -impl ClockKind { - /// Route key a module subscribes under to receive this kind's ticks. - pub fn key(self) -> Service { - Service(match self { - Self::Mins => "clock.mins", - Self::Seconds => "clock.seconds", - }) - } -} - -/// Clock tick payload: the value plus the kind that produced it. -#[derive(Clone, PartialEq, Eq, Debug)] -pub struct ClockPayload { - pub kind: ClockKind, - pub value: String, -} diff --git a/crates/services/datetime/src/lib.rs b/crates/services/datetime/src/lib.rs deleted file mode 100644 index d9a0f2f..0000000 --- a/crates/services/datetime/src/lib.rs +++ /dev/null @@ -1,11 +0,0 @@ -//! Clock service: emits a `ServiceEvent` whenever a clock kind's displayed -//! value changes (minute or second rollover). -//! -//! The ticker knows nothing about the app's `Message` type; it produces -//! protocol events from `common` that core routes to subscribed modules. - -mod kind; -mod ticker; - -pub use kind::{ClockKind, ClockPayload, NAMESPACE}; -pub use ticker::ClockTicker; diff --git a/crates/services/datetime/src/ticker.rs b/crates/services/src/datetime.rs similarity index 69% rename from crates/services/datetime/src/ticker.rs rename to crates/services/src/datetime.rs index eb24845..ecc17d3 100644 --- a/crates/services/datetime/src/ticker.rs +++ b/crates/services/src/datetime.rs @@ -1,11 +1,42 @@ +//! Clock service: emits a `ServiceEvent` whenever a clock kind's displayed +//! value changes (minute or second rollover). +//! +//! The ticker knows nothing about the app's `Message` type; it produces +//! protocol events from `common` that core routes to subscribed modules. + use std::collections::HashMap; use std::sync::Arc; use iced::{futures::SinkExt, Subscription}; -use common::ServiceEvent; +use common::{Service, ServiceEvent}; -use crate::kind::{ClockKind, ClockPayload}; +/// Route-key namespace owned by this service; keys are `"clock."`. +pub const NAMESPACE: &str = "clock."; + +/// What a clock subscription wants: the tick interval and payload selector. +#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] +pub enum ClockKind { + Mins, + Seconds, +} + +impl ClockKind { + /// Route key a module subscribes under to receive this kind's ticks. + pub fn key(self) -> Service { + Service(match self { + Self::Mins => "clock.mins", + Self::Seconds => "clock.seconds", + }) + } +} + +/// Clock tick payload: the value plus the kind that produced it. +#[derive(Clone, PartialEq, Eq, Debug)] +pub struct ClockPayload { + pub kind: ClockKind, + pub value: String, +} /// Emits a payload only when a kind's displayed value changes (minute or /// second rollover). Drive `tick` once per second. diff --git a/crates/services/src/lib.rs b/crates/services/src/lib.rs index d304f90..5ea76a1 100644 --- a/crates/services/src/lib.rs +++ b/crates/services/src/lib.rs @@ -1,11 +1,13 @@ //! Service registry: turns a route key into the subscription that backs it. -//! Adding a service is a new crate under `crates/services/` plus one arm in -//! the impl below — core never changes. +//! Adding a service is a new file under `src/` plus one arm in the impl below +//! — core never changes. use iced::Subscription; use common::{Service, ServiceEvent}; +pub mod datetime; + /// Conversion from a route key to the subscription backing it. /// /// An extension trait (not `impl From for Subscription<...>`) because @@ -18,9 +20,7 @@ pub trait IntoSubscription { impl IntoSubscription for Service { fn into_subscription(self) -> Subscription { match self.0 { - key if key.starts_with(service_datetime::NAMESPACE) => { - service_datetime::ClockTicker::run() - } + key if key.starts_with(datetime::NAMESPACE) => datetime::ClockTicker::run(), _ => Subscription::none(), } } diff --git a/test.toml b/test.toml new file mode 100644 index 0000000..cf0c621 --- /dev/null +++ b/test.toml @@ -0,0 +1,4 @@ +monitor = "DP-2" + +[modules.clock] +format = "meow"