277 lines
7.7 KiB
Plaintext

(defpoll system--hostname :interval "30s"
`hostnamectl hostname --pretty`)
(deflisten system--data :initial "{}"
`~/.config/eww/modules/system/system.py`)
(defwidget system-battery [battery]
(box :orientation "v"
:halign "start"
:class "module text"
:space-evenly false
:spacing 0
(label :class {EWW_BATTERY[battery].status == 'Charging' || EWW_BATTERY[battery].status == 'Full' ? 'green' : EWW_BATTERY[battery].capacity <= 25 ? 'highlight' : 'special'}
:text "${EWW_BATTERY[battery].capacity}%")
(label :text "${EWW_BATTERY[battery].status == 'Charging' || EWW_BATTERY[battery].status == 'Full' ? 'external' : 'internal'} power")))
(defwidget system-name []
(label :halign "center"
:valign "center"
:class "module text big nebula"
:text {system--hostname}))
(defwidget system-cpu-avg []
(box :orientation "v"
:halign "start"
:class "module text"
:space-evenly false
:spacing 0
(label :class {system--data.cpu.avg > 90 ? 'highlight' : 'special'}
:text "${system--data.cpu.avg_display}%")
(label :text "cpu utilization")))
(defwidget system--cpu-core [core]
(label :class {core.value > 90 ? "highlight" : "special"}
:text "${core.display}%"))
(defwidget system-cpu-percore []
(box :orientation "v"
:halign "start"
:class "module text"
:space-evenly false
;; (box :orientation "h"
;; :halign "center"
;; :space-evenly false
;; (for core in {system--data.cpu.cores}
;; (system--cpu-core :core core)))
(label :class "special"
:text {system--data.cpu.cores_display})
(label :text "per-core cpu utilization")
))
(defwidget system-memory []
(box :orientation "v"
:halign "start"
:class "module text"
:space-evenly false
(label :class {system--data.memory.percent > 85 ? "highlight" : "special"}
:text "${round(system--data.memory.used / 1024 / 1024 / 1024, 2)} / ${round(system--data.memory.total / 1024 / 1024 / 1024, 2)} GiB")
(label :text "system memory")))
(defwidget system--gauge [value ?threshold]
(overlay :width 80
:height 80
(circular-progress :value 75
:class "gauge-gutter"
:start-at 37.5
:thickness 2)
(circular-progress :value {value * 0.75}
:class 'gauge ${value > (threshold ?: 80) ? "highlight" : ""}'
:start-at 37.5
:thickness 2)))
(defwidget system-gauges []
(box :orientation "h"
:space-evenly false
:width 200
:halign "start"
:spacing 10
(box :orientation "v"
:space-evenly false
:spacing 20
:width 95
:halign "start"
(system--cpu-gauge)
(system--gpu-gauge)
)
(box :orientation "v"
:space-evenly false
:spacing 20
:width 95
:halign "end"
(system--memory-gauge)
(system--vram-gauge))))
(defwidget system--memory-gauge []
(box :orientation "v"
:halign "end"
:width 95
:space-evenly false
:spacing 10
:class "nebula"
(label :text "RAM"
:class "medium special")
(box :halign "center"
(overlay
(system--gauge :value {system--data.memory.percent})
(transform
:translate-y "-2px"
(box :halign "center"
:valign "center"
:orientation "h"
:space-evenly false
(label :text "%"
:class "invisible")
(label :text {round(system--data.memory.percent, 0)}
:class "medium special")
(transform
:translate-y "3px"
(label :text "%"
:class "offline"))))))))
(defwidget system--cpu-gauge []
(box :orientation "v"
:halign "start"
:width 95
:space-evenly false
:spacing 10
:class "nebula"
(label :text "CPU"
:class "medium special")
(box :halign "center"
(overlay
(system--gauge :value {system--data.cpu.avg})
(transform
:translate-y "-2px"
(box :halign "center"
:valign "center"
:orientation "h"
:space-evenly false
(label :text "%"
:class "invisible")
(label :text {system--data.cpu.avg_display}
:class "medium special")
(transform
:translate-y "3px"
(label :text "%"
:class "offline"))))))
;; (box :orientation "v"
;; :halign "end"
;; :valign "start"
;; :width 100
;; :space-evenly false
;; (for ps in {system--data.cpu_top}
;; (centerbox :width 100
;; :orientation "h"
;; (box :halign "start"
;; (label :text {ps.name}
;; :limit-width 7))
;; ""
;; (box :halign "end"
;; (label :text '${round(ps.cpu, 0)}%')))
;; )
))
(defwidget system--gpu-gauge []
(box :orientation "v"
:halign "start"
:width 95
:space-evenly false
:spacing 10
:class "nebula"
(label :text "GPU"
:class "medium special")
(box :halign "center"
(overlay
(system--gauge :value {system--data.gpu.load * 100})
(transform
:translate-y "-2px"
(box :halign "center"
:valign "center"
:orientation "h"
:space-evenly false
(label :text "%"
:class "invisible")
(label :text {round(system--data.gpu.load * 100, 0)}
:class "medium special")
(transform
:translate-y "3px"
(label :text "%"
:class "offline"))))))))
(defwidget system--vram-gauge []
(box :orientation "v"
:halign "start"
:width 95
:space-evenly false
:spacing 10
:class "nebula"
(label :text "VRAM"
:class "medium special")
(box :halign "center"
(overlay
(system--gauge :value {system--data.gpu.memory * 100})
(transform
:translate-y "-2px"
(box :halign "center"
:valign "center"
:orientation "h"
:space-evenly false
(label :text "%"
:class "invisible")
(label :text {round(system--data.gpu.memory * 100, 0)}
:class "medium special")
(transform
:translate-y "3px"
(label :text "%"
:class "offline"))))))))
(defwidget system--gauge-generic [value value-fmt big-text little-text ?subscript ?threshold]
(box :orientation "h"
:halign "start"
:class "module gauge-widget"
:space-evenly true
:spacing 0
(overlay :width 100
(circular-progress :value 100
:class "gauge-hole"
:start-at 0
:thickness 50
)
(circular-progress :value 80
:class "gauge-gutter"
:start-at 35
:thickness 2)
(circular-progress :value {value * 0.8}
:class 'gauge ${value > (threshold ?: 80) ? "highlight" : ""}'
:start-at 35
:thickness 2)
(transform :translate-y "-5px"
:translate-x "3px"
(box :halign "center"
:valign "center"
:class "big nebula"
:space-evenly false
"${value-fmt}"
(box :class "normal offline"
:halign "start"
:valign "end"
(transform :translate-y "-2px"
:translate-x "1px"
{subscript})))))
(transform :translate-y "-5px"
(box :orientation "v"
:halign "center"
:valign "center"
:space-evenly false
(label :text {big-text}
:class "big nebula")
(label :text {little-text}
:class "nebula special")))))
;; (defwidget system-cpu-gauge []
;; (system--gauge-generic :value {system--data.cpu.avg}
;; :value-fmt {system--data.cpu.avg_display}
;; :big-text "CPU"
;; :little-text "usage"
;; :subscript "%"))
;; (defwidget system-memory-gauge []
;; (system--gauge-generic :value {system--data.memory.percent}
;; :value-fmt {round(system--data.memory.percent, 0)}
;; :big-text "RAM"
;; :little-text "${round(system--data.memory.used / 1024 / 1024 / 1024, 1)} GiB"
;; :subscript "%"))