batery and time working (POC more than anything)

This commit is contained in:
Jiří Maxmilián Stříbrný 2026-03-17 19:25:26 +01:00
parent 70ad7e9b65
commit 958b7714da
7 changed files with 107 additions and 25 deletions

View file

@ -1,19 +1,19 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -e
if [[ ! -d "/mnt/removable/Projects/Rust/wayland_panel" ]]; then if [[ ! -d "/home/maxag/Projects/Rust/wayland_panel" ]]; then
echo "Cannot find source directory; Did you move it?" echo "Cannot find source directory; Did you move it?"
echo "(Looking for "/mnt/removable/Projects/Rust/wayland_panel")" echo "(Looking for "/home/maxag/Projects/Rust/wayland_panel")"
echo 'Cannot force reload with this script - use "direnv reload" manually and then try again' echo 'Cannot force reload with this script - use "direnv reload" manually and then try again'
exit 1 exit 1
fi fi
# rebuild the cache forcefully # rebuild the cache forcefully
_nix_direnv_force_reload=1 direnv exec "/mnt/removable/Projects/Rust/wayland_panel" true _nix_direnv_force_reload=1 direnv exec "/home/maxag/Projects/Rust/wayland_panel" true
# Update the mtime for .envrc. # Update the mtime for .envrc.
# This will cause direnv to reload again - but without re-building. # This will cause direnv to reload again - but without re-building.
touch "/mnt/removable/Projects/Rust/wayland_panel/.envrc" touch "/home/maxag/Projects/Rust/wayland_panel/.envrc"
# Also update the timestamp of whatever profile_rc we have. # Also update the timestamp of whatever profile_rc we have.
# This makes sure that we know we are up to date. # This makes sure that we know we are up to date.
touch -r "/mnt/removable/Projects/Rust/wayland_panel/.envrc" "/mnt/removable/Projects/Rust/wayland_panel/.direnv"/*.rc touch -r "/home/maxag/Projects/Rust/wayland_panel/.envrc" "/home/maxag/Projects/Rust/wayland_panel/.direnv"/*.rc

View file

@ -0,0 +1 @@
/nix/store/hiqaajlf19pcrhc05q5nnwv4dxznhnsq-source

View file

@ -1 +0,0 @@
/nix/store/sgbaklhjmn4dm32y5fvmg70hccrr47qa-source

View file

@ -47,7 +47,7 @@ NIX_BINTOOLS_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu='1'
export NIX_BINTOOLS_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu export NIX_BINTOOLS_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu
NIX_BINTOOLS_WRAPPER_TARGET_TARGET_x86_64_unknown_linux_gnu='1' NIX_BINTOOLS_WRAPPER_TARGET_TARGET_x86_64_unknown_linux_gnu='1'
export NIX_BINTOOLS_WRAPPER_TARGET_TARGET_x86_64_unknown_linux_gnu export NIX_BINTOOLS_WRAPPER_TARGET_TARGET_x86_64_unknown_linux_gnu
NIX_BUILD_CORES='16' NIX_BUILD_CORES='12'
export NIX_BUILD_CORES export NIX_BUILD_CORES
NIX_CC='/nix/store/kbw2j1vag664b3sj3rjwz9v53cqx87sb-gcc-wrapper-15.2.0' NIX_CC='/nix/store/kbw2j1vag664b3sj3rjwz9v53cqx87sb-gcc-wrapper-15.2.0'
export NIX_CC export NIX_CC
@ -65,7 +65,7 @@ NIX_ENFORCE_NO_NATIVE='1'
export NIX_ENFORCE_NO_NATIVE export NIX_ENFORCE_NO_NATIVE
NIX_HARDENING_ENABLE='bindnow format fortify fortify3 libcxxhardeningextensive libcxxhardeningfast pic relro stackclashprotection stackprotector strictoverflow zerocallusedregs' NIX_HARDENING_ENABLE='bindnow format fortify fortify3 libcxxhardeningextensive libcxxhardeningfast pic relro stackclashprotection stackprotector strictoverflow zerocallusedregs'
export NIX_HARDENING_ENABLE export NIX_HARDENING_ENABLE
NIX_LDFLAGS='-rpath /mnt/removable/Projects/Rust/wayland_panel/outputs/out/lib -L/nix/store/fv438zxk1mvcfi2sj20mgn4s91qpjdcd-rust-default-1.94.0/lib -L/nix/store/fv438zxk1mvcfi2sj20mgn4s91qpjdcd-rust-default-1.94.0/lib -L/nix/store/jcc9imfj4samq59gwsskxalcd9rjicip-wayland-1.24.0/lib -L/nix/store/jcc9imfj4samq59gwsskxalcd9rjicip-wayland-1.24.0/lib -L/nix/store/k1gvr4prs9736r1lhqyy1plxrrvv9b4m-libxkbcommon-1.11.0/lib -L/nix/store/k1gvr4prs9736r1lhqyy1plxrrvv9b4m-libxkbcommon-1.11.0/lib -L/nix/store/vl8jkqpr0l3fac3cxiy4nwc5paiww1lv-zlib-1.3.1/lib -L/nix/store/vl8jkqpr0l3fac3cxiy4nwc5paiww1lv-zlib-1.3.1/lib -L/nix/store/5mnq195cx3cagnpbbvf5ncbp4fjgy0sz-libffi-3.5.2/lib -L/nix/store/5mnq195cx3cagnpbbvf5ncbp4fjgy0sz-libffi-3.5.2/lib -L/nix/store/md592gfars4m9madyrpj9yrq5jhckgjf-gettext-0.26/lib -L/nix/store/md592gfars4m9madyrpj9yrq5jhckgjf-gettext-0.26/lib -L/nix/store/1qm74vf93ik1xjrr9kl6qvjrklljlcqh-glib-2.86.3/lib -L/nix/store/1qm74vf93ik1xjrr9kl6qvjrklljlcqh-glib-2.86.3/lib -L/nix/store/1il4q8s87v0p8xp1g2q8mmbswbwkj23l-vulkan-loader-1.4.341.0/lib -L/nix/store/1il4q8s87v0p8xp1g2q8mmbswbwkj23l-vulkan-loader-1.4.341.0/lib -L/nix/store/g7wjwz546f510jv95318n23330c3ni7k-mesa-26.0.2/lib -L/nix/store/g7wjwz546f510jv95318n23330c3ni7k-mesa-26.0.2/lib -L/nix/store/wwckb31fcbwj479g7qwcb3b7cv6416pf-libglvnd-1.7.0/lib -L/nix/store/wwckb31fcbwj479g7qwcb3b7cv6416pf-libglvnd-1.7.0/lib -L/nix/store/fv438zxk1mvcfi2sj20mgn4s91qpjdcd-rust-default-1.94.0/lib -L/nix/store/fv438zxk1mvcfi2sj20mgn4s91qpjdcd-rust-default-1.94.0/lib -L/nix/store/jcc9imfj4samq59gwsskxalcd9rjicip-wayland-1.24.0/lib -L/nix/store/jcc9imfj4samq59gwsskxalcd9rjicip-wayland-1.24.0/lib -L/nix/store/k1gvr4prs9736r1lhqyy1plxrrvv9b4m-libxkbcommon-1.11.0/lib -L/nix/store/k1gvr4prs9736r1lhqyy1plxrrvv9b4m-libxkbcommon-1.11.0/lib -L/nix/store/vl8jkqpr0l3fac3cxiy4nwc5paiww1lv-zlib-1.3.1/lib -L/nix/store/vl8jkqpr0l3fac3cxiy4nwc5paiww1lv-zlib-1.3.1/lib -L/nix/store/5mnq195cx3cagnpbbvf5ncbp4fjgy0sz-libffi-3.5.2/lib -L/nix/store/5mnq195cx3cagnpbbvf5ncbp4fjgy0sz-libffi-3.5.2/lib -L/nix/store/md592gfars4m9madyrpj9yrq5jhckgjf-gettext-0.26/lib -L/nix/store/md592gfars4m9madyrpj9yrq5jhckgjf-gettext-0.26/lib -L/nix/store/1qm74vf93ik1xjrr9kl6qvjrklljlcqh-glib-2.86.3/lib -L/nix/store/1qm74vf93ik1xjrr9kl6qvjrklljlcqh-glib-2.86.3/lib -L/nix/store/1il4q8s87v0p8xp1g2q8mmbswbwkj23l-vulkan-loader-1.4.341.0/lib -L/nix/store/1il4q8s87v0p8xp1g2q8mmbswbwkj23l-vulkan-loader-1.4.341.0/lib -L/nix/store/g7wjwz546f510jv95318n23330c3ni7k-mesa-26.0.2/lib -L/nix/store/g7wjwz546f510jv95318n23330c3ni7k-mesa-26.0.2/lib -L/nix/store/wwckb31fcbwj479g7qwcb3b7cv6416pf-libglvnd-1.7.0/lib -L/nix/store/wwckb31fcbwj479g7qwcb3b7cv6416pf-libglvnd-1.7.0/lib' NIX_LDFLAGS='-rpath /home/maxag/Projects/Rust/wayland_panel/outputs/out/lib -L/nix/store/fv438zxk1mvcfi2sj20mgn4s91qpjdcd-rust-default-1.94.0/lib -L/nix/store/fv438zxk1mvcfi2sj20mgn4s91qpjdcd-rust-default-1.94.0/lib -L/nix/store/jcc9imfj4samq59gwsskxalcd9rjicip-wayland-1.24.0/lib -L/nix/store/jcc9imfj4samq59gwsskxalcd9rjicip-wayland-1.24.0/lib -L/nix/store/k1gvr4prs9736r1lhqyy1plxrrvv9b4m-libxkbcommon-1.11.0/lib -L/nix/store/k1gvr4prs9736r1lhqyy1plxrrvv9b4m-libxkbcommon-1.11.0/lib -L/nix/store/vl8jkqpr0l3fac3cxiy4nwc5paiww1lv-zlib-1.3.1/lib -L/nix/store/vl8jkqpr0l3fac3cxiy4nwc5paiww1lv-zlib-1.3.1/lib -L/nix/store/5mnq195cx3cagnpbbvf5ncbp4fjgy0sz-libffi-3.5.2/lib -L/nix/store/5mnq195cx3cagnpbbvf5ncbp4fjgy0sz-libffi-3.5.2/lib -L/nix/store/md592gfars4m9madyrpj9yrq5jhckgjf-gettext-0.26/lib -L/nix/store/md592gfars4m9madyrpj9yrq5jhckgjf-gettext-0.26/lib -L/nix/store/1qm74vf93ik1xjrr9kl6qvjrklljlcqh-glib-2.86.3/lib -L/nix/store/1qm74vf93ik1xjrr9kl6qvjrklljlcqh-glib-2.86.3/lib -L/nix/store/1il4q8s87v0p8xp1g2q8mmbswbwkj23l-vulkan-loader-1.4.341.0/lib -L/nix/store/1il4q8s87v0p8xp1g2q8mmbswbwkj23l-vulkan-loader-1.4.341.0/lib -L/nix/store/g7wjwz546f510jv95318n23330c3ni7k-mesa-26.0.2/lib -L/nix/store/g7wjwz546f510jv95318n23330c3ni7k-mesa-26.0.2/lib -L/nix/store/wwckb31fcbwj479g7qwcb3b7cv6416pf-libglvnd-1.7.0/lib -L/nix/store/wwckb31fcbwj479g7qwcb3b7cv6416pf-libglvnd-1.7.0/lib -L/nix/store/fv438zxk1mvcfi2sj20mgn4s91qpjdcd-rust-default-1.94.0/lib -L/nix/store/fv438zxk1mvcfi2sj20mgn4s91qpjdcd-rust-default-1.94.0/lib -L/nix/store/jcc9imfj4samq59gwsskxalcd9rjicip-wayland-1.24.0/lib -L/nix/store/jcc9imfj4samq59gwsskxalcd9rjicip-wayland-1.24.0/lib -L/nix/store/k1gvr4prs9736r1lhqyy1plxrrvv9b4m-libxkbcommon-1.11.0/lib -L/nix/store/k1gvr4prs9736r1lhqyy1plxrrvv9b4m-libxkbcommon-1.11.0/lib -L/nix/store/vl8jkqpr0l3fac3cxiy4nwc5paiww1lv-zlib-1.3.1/lib -L/nix/store/vl8jkqpr0l3fac3cxiy4nwc5paiww1lv-zlib-1.3.1/lib -L/nix/store/5mnq195cx3cagnpbbvf5ncbp4fjgy0sz-libffi-3.5.2/lib -L/nix/store/5mnq195cx3cagnpbbvf5ncbp4fjgy0sz-libffi-3.5.2/lib -L/nix/store/md592gfars4m9madyrpj9yrq5jhckgjf-gettext-0.26/lib -L/nix/store/md592gfars4m9madyrpj9yrq5jhckgjf-gettext-0.26/lib -L/nix/store/1qm74vf93ik1xjrr9kl6qvjrklljlcqh-glib-2.86.3/lib -L/nix/store/1qm74vf93ik1xjrr9kl6qvjrklljlcqh-glib-2.86.3/lib -L/nix/store/1il4q8s87v0p8xp1g2q8mmbswbwkj23l-vulkan-loader-1.4.341.0/lib -L/nix/store/1il4q8s87v0p8xp1g2q8mmbswbwkj23l-vulkan-loader-1.4.341.0/lib -L/nix/store/g7wjwz546f510jv95318n23330c3ni7k-mesa-26.0.2/lib -L/nix/store/g7wjwz546f510jv95318n23330c3ni7k-mesa-26.0.2/lib -L/nix/store/wwckb31fcbwj479g7qwcb3b7cv6416pf-libglvnd-1.7.0/lib -L/nix/store/wwckb31fcbwj479g7qwcb3b7cv6416pf-libglvnd-1.7.0/lib'
export NIX_LDFLAGS export NIX_LDFLAGS
NIX_LDFLAGS_FOR_TARGET=' -L/nix/store/fv438zxk1mvcfi2sj20mgn4s91qpjdcd-rust-default-1.94.0/lib -L/nix/store/jcc9imfj4samq59gwsskxalcd9rjicip-wayland-1.24.0/lib -L/nix/store/k1gvr4prs9736r1lhqyy1plxrrvv9b4m-libxkbcommon-1.11.0/lib -L/nix/store/vl8jkqpr0l3fac3cxiy4nwc5paiww1lv-zlib-1.3.1/lib -L/nix/store/5mnq195cx3cagnpbbvf5ncbp4fjgy0sz-libffi-3.5.2/lib -L/nix/store/md592gfars4m9madyrpj9yrq5jhckgjf-gettext-0.26/lib -L/nix/store/1qm74vf93ik1xjrr9kl6qvjrklljlcqh-glib-2.86.3/lib -L/nix/store/1il4q8s87v0p8xp1g2q8mmbswbwkj23l-vulkan-loader-1.4.341.0/lib -L/nix/store/g7wjwz546f510jv95318n23330c3ni7k-mesa-26.0.2/lib -L/nix/store/wwckb31fcbwj479g7qwcb3b7cv6416pf-libglvnd-1.7.0/lib' NIX_LDFLAGS_FOR_TARGET=' -L/nix/store/fv438zxk1mvcfi2sj20mgn4s91qpjdcd-rust-default-1.94.0/lib -L/nix/store/jcc9imfj4samq59gwsskxalcd9rjicip-wayland-1.24.0/lib -L/nix/store/k1gvr4prs9736r1lhqyy1plxrrvv9b4m-libxkbcommon-1.11.0/lib -L/nix/store/vl8jkqpr0l3fac3cxiy4nwc5paiww1lv-zlib-1.3.1/lib -L/nix/store/5mnq195cx3cagnpbbvf5ncbp4fjgy0sz-libffi-3.5.2/lib -L/nix/store/md592gfars4m9madyrpj9yrq5jhckgjf-gettext-0.26/lib -L/nix/store/1qm74vf93ik1xjrr9kl6qvjrklljlcqh-glib-2.86.3/lib -L/nix/store/1il4q8s87v0p8xp1g2q8mmbswbwkj23l-vulkan-loader-1.4.341.0/lib -L/nix/store/g7wjwz546f510jv95318n23330c3ni7k-mesa-26.0.2/lib -L/nix/store/wwckb31fcbwj479g7qwcb3b7cv6416pf-libglvnd-1.7.0/lib'
export NIX_LDFLAGS_FOR_TARGET export NIX_LDFLAGS_FOR_TARGET
@ -178,7 +178,7 @@ name='nix-shell-env'
export name export name
nativeBuildInputs='' nativeBuildInputs=''
export nativeBuildInputs export nativeBuildInputs
out='/mnt/removable/Projects/Rust/wayland_panel/outputs/out' out='/home/maxag/Projects/Rust/wayland_panel/outputs/out'
export out export out
outputBin='out' outputBin='out'
outputDev='out' outputDev='out'
@ -211,7 +211,7 @@ declare -a preFixupHooks=('_moveToShare' '_multioutDocs' '_multioutDevs' )
preInstallPhases=' glibPreInstallPhase' preInstallPhases=' glibPreInstallPhase'
preferLocalBuild='1' preferLocalBuild='1'
export preferLocalBuild export preferLocalBuild
prefix='/mnt/removable/Projects/Rust/wayland_panel/outputs/out' prefix='/home/maxag/Projects/Rust/wayland_panel/outputs/out'
declare -a propagatedBuildDepFiles=('propagated-build-build-deps' 'propagated-native-build-inputs' 'propagated-build-target-deps' ) declare -a propagatedBuildDepFiles=('propagated-build-build-deps' 'propagated-native-build-inputs' 'propagated-build-target-deps' )
propagatedBuildInputs='' propagatedBuildInputs=''
export propagatedBuildInputs export propagatedBuildInputs

38
Cargo.lock generated
View file

@ -261,6 +261,19 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
[[package]]
name = "chrono"
version = "0.4.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c673075a2e0e5f4a1dde27ce9dee1ea4558c7ffe648f576438a20ca1d2acc4b0"
dependencies = [
"iana-time-zone",
"js-sys",
"num-traits",
"wasm-bindgen",
"windows-link",
]
[[package]] [[package]]
name = "clipboard-win" name = "clipboard-win"
version = "5.4.1" version = "5.4.1"
@ -969,6 +982,30 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df" checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df"
[[package]]
name = "iana-time-zone"
version = "0.1.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470"
dependencies = [
"android_system_properties",
"core-foundation-sys",
"iana-time-zone-haiku",
"js-sys",
"log",
"wasm-bindgen",
"windows-core",
]
[[package]]
name = "iana-time-zone-haiku"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
dependencies = [
"cc",
]
[[package]] [[package]]
name = "iced" name = "iced"
version = "0.14.0" version = "0.14.0"
@ -3000,6 +3037,7 @@ dependencies = [
name = "wayland_panel" name = "wayland_panel"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"chrono",
"iced", "iced",
"iced_layershell", "iced_layershell",
"winit", "winit",

View file

@ -4,6 +4,7 @@ version = "0.1.0"
edition = "2024" edition = "2024"
[dependencies] [dependencies]
chrono = "0.4.44"
iced = { version = "0.14.0", default-features = false, features = ["wgpu", "wayland", "tokio"] } iced = { version = "0.14.0", default-features = false, features = ["wgpu", "wayland", "tokio"] }
iced_layershell = { version = "0.15.0", default-features = false } iced_layershell = { version = "0.15.0", default-features = false }
winit = { version = "0.30.12", default-features = false, features = ["wayland"] } winit = { version = "0.30.12", default-features = false, features = ["wayland"] }

View file

@ -1,16 +1,21 @@
use chrono::Local;
use iced::Color;
use iced::Element; use iced::Element;
use iced::Subscription;
use iced::Task; use iced::Task;
use iced::widget::Row;
use iced::widget::container; use iced::widget::container;
use iced::widget::row;
use iced::widget::text;
use iced_layershell::daemon; use iced_layershell::daemon;
use iced_layershell::reexport::Anchor; use iced_layershell::reexport::Anchor;
use iced_layershell::settings::LayerShellSettings; use iced_layershell::settings::LayerShellSettings;
use iced_layershell::settings::Settings; use iced_layershell::settings::Settings;
use iced_layershell::to_layer_message; use iced_layershell::to_layer_message;
use std::time::Duration;
pub fn main() -> Result<(), iced_layershell::Error> { pub fn main() -> Result<(), iced_layershell::Error> {
daemon(App::default, || "rbaw".into(), App::update, App::view) daemon(App::default, || "rbaw".into(), App::update, App::view)
.style(App::style)
.theme(App::theme)
.subscription(App::subscription) .subscription(App::subscription)
.settings(Settings { .settings(Settings {
layer_settings: LayerShellSettings { layer_settings: LayerShellSettings {
@ -25,29 +30,66 @@ pub fn main() -> Result<(), iced_layershell::Error> {
.run() .run()
} }
#[derive(Default)] struct App {
struct App {} time: chrono::DateTime<chrono::Local>,
battery: String,
}
impl Default for App {
fn default() -> Self {
let mut output = Self {
time: Default::default(),
battery: Default::default(),
};
let _ = output.update(Message::Clock);
output
}
}
impl App { impl App {
fn view(&self, _id: iced::window::Id) -> Element<'_, Message> { fn view(&self, _id: iced::window::Id) -> Element<'_, Message> {
let content = Row::new(); let display_time = self.time.format("%H:%M");
container(content) let content = row![
.width(iced::Length::Fill) text!("{}", display_time),
.height(iced::Length::Fill) iced::widget::space().width(iced::Length::Fill),
.into() text!("{}", self.battery),
]
.padding(iced::Padding::from([0, 5]))
.height(iced::Length::Fill)
.width(iced::Length::Fill)
.align_y(iced::Alignment::Center);
container(content).into()
} }
fn update(&mut self, _message: Message) -> Task<Message> {
fn update(&mut self, message: Message) -> Task<Message> {
if let Message::Clock = message {
self.time = Local::now();
self.battery = format!(
"{} 󰁽",
std::fs::read_to_string(std::path::Path::new(
"/sys/class/power_supply/BAT0/capacity",
))
.unwrap()
.trim_ascii_end()
);
}
Task::none() Task::none()
} }
fn style(&self, _theme: &iced::Theme) -> iced::theme::Style { fn style(&self, theme: &iced::Theme) -> iced::theme::Style {
todo!() iced::theme::Style {
background_color: Color::TRANSPARENT,
text_color: theme.palette().text,
}
} }
fn theme(&self) -> iced::Theme { fn theme(&self, _id: iced::window::Id) -> iced::Theme {
todo!() iced::Theme::GruvboxDark
} }
fn subscription(&self) -> iced::Subscription<Message> { fn subscription(&self) -> iced::Subscription<Message> {
Subscription::none() iced::time::every(Duration::from_secs(1)).map(|_| Message::Clock)
} }
} }
@ -55,4 +97,5 @@ impl App {
#[derive(Debug)] #[derive(Debug)]
enum Message { enum Message {
IcedEvent(iced::Event), IcedEvent(iced::Event),
Clock,
} }