bar: warning for high resource usage

This commit is contained in:
end-4
2025-08-26 09:15:59 +07:00
parent 376f2bfeb1
commit 63b7a3a36c
6 changed files with 22 additions and 13 deletions
@@ -10,11 +10,13 @@ Item {
id: root
required property string iconName
required property double percentage
property int warningThreshold: 100
property bool shown: true
clip: true
visible: width > 0 && height > 0
implicitWidth: resourceRowLayout.x < 0 ? 0 : resourceRowLayout.implicitWidth
implicitHeight: Appearance.sizes.barHeight
property bool warning: percentage * 100 >= warningThreshold
RowLayout {
id: resourceRowLayout
@@ -30,7 +32,8 @@ Item {
lineWidth: Appearance.rounding.unsharpen
value: percentage
implicitSize: 20
colPrimary: Appearance.colors.colOnSecondaryContainer
colPrimary: root.warning ? Appearance.colors.colError : Appearance.colors.colOnSecondaryContainer
accountForLightBleeding: !root.warning
enableAnimation: false
Item {
@@ -1,7 +1,5 @@
import qs.modules.common
import qs.modules.common.widgets
import qs.services
import qs
import QtQuick
import QtQuick.Layouts
@@ -24,6 +22,7 @@ MouseArea {
Resource {
iconName: "memory"
percentage: ResourceUsage.memoryUsedPercentage
warningThreshold: Config.options.bar.resources.memoryWarningThreshold
}
Resource {
@@ -33,6 +32,7 @@ MouseArea {
(MprisController.activePlayer?.trackTitle == null) ||
root.alwaysShowAllResources
Layout.leftMargin: shown ? 6 : 0
warningThreshold: Config.options.bar.resources.swapWarningThreshold
}
Resource {
@@ -42,6 +42,7 @@ MouseArea {
!(MprisController.activePlayer?.trackTitle?.length > 0) ||
root.alwaysShowAllResources
Layout.leftMargin: shown ? 6 : 0
warningThreshold: Config.options.bar.resources.cpuWarningThreshold
}
}
@@ -150,6 +150,9 @@ Singleton {
property JsonObject resources: JsonObject {
property bool alwaysShowSwap: true
property bool alwaysShowCpu: false
property int memoryWarningThreshold: 95
property int swapWarningThreshold: 85
property int cpuWarningThreshold: 90
}
property list<string> screenList: [] // List of names, like "eDP-1", find out with 'hyprctl monitors' command
property JsonObject utilButtons: JsonObject {
@@ -18,6 +18,7 @@ Item {
property bool enableAnimation: true
property int animationDuration: 800
property var easingType: Easing.OutCubic
property bool accountForLightBleeding: true
default property Item textMask: Item {
width: implicitSize
height: implicitSize
@@ -35,7 +36,7 @@ Item {
property real degree: value * 360
property real centerX: root.width / 2
property real centerY: root.height / 2
property real arcRadius: root.implicitSize / 2 - root.lineWidth / 2 - 0.5 // the 0.5 is to account for light bleeding
property real arcRadius: root.implicitSize / 2 - root.lineWidth / 2 - (0.5 * root.accountForLightBleeding)
property real startAngle: -90
Behavior on degree {
@@ -1,29 +1,27 @@
import qs
import qs.modules.common
import qs.modules.common.functions
import qs.modules.common.widgets
import qs.services
import QtQuick
import QtQuick.Layouts
import Quickshell
Item {
id: root
required property string iconName
required property double percentage
property int warningThreshold: 100
implicitHeight: resourceProgress.implicitHeight
implicitWidth: Appearance.sizes.verticalBarWidth
// Helper function to format KB to GB
function formatKB(kb) {
return (kb / (1024 * 1024)).toFixed(1) + " GB";
}
property bool warning: percentage * 100 >= warningThreshold
ClippedFilledCircularProgress {
id: resourceProgress
anchors.centerIn: parent
value: percentage
enableAnimation: false
colPrimary: root.warning ? Appearance.colors.colError : Appearance.colors.colOnSecondaryContainer
accountForLightBleeding: !root.warning
MaterialSymbol {
font.weight: Font.Medium
fill: 1
@@ -40,5 +38,4 @@ Item {
acceptedButtons: Qt.NoButton
enabled: root.visible
}
}
@@ -1,4 +1,5 @@
import qs.services
import qs.modules.common
import QtQuick
import QtQuick.Layouts
import "../bar" as Bar
@@ -19,18 +20,21 @@ MouseArea {
Layout.alignment: Qt.AlignHCenter
iconName: "memory"
percentage: ResourceUsage.memoryUsedPercentage
warningThreshold: Config.options.bar.resources.memoryWarningThreshold
}
Resource {
Layout.alignment: Qt.AlignHCenter
iconName: "swap_horiz"
percentage: ResourceUsage.swapUsedPercentage
warningThreshold: Config.options.bar.resources.swapWarningThreshold
}
Resource {
Layout.alignment: Qt.AlignHCenter
iconName: "planner_review"
percentage: ResourceUsage.cpuUsage
warningThreshold: Config.options.bar.resources.cpuWarningThreshold
}
}