From 63b7a3a36c78d651674aa0e25de14946a033fc77 Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Tue, 26 Aug 2025 09:15:59 +0700 Subject: [PATCH] bar: warning for high resource usage --- .config/quickshell/ii/modules/bar/Resource.qml | 5 ++++- .config/quickshell/ii/modules/bar/Resources.qml | 5 +++-- .config/quickshell/ii/modules/common/Config.qml | 3 +++ .../widgets/ClippedFilledCircularProgress.qml | 3 ++- .../ii/modules/verticalBar/Resource.qml | 15 ++++++--------- .../ii/modules/verticalBar/Resources.qml | 4 ++++ 6 files changed, 22 insertions(+), 13 deletions(-) diff --git a/.config/quickshell/ii/modules/bar/Resource.qml b/.config/quickshell/ii/modules/bar/Resource.qml index acb900ac0..6d1dec043 100644 --- a/.config/quickshell/ii/modules/bar/Resource.qml +++ b/.config/quickshell/ii/modules/bar/Resource.qml @@ -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 { diff --git a/.config/quickshell/ii/modules/bar/Resources.qml b/.config/quickshell/ii/modules/bar/Resources.qml index 4f477acd2..6c25ab507 100644 --- a/.config/quickshell/ii/modules/bar/Resources.qml +++ b/.config/quickshell/ii/modules/bar/Resources.qml @@ -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 } } diff --git a/.config/quickshell/ii/modules/common/Config.qml b/.config/quickshell/ii/modules/common/Config.qml index 35b125cd5..a9a89ba14 100644 --- a/.config/quickshell/ii/modules/common/Config.qml +++ b/.config/quickshell/ii/modules/common/Config.qml @@ -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 screenList: [] // List of names, like "eDP-1", find out with 'hyprctl monitors' command property JsonObject utilButtons: JsonObject { diff --git a/.config/quickshell/ii/modules/common/widgets/ClippedFilledCircularProgress.qml b/.config/quickshell/ii/modules/common/widgets/ClippedFilledCircularProgress.qml index d4a276792..d6522e61d 100644 --- a/.config/quickshell/ii/modules/common/widgets/ClippedFilledCircularProgress.qml +++ b/.config/quickshell/ii/modules/common/widgets/ClippedFilledCircularProgress.qml @@ -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 { diff --git a/.config/quickshell/ii/modules/verticalBar/Resource.qml b/.config/quickshell/ii/modules/verticalBar/Resource.qml index 72b0acabb..b5055351b 100644 --- a/.config/quickshell/ii/modules/verticalBar/Resource.qml +++ b/.config/quickshell/ii/modules/verticalBar/Resource.qml @@ -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 } - } diff --git a/.config/quickshell/ii/modules/verticalBar/Resources.qml b/.config/quickshell/ii/modules/verticalBar/Resources.qml index 900bb167e..e4bba0187 100644 --- a/.config/quickshell/ii/modules/verticalBar/Resources.qml +++ b/.config/quickshell/ii/modules/verticalBar/Resources.qml @@ -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 } }