diff --git a/modules/Modules.qml b/modules/Modules.qml index eea208d..0a2b753 100644 --- a/modules/Modules.qml +++ b/modules/Modules.qml @@ -55,6 +55,7 @@ QtObject { }) property var temperature: ({ enable: true, + interval: 2000, warm: 80, hot: 90 }) diff --git a/modules/SystemStats.qml b/modules/SystemStats.qml index 13c99a8..cb7a0ad 100644 --- a/modules/SystemStats.qml +++ b/modules/SystemStats.qml @@ -14,9 +14,6 @@ QtObject { property var cpuCoreMaxFreq: [] property var cpuCoreTypes: [] - // ── Temperature ────────────────────────────────────────────────────── - property int tempCelsius: 0 - // ── Memory ─────────────────────────────────────────────────────────── property int memPercent: 0 property real memUsedGb: 0 @@ -55,8 +52,6 @@ QtObject { history: hist.length > histLen ? hist.slice(hist.length - histLen) : hist }; }); - } else if (ev.type === "temp") { - root.tempCelsius = ev.celsius; } else if (ev.type === "mem") { root.memPercent = ev.percent; root.memUsedGb = ev.used_gb; diff --git a/modules/Temperature.qml b/modules/Temperature.qml index d6f9ade..ec2983c 100644 --- a/modules/Temperature.qml +++ b/modules/Temperature.qml @@ -1,25 +1,39 @@ import QtQuick +import Quickshell.Io import "." as M M.BarSection { id: root spacing: Math.max(1, M.Theme.moduleSpacing - 2) - tooltip: "Temperature: " + M.SystemStats.tempCelsius + "\u00B0C" + tooltip: "Temperature: " + root.celsius + "\u00B0C" - property color _stateColor: M.SystemStats.tempCelsius > (M.Modules.temperature.hot || 80) ? M.Theme.base09 : M.SystemStats.tempCelsius > (M.Modules.temperature.warm || 60) ? M.Theme.base0A : root.accentColor + property int celsius: 0 + property color _stateColor: celsius > (M.Modules.temperature.hot || 80) ? M.Theme.base09 : celsius > (M.Modules.temperature.warm || 60) ? M.Theme.base0A : root.accentColor Behavior on _stateColor { ColorAnimation { duration: 300 } } + FileView { + id: thermal + path: "/sys/class/thermal/thermal_zone0/temp" + onLoaded: root.celsius = Math.round(parseInt(text()) / 1000) + } + Timer { + interval: M.Modules.temperature.interval || 2000 + running: true + repeat: true + onTriggered: thermal.reload() + } + M.BarIcon { icon: "\uF2C9" color: root._stateColor anchors.verticalCenter: parent.verticalCenter } M.BarLabel { - label: M.SystemStats.tempCelsius + "\u00B0C" + label: root.celsius + "\u00B0C" minText: "100\u00B0C" color: root._stateColor anchors.verticalCenter: parent.verticalCenter diff --git a/nix/hm-module.nix b/nix/hm-module.nix index eec773a..aa71894 100644 --- a/nix/hm-module.nix +++ b/nix/hm-module.nix @@ -127,18 +127,21 @@ in description = "Brightness adjustment step (%)."; }; }; - temperature = moduleOpt "temperature" { - warm = lib.mkOption { - type = lib.types.int; - default = 80; - description = "Temperature threshold for warm state (°C)."; - }; - hot = lib.mkOption { - type = lib.types.int; - default = 90; - description = "Temperature threshold for hot state (°C)."; - }; - }; + temperature = moduleOpt "temperature" ( + (intervalOpt 2000) + // { + warm = lib.mkOption { + type = lib.types.int; + default = 80; + description = "Temperature threshold for warm state (°C)."; + }; + hot = lib.mkOption { + type = lib.types.int; + default = 90; + description = "Temperature threshold for hot state (°C)."; + }; + } + ); battery = moduleOpt "battery" { warning = lib.mkOption { type = lib.types.int; diff --git a/stats-daemon/src/main.rs b/stats-daemon/src/main.rs index b206397..c66ab5a 100644 --- a/stats-daemon/src/main.rs +++ b/stats-daemon/src/main.rs @@ -93,23 +93,6 @@ fn read_stat() -> Vec { parse_stat(&fs::read_to_string("/proc/stat").unwrap_or_default()) } -fn read_temp_celsius() -> Option { - let mut max: Option = None; - for i in 0.. { - let path = format!("/sys/class/thermal/thermal_zone{i}/temp"); - match fs::read_to_string(&path) { - Ok(s) => { - if let Ok(millic) = s.trim().parse::() { - let c = millic / 1000; - max = Some(max.map_or(c, |m: i32| m.max(c))); - } - } - Err(_) => break, - } - } - max -} - fn read_core_freqs() -> Vec { let mut freqs = Vec::new(); for i in 0.. { @@ -165,12 +148,6 @@ fn emit_cpu(out: &mut impl Write, prev: &[Sample], curr: &[Sample], freqs: &[f64 let _ = writeln!(out, "]}}"); } -fn emit_temp(out: &mut impl Write) { - if let Some(c) = read_temp_celsius() { - let _ = writeln!(out, "{{\"type\":\"temp\",\"celsius\":{c}}}"); - } -} - fn emit_mem(out: &mut impl Write) { let content = fs::read_to_string("/proc/meminfo").unwrap_or_default(); if let Some(m) = parse_meminfo(&content) { @@ -213,7 +190,6 @@ fn main() { if tick.is_multiple_of(2) { emit_mem(&mut out); - emit_temp(&mut out); } let _ = out.flush();