From 1c259d7878c00592916dc6acdb6e22771b22bbf1 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Sat, 12 Jul 2025 23:21:58 +0800 Subject: finish organize --- bar/Cpu.qml | 23 ++++----------- bar/Gpu.qml | 22 +++----------- bar/Memory.qml | 21 +++---------- bar/Network.qml | 6 ++-- bar/Power.qml | 27 +++++++++++++++++ bar/Temp.qml | 21 +++---------- bar/TimeDate.qml | 2 +- components/Icons.qml | 34 ++++++++++++++++++++++ components/SimpleResource.qml | 26 +++++++++++++++++ services/NetworkUsage.qml | 68 +++++++++++++++++++++++++++++++++++++++++++ utils/Icons.qml | 34 ---------------------- utils/NetworkUsage.qml | 68 ------------------------------------------- 12 files changed, 176 insertions(+), 176 deletions(-) create mode 100644 bar/Power.qml create mode 100644 components/Icons.qml create mode 100644 components/SimpleResource.qml create mode 100644 services/NetworkUsage.qml delete mode 100644 utils/Icons.qml delete mode 100644 utils/NetworkUsage.qml diff --git a/bar/Cpu.qml b/bar/Cpu.qml index 5d65415..00cf53c 100644 --- a/bar/Cpu.qml +++ b/bar/Cpu.qml @@ -1,27 +1,14 @@ import QtQuick import QtQuick.Layouts +import qs.components +import qs.config import qs.services as Services -import qs.utils -import qs.config as Config Item { id: root - RowLayout { - Item { - Layout.fillWidth: true - } - anchors.fill: parent - spacing: Config.Bar.resourceIconTextSpacing - - Icons { - text: Config.Icons.resource.cpu - } - Text { - text: Math.round(Services.Resource.cpuUsage * 100) - } - Item { - Layout.fillWidth: true - } + SimpleResource { + text: Math.round(Services.Resource.cpuUsage * 100) + icon: Icons.resource.cpu } } diff --git a/bar/Gpu.qml b/bar/Gpu.qml index e47d8f8..a0e1dd6 100644 --- a/bar/Gpu.qml +++ b/bar/Gpu.qml @@ -2,26 +2,12 @@ import QtQuick import QtQuick.Layouts import qs.services as Services -import qs.utils +import qs.components import qs.config as Config Item { - id: root - RowLayout { - Item { - Layout.fillWidth: true - } - anchors.fill: parent - spacing: Config.Bar.resourceIconTextSpacing - - Icons { - text: Config.Icons.resource.gpu - } - Text { - text: Services.Resource.gpuUsage - } - Item { - Layout.fillWidth: true - } + SimpleResource { + icon: Config.Icons.resource.gpu + text: Services.Resource.gpuUsage } } diff --git a/bar/Memory.qml b/bar/Memory.qml index 130c9ea..30a17e6 100644 --- a/bar/Memory.qml +++ b/bar/Memory.qml @@ -2,26 +2,13 @@ import QtQuick import QtQuick.Layouts import qs.services as Services -import qs.utils +import qs.components import qs.config as Config Item { id: root - RowLayout { - Item { - Layout.fillWidth: true - } - anchors.fill: parent - spacing: Config.Bar.resourceIconTextSpacing - - Icons { - text: Config.Icons.resource.memory - } - Text { - text: Math.round(Services.Resource.memoryUsedPercentage * 100) + "%" - } - Item { - Layout.fillWidth: true - } + SimpleResource { + icon: Config.Icons.resource.memory + text: Math.round(Services.Resource.memoryUsedPercentage * 100) + "%" } } diff --git a/bar/Network.qml b/bar/Network.qml index df70ecd..3559df0 100644 --- a/bar/Network.qml +++ b/bar/Network.qml @@ -2,7 +2,7 @@ import QtQuick import QtQuick.Layouts import qs.services as Services -import qs.utils +import qs.components import qs.config as Config Item { @@ -22,10 +22,10 @@ Item { text: Math.round(Services.Resource.cpuUsage * 100) } Text { - text: NetworkUsage.up + " " + NetworkUsage.upUnit + text: Services.NetworkUsage.up + " " + Services.NetworkUsage.upUnit } Text { - text: NetworkUsage.down + " " + NetworkUsage.downUnit + text: Services.NetworkUsage.down + " " + Services.NetworkUsage.downUnit } Item { Layout.fillWidth: true diff --git a/bar/Power.qml b/bar/Power.qml new file mode 100644 index 0000000..93da141 --- /dev/null +++ b/bar/Power.qml @@ -0,0 +1,27 @@ +import QtQuick +import QtQuick.Layouts + +import qs.services as Services +import qs.utils +import qs.config as Config + +Item { + id: root + RowLayout { + Item { + Layout.fillWidth: true + } + anchors.fill: parent + spacing: Config.Bar.resourceIconTextSpacing + + Icons { + text: Config.Icons.resource.clock + } + Text { + text: Services.TimeDate.time + } + Item { + Layout.fillWidth: true + } + } +} diff --git a/bar/Temp.qml b/bar/Temp.qml index c2c5f1d..fb84e5a 100644 --- a/bar/Temp.qml +++ b/bar/Temp.qml @@ -2,26 +2,13 @@ import QtQuick import QtQuick.Layouts import qs.services as Services -import qs.utils +import qs.components import qs.config as Config Item { id: root - RowLayout { - Item { - Layout.fillWidth: true - } - anchors.fill: parent - spacing: Config.Bar.resourceIconTextSpacing - - Icons { - text: Config.Icons.resource.temp - } - Text { - text: Math.round(Services.Resource.cpuTemp * 100) - } - Item { - Layout.fillWidth: true - } + SimpleResource { + icon: Config.Icons.resource.temp + text: Math.round(Services.Resource.cpuTemp * 100) } } diff --git a/bar/TimeDate.qml b/bar/TimeDate.qml index 93da141..807566a 100644 --- a/bar/TimeDate.qml +++ b/bar/TimeDate.qml @@ -2,7 +2,7 @@ import QtQuick import QtQuick.Layouts import qs.services as Services -import qs.utils +import qs.components import qs.config as Config Item { diff --git a/components/Icons.qml b/components/Icons.qml new file mode 100644 index 0000000..4b3915c --- /dev/null +++ b/components/Icons.qml @@ -0,0 +1,34 @@ +import QtQuick +import QtQuick.Layouts + +import qs.config + +Text { + id: root + property real iconSize: General.iconSize + property real fill: 0 + property real truncatedFill: Math.round(fill * 100) / 100 // Reduce memory consumption spikes from constant font remapping + renderType: Text.NativeRendering + font { + hintingPreference: Font.PreferFullHinting + family: Style.font.family.symbols ?? "Symbols Nerd Font" + pixelSize: iconSize + weight: Font.Normal + (Font.DemiBold - Font.Normal) * fill + variableAxes: { + "FILL": truncatedFill, + // "wght": font.weight, + // "GRAD": 0, + "opsz": iconSize + } + } + verticalAlignment: Text.AlignVCenter + // color: Style.m3colors.m3onBackground + + // Behavior on fill { + // NumberAnimation { + // duration: Appearance?.animation.elementMoveFast.duration ?? 200 + // easing.type: Appearance?.animation.elementMoveFast.type ?? Easing.BezierSpline + // easing.bezierCurve: Appearance?.animation.elementMoveFast.bezierCurve ?? [0.34, 0.80, 0.34, 1.00, 1, 1] + // } + // } +} diff --git a/components/SimpleResource.qml b/components/SimpleResource.qml new file mode 100644 index 0000000..786e37b --- /dev/null +++ b/components/SimpleResource.qml @@ -0,0 +1,26 @@ +import QtQuick +import Quickshell +import QtQuick.Layouts +import qs.config as Config +import qs.components + +RowLayout { + id: root + required property string text + required property string icon + Item { + Layout.fillWidth: true + } + anchors.fill: parent + spacing: Config.Bar.resourceIconTextSpacing + + Icons { + text: root.icon + } + Text { + text: root.text + } + Item { + Layout.fillWidth: true + } +} diff --git a/services/NetworkUsage.qml b/services/NetworkUsage.qml new file mode 100644 index 0000000..844a5a5 --- /dev/null +++ b/services/NetworkUsage.qml @@ -0,0 +1,68 @@ +pragma Singleton +// pragma ComponentBehavior: Bound + +import Quickshell +import Quickshell.Io +import QtQuick +import "../utils/networkUsage.js" as Network +import qs.config + +Singleton { + property int up: 0 + property string upUnit: "" + property int down: 0 + property string downUnit: "" + + property string __iface: "" + property var __prev: ({ + rx: 0, + tx: 0 + }) + + Timer { + interval: General.resourceUpdateInterval * 1000 + running: true + repeat: true + onTriggered: update() + } + + function update() { + __iface = Network.defaultInterface(getRouteProcess.stdout.text); + const cur = Network.getRxTxBytes(getNetDevProcess.stdout.text, __iface); + const sec = General.resourceUpdateInterval; + const rawUp = (cur.tx - __prev.tx) / sec; + const rawDown = (cur.rx - __prev.rx) / sec; + + up = Network.formatSize(rawUp, false); + upUnit = Network.formatSize(rawUp, true); + down = Network.formatSize(rawDown, false); + downUnit = Network.formatSize(rawDown, true); + + __prev = cur; + getRouteProcess.running = true; + getNetDevProcess.running = true; + } + + Process { + id: getRouteProcess + running: true + command: ["ip", "route"] + stdout: StdioCollector {} + } + + Process { + id: getNetDevProcess + running: true + command: ["cat", "/proc/net/dev"] + stdout: StdioCollector {} + } + + Component.onCompleted: { + getRouteProcess.running = true; + getNetDevProcess.running = true; + if (getRouteProcess.stdout.text) + __iface = Network.defaultInterface(getRouteProcess.stdout.text); + if (getNetDevProcess.stdout.text) + __prev = Network.getRxTxBytes(getNetDevProcess.stdout.text, __iface); + } +} diff --git a/utils/Icons.qml b/utils/Icons.qml deleted file mode 100644 index 4b3915c..0000000 --- a/utils/Icons.qml +++ /dev/null @@ -1,34 +0,0 @@ -import QtQuick -import QtQuick.Layouts - -import qs.config - -Text { - id: root - property real iconSize: General.iconSize - property real fill: 0 - property real truncatedFill: Math.round(fill * 100) / 100 // Reduce memory consumption spikes from constant font remapping - renderType: Text.NativeRendering - font { - hintingPreference: Font.PreferFullHinting - family: Style.font.family.symbols ?? "Symbols Nerd Font" - pixelSize: iconSize - weight: Font.Normal + (Font.DemiBold - Font.Normal) * fill - variableAxes: { - "FILL": truncatedFill, - // "wght": font.weight, - // "GRAD": 0, - "opsz": iconSize - } - } - verticalAlignment: Text.AlignVCenter - // color: Style.m3colors.m3onBackground - - // Behavior on fill { - // NumberAnimation { - // duration: Appearance?.animation.elementMoveFast.duration ?? 200 - // easing.type: Appearance?.animation.elementMoveFast.type ?? Easing.BezierSpline - // easing.bezierCurve: Appearance?.animation.elementMoveFast.bezierCurve ?? [0.34, 0.80, 0.34, 1.00, 1, 1] - // } - // } -} diff --git a/utils/NetworkUsage.qml b/utils/NetworkUsage.qml deleted file mode 100644 index a5e584f..0000000 --- a/utils/NetworkUsage.qml +++ /dev/null @@ -1,68 +0,0 @@ -pragma Singleton -// pragma ComponentBehavior: Bound - -import Quickshell -import Quickshell.Io -import QtQuick -import "networkUsage.js" as Network -import qs.config - -Singleton { - property int up: 0 - property string upUnit: "" - property int down: 0 - property string downUnit: "" - - property string __iface: "" - property var __prev: ({ - rx: 0, - tx: 0 - }) - - Timer { - interval: General.resourceUpdateInterval * 1000 - running: true - repeat: true - onTriggered: update() - } - - function update() { - __iface = Network.defaultInterface(getRouteProcess.stdout.text); - const cur = Network.getRxTxBytes(getNetDevProcess.stdout.text, __iface); - const sec = General.resourceUpdateInterval; - const rawUp = (cur.tx - __prev.tx) / sec; - const rawDown = (cur.rx - __prev.rx) / sec; - - up = Network.formatSize(rawUp, false); - upUnit = Network.formatSize(rawUp, true); - down = Network.formatSize(rawDown, false); - downUnit = Network.formatSize(rawDown, true); - - __prev = cur; - getRouteProcess.running = true; - getNetDevProcess.running = true; - } - - Process { - id: getRouteProcess - running: true - command: ["ip", "route"] - stdout: StdioCollector {} - } - - Process { - id: getNetDevProcess - running: true - command: ["cat", "/proc/net/dev"] - stdout: StdioCollector {} - } - - Component.onCompleted: { - getRouteProcess.running = true; - getNetDevProcess.running = true; - if (getRouteProcess.stdout.text) - __iface = Network.defaultInterface(getRouteProcess.stdout.text); - if (getNetDevProcess.stdout.text) - __prev = Network.getRxTxBytes(getNetDevProcess.stdout.text, __iface); - } -} -- cgit v1.2.3