1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2025-12-07 14:05:38 -05:00

Improve system monitor display

This commit is contained in:
bbedward
2025-07-14 13:17:06 -04:00
parent 4486e79afe
commit d5d45b11c3
2 changed files with 499 additions and 188 deletions

View File

@@ -12,6 +12,15 @@ Singleton {
property bool isUpdating: false property bool isUpdating: false
property int processUpdateInterval: 3000 property int processUpdateInterval: 3000
// System information properties
property int totalMemoryKB: 0
property int usedMemoryKB: 0
property int totalSwapKB: 0
property int usedSwapKB: 0
property int cpuCount: 1
property real totalCpuUsage: 0.0
property bool systemInfoAvailable: false
// Sorting options // Sorting options
property string sortBy: "cpu" // "cpu", "memory", "name", "pid" property string sortBy: "cpu" // "cpu", "memory", "name", "pid"
property bool sortDescending: true property bool sortDescending: true
@@ -23,10 +32,32 @@ Singleton {
console.log("ProcessMonitorService: Initialization complete") console.log("ProcessMonitorService: Initialization complete")
} }
// System information monitoring
Process {
id: systemInfoProcess
command: ["bash", "-c", "cat /proc/meminfo; echo '---CPU---'; nproc; echo '---CPUSTAT---'; grep '^cpu ' /proc/stat"]
running: false
stdout: StdioCollector {
onStreamFinished: {
if (text.trim()) {
parseSystemInfo(text.trim())
}
}
}
onExited: (exitCode) => {
if (exitCode !== 0) {
console.warn("System info check failed with exit code:", exitCode)
root.systemInfoAvailable = false
}
}
}
// Process monitoring with ps command // Process monitoring with ps command
Process { Process {
id: processListProcess id: processListProcess
command: ["bash", "-c", "ps axo pid,ppid,pcpu,pmem,comm,cmd --sort=-pcpu | head -" + (root.maxProcesses + 1)] command: ["bash", "-c", "ps axo pid,ppid,pcpu,pmem,rss,comm,cmd --sort=-pcpu | head -" + (root.maxProcesses + 1)]
running: false running: false
stdout: StdioCollector { stdout: StdioCollector {
@@ -40,21 +71,23 @@ Singleton {
const line = lines[i].trim() const line = lines[i].trim()
if (!line) continue if (!line) continue
// Parse ps output: PID PPID %CPU %MEM COMMAND CMD // Parse ps output: PID PPID %CPU %MEM RSS COMMAND CMD
const parts = line.split(/\s+/) const parts = line.split(/\s+/)
if (parts.length >= 6) { if (parts.length >= 7) {
const pid = parseInt(parts[0]) const pid = parseInt(parts[0])
const ppid = parseInt(parts[1]) const ppid = parseInt(parts[1])
const cpu = parseFloat(parts[2]) const cpu = parseFloat(parts[2])
const memory = parseFloat(parts[3]) const memoryPercent = parseFloat(parts[3])
const command = parts[4] const memoryKB = parseInt(parts[4])
const fullCmd = parts.slice(5).join(' ') const command = parts[5]
const fullCmd = parts.slice(6).join(' ')
newProcesses.push({ newProcesses.push({
pid: pid, pid: pid,
ppid: ppid, ppid: ppid,
cpu: cpu, cpu: cpu,
memory: memory, memoryPercent: memoryPercent,
memoryKB: memoryKB,
command: command, command: command,
fullCommand: fullCmd, fullCommand: fullCmd,
displayName: command.length > 15 ? command.substring(0, 15) + "..." : command displayName: command.length > 15 ? command.substring(0, 15) + "..." : command
@@ -76,7 +109,7 @@ Singleton {
} }
} }
// Process monitoring timer // System and process monitoring timer
Timer { Timer {
id: processTimer id: processTimer
interval: root.processUpdateInterval interval: root.processUpdateInterval
@@ -84,11 +117,18 @@ Singleton {
repeat: true repeat: true
onTriggered: { onTriggered: {
updateSystemInfo()
updateProcessList() updateProcessList()
} }
} }
// Public functions // Public functions
function updateSystemInfo() {
if (!systemInfoProcess.running) {
systemInfoProcess.running = true
}
}
function updateProcessList() { function updateProcessList() {
if (!root.isUpdating) { if (!root.isUpdating) {
root.isUpdating = true root.isUpdating = true
@@ -112,7 +152,7 @@ Singleton {
sortOption = "--sort=-pcpu" sortOption = "--sort=-pcpu"
} }
processListProcess.command = ["bash", "-c", "ps axo pid,ppid,pcpu,pmem,comm,cmd " + sortOption + " | head -" + (root.maxProcesses + 1)] processListProcess.command = ["bash", "-c", "ps axo pid,ppid,pcpu,pmem,rss,comm,cmd " + sortOption + " | head -" + (root.maxProcesses + 1)]
processListProcess.running = true processListProcess.running = true
} }
} }
@@ -167,7 +207,76 @@ Singleton {
return cpu.toFixed(1) + "%" return cpu.toFixed(1) + "%"
} }
function formatMemoryUsage(memory) { function formatMemoryUsage(memoryKB) {
return memory.toFixed(1) + "%" if (memoryKB < 1024) {
return memoryKB.toFixed(0) + " KB"
} else if (memoryKB < 1024 * 1024) {
return (memoryKB / 1024).toFixed(1) + " MB"
} else {
return (memoryKB / (1024 * 1024)).toFixed(1) + " GB"
}
}
function formatSystemMemory(memoryKB) {
if (memoryKB < 1024 * 1024) {
return (memoryKB / 1024).toFixed(0) + " MB"
} else {
return (memoryKB / (1024 * 1024)).toFixed(1) + " GB"
}
}
function parseSystemInfo(text) {
const lines = text.split('\n')
let section = 'memory'
for (let i = 0; i < lines.length; i++) {
const line = lines[i].trim()
if (line === '---CPU---') {
section = 'cpucount'
continue
} else if (line === '---CPUSTAT---') {
section = 'cpustat'
continue
}
if (section === 'memory') {
if (line.startsWith('MemTotal:')) {
root.totalMemoryKB = parseInt(line.split(/\s+/)[1])
} else if (line.startsWith('MemAvailable:')) {
const availableKB = parseInt(line.split(/\s+/)[1])
root.usedMemoryKB = root.totalMemoryKB - availableKB
} else if (line.startsWith('SwapTotal:')) {
root.totalSwapKB = parseInt(line.split(/\s+/)[1])
} else if (line.startsWith('SwapFree:')) {
const freeSwapKB = parseInt(line.split(/\s+/)[1])
root.usedSwapKB = root.totalSwapKB - freeSwapKB
}
} else if (section === 'cpucount') {
const count = parseInt(line)
if (!isNaN(count)) {
root.cpuCount = count
}
} else if (section === 'cpustat') {
if (line.startsWith('cpu ')) {
const parts = line.split(/\s+/)
if (parts.length >= 8) {
const user = parseInt(parts[1])
const nice = parseInt(parts[2])
const system = parseInt(parts[3])
const idle = parseInt(parts[4])
const iowait = parseInt(parts[5])
const irq = parseInt(parts[6])
const softirq = parseInt(parts[7])
const total = user + nice + system + idle + iowait + irq + softirq
const used = total - idle - iowait
root.totalCpuUsage = total > 0 ? (used / total) * 100 : 0
}
}
}
}
root.systemInfoAvailable = true
} }
} }

View File

@@ -17,8 +17,8 @@ PanelWindow {
visible: isVisible visible: isVisible
implicitWidth: 500 implicitWidth: 600
implicitHeight: 500 implicitHeight: 600
WlrLayershell.layer: WlrLayershell.Overlay WlrLayershell.layer: WlrLayershell.Overlay
WlrLayershell.exclusiveZone: -1 WlrLayershell.exclusiveZone: -1
@@ -41,8 +41,8 @@ PanelWindow {
Rectangle { Rectangle {
id: dropdownContent id: dropdownContent
width: Math.min(500, parent.width - Theme.spacingL * 2) width: Math.min(600, parent.width - Theme.spacingL * 2)
height: Math.min(500, parent.height - Theme.barHeight - Theme.spacingS * 2) height: Math.min(600, parent.height - Theme.barHeight - Theme.spacingS * 2)
x: Math.max(Theme.spacingL, parent.width - width - Theme.spacingL) x: Math.max(Theme.spacingL, parent.width - width - Theme.spacingL)
y: Theme.barHeight + Theme.spacingXS y: Theme.barHeight + Theme.spacingXS
@@ -94,145 +94,191 @@ PanelWindow {
anchors.margins: Theme.spacingL anchors.margins: Theme.spacingL
spacing: Theme.spacingM spacing: Theme.spacingM
// Header // System overview and controls
Column { Column {
Layout.fillWidth: true Layout.fillWidth: true
spacing: Theme.spacingM spacing: Theme.spacingM
// Enhanced system overview with integrated controls
Row { Row {
width: parent.width width: parent.width
height: 32 spacing: Theme.spacingM
Text { // CPU Overview Card (clickable for sorting)
id: processTitle Rectangle {
text: "System Processes" width: (parent.width - Theme.spacingM * 2) / 3
font.pixelSize: Theme.fontSizeLarge height: 80
font.weight: Font.Medium radius: Theme.cornerRadiusLarge
color: Theme.surfaceText color: {
anchors.verticalCenter: parent.verticalCenter if (ProcessMonitorService.sortBy === "cpu") {
} return Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.16)
} else if (cpuCardMouseArea.containsMouse) {
Item { return Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.12)
width: parent.width - processTitle.width - sortControls.width - Theme.spacingM } else {
height: 1 return Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.08)
}
// Sort controls
Row {
id: sortControls
spacing: Theme.spacingXS
anchors.verticalCenter: parent.verticalCenter
Rectangle {
width: cpuButton.width + ramButton.width + Theme.spacingXS
height: 28
radius: Theme.cornerRadius
color: Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.3)
Row {
anchors.centerIn: parent
spacing: 0
Button {
id: cpuButton
text: "CPU"
flat: true
checkable: true
checked: ProcessMonitorService.sortBy === "cpu"
onClicked: ProcessMonitorService.setSortBy("cpu")
font.pixelSize: Theme.fontSizeSmall
hoverEnabled: true
MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
onClicked: parent.clicked()
}
contentItem: Text {
text: parent.text
font: parent.font
color: parent.checked ? Theme.primary : Theme.surfaceText
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
background: Rectangle {
color: parent.checked ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.12) : "transparent"
radius: Theme.cornerRadius
Behavior on color {
ColorAnimation { duration: Theme.shortDuration }
}
}
}
Button {
id: ramButton
text: "RAM"
flat: true
checkable: true
checked: ProcessMonitorService.sortBy === "memory"
onClicked: ProcessMonitorService.setSortBy("memory")
font.pixelSize: Theme.fontSizeSmall
hoverEnabled: true
MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
onClicked: parent.clicked()
}
contentItem: Text {
text: parent.text
font: parent.font
color: parent.checked ? Theme.primary : Theme.surfaceText
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
background: Rectangle {
color: parent.checked ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.12) : "transparent"
radius: Theme.cornerRadius
Behavior on color {
ColorAnimation { duration: Theme.shortDuration }
}
}
}
} }
} }
border.color: ProcessMonitorService.sortBy === "cpu" ?
Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.4) :
Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.2)
border.width: ProcessMonitorService.sortBy === "cpu" ? 2 : 1
Rectangle { MouseArea {
width: 28 id: cpuCardMouseArea
height: 28 anchors.fill: parent
radius: Theme.cornerRadius hoverEnabled: true
color: sortOrderArea.containsMouse ? cursorShape: Qt.PointingHandCursor
Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.08) : onClicked: ProcessMonitorService.setSortBy("cpu")
"transparent" }
Behavior on color {
ColorAnimation { duration: Theme.shortDuration }
}
Behavior on border.color {
ColorAnimation { duration: Theme.shortDuration }
}
Column {
anchors.left: parent.left
anchors.leftMargin: Theme.spacingM
anchors.verticalCenter: parent.verticalCenter
spacing: 2
Text { Text {
text: ProcessMonitorService.sortDescending ? "↓" : "↑" text: "CPU"
font.pixelSize: Theme.fontSizeMedium font.pixelSize: Theme.fontSizeSmall
font.weight: Font.Medium
color: ProcessMonitorService.sortBy === "cpu" ? Theme.primary : Theme.secondary
opacity: ProcessMonitorService.sortBy === "cpu" ? 1.0 : 0.8
}
Text {
text: ProcessMonitorService.totalCpuUsage.toFixed(1) + "%"
font.pixelSize: Theme.fontSizeLarge
font.weight: Font.Bold
color: Theme.surfaceText color: Theme.surfaceText
anchors.centerIn: parent
} }
MouseArea { Text {
id: sortOrderArea text: ProcessMonitorService.cpuCount + " cores"
anchors.fill: parent font.pixelSize: Theme.fontSizeSmall
hoverEnabled: true color: Theme.surfaceText
cursorShape: Qt.PointingHandCursor opacity: 0.7
onClicked: ProcessMonitorService.toggleSortOrder() }
}
}
// Memory Overview Card (clickable for sorting)
Rectangle {
width: (parent.width - Theme.spacingM * 2) / 3
height: 80
radius: Theme.cornerRadiusLarge
color: {
if (ProcessMonitorService.sortBy === "memory") {
return Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.16)
} else if (memoryCardMouseArea.containsMouse) {
return Qt.rgba(Theme.secondary.r, Theme.secondary.g, Theme.secondary.b, 0.12)
} else {
return Qt.rgba(Theme.secondary.r, Theme.secondary.g, Theme.secondary.b, 0.08)
}
}
border.color: ProcessMonitorService.sortBy === "memory" ?
Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.4) :
Qt.rgba(Theme.secondary.r, Theme.secondary.g, Theme.secondary.b, 0.2)
border.width: ProcessMonitorService.sortBy === "memory" ? 2 : 1
MouseArea {
id: memoryCardMouseArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: ProcessMonitorService.setSortBy("memory")
}
Behavior on color {
ColorAnimation { duration: Theme.shortDuration }
}
Behavior on border.color {
ColorAnimation { duration: Theme.shortDuration }
}
Column {
anchors.left: parent.left
anchors.leftMargin: Theme.spacingM
anchors.verticalCenter: parent.verticalCenter
spacing: 2
Text {
text: "Memory"
font.pixelSize: Theme.fontSizeSmall
font.weight: Font.Medium
color: ProcessMonitorService.sortBy === "memory" ? Theme.primary : Theme.secondary
opacity: ProcessMonitorService.sortBy === "memory" ? 1.0 : 0.8
} }
Behavior on color { Text {
ColorAnimation { duration: Theme.shortDuration } text: ProcessMonitorService.formatSystemMemory(ProcessMonitorService.usedMemoryKB)
font.pixelSize: Theme.fontSizeLarge
font.weight: Font.Bold
color: Theme.surfaceText
}
Text {
text: "of " + ProcessMonitorService.formatSystemMemory(ProcessMonitorService.totalMemoryKB)
font.pixelSize: Theme.fontSizeSmall
color: Theme.surfaceText
opacity: 0.7
}
}
}
// Swap Overview Card
Rectangle {
width: (parent.width - Theme.spacingM * 2) / 3
height: 80
radius: Theme.cornerRadiusLarge
color: ProcessMonitorService.totalSwapKB > 0 ?
Qt.rgba(Theme.tertiary.r, Theme.tertiary.g, Theme.tertiary.b, 0.08) :
Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.04)
border.color: ProcessMonitorService.totalSwapKB > 0 ?
Qt.rgba(Theme.tertiary.r, Theme.tertiary.g, Theme.tertiary.b, 0.2) :
Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.12)
border.width: 1
Column {
anchors.left: parent.left
anchors.leftMargin: Theme.spacingM
anchors.verticalCenter: parent.verticalCenter
spacing: 2
Text {
text: "Swap"
font.pixelSize: Theme.fontSizeSmall
font.weight: Font.Medium
color: ProcessMonitorService.totalSwapKB > 0 ? Theme.tertiary : Theme.surfaceText
opacity: 0.8
}
Text {
text: ProcessMonitorService.totalSwapKB > 0 ? ProcessMonitorService.formatSystemMemory(ProcessMonitorService.usedSwapKB) : "None"
font.pixelSize: Theme.fontSizeLarge
font.weight: Font.Bold
color: Theme.surfaceText
}
Text {
text: ProcessMonitorService.totalSwapKB > 0 ? "of " + ProcessMonitorService.formatSystemMemory(ProcessMonitorService.totalSwapKB) : "No swap configured"
font.pixelSize: Theme.fontSizeSmall
color: Theme.surfaceText
opacity: 0.7
} }
} }
} }
} }
// Separator // Separator
Rectangle { Rectangle {
width: parent.width width: parent.width
@@ -242,52 +288,106 @@ PanelWindow {
} }
// Headers // Headers
Row { Item {
id: columnHeaders id: columnHeaders
Layout.fillWidth: true Layout.fillWidth: true
Layout.leftMargin: 8 Layout.leftMargin: 8
spacing: 8 height: 24
// Icon placeholder + Process name // Process name header
Text { Text {
text: "Process" text: "Process"
font.pixelSize: Theme.fontSizeSmall font.pixelSize: Theme.fontSizeSmall
font.weight: Font.Medium font.weight: Font.Medium
color: Theme.surfaceText color: Theme.surfaceText
opacity: 0.7 opacity: 0.7
width: Theme.iconSize - 4 + 8 + 150 // icon width + spacing + name width anchors.left: parent.left
anchors.leftMargin: 0 // Left align with content area
anchors.verticalCenter: parent.verticalCenter
} }
Item { width: parent.parent.width - 280 - 16 } // Flexible spacer to match process list (280 from row + 16 for margins) // CPU header - positioned exactly like CPU badge
Rectangle {
width: 80
height: 20
color: "transparent"
anchors.right: parent.right
anchors.rightMargin: 200 // Slight adjustment to move right
anchors.verticalCenter: parent.verticalCenter
Text { Text {
text: "CPU" text: "CPU"
font.pixelSize: Theme.fontSizeSmall font.pixelSize: Theme.fontSizeSmall
font.weight: Font.Medium font.weight: Font.Medium
color: Theme.surfaceText color: Theme.surfaceText
opacity: 0.7 opacity: 0.7
width: 60 anchors.centerIn: parent
horizontalAlignment: Text.AlignRight }
} }
Text { // RAM header - positioned exactly like memory badge
text: "RAM" Rectangle {
font.pixelSize: Theme.fontSizeSmall width: 80
font.weight: Font.Medium height: 20
color: Theme.surfaceText color: "transparent"
opacity: 0.7 anchors.right: parent.right
width: 60 anchors.rightMargin: 112 // Move right by decreasing rightMargin
horizontalAlignment: Text.AlignRight anchors.verticalCenter: parent.verticalCenter
Text {
text: "RAM"
font.pixelSize: Theme.fontSizeSmall
font.weight: Font.Medium
color: Theme.surfaceText
opacity: 0.7
anchors.centerIn: parent
}
} }
// PID header - positioned exactly like PID text
Text { Text {
text: "PID" text: "PID"
font.pixelSize: Theme.fontSizeSmall font.pixelSize: Theme.fontSizeSmall
font.weight: Font.Medium font.weight: Font.Medium
color: Theme.surfaceText color: Theme.surfaceText
opacity: 0.7 opacity: 0.7
width: 60 width: 50
horizontalAlignment: Text.AlignRight horizontalAlignment: Text.AlignRight
anchors.right: parent.right
anchors.rightMargin: 53 // Move left by increasing rightMargin
anchors.verticalCenter: parent.verticalCenter
}
// Sort direction arrow - far right
Rectangle {
width: 28
height: 28
radius: Theme.cornerRadius
color: sortOrderArea.containsMouse ?
Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.08) :
"transparent"
anchors.right: parent.right
anchors.rightMargin: 8
anchors.verticalCenter: parent.verticalCenter
Text {
text: ProcessMonitorService.sortDescending ? "↓" : "↑"
font.pixelSize: Theme.fontSizeMedium
color: Theme.surfaceText
anchors.centerIn: parent
}
MouseArea {
id: sortOrderArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: ProcessMonitorService.toggleSortOrder()
}
Behavior on color {
ColorAnimation { duration: Theme.shortDuration }
}
} }
} }
@@ -305,15 +405,19 @@ PanelWindow {
id: processListView id: processListView
anchors.fill: parent anchors.fill: parent
model: ProcessMonitorService.processes model: ProcessMonitorService.processes
spacing: 2 spacing: 4
delegate: Rectangle { delegate: Rectangle {
width: processListView.width - 16 width: processListView.width
height: 36 height: 40
radius: Theme.cornerRadius radius: Theme.cornerRadiusLarge
color: processMouseArea.containsMouse ? color: processMouseArea.containsMouse ?
Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.08) : Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.08) :
"transparent" "transparent"
border.color: processMouseArea.containsMouse ?
Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.12) :
"transparent"
border.width: 1
MouseArea { MouseArea {
id: processMouseArea id: processMouseArea
@@ -342,15 +446,13 @@ PanelWindow {
} }
} }
Row { Item {
anchors.left: parent.left anchors.fill: parent
anchors.leftMargin: 8 anchors.margins: 8
anchors.verticalCenter: parent.verticalCenter
spacing: 8
width: parent.width - 16
// Process icon // Process icon
Text { Text {
id: processIcon
text: ProcessMonitorService.getProcessIcon(modelData ? modelData.command : "") text: ProcessMonitorService.getProcessIcon(modelData ? modelData.command : "")
font.family: Theme.iconFont font.family: Theme.iconFont
font.pixelSize: Theme.iconSize - 4 font.pixelSize: Theme.iconSize - 4
@@ -360,6 +462,7 @@ PanelWindow {
return Theme.surfaceText return Theme.surfaceText
} }
opacity: 0.8 opacity: 0.8
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
} }
@@ -367,42 +470,70 @@ PanelWindow {
Text { Text {
text: modelData ? modelData.displayName : "" text: modelData ? modelData.displayName : ""
font.pixelSize: Theme.fontSizeSmall font.pixelSize: Theme.fontSizeSmall
font.weight: Font.Medium
color: Theme.surfaceText color: Theme.surfaceText
width: 150 width: 250
elide: Text.ElideRight elide: Text.ElideRight
anchors.left: processIcon.right
anchors.leftMargin: 8
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
} }
Item { width: parent.width - 280 }
// CPU usage // CPU usage
Text { Rectangle {
text: ProcessMonitorService.formatCpuUsage(modelData ? modelData.cpu : 0) id: cpuBadge
font.pixelSize: Theme.fontSizeSmall width: 80
font.weight: Font.Medium height: 20
radius: Theme.cornerRadius
color: { color: {
if (modelData && modelData.cpu > 80) return Theme.error if (modelData && modelData.cpu > 80) return Qt.rgba(Theme.error.r, Theme.error.g, Theme.error.b, 0.12)
if (modelData && modelData.cpu > 50) return Theme.warning if (modelData && modelData.cpu > 50) return Qt.rgba(Theme.warning.r, Theme.warning.g, Theme.warning.b, 0.12)
return Theme.surfaceText return Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.08)
} }
width: 60 anchors.right: parent.right
horizontalAlignment: Text.AlignRight anchors.rightMargin: 194 // 28 (menu) + 12 + 50 (pid) + 12 + 80 (mem) + 12 spacing
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
Text {
text: ProcessMonitorService.formatCpuUsage(modelData ? modelData.cpu : 0)
font.pixelSize: Theme.fontSizeSmall
font.weight: Font.Bold
color: {
if (modelData && modelData.cpu > 80) return Theme.error
if (modelData && modelData.cpu > 50) return Theme.warning
return Theme.surfaceText
}
anchors.centerIn: parent
}
} }
// Memory usage // Memory usage
Text { Rectangle {
text: ProcessMonitorService.formatMemoryUsage(modelData ? modelData.memory : 0) id: memoryBadge
font.pixelSize: Theme.fontSizeSmall width: 80
font.weight: Font.Medium height: 20
radius: Theme.cornerRadius
color: { color: {
if (modelData && modelData.memory > 10) return Theme.error if (modelData && modelData.memoryKB > 1024 * 1024) return Qt.rgba(Theme.error.r, Theme.error.g, Theme.error.b, 0.12) // > 1GB
if (modelData && modelData.memory > 5) return Theme.warning if (modelData && modelData.memoryKB > 512 * 1024) return Qt.rgba(Theme.warning.r, Theme.warning.g, Theme.warning.b, 0.12) // > 512MB
return Theme.surfaceText return Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.08)
} }
width: 60 anchors.right: parent.right
horizontalAlignment: Text.AlignRight anchors.rightMargin: 102 // 28 (menu) + 12 + 50 (pid) + 12 spacing
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
Text {
text: ProcessMonitorService.formatMemoryUsage(modelData ? modelData.memoryKB : 0)
font.pixelSize: Theme.fontSizeSmall
font.weight: Font.Bold
color: {
if (modelData && modelData.memoryKB > 1024 * 1024) return Theme.error // > 1GB
if (modelData && modelData.memoryKB > 512 * 1024) return Theme.warning // > 512MB
return Theme.surfaceText
}
anchors.centerIn: parent
}
} }
// PID // PID
@@ -411,10 +542,54 @@ PanelWindow {
font.pixelSize: Theme.fontSizeSmall font.pixelSize: Theme.fontSizeSmall
color: Theme.surfaceText color: Theme.surfaceText
opacity: 0.7 opacity: 0.7
width: 60 width: 50
horizontalAlignment: Text.AlignRight horizontalAlignment: Text.AlignRight
anchors.right: parent.right
anchors.rightMargin: 40 // 28 (menu) + 12 spacing
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
} }
// 3-dot menu button (far right)
Rectangle {
id: menuButton
width: 28
height: 28
radius: Theme.cornerRadius
color: menuButtonArea.containsMouse ?
Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.08) :
"transparent"
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
Text {
text: "more_vert"
font.family: Theme.iconFont
font.weight: Theme.iconFontWeight
font.pixelSize: Theme.iconSize - 2
color: Theme.surfaceText
opacity: 0.6
anchors.centerIn: parent
}
MouseArea {
id: menuButtonArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: {
if (modelData && modelData.pid > 0) {
processContextMenuWindow.processData = modelData
let globalPos = menuButtonArea.mapToGlobal(menuButtonArea.width / 2, menuButtonArea.height)
processContextMenuWindow.show(globalPos.x, globalPos.y)
}
}
}
Behavior on color {
ColorAnimation { duration: Theme.shortDuration }
}
}
} }
} }
} }
@@ -674,8 +849,34 @@ PanelWindow {
} }
function show(x, y) { function show(x, y) {
processContextMenu.x = x // Smart positioning to prevent off-screen cutoff
processContextMenu.y = y const menuWidth = 180
const menuHeight = menuColumn.implicitHeight + Theme.spacingS * 2
// Get screen dimensions from the monitor
const screenWidth = processContextMenuWindow.screen ? processContextMenuWindow.screen.width : 1920
const screenHeight = processContextMenuWindow.screen ? processContextMenuWindow.screen.height : 1080
// Calculate optimal position
let finalX = x
let finalY = y
// Check horizontal bounds - if too close to right edge, position to the left
if (x + menuWidth > screenWidth - 20) {
finalX = x - menuWidth
}
// Check vertical bounds - if too close to bottom edge, position above
if (y + menuHeight > screenHeight - 20) {
finalY = y - menuHeight
}
// Ensure we don't go off the left or top edges
finalX = Math.max(20, finalX)
finalY = Math.max(20, finalY)
processContextMenu.x = finalX
processContextMenu.y = finalY
processContextMenuWindow.menuVisible = true processContextMenuWindow.menuVisible = true
} }
@@ -721,6 +922,7 @@ PanelWindow {
function show() { function show() {
isVisible = true isVisible = true
ProcessMonitorService.updateSystemInfo()
ProcessMonitorService.updateProcessList() ProcessMonitorService.updateProcessList()
} }