Port the AGS widgets into the shell as plugins
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
import QtQuick
|
||||
import qs.Commons
|
||||
|
||||
Column {
|
||||
id: root
|
||||
|
||||
property string icon: ""
|
||||
property string name: ""
|
||||
property int percent: 0
|
||||
property string detail: ""
|
||||
|
||||
spacing: Style.spaceReal(4)
|
||||
|
||||
Item {
|
||||
width: parent.width
|
||||
implicitHeight: nameText.implicitHeight
|
||||
|
||||
Text {
|
||||
id: iconText
|
||||
anchors.left: parent.left
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
width: Style.spaceReal(22)
|
||||
text: root.icon
|
||||
textFormat: Text.PlainText
|
||||
color: Color.magenta
|
||||
font.family: Style.font.family
|
||||
font.pixelSize: Style.font.body
|
||||
}
|
||||
|
||||
Text {
|
||||
id: nameText
|
||||
anchors.left: iconText.right
|
||||
anchors.leftMargin: Style.spaceReal(8)
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
text: root.name
|
||||
textFormat: Text.PlainText
|
||||
color: Color.foreground
|
||||
font.family: Style.font.family
|
||||
font.pixelSize: Style.font.bodySmall
|
||||
font.bold: true
|
||||
}
|
||||
|
||||
Text {
|
||||
anchors.right: parent.right
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
text: root.detail
|
||||
textFormat: Text.PlainText
|
||||
color: Util.alpha(Color.foreground, 0.8)
|
||||
font.family: Style.font.family
|
||||
font.pixelSize: Style.font.bodySmall
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
width: parent.width
|
||||
height: Style.spaceReal(8)
|
||||
radius: Style.cardRadius
|
||||
color: Util.alpha(Color.foreground, 0.2)
|
||||
|
||||
Rectangle {
|
||||
width: parent.width * Math.max(0, Math.min(100, root.percent)) / 100
|
||||
height: parent.height
|
||||
radius: Style.cardRadius
|
||||
color: Color.accent
|
||||
|
||||
Behavior on width {
|
||||
NumberAnimation { duration: 200 }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
import Quickshell.Wayland
|
||||
import qs.Commons
|
||||
import qs.Ui
|
||||
|
||||
Item {
|
||||
id: root
|
||||
|
||||
property var shell: null
|
||||
property var manifest: null
|
||||
property bool opened: false
|
||||
|
||||
readonly property string pluginId: (manifest && manifest.id) || "blob.sysmon"
|
||||
|
||||
property int cpuPercent: 0
|
||||
property int memoryPercent: 0
|
||||
property string memoryDetail: ""
|
||||
property int diskPercent: 0
|
||||
property string diskDetail: ""
|
||||
property int temperature: 0
|
||||
|
||||
property real previousIdle: 0
|
||||
property real previousTotal: 0
|
||||
|
||||
function open(payloadJson) {
|
||||
root.opened = true
|
||||
}
|
||||
|
||||
function close() {
|
||||
root.opened = false
|
||||
}
|
||||
|
||||
function dismiss() {
|
||||
root.opened = false
|
||||
if (root.shell && typeof root.shell.hide === "function")
|
||||
root.shell.hide(root.pluginId)
|
||||
}
|
||||
|
||||
function readCpu(raw) {
|
||||
var values = String(raw).trim().split(/\s+/).slice(1).map(Number)
|
||||
var idle = (values[3] || 0) + (values[4] || 0)
|
||||
var total = 0
|
||||
for (var i = 0; i < values.length; i++) total += values[i] || 0
|
||||
var idleDelta = idle - root.previousIdle
|
||||
var totalDelta = total - root.previousTotal
|
||||
root.previousIdle = idle
|
||||
root.previousTotal = total
|
||||
if (totalDelta <= 0) return
|
||||
root.cpuPercent = Math.round((1 - idleDelta / totalDelta) * 100)
|
||||
}
|
||||
|
||||
function readMemory(raw) {
|
||||
var parts = String(raw).trim().split(/\s+/).map(Number)
|
||||
var used = parts[0] || 0
|
||||
var total = parts[1] || 0
|
||||
if (!total) {
|
||||
root.memoryPercent = 0
|
||||
root.memoryDetail = ""
|
||||
return
|
||||
}
|
||||
root.memoryPercent = Math.round(used / total * 100)
|
||||
root.memoryDetail = (used / 1024).toFixed(1) + "G / " + (total / 1024).toFixed(1) + "G"
|
||||
}
|
||||
|
||||
function readDisk(raw) {
|
||||
var parts = String(raw).trim().split(/\s+/)
|
||||
root.diskPercent = Number(String(parts[0] || "").replace("%", "")) || 0
|
||||
root.diskDetail = (parts[1] || "0") + " / " + (parts[2] || "0")
|
||||
}
|
||||
|
||||
Process {
|
||||
id: cpuProbe
|
||||
command: ["bash", "-c", "grep '^cpu ' /proc/stat"]
|
||||
stdout: StdioCollector { onStreamFinished: root.readCpu(text) }
|
||||
}
|
||||
|
||||
Process {
|
||||
id: memoryProbe
|
||||
command: ["bash", "-c", "free -m | awk '/^Mem:/ {print $3\" \"$2}'"]
|
||||
stdout: StdioCollector { onStreamFinished: root.readMemory(text) }
|
||||
}
|
||||
|
||||
Process {
|
||||
id: diskProbe
|
||||
command: ["bash", "-c", "df -h --output=pcent,used,size / | tail -1"]
|
||||
stdout: StdioCollector { onStreamFinished: root.readDisk(text) }
|
||||
}
|
||||
|
||||
Process {
|
||||
id: temperatureProbe
|
||||
command: ["bash", "-c", "cat /sys/class/thermal/thermal_zone0/temp 2>/dev/null || echo 0"]
|
||||
stdout: StdioCollector {
|
||||
onStreamFinished: root.temperature = Math.round(Number(String(text).trim()) / 1000) || 0
|
||||
}
|
||||
}
|
||||
|
||||
function refreshFast() {
|
||||
if (!cpuProbe.running) cpuProbe.running = true
|
||||
if (!memoryProbe.running) memoryProbe.running = true
|
||||
if (!temperatureProbe.running) temperatureProbe.running = true
|
||||
}
|
||||
|
||||
function refreshSlow() {
|
||||
if (!diskProbe.running) diskProbe.running = true
|
||||
}
|
||||
|
||||
Timer {
|
||||
interval: 2000
|
||||
running: root.opened
|
||||
repeat: true
|
||||
onTriggered: root.refreshFast()
|
||||
}
|
||||
|
||||
Timer {
|
||||
interval: 30000
|
||||
running: root.opened
|
||||
repeat: true
|
||||
onTriggered: root.refreshSlow()
|
||||
}
|
||||
|
||||
onOpenedChanged: {
|
||||
if (!root.opened) return
|
||||
root.refreshFast()
|
||||
root.refreshSlow()
|
||||
}
|
||||
|
||||
PanelWindow {
|
||||
visible: root.opened
|
||||
anchors { top: true; bottom: true; left: true; right: true }
|
||||
color: "transparent"
|
||||
WlrLayershell.namespace: "blob-sysmon"
|
||||
WlrLayershell.layer: WlrLayer.Overlay
|
||||
WlrLayershell.keyboardFocus: WlrKeyboardFocus.None
|
||||
exclusionMode: ExclusionMode.Ignore
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: root.dismiss()
|
||||
}
|
||||
|
||||
Card {
|
||||
anchors.top: parent.top
|
||||
anchors.right: parent.right
|
||||
anchors.topMargin: Style.spaceReal(10)
|
||||
anchors.rightMargin: Style.spaceReal(10)
|
||||
implicitWidth: Style.spaceReal(400)
|
||||
fillColor: Util.alpha(Color.background, Style.panelFillAlpha)
|
||||
spacing: Style.spaceReal(12)
|
||||
|
||||
Text {
|
||||
text: "System Monitor"
|
||||
textFormat: Text.PlainText
|
||||
color: Color.foreground
|
||||
font.family: Style.font.family
|
||||
font.pixelSize: Style.font.body
|
||||
font.bold: true
|
||||
}
|
||||
|
||||
Metric {
|
||||
width: parent.width
|
||||
icon: ""
|
||||
name: "CPU"
|
||||
percent: root.cpuPercent
|
||||
detail: root.cpuPercent + "%"
|
||||
}
|
||||
|
||||
Metric {
|
||||
width: parent.width
|
||||
icon: ""
|
||||
name: "Memory"
|
||||
percent: root.memoryPercent
|
||||
detail: root.memoryDetail
|
||||
}
|
||||
|
||||
Metric {
|
||||
width: parent.width
|
||||
icon: ""
|
||||
name: "Disk"
|
||||
percent: root.diskPercent
|
||||
detail: root.diskDetail
|
||||
}
|
||||
|
||||
Metric {
|
||||
width: parent.width
|
||||
icon: ""
|
||||
name: "Temperature"
|
||||
percent: root.temperature
|
||||
detail: root.temperature + "°C"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"name": "System monitor",
|
||||
"version": "1.0.0",
|
||||
"author": "Blob",
|
||||
"description": "CPU, memory, disk, and temperature meters",
|
||||
"id": "blob.sysmon",
|
||||
"kinds": [
|
||||
"overlay"
|
||||
],
|
||||
"keepLoaded": true,
|
||||
"entryPoints": {
|
||||
"overlay": "SysMonitor.qml"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user