From c8d71bd8712d5bc28868823f360097f9925fe6d7 Mon Sep 17 00:00:00 2001 From: Damocles Date: Wed, 15 Apr 2026 18:58:24 +0200 Subject: [PATCH 1/3] perf: merge cpuCoreUsage/cpuCoreFreq/cpuCoreHistory into single cpuCores array --- modules/Cpu.qml | 12 +++++------- modules/SystemStats.qml | 24 +++++++++++------------- stats-daemon/src/main.rs | 23 +++++++++-------------- 3 files changed, 25 insertions(+), 34 deletions(-) diff --git a/modules/Cpu.qml b/modules/Cpu.qml index cfe49c1..e3fd9f8 100644 --- a/modules/Cpu.qml +++ b/modules/Cpu.qml @@ -22,9 +22,7 @@ M.BarSection { } } - readonly property var _coreUsage: M.SystemStats.cpuCoreUsage - readonly property var _coreFreq: M.SystemStats.cpuCoreFreq - readonly property var _coreHistory: M.SystemStats.cpuCoreHistory + readonly property var _cores: M.SystemStats.cpuCores readonly property var _coreMaxFreq: M.SystemStats.cpuCoreMaxFreq readonly property var _coreTypes: M.SystemStats.cpuCoreTypes @@ -114,14 +112,14 @@ M.BarSection { // Per-core rows Repeater { - model: root._coreUsage.length + model: root._cores.length delegate: Item { required property int index width: hoverPanel.contentWidth - readonly property int _u: root._coreUsage[index] ?? 0 - readonly property real _f: root._coreFreq[index] ?? 0 + readonly property int _u: root._cores[index]?.usage ?? 0 + readonly property real _f: root._cores[index]?.freq_ghz ?? 0 readonly property color _barColor: root._loadColor(_u) readonly property bool _throttled: { const maxF = root._coreMaxFreq[index] ?? 0; @@ -204,7 +202,7 @@ M.BarSection { width: 32 height: 10 - property var _hist: root._coreHistory[parent.parent.index] || [] + property var _hist: root._cores[parent.parent.index]?.history ?? [] property color _col: parent.parent._barColor on_HistChanged: if (root._showPanel) diff --git a/modules/SystemStats.qml b/modules/SystemStats.qml index fd0c20d..16c264d 100644 --- a/modules/SystemStats.qml +++ b/modules/SystemStats.qml @@ -10,9 +10,7 @@ QtObject { // ── CPU ────────────────────────────────────────────────────────────── property int cpuUsage: 0 property real cpuFreqGhz: 0 - property var cpuCoreUsage: [] - property var cpuCoreFreq: [] - property var cpuCoreHistory: [] + property var cpuCores: [] // [{usage, freq_ghz, history:[]}] property var cpuCoreMaxFreq: [] property var cpuCoreTypes: [] @@ -40,17 +38,17 @@ QtObject { if (ev.type === "cpu") { root.cpuUsage = ev.usage; root.cpuFreqGhz = ev.freq_ghz; - root.cpuCoreUsage = ev.core_usage; - root.cpuCoreFreq = ev.core_freq_ghz; const histLen = 16; - const oldH = root.cpuCoreHistory; - const newH = []; - for (let i = 0; i < ev.core_usage.length; i++) { - const prev = i < oldH.length ? oldH[i] : []; - const next = prev.concat([ev.core_usage[i]]); - newH.push(next.length > histLen ? next.slice(next.length - histLen) : next); - } - root.cpuCoreHistory = newH; + const prev = root.cpuCores; + root.cpuCores = ev.cores.map((c, i) => { + const oldHist = prev[i]?.history ?? []; + const hist = oldHist.concat([c.usage]); + return { + usage: c.usage, + freq_ghz: c.freq_ghz, + history: hist.length > histLen ? hist.slice(hist.length - histLen) : hist + }; + }); } else if (ev.type === "mem") { root.memPercent = ev.percent; root.memUsedGb = ev.used_gb; diff --git a/stats-daemon/src/main.rs b/stats-daemon/src/main.rs index 1324530..7153961 100644 --- a/stats-daemon/src/main.rs +++ b/stats-daemon/src/main.rs @@ -132,22 +132,18 @@ fn emit_cpu(out: &mut impl Write, prev: &[Sample], curr: &[Sample], freqs: &[f64 freqs.iter().sum::() / freqs.len() as f64 }; + let n = core_usage.len().max(freqs.len()); let _ = write!( out, - "{{\"type\":\"cpu\",\"usage\":{usage},\"freq_ghz\":{avg_freq:.3},\"core_usage\":[" + "{{\"type\":\"cpu\",\"usage\":{usage},\"freq_ghz\":{avg_freq:.3},\"cores\":[" ); - for (i, u) in core_usage.iter().enumerate() { + for i in 0..n { if i > 0 { let _ = write!(out, ","); } - let _ = write!(out, "{u}"); - } - let _ = write!(out, "],\"core_freq_ghz\":["); - for (i, f) in freqs.iter().enumerate() { - if i > 0 { - let _ = write!(out, ","); - } - let _ = write!(out, "{f:.3}"); + let u = core_usage.get(i).copied().unwrap_or(0); + let f = freqs.get(i).copied().unwrap_or(0.0); + let _ = write!(out, "{{\"usage\":{u},\"freq_ghz\":{f:.3}}}"); } let _ = writeln!(out, "]}}"); } @@ -360,8 +356,7 @@ SwapFree: 8192000 kB"; assert!(s.contains("\"type\":\"cpu\"")); assert!(s.contains("\"usage\":")); assert!(s.contains("\"freq_ghz\":")); - assert!(s.contains("\"core_usage\":")); - assert!(s.contains("\"core_freq_ghz\":")); + assert!(s.contains("\"cores\":")); assert!(s.trim().ends_with('}')); } @@ -399,8 +394,8 @@ SwapFree: 8192000 kB"; let mut buf = Vec::new(); emit_cpu(&mut buf, &curr, &curr, &freqs); let s = String::from_utf8(buf).unwrap(); - assert!(s.contains("3.200"), "got: {s}"); - assert!(s.contains("2.900"), "got: {s}"); + assert!(s.contains("\"freq_ghz\":3.200"), "got: {s}"); + assert!(s.contains("\"freq_ghz\":2.900"), "got: {s}"); } // ── emit_mem (via parse_meminfo) ───────────────────────────────────── From 937ae5af2e133f9170c6062584bae910073e4606 Mon Sep 17 00:00:00 2001 From: Damocles Date: Wed, 15 Apr 2026 19:01:29 +0200 Subject: [PATCH 2/3] feat: add statsDaemon.interval setting, pass --interval to nova-stats --- modules/Modules.qml | 3 +++ modules/SystemStats.qml | 5 ++++- nix/hm-module.nix | 11 +++++++++++ stats-daemon/src/main.rs | 19 +++++++++++++++++-- 4 files changed, 35 insertions(+), 3 deletions(-) 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); } } } From c96b023fbe1507abfdc4fa73b6e5145cfdd086ce Mon Sep 17 00:00:00 2001 From: Damocles Date: Wed, 15 Apr 2026 19:03:56 +0200 Subject: [PATCH 3/3] perf/feat: gate cpu behaviors on _showPanel; add reducedMotion theme setting for ambient animations --- modules/BackgroundOverlay.qml | 6 +++++- modules/Cpu.qml | 2 ++ modules/OverviewBackdrop.qml | 2 +- modules/Theme.qml | 3 +++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/modules/BackgroundOverlay.qml b/modules/BackgroundOverlay.qml index bd028b6..1936770 100644 --- a/modules/BackgroundOverlay.qml +++ b/modules/BackgroundOverlay.qml @@ -54,6 +54,7 @@ PanelWindow { text: ":" color: colon._colors[colon._colorIdx % colon._colors.length] Behavior on color { + enabled: !M.Theme.reducedMotion ColorAnimation { duration: 800 } @@ -110,6 +111,7 @@ PanelWindow { readonly property var _colors: [M.Theme.base08, M.Theme.base09, M.Theme.base0A, M.Theme.base0B, M.Theme.base0C, M.Theme.base0D, M.Theme.base0E, M.Theme.base05] color: _colors[_colorIdx % _colors.length] Behavior on color { + enabled: !M.Theme.reducedMotion ColorAnimation { duration: 800 } @@ -117,7 +119,7 @@ PanelWindow { SequentialAnimation { loops: Animation.Infinite - running: true + running: !M.Theme.reducedMotion NumberAnimation { target: colon property: "opacity" @@ -187,6 +189,7 @@ PanelWindow { height: parent.height color: colon._colors[colon._colorIdx % colon._colors.length] Behavior on color { + enabled: !M.Theme.reducedMotion ColorAnimation { duration: 800 } @@ -195,6 +198,7 @@ PanelWindow { opacity: 0.6 Behavior on width { + enabled: !M.Theme.reducedMotion NumberAnimation { duration: 300 } diff --git a/modules/Cpu.qml b/modules/Cpu.qml index e3fd9f8..c0d7274 100644 --- a/modules/Cpu.qml +++ b/modules/Cpu.qml @@ -8,6 +8,7 @@ M.BarSection { property int usage: M.SystemStats.cpuUsage Behavior on usage { + enabled: root._showPanel NumberAnimation { duration: 400 easing.type: Easing.OutCubic @@ -16,6 +17,7 @@ M.BarSection { property real freqGhz: M.SystemStats.cpuFreqGhz Behavior on freqGhz { + enabled: root._showPanel NumberAnimation { duration: 400 easing.type: Easing.OutCubic diff --git a/modules/OverviewBackdrop.qml b/modules/OverviewBackdrop.qml index c9652a6..ab17be2 100644 --- a/modules/OverviewBackdrop.qml +++ b/modules/OverviewBackdrop.qml @@ -48,7 +48,7 @@ PanelWindow { // Wave animation: 6s sweep + 8s pause, only while overview is open SequentialAnimation on uWavePhase { loops: Animation.Infinite - running: M.NiriIpc.overviewOpen + running: M.NiriIpc.overviewOpen && !M.Theme.reducedMotion NumberAnimation { from: -200 to: fx.width + 200 diff --git a/modules/Theme.qml b/modules/Theme.qml index f924df9..13ac23c 100644 --- a/modules/Theme.qml +++ b/modules/Theme.qml @@ -35,6 +35,7 @@ QtObject { property int groupSpacing: 6 property int radius: 4 property int screenRadius: 15 + property bool reducedMotion: false property FileView _themeFile: FileView { path: (Quickshell.env("XDG_CONFIG_HOME") || (Quickshell.env("HOME") + "/.config")) + "/nova-shell/theme.json" @@ -75,5 +76,7 @@ QtObject { root.radius = data.radius; if (data.screenRadius !== undefined) root.screenRadius = data.screenRadius; + if (data.reducedMotion !== undefined) + root.reducedMotion = data.reducedMotion; } }