Bar: SysMon

This commit is contained in:
quadbyte 2025-08-13 08:04:26 -04:00
parent 53901f2c9f
commit b53cc0466d
4 changed files with 100 additions and 14 deletions

View file

@ -28,7 +28,7 @@ TEMP_SENSOR_TYPE=""
# --- Data Collection Functions ---
#
# Gets memory usage in GB and as a percentage.
# Gets memory usage in GB, MB, and as a percentage.
#
get_memory_info() {
awk '
@ -39,11 +39,10 @@ get_memory_info() {
usage_kb = total - available
usage_gb = usage_kb / 1000000
usage_percent = (usage_kb / total) * 100
# MODIFIED: Round the memory percentage to the nearest integer.
printf "%.1f %.0f\n", usage_gb, usage_percent
} else {
# Fallback if /proc/meminfo is unreadable or empty.
print "0.0 0.0"
print "0.0 0 0"
}
}
' /proc/meminfo
@ -95,10 +94,8 @@ get_cpu_usage() {
if (total > 0) {
# Formula: 100 * (Total - Idle) / Total
usage = 100 * (total - idle) / total
# MODIFIED: Changed format from "%.2f" back to "%.1f" for one decimal place.
printf "%.1f\n", usage
} else {
# MODIFIED: Changed output back to "0.0" to match the precision.
print "0.0"
}
}'
@ -171,7 +168,7 @@ get_cpu_temp() {
# This loop runs indefinitely, gathering and printing stats.
while true; do
# Call the functions to gather all the data.
# 'read' is used to capture the two output values from get_memory_info.
# get_memory_info
read -r mem_gb mem_per <<< "$(get_memory_info)"
# Command substitution captures the single output from the other functions.
@ -179,11 +176,11 @@ while true; do
cpu_usage=$(get_cpu_usage)
cpu_temp=$(get_cpu_temp)
# Use printf to format the final JSON output string, matching the Zig program.
printf '{"mem":"%s", "cpu": "%s", "cputemp": "%s", "memper": "%s", "diskper": "%s"}\n' \
"$mem_gb" \
# Use printf to format the final JSON output string, adding the mem_mb key.
printf '{"cpu": "%s", "cputemp": "%s", "memgb":"%s", "memper": "%s", "diskper": "%s"}\n' \
"$cpu_usage" \
"$cpu_temp" \
"$mem_gb" \
"$mem_per" \
"$disk_per"

View file

@ -50,11 +50,14 @@ Variants {
anchors.verticalCenter: parent.verticalCenter
spacing: Style.marginSmall * scaling
NText {
text: screen.name
anchors.verticalCenter: parent.verticalCenter
font.weight: Style.fontWeightBold
}
// Debug show monitor name
// NText {
// text: screen.name
// anchors.verticalCenter: parent.verticalCenter
// font.weight: Style.fontWeightBold
// }
SystemMonitor {}
}
// Center

View file

@ -0,0 +1,84 @@
import QtQuick
import Quickshell
import qs.Services
import qs.Widgets
Row {
id: layout
anchors.verticalCenter: parent.verticalCenter
spacing: Style.marginSmall * scaling
visible: Settings.data.bar.showSystemInfo
// Ensure our width is an integer
width: Math.floor(cpuUsageLayout.width + cpuTempLayout.width + memoryUsageLayout.width + (2 * 10))
Row {
id: cpuUsageLayout
spacing: Style.marginTiny * scaling
NText {
id: cpuUsageIcon
text: "speed"
font.family: "Material Symbols Outlined"
font.pointSize: Style.fontSizeLarge * scaling
verticalAlignment: Text.AlignVCenter
anchors.verticalCenter: parent.verticalCenter
color: Colors.accentPrimary
}
NText {
id: cpuUsageText
text: `${SystemStats.cpuUsage}%`
font.pointSize: Style.fontSizeSmall * scaling
font.weight: Style.fontWeightBold
anchors.verticalCenter: parent.verticalCenter
verticalAlignment: Text.AlignVCenter
}
}
// CPU Temperature Component
Row {
id: cpuTempLayout
spacing: Style.marginTiny * scaling
NText {
text: "thermometer"
font.family: "Material Symbols Outlined"
font.pointSize: Style.fontSizeLarge * scaling
color: Colors.accentPrimary
verticalAlignment: Text.AlignVCenter
anchors.verticalCenter: parent.verticalCenter
}
NText {
text: `${SystemStats.cpuTemp}°C`
font.pointSize: Style.fontSizeSmall * scaling
font.weight: Style.fontWeightBold
anchors.verticalCenter: parent.verticalCenter
verticalAlignment: Text.AlignVCenter
}
}
// Memory Usage Component
Row {
id: memoryUsageLayout
spacing: Style.marginTiny * scaling
NText {
text: "memory"
font.family: "Material Symbols Outlined"
font.pointSize: Style.fontSizeLarge * scaling
color: Colors.accentPrimary
verticalAlignment: Text.AlignVCenter
anchors.verticalCenter: parent.verticalCenter
}
NText {
text: `${SystemStats.memoryUsageGb}G`
font.pointSize: Style.fontSizeSmall * scaling
font.weight: Style.fontWeightBold
anchors.verticalCenter: parent.verticalCenter
verticalAlignment: Text.AlignVCenter
}
}
}

View file

@ -11,6 +11,7 @@ Singleton {
// Public values
property real cpuUsage: 0
property real cpuTemp: 0
property real memoryUsageGb: 0
property real memoryUsagePer: 0
property real diskUsage: 0
@ -25,6 +26,7 @@ Singleton {
const data = JSON.parse(line)
root.cpuUsage = data.cpu
root.cpuTemp = data.cputemp
root.memoryUsageGb = data.memgb
root.memoryUsagePer = data.memper
root.diskUsage = data.diskper
} catch (e) {