summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2025-07-16 14:54:53 +0800
committerlittleblack111 <littleblack11111@gmail.com>2025-07-16 14:54:53 +0800
commit5109ebe7179ced7107f4152e585423782ccb826b (patch)
tree59b8020e0351d0abd43c985c73128ea166283cda
parentb147652efdcbc1a3408d20c6e02606163725452a (diff)
Resources: alt texts
-rw-r--r--bar/Mpris.qml6
-rw-r--r--bar/Resources.qml27
-rw-r--r--bar/TimeDate.qml112
-rw-r--r--components/SimpleResource.qml21
-rw-r--r--services/Resource.qml35
5 files changed, 139 insertions, 62 deletions
diff --git a/bar/Mpris.qml b/bar/Mpris.qml
index f09076d..31c984c 100644
--- a/bar/Mpris.qml
+++ b/bar/Mpris.qml
@@ -97,7 +97,7 @@ Item {
width: Bar.appIconSize
height: Bar.appIconSize
- opacity: activePlayer.playbackState === MprisPlaybackState.Playing ? 1 : Bar.mediaPausedOpacity
+ opacity: activePlayer?.playbackState === MprisPlaybackState.Playing ? 1 : Bar.mediaPausedOpacity
// put shadow
Image {
@@ -132,8 +132,8 @@ Item {
}
IText {
animate: true
- opacity: activePlayer.playbackState === MprisPlaybackState.Playing ? 1 : Bar.mediaPausedOpacity
- color: activePlayer.playbackState === MprisPlaybackState.Playing ? WallustColors.foreground : WallustColors.color15
+ opacity: activePlayer?.playbackState === MprisPlaybackState.Playing ? 1 : Bar.mediaPausedOpacity
+ color: activePlayer?.playbackState === MprisPlaybackState.Playing ? WallustColors.foreground : WallustColors.color15
text: root.cleanedTitle
Behavior on opacity {
diff --git a/bar/Resources.qml b/bar/Resources.qml
index 3e393e4..607c704 100644
--- a/bar/Resources.qml
+++ b/bar/Resources.qml
@@ -21,30 +21,37 @@ Item {
id: layout
anchors.centerIn: parent
SimpleResource {
- value: Services.Resource.cpuUsage
+ value: Math.round(Services.Resource.cpuUsage * 100)
+ altValue: Math.round(Services.Resource.cpuFreq / 10) / 100
suffix: "%"
+ altSuffix: "GHz"
icon: Config.Icons.resource.cpu
}
SimpleResource {
icon: Config.Icons.resource.memory
- value: Services.Resource.memoryUsedPercentage
+ value: Math.round(Services.Resource.memoryUsedPercentage * 100)
+ altValue: Math.round(Services.Resource.memoryUsed / 1024 / 1024)
suffix: "%"
+ altSuffix: "GB"
}
SimpleResource {
icon: Config.Icons.resource.gpu
- value: Services.Resource.gpuUsage / 100
+ value: Services.Resource.gpuUsage
+ altValue: Services.Resource.gpuTemp
suffix: "%"
- thresholdL1: 0.60
- thresholdL2: 0.70
- thresholdL3: 0.80
+ altSuffix: "°C"
+ altIcon: Config.Icons.resource.temp
+ thresholdL1: 60
+ thresholdL2: 70
+ thresholdL3: 80
}
SimpleResource {
icon: Config.Icons.resource.temp
- value: Services.Resource.cpuTemp
+ value: Math.round(Services.Resource.cpuTemp * 100)
suffix: "°C"
- thresholdL1: 0.60
- thresholdL2: 0.80
- thresholdL3: 0.90
+ thresholdL1: 60
+ thresholdL2: 80
+ thresholdL3: 90
}
}
}
diff --git a/bar/TimeDate.qml b/bar/TimeDate.qml
index 5844aab..dddd71c 100644
--- a/bar/TimeDate.qml
+++ b/bar/TimeDate.qml
@@ -6,6 +6,9 @@ import qs.components
import qs.config
Item {
+ id: root
+ property bool isAlt: false
+
implicitWidth: container.implicitWidth
implicitHeight: container.implicitHeight - General.rectMargin
Rectangle {
@@ -16,51 +19,90 @@ Item {
horizontalCenter: parent.horizontalCenter
}
- implicitWidth: layout.implicitWidth + General.rectMargin * 2
+ implicitWidth: !isAlt ? nonAlt.implicitWidth + General.rectMargin * 2 : alt.implicitWidth + General.rectMargin * 2
implicitHeight: Bar.height
color: WallustColors.color4
radius: Style.rounding.large
- RowLayout {
- id: layout
- Item {
- Layout.fillWidth: true
- }
+ Loader {
+ id: nonAlt
anchors.fill: parent
- spacing: Bar.resourceIconTextSpacing
+ active: !root.isAlt
+ sourceComponent: Component {
+ RowLayout {
+ Item {
+ Layout.fillWidth: true
+ }
+ anchors.fill: parent
+ spacing: Bar.resourceIconTextSpacing
- Icon {
- text: Icons.resource.clock
- font.pixelSize: Style.font.size.larger
- }
- RowLayout {
- property int h: Services.TimeDate.hours
- property int m: Services.TimeDate.minutes
- property int s: Services.TimeDate.seconds
- spacing: 0
- IText {
- animate: true
- text: (parent.h >= 10 ? "" : "0") + parent.h
- }
- IText {
- text: ":"
- }
- IText {
- animate: true
- text: (parent.m >= 10 ? "" : "0") + parent.m
- }
- IText {
- text: ":"
- }
- IText {
- animate: true
- text: (parent.s >= 10 ? "" : "0") + parent.s
+ Icon {
+ text: Icons.resource.clock
+ font.pixelSize: Style.font.size.larger
+ }
+ RowLayout {
+ property int h: Services.TimeDate.hours
+ property int m: Services.TimeDate.minutes
+ property int s: Services.TimeDate.seconds
+ spacing: 0
+ IText {
+ animate: true
+ text: (parent.h >= 10 ? "" : "0") + parent.h
+ }
+ IText {
+ text: ":"
+ }
+ IText {
+ animate: true
+ text: (parent.m >= 10 ? "" : "0") + parent.m
+ }
+ IText {
+ text: ":"
+ }
+ IText {
+ animate: true
+ text: (parent.s >= 10 ? "" : "0") + parent.s
+ }
+ }
+ Item {
+ Layout.fillWidth: true
+ }
}
}
- Item {
- Layout.fillWidth: true
+ }
+ Loader {
+ id: alt
+ anchors.fill: parent
+ active: root.isAlt
+ sourceComponent: Component {
+ RowLayout {
+ Item {
+ Layout.fillWidth: true
+ }
+ anchors.fill: parent
+ spacing: Bar.resourceIconTextSpacing
+
+ Icon {
+ text: Icons.resource.calendar
+ font.pixelSize: Style.font.size.larger
+ }
+ IText {
+ animate: true
+ text: Services.TimeDate.date
+ }
+ Item {
+ Layout.fillWidth: true
+ }
+ }
}
}
}
+ MouseArea {
+ anchors.fill: parent
+ cursorShape: Qt.PointingHandCursor
+ onPressed: {
+ root.isAlt = !root.isAlt;
+ }
+ }
}
diff --git a/components/SimpleResource.qml b/components/SimpleResource.qml
index 08d29b4..069dc0c 100644
--- a/components/SimpleResource.qml
+++ b/components/SimpleResource.qml
@@ -10,14 +10,20 @@ Item {
required property real value
required property string suffix // unit
required property string icon
- property string text: Math.round(root.value * 100) + root.suffix
- property real thresholdL1: 40 / 100
+ property string altValue: value
+ property string altSuffix: suffix
+ property string altIcon: icon
+ property string text: root.value + root.suffix
+ property string altText: root.altValue + root.altSuffix
+ property real thresholdL1: 40
property real thresholdL2: thresholdL1 * 1.5
property real thresholdL3: thresholdL2 * 1.5
property color thresholdColorL1: Colors.cyan
property color thresholdColorL2: Colors.yellow
property color thresholdColorL3: Colors.red
+ property bool isAlt: false
+
implicitWidth: layout.implicitWidth
implicitHeight: layout.implicitHeight
@@ -31,12 +37,12 @@ Item {
}
Icon {
- text: root.icon
+ text: !root.isAlt ? root.icon : root.altIcon
color: root.value < root.thresholdL1 ? WallustColors.color15 : root.value >= root.thresholdL3 ? root.thresholdColorL3 : root.value >= root.thresholdL2 ? root.thresholdColorL2 : root.thresholdColorL1
}
IText {
animate: true
- text: root.text
+ text: !root.isAlt ? root.text : root.altText
color: root.value < root.thresholdL1 ? WallustColors.foreground : root.value >= root.thresholdL3 ? root.thresholdColorL3 : root.value >= root.thresholdL2 ? root.thresholdColorL2 : root.thresholdColorL1
}
@@ -44,4 +50,11 @@ Item {
Layout.fillWidth: true
}
}
+ MouseArea {
+ anchors.fill: parent
+ cursorShape: altValue != value ? Qt.PointingHandCursor : Qt.ArrowCursor
+ onPressed: {
+ root.isAlt = !root.isAlt;
+ }
+ }
}
diff --git a/services/Resource.qml b/services/Resource.qml
index d2ab9af..0c2d1d6 100644
--- a/services/Resource.qml
+++ b/services/Resource.qml
@@ -20,6 +20,7 @@ Singleton {
property double cpuUsage: 0
property double cpuTemp: 0
+ property double cpuFreq: 0
property var previousCpuStats
property int gpuUsage: 0
@@ -33,14 +34,15 @@ Singleton {
fileMeminfo.reload();
fileStat.reload();
fileCpuThermal.reload();
+ fileCpuInfo.reload();
const textMeminfo = fileMeminfo.text();
- memoryTotal = Number(textMeminfo.match(/MemTotal: *(\d+)/)[1] ?? 1);
- memoryFree = Number(textMeminfo.match(/MemAvailable: *(\d+)/)[1] ?? 0);
+ memoryTotal = Number(textMeminfo.match(/MemTotal:\s*(\d+)/)[1] ?? 1);
+ memoryFree = Number(textMeminfo.match(/MemAvailable:\s*(\d+)/)[1] ?? 0);
memoryUsed = memoryTotal - memoryFree;
memoryUsedPercentage = memoryUsed / memoryTotal;
- swapTotal = Number(textMeminfo.match(/SwapTotal: *(\d+)/)[1] ?? 1);
- swapFree = Number(textMeminfo.match(/SwapFree: *(\d+)/)[1] ?? 0);
+ swapTotal = Number(textMeminfo.match(/SwapTotal:\s*(\d+)/)[1] ?? 1);
+ swapFree = Number(textMeminfo.match(/SwapFree:\s*(\d+)/)[1] ?? 0);
const textStat = fileStat.text();
const cpuLine = textStat.match(/^cpu\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/);
@@ -48,21 +50,30 @@ Singleton {
const stats = cpuLine.slice(1).map(Number);
const total = stats.reduce((a, b) => a + b, 0);
const idle = stats[3];
-
if (root.previousCpuStats) {
- const totalDiff = total - root.previousCpuStats.total;
- const idleDiff = idle - root.previousCpuStats.idle;
- cpuUsage = totalDiff > 0 ? (1 - idleDiff / totalDiff) : 0;
+ const td = total - root.previousCpuStats.total;
+ const id = idle - root.previousCpuStats.idle;
+ cpuUsage = td > 0 ? (1 - id / td) : 0;
}
-
root.previousCpuStats = {
total,
idle
};
}
+
const cpuTempText = fileCpuThermal.text();
cpuTemp = cpuTempText ? parseInt(cpuTempText.trim()) / 100000 : 0;
+ const textCpuInfo = fileCpuInfo.text();
+ let sum = 0, cnt = 0;
+ const re = /^cpu MHz\s*:\s*([\d.]+)/mg;
+ let m;
+ while ((m = re.exec(textCpuInfo)) !== null) {
+ sum += Number(m[1]);
+ cnt++;
+ }
+ cpuFreq = cnt ? sum / cnt : 0;
+
gpuUsageProc.running = true;
gpuTempProc.running = true;
interval = General.resourceUpdateInterval * 1000;
@@ -81,7 +92,11 @@ Singleton {
id: fileCpuThermal
path: General.cpuThermalPath
}
- // nvidia-smi may be dead if firmware update so ABI break etc.
+ FileView {
+ id: fileCpuInfo
+ path: "/proc/cpuinfo"
+ }
+
Process {
id: gpuUsageProc
running: true