
(defwidget cpu-sys-win []
  (box
    :orientation "v"
    :space-evenly false
    (box :class "sys-label" "CPU")
    (box
      :orientation "v"
      (for core in {EWW_CPU.cores}
        (box
          :space-evenly false
          :class "cpu-core ${core.core}"
          (progress
            :value {core.usage}
            :orientation "h"
            :flipped true
            :class "cpu-core-usage"
            :tooltip "${core.core} @ ${core.freq}Mhz"
          )
        )
      )
    )
  )
)

(defwidget gpu-sys-win []
  (box
    :orientation "v"
    :space-evenly false
    (box :class "sys-label" "GPU")
    (progress
      :value {gpu.devices[0].GRBM2?.CommandProcessor-Compute?.value?:0.0}
      :orientation "h"
      :flipped true
      :class "gpu-core-usage"
      :tooltip "Compute"
    )    
    (progress
      :value {gpu.devices[0].GRBM2?.CommandProcessor-Fetcher?.value?:0.0}
      :orientation "h"
      :flipped true
      :class "gpu-core-usage"
      :tooltip "Fetcher"
    )
    (progress
      :value {gpu.devices[0].GRBM2?.CommandProcessor-Graphics?.value?:0.0}
      :orientation "h"
      :flipped true
      :class "gpu-core-usage"
      :tooltip "Graphics"
    )
    (box :class "spacer")
    (progress
      :value {gpu.devices[0]?.gpu_activity?.GFX?.value?:0.0}
      :orientation "h"
      :flipped true
      :class "gpu-core-usage"
      :tooltip "GFX"
    )    
    (progress
      :value {gpu.devices[0]?.gpu_activity?.Memory?.value?:0.0}
      :orientation "h"
      :flipped true
      :class "gpu-core-usage"
      :tooltip "Memory"
    )
    (progress
      :value {gpu.devices[0]?.gpu_activity?.MediaEngine?.value?:0.0}
      :orientation "h"
      :flipped true
      :class "gpu-core-usage"
      :tooltip "Media"
    )
    (box :class "spacer")
    (progress
      :value {100*(gpu.devices[0]?.VRAM?.TotalVRAMUsage?.value?:0.0)/(gpu.devices[0]?.VRAM?.TotalVRAM?.value?:1.0)}
      :orientation "h"
      :flipped true
      :class "gpu-core-usage"
      :tooltip "VRAM"
    )
  )
)

(defwidget ram-sys-win []
  (box
    :orientation "v"
    :space-evenly false
    (box :class "sys-label" "RAM")
    (progress
      :value {100*memory.used/memory.total}
      :orientation "h"
      :flipped true
      :class "memory-usage"
      :tooltip "RAM"
    )
  )
)

(defwidget sys-win []
  (box
    :class "sys-win"
    :space-evenly false
    :orientation "h"
    (box
      :space-evenly false
      :orientation "v"
      (cpu-sys-win)
      (box :class "spacer")
      (box :class "spacer")
      (gpu-sys-win)
      (box :class "spacer")
      (box :class "spacer")
      (ram-sys-win)
    )
    (box
      :visible {battery.visible}
      :height 200
      (graph
        :height 200
        :value {battery.percentage}
        :time-range "30min"
        :min "0.0"
        :max "100.0"
        :dynamic true
      )
    )
  )
)

(defwindow sys
  :monitor 0
  :stacking "overlay"
  :geometry (geometry
    :x "0%"
    :y "0%"
  	:anchor "bottom right"
    :width "0px"
    :height "0px")
  (window (sys-win)))
