diff --git a/modules/Battery.qml b/modules/Battery.qml index 5bc6cfb..4282dd7 100644 --- a/modules/Battery.qml +++ b/modules/Battery.qml @@ -19,8 +19,10 @@ M.BarSection { readonly property var dev: UPower.displayDevice readonly property real pct: (dev?.percentage ?? 0) * 100 readonly property bool charging: dev?.state === UPowerDeviceState.Charging - readonly property bool _critical: pct < 15 && !charging - property color _stateColor: charging ? M.Theme.base0B : _critical ? M.Theme.base09 : pct < 30 ? M.Theme.base0A : M.Theme.base08 + readonly property int _critThresh: M.Modules.battery.critical || 15 + readonly property int _warnThresh: M.Modules.battery.warning || 25 + readonly property bool _critical: pct < _critThresh && !charging + property color _stateColor: charging ? M.Theme.base0B : _critical ? M.Theme.base09 : pct < _warnThresh ? M.Theme.base0A : M.Theme.base08 property real _blinkOpacity: 1 SequentialAnimation { @@ -37,11 +39,11 @@ M.BarSection { onChargingChanged: { _warnSent = false; _critSent = false; } onPctChanged: { if (charging) return; - if (pct < 15 && !_critSent) { + if (pct < _critThresh && !_critSent) { _critSent = true; _warnSent = true; _notif.command = ["notify-send", "--urgency=critical", "--icon=battery-low", "--category=device", "Very Low Battery", "Connect to power now!"]; _notif.running = true; - } else if (pct < 25 && !_warnSent) { + } else if (pct < _warnThresh && !_warnSent) { _warnSent = true; _notif.command = ["notify-send", "--icon=battery-caution", "--category=device", "Low Battery"]; _notif.running = true; diff --git a/modules/Bluetooth.qml b/modules/Bluetooth.qml index 3a84414..2f7812a 100644 --- a/modules/Bluetooth.qml +++ b/modules/Bluetooth.qml @@ -41,7 +41,7 @@ M.BarSection { } } Timer { - interval: 5000 + interval: M.Modules.bluetooth.interval || 5000 running: true repeat: true onTriggered: proc.running = true diff --git a/modules/Cpu.qml b/modules/Cpu.qml index 764e193..e2422f0 100644 --- a/modules/Cpu.qml +++ b/modules/Cpu.qml @@ -43,7 +43,7 @@ M.BarSection { } } Timer { - interval: 1000 + interval: M.Modules.cpu.interval || 1000 running: true repeat: true onTriggered: { diff --git a/modules/Disk.qml b/modules/Disk.qml index 90700b6..0b6180e 100644 --- a/modules/Disk.qml +++ b/modules/Disk.qml @@ -26,7 +26,7 @@ M.BarSection { } } Timer { - interval: 30000 + interval: M.Modules.disk.interval || 30000 running: true repeat: true onTriggered: proc.running = true diff --git a/modules/Memory.qml b/modules/Memory.qml index 6461c7c..21395cb 100644 --- a/modules/Memory.qml +++ b/modules/Memory.qml @@ -26,7 +26,7 @@ M.BarSection { } } Timer { - interval: 2000 + interval: M.Modules.memory.interval || 2000 running: true repeat: true onTriggered: meminfo.reload() diff --git a/modules/Modules.qml b/modules/Modules.qml index e645ac0..7a978e0 100644 --- a/modules/Modules.qml +++ b/modules/Modules.qml @@ -14,17 +14,17 @@ QtObject { property var notifications: ({ enable: true }) property var mpris: ({ enable: true }) property var volume: ({ enable: true }) - property var bluetooth: ({ enable: true }) + property var bluetooth: ({ enable: true, interval: 5000 }) property var backlight: ({ enable: true, step: 5 }) - property var network: ({ enable: true }) - property var powerProfile: ({ enable: true }) + property var network: ({ enable: true, interval: 5000 }) + property var powerProfile: ({ enable: true, interval: 5000 }) property var idleInhibitor: ({ enable: true }) - property var weather: ({ enable: true, args: ["--nerd"] }) - property var temperature: ({ enable: true }) - property var cpu: ({ enable: true }) - property var memory: ({ enable: true }) - property var disk: ({ enable: true }) - property var battery: ({ enable: true }) + property var weather: ({ enable: true, args: ["--nerd"], interval: 3600000 }) + property var temperature: ({ enable: true, interval: 2000, warm: 60, hot: 80 }) + property var cpu: ({ enable: true, interval: 1000 }) + property var memory: ({ enable: true, interval: 2000 }) + property var disk: ({ enable: true, interval: 30000 }) + property var battery: ({ enable: true, warning: 25, critical: 15 }) property var power: ({ enable: true }) property FileView _file: FileView { diff --git a/modules/Network.qml b/modules/Network.qml index d093be6..beb09e4 100644 --- a/modules/Network.qml +++ b/modules/Network.qml @@ -65,7 +65,7 @@ M.BarSection { } } Timer { - interval: 5000 + interval: M.Modules.network.interval || 5000 running: true repeat: true onTriggered: proc.running = true diff --git a/modules/PowerProfile.qml b/modules/PowerProfile.qml index 07813ca..c3a2426 100644 --- a/modules/PowerProfile.qml +++ b/modules/PowerProfile.qml @@ -29,7 +29,7 @@ M.BarIcon { } } Timer { - interval: 5000 + interval: M.Modules.powerProfile.interval || 5000 running: true repeat: true onTriggered: proc.running = true diff --git a/modules/Temperature.qml b/modules/Temperature.qml index 8177b8d..ba9982c 100644 --- a/modules/Temperature.qml +++ b/modules/Temperature.qml @@ -8,7 +8,8 @@ M.BarSection { tooltip: "Temperature: " + root.celsius + "\u00B0C" property int celsius: 0 - property color _stateColor: celsius > 80 ? M.Theme.base09 : celsius > 60 ? M.Theme.base0A : M.Theme.base08 + property color _stateColor: celsius > (M.Modules.temperature.hot || 80) ? M.Theme.base09 + : celsius > (M.Modules.temperature.warm || 60) ? M.Theme.base0A : M.Theme.base08 Behavior on _stateColor { ColorAnimation { duration: 300 } } FileView { @@ -17,7 +18,7 @@ M.BarSection { onLoaded: root.celsius = Math.round(parseInt(text()) / 1000) } Timer { - interval: 2000 + interval: M.Modules.temperature.interval || 2000 running: true repeat: true onTriggered: thermal.reload() diff --git a/modules/Weather.qml b/modules/Weather.qml index dc56dd3..3910c6d 100644 --- a/modules/Weather.qml +++ b/modules/Weather.qml @@ -27,7 +27,7 @@ M.BarSection { } } Timer { - interval: 3600000 + interval: M.Modules.weather.interval || 3600000 running: true repeat: true onTriggered: proc.running = true diff --git a/nix/hm-module.nix b/nix/hm-module.nix index e3fcbb8..eb2375d 100644 --- a/nix/hm-module.nix +++ b/nix/hm-module.nix @@ -69,6 +69,13 @@ in } // extra; }; }; + intervalOpt = default: { + interval = lib.mkOption { + type = lib.types.int; + inherit default; + description = "Polling interval in milliseconds."; + }; + }; simpleModules = lib.genAttrs [ "workspaces" "tray" @@ -77,20 +84,18 @@ in "notifications" "mpris" "volume" - "bluetooth" - "network" - "powerProfile" "idleInhibitor" - "temperature" - "cpu" - "memory" - "disk" - "battery" "power" ] (name: moduleOpt name { }); in simpleModules // { + bluetooth = moduleOpt "bluetooth" (intervalOpt 5000); + network = moduleOpt "network" (intervalOpt 5000); + powerProfile = moduleOpt "powerProfile" (intervalOpt 5000); + cpu = moduleOpt "cpu" (intervalOpt 1000); + memory = moduleOpt "memory" (intervalOpt 2000); + disk = moduleOpt "disk" (intervalOpt 30000); backlight = moduleOpt "backlight" { step = lib.mkOption { type = lib.types.int; @@ -98,7 +103,31 @@ in description = "Brightness adjustment step (%)."; }; }; - weather = moduleOpt "weather" { + temperature = moduleOpt "temperature" ((intervalOpt 2000) // { + warm = lib.mkOption { + type = lib.types.int; + default = 60; + description = "Temperature threshold for warm state (°C)."; + }; + hot = lib.mkOption { + type = lib.types.int; + default = 80; + description = "Temperature threshold for hot state (°C)."; + }; + }); + battery = moduleOpt "battery" { + warning = lib.mkOption { + type = lib.types.int; + default = 25; + description = "Battery percentage for warning notification."; + }; + critical = lib.mkOption { + type = lib.types.int; + default = 15; + description = "Battery percentage for critical notification and blink."; + }; + }; + weather = moduleOpt "weather" ((intervalOpt 3600000) // { args = lib.mkOption { type = lib.types.listOf lib.types.str; default = [ "--nerd" ]; @@ -109,7 +138,7 @@ in "Berlin" ]; }; - }; + }); }; theme = lib.mkOption {