diff --git a/CHANGELOG.md b/CHANGELOG.md index e7f086da..9c1b3a39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ All notable changes to eww will be listed here, starting at changes since versio - Add `jq` function, offering jq-style json processing - Add `justify` property to the label widget, allowing text justification (By: n3oney) - Add `EWW_TIME` magic variable (By: Erenoit) +- Add `EWW_IPV4`, `EWW_IPV6` magic variable (By: Lanpingner) - Add trigonometric functions (`sin`, `cos`, `tan`, `cot`) and degree/radian conversions (`degtorad`, `radtodeg`) (By: end-4) - Add `substring` function to simplexpr - Add `--duration` flag to `eww open` diff --git a/Cargo.lock b/Cargo.lock index 55fef71c..a71b2571 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -216,6 +216,12 @@ version = "3.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d32a994c2b3ca201d9b263612a374263f05e7adde37c4707f693dcd375076d1f" +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + [[package]] name = "bytes" version = "1.5.0" @@ -641,6 +647,7 @@ dependencies = [ "gtk-layer-shell", "itertools 0.12.1", "libc", + "local-ip-address", "log", "maplit", "nix 0.27.1", @@ -1450,6 +1457,18 @@ version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" +[[package]] +name = "local-ip-address" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fefe707432eb6bd4704b3dacfc87aab269d56667ad05dcd6869534e8890e767" +dependencies = [ + "libc", + "neli", + "thiserror", + "windows-sys 0.48.0", +] + [[package]] name = "lock_api" version = "0.4.11" @@ -1517,6 +1536,31 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "neli" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1100229e06604150b3becd61a4965d5c70f3be1759544ea7274166f4be41ef43" +dependencies = [ + "byteorder", + "libc", + "log", + "neli-proc-macros", +] + +[[package]] +name = "neli-proc-macros" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c168194d373b1e134786274020dae7fc5513d565ea2ebb9bc9ff17ffb69106d4" +dependencies = [ + "either", + "proc-macro2", + "quote", + "serde", + "syn 1.0.109", +] + [[package]] name = "new_debug_unreachable" version = "1.0.4" diff --git a/crates/eww/Cargo.toml b/crates/eww/Cargo.toml index 554fd86d..e4f3a589 100644 --- a/crates/eww/Cargo.toml +++ b/crates/eww/Cargo.toml @@ -34,6 +34,43 @@ gtk-layer-shell = { version = "0.6.1", optional = true } gdkx11 = { version = "0.17", optional = true } x11rb = { version = "0.11.1", features = ["randr"], optional = true } +regex = "1.9.3" +bincode = "1.3.3" +anyhow = "1.0.70" +derive_more = "0.99" +maplit = "1" +clap = {version = "4.3.21", features = ["derive"] } +serde = {version = "1.0", features = ["derive"]} +serde_json = "1.0" +extend = "1.2" +grass = {version = "0.13.1", default-features = false} +itertools = "0.11" +log = "0.4" +pretty_env_logger = "0.5" +libc = "0.2" +once_cell = "1.18" +nix = "0.26.2" +simple-signal = "1.1" +unescape = "0.1" + +tokio = { version = "1.31.0", features = ["full"] } +futures = "0.3.28" +tokio-util = "0.7.8" + +sysinfo = "0.29.8" +chrono = "0.4.26" +local-ip-address = "0.5.3" + +wait-timeout = "0.2" + +notify = "6.0.1" + +codespan-reporting = "0.11" + +simplexpr = { version = "0.1.0", path = "../simplexpr" } +eww_shared_util = { version = "0.1.0", path = "../eww_shared_util" } +yuck = { version = "0.1.0", path = "../yuck", default-features = false} + anyhow.workspace = true bincode.workspace = true chrono.workspace = true @@ -61,3 +98,4 @@ tokio-util.workspace = true tokio = { workspace = true, features = ["full"] } unescape.workspace = true wait-timeout.workspace = true + diff --git a/crates/eww/src/config/inbuilt.rs b/crates/eww/src/config/inbuilt.rs index 13cf1e65..b367cca0 100644 --- a/crates/eww/src/config/inbuilt.rs +++ b/crates/eww/src/config/inbuilt.rs @@ -64,6 +64,12 @@ define_builtin_vars! { // @desc EWW_TIME - the current UNIX timestamp "EWW_TIME" [1] => || Ok(DynVal::from(get_time())) , + + // @desc EWW_IPV4 - Information about the IPv4 address on all interfaces except "lo" + "EWW_IPV4" [1] => || Ok(DynVal::from(get_ipv4())), + + // @desc EWW_IPV6 - Information about the IPv6 address on all interfaces except "lo" + "EWW_IPV6" [1] => || Ok(DynVal::from(get_ipv6())), } macro_rules! define_magic_constants { diff --git a/crates/eww/src/config/system_stats.rs b/crates/eww/src/config/system_stats.rs index 995d7ada..e78bfb7b 100644 --- a/crates/eww/src/config/system_stats.rs +++ b/crates/eww/src/config/system_stats.rs @@ -1,8 +1,10 @@ use crate::util::IterAverage; use anyhow::{Context, Result}; +use itertools::Itertools; use once_cell::sync::Lazy; use std::{fs::read_to_string, sync::Mutex}; use sysinfo::System; +use local_ip_address::list_afinet_netifas; struct RefreshTime(std::time::Instant); impl RefreshTime { @@ -229,3 +231,17 @@ pub fn net() -> String { pub fn get_time() -> String { chrono::offset::Utc::now().timestamp().to_string() } + +pub fn get_ipv4() -> String { + let ifas = list_afinet_netifas().unwrap(); + let joined = + ifas.iter().filter(|ipv| ipv.1.is_ipv4() && ipv.0 != "lo").map(|ip| format!("{}", ip.1)).collect::>().join(", "); + joined +} + +pub fn get_ipv6() -> String { + let ifas = list_afinet_netifas().unwrap(); + let joined = + ifas.iter().filter(|ipv| ipv.1.is_ipv6() && ipv.0 != "lo").map(|ip| format!("{}", ip.1)).collect::>().join(", "); + joined +}