added three new modules (Crypto.qml, Battery.qml, Network.qml), improved Stats.qml, improved Tray.qml, optimized code in general, added a polkit agent, configurations change (check configs)

This commit is contained in:
SomeElse
2026-05-14 04:56:33 +00:00
parent 046a36fbec
commit e3bfa6661f
31 changed files with 5857 additions and 353 deletions

View File

@@ -1,6 +1,5 @@
import QtQuick
import QtQuick.Layouts
import Quickshell
import Quickshell.Io
import "../../config" as Cfg
@@ -25,7 +24,19 @@ Rectangle {
NumberAnimation { duration: 250; easing.type: Easing.OutCubic }
}
HoverHandler { cursorShape: Qt.PointingHandCursor }
property bool expanded: Cfg.Config.statsStartExpanded
property bool hovered: false
HoverHandler {
onHoveredChanged: root.hovered = hovered
}
TapHandler {
onTapped: {
root.expanded = !root.expanded
if (!root.expanded) root.hovered = false
}
}
property real cpuVal: 0
property real memVal: 0
@@ -36,166 +47,162 @@ Rectangle {
running: true
repeat: true
triggeredOnStart: true
onTriggered: {
cpuProc.running = true
memProc.running = true
diskProc.running = true
}
onTriggered: { statsProc.running = true }
}
Process {
id: cpuProc
command: ["sh", "-c", "top -bn1 | awk '/^%Cpu/ {print 100-$8}'"]
id: statsProc
command: ["sh", "-c", "top -bn1 | awk '/^%Cpu/ {print 100-$8}'; free | awk '/Mem:/ {print ($2-$7)/$2 * 100}'; df / --output=pcent | tail -1 | tr -dc '0-9'"]
property string rawOutput: ""
stdout: SplitParser {
onRead: data => {
let val = parseFloat(data.trim())
root.cpuVal = isNaN(val) ? 0 : val
onRead: data => { statsProc.rawOutput += data + "\n" }
}
onRunningChanged: {
if (!statsProc.running && statsProc.rawOutput) {
const lines = statsProc.rawOutput.trim().split("\n")
if (lines.length >= 3) {
let v = parseFloat(lines[0]); root.cpuVal = isNaN(v) ? 0 : v
v = parseFloat(lines[1]); root.memVal = isNaN(v) ? 0 : v
v = parseFloat(lines[2]); root.diskVal = isNaN(v) ? 0 : v
}
statsProc.rawOutput = ""
}
}
}
Process {
id: memProc
command: ["sh", "-c", "free | awk '/Mem:/ {print ($2-$7)/$2 * 100}'"]
stdout: SplitParser {
onRead: data => {
let val = parseFloat(data.trim())
root.memVal = isNaN(val) ? 0 : val
}
}
}
Process {
id: diskProc
command: ["sh", "-c", "df / --output=pcent | tail -1 | tr -dc '0-9'"]
stdout: SplitParser {
onRead: data => {
let val = parseFloat(data.trim())
root.diskVal = isNaN(val) ? 0 : val
}
}
}
component StatRing: Item {
component StatRing: RowLayout {
id: ring
spacing: 5
property real value: 0.0
property string label: ""
property string icon: ""
property real iconXOff: 0
property color ringColor: Cfg.Config.theme.accent
property color trackColor: Cfg.Config.theme.statsTrackColor
property color labelColor: Cfg.Config.theme.textMain
Behavior on value {
NumberAnimation {
duration: 800
easing.type: Easing.OutCubic
}
NumberAnimation { duration: 800; easing.type: Easing.OutCubic }
}
readonly property real fraction: Math.max(0, Math.min(value, 100)) / 100
width: Cfg.Config.statsRingSize
height: Cfg.Config.statsRingSize
Text {
id: leftPct
text: Math.round(ring.value) + "%"
color: ring.ringColor
font.pixelSize: Cfg.Config.statsRingFontSize
font.bold: true
font.family: "monospace"
Layout.alignment: Qt.AlignVCenter
clip: true
onFractionChanged: arc.requestPaint()
onRingColorChanged: arc.requestPaint()
readonly property bool active: Cfg.Config.statsLabelPosition === "left" && (root.expanded || root.hovered)
opacity: active ? 1 : 0
Layout.preferredWidth: active ? implicitWidth : 0
Canvas {
id: arc
anchors.fill: parent
antialiasing: true
Behavior on opacity { NumberAnimation { duration: 200; easing.type: Easing.OutCubic } }
Behavior on Layout.preferredWidth { NumberAnimation { duration: 200; easing.type: Easing.OutCubic } }
}
onPaint: {
var ctx = getContext("2d")
ctx.reset()
Item {
id: ringCore
Layout.preferredWidth: Cfg.Config.statsRingSize
Layout.preferredHeight: Cfg.Config.statsRingSize
var cx = width / 2
var cy = height / 2
var lw = 2.8
var r = Math.min(cx, cy) - lw / 2 - 0.5
onVisibleChanged: if (visible) arc.requestPaint()
ctx.beginPath()
ctx.arc(cx, cy, r, 0, Math.PI * 2)
ctx.strokeStyle = ring.trackColor
ctx.lineWidth = lw
ctx.stroke()
Canvas {
id: arc
anchors.fill: parent
antialiasing: true
Connections {
target: ring
function onFractionChanged() { arc.requestPaint() }
function onRingColorChanged() { arc.requestPaint() }
}
onPaint: {
var ctx = getContext("2d")
ctx.reset()
var cx = width / 2
var cy = height / 2
var lw = 2.8
var r = Math.min(cx, cy) - lw / 2 - 0.5
if (ring.fraction > 0) {
var start = -Math.PI / 2
var end = start + (ring.fraction * Math.PI * 2)
ctx.beginPath()
ctx.arc(cx, cy, r, start, end)
ctx.strokeStyle = ring.ringColor
ctx.arc(cx, cy, r, 0, Math.PI * 2)
ctx.strokeStyle = ring.trackColor
ctx.lineWidth = lw
ctx.lineCap = "round"
ctx.stroke()
if (ring.fraction > 0) {
var start = -Math.PI / 2
var end = start + (ring.fraction * Math.PI * 2)
ctx.beginPath()
ctx.arc(cx, cy, r, start, end)
ctx.strokeStyle = ring.ringColor
ctx.lineWidth = lw
ctx.lineCap = "round"
ctx.stroke()
}
}
}
}
HoverHandler {
id: hov
onHoveredChanged: if (!hovered) ring.showAlt = false
}
property bool showAlt: false
onShowAltChanged: arc.requestPaint()
TapHandler {
enabled: !Cfg.Config.statsHideTextUntilHover || hov.hovered
onTapped: ring.showAlt = !ring.showAlt
Text {
anchors.centerIn: parent
anchors.horizontalCenterOffset: ring.iconXOff
text: ring.icon
color: ring.ringColor
font.pixelSize: Cfg.Config.statsIconSize
}
}
Text {
anchors.centerIn: parent
id: rightPct
text: Math.round(ring.value) + "%"
color: ring.ringColor
font.pixelSize: Cfg.Config.statsRingFontSize
font.bold: true
font.family: "monospace"
Layout.alignment: Qt.AlignVCenter
clip: true
text: {
const hide = Cfg.Config.statsHideTextUntilHover
const byDefault = Cfg.Config.statsShowPercentByDefault
if (hide && !hov.hovered) return ""
const showPct = ring.showAlt ? !byDefault : byDefault
return showPct ? Math.round(ring.value) + "%" : ring.label
}
readonly property bool active: Cfg.Config.statsLabelPosition === "right" && (root.expanded || root.hovered)
opacity: active ? 1 : 0
Layout.preferredWidth: active ? implicitWidth : 0
color: ring.labelColor
font.pixelSize: Cfg.Config.statsRingFontSize
font.bold: true
font.family: "monospace"
opacity: (Cfg.Config.statsHideTextUntilHover && !hov.hovered) ? 0 : 1
Behavior on opacity {
NumberAnimation { duration: 180; easing.type: Easing.OutCubic }
}
Behavior on opacity { NumberAnimation { duration: 200; easing.type: Easing.OutCubic } }
Behavior on Layout.preferredWidth { NumberAnimation { duration: 200; easing.type: Easing.OutCubic } }
}
}
RowLayout {
id: statsLayout
anchors.centerIn: parent
spacing: 10
spacing: 8
StatRing {
value: root.cpuVal
label: "cpu"
icon: "󰍛"
iconXOff: 0.3
ringColor: root.t.statsCpuColor
trackColor: root.t.statsTrackColor
labelColor: root.t.statsText
}
StatRing {
value: root.memVal
label: "ram"
icon: "󰑭"
ringColor: root.t.statsMemColor
trackColor: root.t.statsTrackColor
labelColor: root.t.statsText
}
StatRing {
value: root.diskVal
label: "disk"
icon: "󰒋"
ringColor: root.t.statsDiskColor
trackColor: root.t.statsTrackColor
labelColor: root.t.statsText
}
}
}