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
Generated
+129 -22
View File
@@ -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"
+2 -2
View File
@@ -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.
+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 {
pub fn new(config: Option<Table>) -> Self {
let module_config = config_clock(config);
match module_config {
Some(x) => Self {
value: "--:--:--".to_string(),
show_seconds: true,
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(),
}
}
+4
View File
@@ -0,0 +1,4 @@
monitor = "DP-2"
[modules.clock]
format = "meow"