refactor: ProcessList non-singleton with sortBy+active, each panel owns one instance gated on _showPanel

This commit is contained in:
Damocles 2026-04-15 18:01:49 +02:00
parent d55f9a0829
commit 8fdd9692e6
4 changed files with 28 additions and 23 deletions

View file

@ -32,6 +32,11 @@ M.BarSection {
readonly property bool _anyHover: root._hovered || hoverPanel.panelHovered readonly property bool _anyHover: root._hovered || hoverPanel.panelHovered
readonly property bool _showPanel: _anyHover || _pinned readonly property bool _showPanel: _anyHover || _pinned
property M.ProcessList _procs: M.ProcessList {
sortBy: "cpu"
active: root._showPanel
}
on_AnyHoverChanged: { on_AnyHoverChanged: {
if (_anyHover) if (_anyHover)
_unpinTimer.stop(); _unpinTimer.stop();
@ -258,7 +263,7 @@ M.BarSection {
// Top processes by CPU // Top processes by CPU
Repeater { Repeater {
model: M.ProcessList.byCpu model: root._procs.processes
delegate: Item { delegate: Item {
required property var modelData required property var modelData

View file

@ -21,6 +21,11 @@ M.BarSection {
readonly property bool _anyHover: root._hovered || hoverPanel.panelHovered readonly property bool _anyHover: root._hovered || hoverPanel.panelHovered
readonly property bool _showPanel: _anyHover || _pinned readonly property bool _showPanel: _anyHover || _pinned
property M.ProcessList _procs: M.ProcessList {
sortBy: "mem"
active: root._showPanel
}
on_AnyHoverChanged: { on_AnyHoverChanged: {
if (_anyHover) if (_anyHover)
_unpinTimer.stop(); _unpinTimer.stop();
@ -223,7 +228,7 @@ M.BarSection {
// Top processes by memory // Top processes by memory
Repeater { Repeater {
model: M.ProcessList.byMem model: root._procs.processes
delegate: Item { delegate: Item {
required property var modelData required property var modelData

View file

@ -1,48 +1,43 @@
pragma Singleton
import QtQuick import QtQuick
import Quickshell.Io import Quickshell.Io
import "." as M
QtObject { QtObject {
id: root id: root
property var byCpu: [] property string sortBy: "cpu" // "cpu" or "mem"
property var byMem: []
property int maxItems: 8 property int maxItems: 8
property bool active: false
property var processes: []
property Process _proc: Process { property Process _proc: Process {
id: proc command: ["sh", "-c", "ps --no-headers -eo pid,pcpu,pmem,comm --sort=-%" + root.sortBy + " | head -" + root.maxItems]
running: true
command: ["sh", "-c", "ps aux --sort=-%cpu 2>/dev/null | awk 'NR>1 && NR<=50 {cmd=$11; for(i=12;i<=NF&&i<=13;i++) cmd=cmd\" \"$i; print $1\"|\"$2\"|\"$3\"|\"$4\"|\"cmd}'"]
stdout: StdioCollector { stdout: StdioCollector {
onStreamFinished: { onStreamFinished: {
const rows = []; const rows = [];
for (const line of text.trim().split("\n")) { for (const line of text.trim().split("\n")) {
if (!line) if (!line)
continue; continue;
const p = line.split("|"); const p = line.trim().split(/\s+/);
if (p.length < 5) if (p.length < 4)
continue; continue;
const cmd = p[4].replace(/^.*\//, "");
rows.push({ rows.push({
"user": p[0], "pid": parseInt(p[0]),
"pid": parseInt(p[1]), "cpu": parseFloat(p[1]),
"cpu": parseFloat(p[2]), "mem": parseFloat(p[2]),
"mem": parseFloat(p[3]), "cmd": p.slice(3).join(" ")
"cmd": cmd || p[4]
}); });
} }
root.byCpu = rows.slice().sort((a, b) => b.cpu - a.cpu).slice(0, root.maxItems); root.processes = rows;
root.byMem = rows.slice().sort((a, b) => b.mem - a.mem).slice(0, root.maxItems);
} }
} }
} }
property Timer _timer: Timer { property Timer _timer: Timer {
interval: 2000 interval: 2000
running: true running: root.active
repeat: true repeat: true
onTriggered: proc.running = true triggeredOnStart: true
onTriggered: root._proc.running = true
} }
} }

View file

@ -34,7 +34,7 @@ IdleInhibitor 1.0 IdleInhibitor.qml
Notifications 1.0 Notifications.qml Notifications 1.0 Notifications.qml
singleton NiriIpc 1.0 NiriIpc.qml singleton NiriIpc 1.0 NiriIpc.qml
singleton SystemStats 1.0 SystemStats.qml singleton SystemStats 1.0 SystemStats.qml
singleton ProcessList 1.0 ProcessList.qml ProcessList 1.0 ProcessList.qml
singleton NotifService 1.0 NotifService.qml singleton NotifService 1.0 NotifService.qml
NotifItem 1.0 NotifItem.qml NotifItem 1.0 NotifItem.qml
NotifPopup 1.0 NotifPopup.qml NotifPopup 1.0 NotifPopup.qml