Bar: SysMon
This commit is contained in:
parent
53901f2c9f
commit
b53cc0466d
4 changed files with 100 additions and 14 deletions
|
|
@ -28,7 +28,7 @@ TEMP_SENSOR_TYPE=""
|
||||||
# --- Data Collection Functions ---
|
# --- 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() {
|
get_memory_info() {
|
||||||
awk '
|
awk '
|
||||||
|
|
@ -39,11 +39,10 @@ get_memory_info() {
|
||||||
usage_kb = total - available
|
usage_kb = total - available
|
||||||
usage_gb = usage_kb / 1000000
|
usage_gb = usage_kb / 1000000
|
||||||
usage_percent = (usage_kb / total) * 100
|
usage_percent = (usage_kb / total) * 100
|
||||||
# MODIFIED: Round the memory percentage to the nearest integer.
|
|
||||||
printf "%.1f %.0f\n", usage_gb, usage_percent
|
printf "%.1f %.0f\n", usage_gb, usage_percent
|
||||||
} else {
|
} else {
|
||||||
# Fallback if /proc/meminfo is unreadable or empty.
|
# Fallback if /proc/meminfo is unreadable or empty.
|
||||||
print "0.0 0.0"
|
print "0.0 0 0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
' /proc/meminfo
|
' /proc/meminfo
|
||||||
|
|
@ -95,10 +94,8 @@ get_cpu_usage() {
|
||||||
if (total > 0) {
|
if (total > 0) {
|
||||||
# Formula: 100 * (Total - Idle) / Total
|
# Formula: 100 * (Total - Idle) / Total
|
||||||
usage = 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
|
printf "%.1f\n", usage
|
||||||
} else {
|
} else {
|
||||||
# MODIFIED: Changed output back to "0.0" to match the precision.
|
|
||||||
print "0.0"
|
print "0.0"
|
||||||
}
|
}
|
||||||
}'
|
}'
|
||||||
|
|
@ -171,7 +168,7 @@ get_cpu_temp() {
|
||||||
# This loop runs indefinitely, gathering and printing stats.
|
# This loop runs indefinitely, gathering and printing stats.
|
||||||
while true; do
|
while true; do
|
||||||
# Call the functions to gather all the data.
|
# 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)"
|
read -r mem_gb mem_per <<< "$(get_memory_info)"
|
||||||
|
|
||||||
# Command substitution captures the single output from the other functions.
|
# Command substitution captures the single output from the other functions.
|
||||||
|
|
@ -179,11 +176,11 @@ while true; do
|
||||||
cpu_usage=$(get_cpu_usage)
|
cpu_usage=$(get_cpu_usage)
|
||||||
cpu_temp=$(get_cpu_temp)
|
cpu_temp=$(get_cpu_temp)
|
||||||
|
|
||||||
# Use printf to format the final JSON output string, matching the Zig program.
|
# Use printf to format the final JSON output string, adding the mem_mb key.
|
||||||
printf '{"mem":"%s", "cpu": "%s", "cputemp": "%s", "memper": "%s", "diskper": "%s"}\n' \
|
printf '{"cpu": "%s", "cputemp": "%s", "memgb":"%s", "memper": "%s", "diskper": "%s"}\n' \
|
||||||
"$mem_gb" \
|
|
||||||
"$cpu_usage" \
|
"$cpu_usage" \
|
||||||
"$cpu_temp" \
|
"$cpu_temp" \
|
||||||
|
"$mem_gb" \
|
||||||
"$mem_per" \
|
"$mem_per" \
|
||||||
"$disk_per"
|
"$disk_per"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,11 +50,14 @@ Variants {
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
spacing: Style.marginSmall * scaling
|
spacing: Style.marginSmall * scaling
|
||||||
|
|
||||||
NText {
|
// Debug show monitor name
|
||||||
text: screen.name
|
// NText {
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
// text: screen.name
|
||||||
font.weight: Style.fontWeightBold
|
// anchors.verticalCenter: parent.verticalCenter
|
||||||
}
|
// font.weight: Style.fontWeightBold
|
||||||
|
// }
|
||||||
|
|
||||||
|
SystemMonitor {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Center
|
// Center
|
||||||
|
|
|
||||||
84
Modules/Bar/SystemMonitor.qml
Normal file
84
Modules/Bar/SystemMonitor.qml
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -11,6 +11,7 @@ Singleton {
|
||||||
// Public values
|
// Public values
|
||||||
property real cpuUsage: 0
|
property real cpuUsage: 0
|
||||||
property real cpuTemp: 0
|
property real cpuTemp: 0
|
||||||
|
property real memoryUsageGb: 0
|
||||||
property real memoryUsagePer: 0
|
property real memoryUsagePer: 0
|
||||||
property real diskUsage: 0
|
property real diskUsage: 0
|
||||||
|
|
||||||
|
|
@ -25,6 +26,7 @@ Singleton {
|
||||||
const data = JSON.parse(line)
|
const data = JSON.parse(line)
|
||||||
root.cpuUsage = data.cpu
|
root.cpuUsage = data.cpu
|
||||||
root.cpuTemp = data.cputemp
|
root.cpuTemp = data.cputemp
|
||||||
|
root.memoryUsageGb = data.memgb
|
||||||
root.memoryUsagePer = data.memper
|
root.memoryUsagePer = data.memper
|
||||||
root.diskUsage = data.diskper
|
root.diskUsage = data.diskper
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue