basic battery module/service

This commit is contained in:
2026-09-16 11:06:12 +01:00
parent 120eaf5855
commit 63e1c0ee4c
10 changed files with 639 additions and 1 deletions
+2
View File
@@ -17,6 +17,7 @@ pub struct BarbarConfig {
#[serde(rename_all = "lowercase")]
pub enum Modules {
Audio,
Battery,
Clock,
Weather,
Workspaces,
@@ -26,6 +27,7 @@ impl Modules {
pub fn to_string(&self) -> &str {
match self {
Modules::Audio => "audio",
Modules::Battery => "battery",
Modules::Clock => "clock",
Modules::Weather => "weather",
Modules::Workspaces => "workspaces",
@@ -0,0 +1,44 @@
//! Battery service messages.
use crate::Service;
/// Route key a module subscribes under to receive battery events. One
/// stream carries every event; the [`BatteryEvent`] payload tags which one,
/// so modules filter on it.
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
pub enum BatteryMsg {
Events,
}
impl BatteryMsg {
/// Route key a module subscribes under to receive this service's events.
pub fn key(self) -> Service {
Service(match self {
Self::Events => "battery.events",
})
}
}
/// Charge state of the first battery, without depending on D-Bus types
/// outside the service itself.
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Default)]
pub enum BatteryStatus {
#[default]
Unknown,
Charging,
Discharging,
Empty,
Full,
}
/// A battery event, published to subscribers of the events key.
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
pub enum BatteryEvent {
/// Charge percentage changed (0..=100).
PercentageChanged(i32),
/// Charging state changed.
StatusChanged(BatteryStatus),
/// Seconds until full (charging) or empty (discharging) changed;
/// `None` when unknown or not applicable.
EtaChanged(Option<u64>),
}
@@ -1,10 +1,12 @@
//! Messages owned by services.
mod battery;
mod datetime;
mod hyprland;
mod pipewire;
mod weather;
pub use battery::*;
pub use datetime::*;
pub use hyprland::*;
pub use pipewire::*;