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