diff --git a/modules/Modules.qml b/modules/Modules.qml index f1f07ed..0a2b753 100644 --- a/modules/Modules.qml +++ b/modules/Modules.qml @@ -89,6 +89,9 @@ QtObject { property var overviewBackdrop: ({ enable: true }) + property var statsDaemon: ({ + interval: -1 + }) property FileView _file: FileView { path: (Quickshell.env("XDG_CONFIG_HOME") || (Quickshell.env("HOME") + "/.config")) + "/nova-shell/modules.json" diff --git a/modules/SystemStats.qml b/modules/SystemStats.qml index 16c264d..cb7a0ad 100644 --- a/modules/SystemStats.qml +++ b/modules/SystemStats.qml @@ -29,7 +29,10 @@ QtObject { // nova-stats stream (cpu + mem) property var _statsProc: Process { running: true - command: ["nova-stats"] + command: { + const ms = M.Modules.statsDaemon.interval; + return ms > 0 ? ["nova-stats", "--interval", ms.toString()] : ["nova-stats"]; + } stdout: SplitParser { splitMarker: "\n" onRead: line => { diff --git a/nix/hm-module.nix b/nix/hm-module.nix index 343af64..aa71894 100644 --- a/nix/hm-module.nix +++ b/nix/hm-module.nix @@ -169,6 +169,17 @@ in }; } ); + statsDaemon = lib.mkOption { + default = { }; + description = "Configuration for the nova-stats daemon."; + type = lib.types.submodule { + options.interval = lib.mkOption { + type = lib.types.int; + default = -1; + description = "nova-stats polling interval in milliseconds (-1 = use binary default of 1s)."; + }; + }; + }; }; theme = lib.mkOption { diff --git a/stats-daemon/src/main.rs b/stats-daemon/src/main.rs index 7153961..c66ab5a 100644 --- a/stats-daemon/src/main.rs +++ b/stats-daemon/src/main.rs @@ -159,7 +159,22 @@ fn emit_mem(out: &mut impl Write) { } } +fn parse_interval_ms() -> u64 { + let args: Vec = std::env::args().collect(); + let mut i = 1; + while i < args.len() { + if args[i] == "--interval" { + if let Some(ms) = args.get(i + 1).and_then(|s| s.parse().ok()) { + return ms; + } + } + i += 1; + } + 1000 +} + fn main() { + let interval = Duration::from_millis(parse_interval_ms()); let stdout = io::stdout(); let mut out = io::BufWriter::new(stdout.lock()); let mut prev: Vec = vec![]; @@ -181,8 +196,8 @@ fn main() { tick += 1; let elapsed = t0.elapsed(); - if elapsed < Duration::from_secs(1) { - thread::sleep(Duration::from_secs(1) - elapsed); + if elapsed < interval { + thread::sleep(interval - elapsed); } } }