From aabfb080e135650b04703e64141f3bec7613b7e2 Mon Sep 17 00:00:00 2001 From: bbedward Date: Mon, 24 Aug 2026 12:41:15 -0400 Subject: [PATCH] dankbar: set tnum: 1 in Numerictext for CPU/GPU/Ram/Battery widgets related #3161 --- dank-qml-common | 2 +- flake.lock | 6 +- .../Modules/DankBar/Widgets/CpuMonitor.qml | 53 +++-------- .../DankBar/Widgets/CpuTemperature.qml | 45 +++------ .../DankBar/Widgets/GpuTemperature.qml | 45 +++------ .../Modules/DankBar/Widgets/RamMonitor.qml | 91 ++++++++----------- quickshell/Widgets/BatteryMeter.qml | 6 +- 7 files changed, 89 insertions(+), 159 deletions(-) diff --git a/dank-qml-common b/dank-qml-common index 13b7f2e99..8b448932d 160000 --- a/dank-qml-common +++ b/dank-qml-common @@ -1 +1 @@ -Subproject commit 13b7f2e99a08438a94c37b474b355aff3a5c1db8 +Subproject commit 8b448932de27dad60a92ea31c8055e46b293346a diff --git a/flake.lock b/flake.lock index d8df6fa53..52e6cb999 100644 --- a/flake.lock +++ b/flake.lock @@ -3,11 +3,11 @@ "dank-qml-common": { "flake": false, "locked": { - "lastModified": 1787413952, - "narHash": "sha256-jRqu1xKyWZkFdBlR8sP5qJMFrs+kWjs3Gt6BaNO92Ko=", + "lastModified": 1787589656, + "narHash": "sha256-RIia8PIMeQGjOK/zrRWDlGLYyfrnqZhwyAnD3ou6l5g=", "owner": "AvengeMedia", "repo": "dank-qml-common", - "rev": "13b7f2e99a08438a94c37b474b355aff3a5c1db8", + "rev": "8b448932de27dad60a92ea31c8055e46b293346a", "type": "github" }, "original": { diff --git a/quickshell/Modules/DankBar/Widgets/CpuMonitor.qml b/quickshell/Modules/DankBar/Widgets/CpuMonitor.qml index 212f9b52e..028b9a707 100644 --- a/quickshell/Modules/DankBar/Widgets/CpuMonitor.qml +++ b/quickshell/Modules/DankBar/Widgets/CpuMonitor.qml @@ -51,7 +51,8 @@ BasePill { anchors.horizontalCenter: parent.horizontalCenter } - StyledText { + NumericText { + isMonospace: false text: { if (DgopService.cpuUsage === undefined || DgopService.cpuUsage === null || DgopService.cpuUsage === 0) { return "--"; @@ -89,45 +90,21 @@ BasePill { anchors.verticalCenter: parent.verticalCenter } - Item { - id: textBox - anchors.verticalCenter: parent.verticalCenter - - implicitWidth: root.minimumWidth ? Math.max(cpuBaseline.width, cpuCurrent.width) : cpuCurrent.width - implicitHeight: cpuText.implicitHeight - - width: implicitWidth - height: implicitHeight - - StyledTextMetrics { - id: cpuBaseline - font.pixelSize: Theme.barTextSize(root.barThickness, root.barConfig?.fontScale, root.barConfig?.maximizeWidgetText) - text: "100%" - } - - StyledTextMetrics { - id: cpuCurrent - font.pixelSize: Theme.barTextSize(root.barThickness, root.barConfig?.fontScale, root.barConfig?.maximizeWidgetText) - text: cpuText.text - } - - StyledText { - id: cpuText - text: { - const v = DgopService.cpuUsage; - if (v === undefined || v === null || v === 0) { - return "--%"; - } - return v.toFixed(0) + "%"; + NumericText { + isMonospace: false + text: { + const v = DgopService.cpuUsage; + if (v === undefined || v === null || v === 0) { + return "--%"; } - font.pixelSize: Theme.barTextSize(root.barThickness, root.barConfig?.fontScale, root.barConfig?.maximizeWidgetText) - color: Theme.widgetTextColor - - anchors.fill: parent - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter - elide: Text.ElideNone + return v.toFixed(0) + "%"; } + reserveText: root.minimumWidth ? "100%" : "" + width: Math.ceil(Math.max(implicitWidth, reservedWidth)) + horizontalAlignment: Text.AlignHCenter + font.pixelSize: Theme.barTextSize(root.barThickness, root.barConfig?.fontScale, root.barConfig?.maximizeWidgetText) + color: Theme.widgetTextColor + anchors.verticalCenter: parent.verticalCenter } } } diff --git a/quickshell/Modules/DankBar/Widgets/CpuTemperature.qml b/quickshell/Modules/DankBar/Widgets/CpuTemperature.qml index 40663871d..f336362a5 100644 --- a/quickshell/Modules/DankBar/Widgets/CpuTemperature.qml +++ b/quickshell/Modules/DankBar/Widgets/CpuTemperature.qml @@ -51,7 +51,8 @@ BasePill { anchors.horizontalCenter: parent.horizontalCenter } - StyledText { + NumericText { + isMonospace: false text: { if (DgopService.cpuTemperature === undefined || DgopService.cpuTemperature === null || DgopService.cpuTemperature < 0) { return "--"; @@ -89,39 +90,21 @@ BasePill { anchors.verticalCenter: parent.verticalCenter } - Item { - id: textBox - anchors.verticalCenter: parent.verticalCenter - - implicitWidth: root.minimumWidth ? Math.max(tempBaseline.width, cpuTempText.paintedWidth) : cpuTempText.paintedWidth - implicitHeight: cpuTempText.implicitHeight - - width: implicitWidth - height: implicitHeight - - StyledTextMetrics { - id: tempBaseline - font.pixelSize: Theme.barTextSize(root.barThickness, root.barConfig?.fontScale, root.barConfig?.maximizeWidgetText) - text: "88°" - } - - StyledText { - id: cpuTempText - text: { - if (DgopService.cpuTemperature === undefined || DgopService.cpuTemperature === null || DgopService.cpuTemperature < 0) { - return "--°"; - } - - return Math.round(DgopService.cpuTemperature) + "°"; + NumericText { + isMonospace: false + text: { + if (DgopService.cpuTemperature === undefined || DgopService.cpuTemperature === null || DgopService.cpuTemperature < 0) { + return "--°"; } - font.pixelSize: Theme.barTextSize(root.barThickness, root.barConfig?.fontScale, root.barConfig?.maximizeWidgetText) - color: Theme.widgetTextColor - anchors.fill: parent - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter - elide: Text.ElideNone + return Math.round(DgopService.cpuTemperature) + "°"; } + reserveText: root.minimumWidth ? "88°" : "" + width: Math.ceil(Math.max(implicitWidth, reservedWidth)) + horizontalAlignment: Text.AlignHCenter + font.pixelSize: Theme.barTextSize(root.barThickness, root.barConfig?.fontScale, root.barConfig?.maximizeWidgetText) + color: Theme.widgetTextColor + anchors.verticalCenter: parent.verticalCenter } } } diff --git a/quickshell/Modules/DankBar/Widgets/GpuTemperature.qml b/quickshell/Modules/DankBar/Widgets/GpuTemperature.qml index 215e70927..ae28ca17e 100644 --- a/quickshell/Modules/DankBar/Widgets/GpuTemperature.qml +++ b/quickshell/Modules/DankBar/Widgets/GpuTemperature.qml @@ -119,7 +119,8 @@ BasePill { anchors.horizontalCenter: parent.horizontalCenter } - StyledText { + NumericText { + isMonospace: false text: { if (root.displayTemp === undefined || root.displayTemp === null || root.displayTemp === 0) { return "--"; @@ -157,39 +158,21 @@ BasePill { anchors.verticalCenter: parent.verticalCenter } - Item { - id: textBox - anchors.verticalCenter: parent.verticalCenter - - implicitWidth: root.minimumWidth ? Math.max(gpuTempBaseline.width, gpuTempText.paintedWidth) : gpuTempText.paintedWidth - implicitHeight: gpuTempText.implicitHeight - - width: implicitWidth - height: implicitHeight - - StyledTextMetrics { - id: gpuTempBaseline - font.pixelSize: Theme.barTextSize(root.barThickness, root.barConfig?.fontScale, root.barConfig?.maximizeWidgetText) - text: "88°" - } - - StyledText { - id: gpuTempText - text: { - if (root.displayTemp === undefined || root.displayTemp === null || root.displayTemp === 0) { - return "--°"; - } - - return Math.round(root.displayTemp) + "°"; + NumericText { + isMonospace: false + text: { + if (root.displayTemp === undefined || root.displayTemp === null || root.displayTemp === 0) { + return "--°"; } - font.pixelSize: Theme.barTextSize(root.barThickness, root.barConfig?.fontScale, root.barConfig?.maximizeWidgetText) - color: Theme.widgetTextColor - anchors.fill: parent - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter - elide: Text.ElideNone + return Math.round(root.displayTemp) + "°"; } + reserveText: root.minimumWidth ? "88°" : "" + width: Math.ceil(Math.max(implicitWidth, reservedWidth)) + horizontalAlignment: Text.AlignHCenter + font.pixelSize: Theme.barTextSize(root.barThickness, root.barConfig?.fontScale, root.barConfig?.maximizeWidgetText) + color: Theme.widgetTextColor + anchors.verticalCenter: parent.verticalCenter } } } diff --git a/quickshell/Modules/DankBar/Widgets/RamMonitor.qml b/quickshell/Modules/DankBar/Widgets/RamMonitor.qml index f5d6de59f..ed530fed7 100644 --- a/quickshell/Modules/DankBar/Widgets/RamMonitor.qml +++ b/quickshell/Modules/DankBar/Widgets/RamMonitor.qml @@ -54,7 +54,8 @@ BasePill { anchors.horizontalCenter: parent.horizontalCenter } - StyledText { + NumericText { + isMonospace: false text: { if (DgopService.memoryUsage === undefined || DgopService.memoryUsage === null || DgopService.memoryUsage === 0) { return "--"; @@ -71,7 +72,8 @@ BasePill { anchors.horizontalCenter: parent.horizontalCenter } - StyledText { + NumericText { + isMonospace: false visible: root.showSwap && DgopService.totalSwapKB > 0 text: root.swapUsage.toFixed(0) font.pixelSize: Theme.barTextSize(root.barThickness, root.barConfig?.fontScale, root.barConfig?.maximizeWidgetText) @@ -104,59 +106,40 @@ BasePill { anchors.verticalCenter: parent.verticalCenter } - Item { - id: textBox + NumericText { + isMonospace: false + text: { + if (DgopService.memoryUsage === undefined || DgopService.memoryUsage === null || DgopService.memoryUsage === 0) { + return root.showInGb ? "-- GB" : "--%"; + } + + let ramText = ""; + if (root.showInGb) { + ramText = (DgopService.usedMemoryMB / 1024).toFixed(1) + " GB"; + } else { + ramText = DgopService.memoryUsage.toFixed(0) + "%"; + } + + if (root.showSwap && DgopService.totalSwapKB > 0) { + return ramText + " · " + root.swapUsage.toFixed(0) + "%"; + } + return ramText; + } + reserveText: { + if (!root.minimumWidth) { + return ""; + } + const baseText = root.showInGb ? "88.8 GB" : "88%"; + if (!root.showSwap) { + return baseText; + } + return root.swapUsage < 10 ? baseText + " · 0%" : baseText + " · 88%"; + } + width: Math.ceil(Math.max(implicitWidth, reservedWidth)) + horizontalAlignment: Text.AlignHCenter + font.pixelSize: Theme.barTextSize(root.barThickness, root.barConfig?.fontScale, root.barConfig?.maximizeWidgetText) + color: Theme.widgetTextColor anchors.verticalCenter: parent.verticalCenter - - implicitWidth: root.minimumWidth ? Math.max(ramBaseline.width, ramText.paintedWidth) : ramText.paintedWidth - implicitHeight: ramText.implicitHeight - - width: implicitWidth - height: implicitHeight - - StyledTextMetrics { - id: ramBaseline - font.pixelSize: Theme.barTextSize(root.barThickness, root.barConfig?.fontScale, root.barConfig?.maximizeWidgetText) - text: { - let baseText = root.showInGb ? "88.8 GB" : "88%"; - if (!root.showSwap) { - return baseText; - } - if (root.swapUsage < 10) { - return baseText + " · 0%"; - } - return baseText + " · 88%"; - } - } - - StyledText { - id: ramText - text: { - if (DgopService.memoryUsage === undefined || DgopService.memoryUsage === null || DgopService.memoryUsage === 0) { - return root.showInGb ? "-- GB" : "--%"; - } - - let ramText = ""; - if (root.showInGb) { - ramText = (DgopService.usedMemoryMB / 1024).toFixed(1) + " GB"; - } else { - ramText = DgopService.memoryUsage.toFixed(0) + "%"; - } - - if (root.showSwap && DgopService.totalSwapKB > 0) { - return ramText + " · " + root.swapUsage.toFixed(0) + "%"; - } - return ramText; - } - font.pixelSize: Theme.barTextSize(root.barThickness, root.barConfig?.fontScale, root.barConfig?.maximizeWidgetText) - color: Theme.widgetTextColor - - anchors.fill: parent - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter - elide: Text.ElideNone - wrapMode: Text.NoWrap - } } } } diff --git a/quickshell/Widgets/BatteryMeter.qml b/quickshell/Widgets/BatteryMeter.qml index 20dbbffdc..c22c07b53 100644 --- a/quickshell/Widgets/BatteryMeter.qml +++ b/quickshell/Widgets/BatteryMeter.qml @@ -75,6 +75,9 @@ Item { font.weight: root.glyphWeight font.pixelSize: Math.max(1, root.baseTextSize) + font.features: { + "tnum": 1 + } text: root.numberText } @@ -207,9 +210,10 @@ Item { width: root.width height: root.height - StyledText { + NumericText { id: numberGlyph + isMonospace: false visible: root.numberInside x: root.textCanvasLeft + (root.textCanvasWidth - implicitWidth - signGlyph.implicitWidth) / 2 y: root.textBaseline - baselineOffset