fucking something i forgot

This commit is contained in:
2026-09-12 12:24:36 +01:00
parent bdec970b62
commit 539c80cda9
20 changed files with 260 additions and 128 deletions
+1
View File
@@ -10,3 +10,4 @@ path = "src/lib.rs"
[dependencies]
iced = { workspace = true }
toml = { workspace = true }
serde = { workspace = true }
+10
View File
@@ -0,0 +1,10 @@
use serde::{Deserialize, Serialize};
use toml::Table;
#[derive(Serialize, Deserialize)]
pub struct BarbarConfig {
pub monitor: Option<String>,
pub ups: Option<i32>, // Updates per second
pub modules: Option<Table>, // 'clock': [clock settings]
pub services: Option<Table>, // 'clockticker': [clockticker settings]
}
+2
View File
@@ -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};
+2
View File
@@ -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" }
+10
View File
@@ -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,
}
+21 -2
View File
@@ -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,
};
+5 -1
View File
@@ -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}
-15
View File
@@ -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 }
-7
View File
@@ -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};
@@ -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<Table>) -> 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<Table>) -> Option<ClockConfig> {
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<dyn std::error::Error>> {
if let toml::Value::Boolean(e) = config["format"] {
if e {
self.show_seconds = true;
};
}
Ok(())
}
}
+7 -4
View File
@@ -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<Box<dyn BarModule>> {
vec![Box::new(module_clock::Clock::new())]
pub fn all(module_config: Table) -> Vec<Box<dyn BarModule>> {
vec![Box::new(clock::Clock::new(Some(module_config)))]
}
+2 -1
View File
@@ -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 }
-14
View File
@@ -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 }
-28
View File
@@ -1,28 +0,0 @@
use common::Service;
/// Route-key namespace owned by this service; keys are `"clock.<kind>"`.
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,
}
-11
View File
@@ -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;
@@ -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.<kind>"`.
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.
+5 -5
View File
@@ -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<Service> for Subscription<...>`) because
@@ -18,9 +20,7 @@ pub trait IntoSubscription {
impl IntoSubscription for Service {
fn into_subscription(self) -> Subscription<ServiceEvent> {
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(),
}
}