From 37497ddb10d93b5f5013c82b9c0eee5caf27920d Mon Sep 17 00:00:00 2001 From: Benjamin Palko Date: Thu, 24 Jul 2025 11:33:54 -0400 Subject: [PATCH 1/2] ben used steal, it was super effective --- services/NetworkService.qml | 81 +++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 services/NetworkService.qml diff --git a/services/NetworkService.qml b/services/NetworkService.qml new file mode 100644 index 0000000..8515ef5 --- /dev/null +++ b/services/NetworkService.qml @@ -0,0 +1,81 @@ +pragma Singleton + +import Quickshell +import Quickshell.Io +import QtQuick + +Singleton { + id: root + + readonly property list networks: [] + readonly property AccessPoint active: networks.find(n => n.active) ?? null + + reloadableId: "network" + + Process { + running: true + command: ["nmcli", "m"] + stdout: SplitParser { + onRead: getNetworks.running = true + } + } + + Process { + id: getNetworks + running: true + command: ["nmcli", "-g", "ACTIVE,SIGNAL,FREQ,SSID,BSSID", "d", "w"] + environment: ({ + LANG: "C", + LC_ALL: "C" + }) + stdout: StdioCollector { + onStreamFinished: { + const PLACEHOLDER = "STRINGWHICHHOPEFULLYWONTBEUSED"; + const rep = new RegExp("\\\\:", "g"); + const rep2 = new RegExp(PLACEHOLDER, "g"); + + const networks = text.trim().split("\n").map(n => { + const net = n.replace(rep, PLACEHOLDER).split(":"); + return { + active: net[0] === "yes", + strength: parseInt(net[1]), + frequency: parseInt(net[2]), + ssid: net[3], + bssid: net[4]?.replace(rep2, ":") ?? "" + }; + }); + const rNetworks = root.networks; + + const destroyed = rNetworks.filter(rn => !networks.find(n => n.frequency === rn.frequency && n.ssid === rn.ssid && n.bssid === rn.bssid)); + for (const network of destroyed) + rNetworks.splice(rNetworks.indexOf(network), 1).forEach(n => n.destroy()); + + for (const network of networks) { + const match = rNetworks.find(n => n.frequency === network.frequency && n.ssid === network.ssid && n.bssid === network.bssid); + if (match) { + match.lastIpcObject = network; + } else { + rNetworks.push(apComp.createObject(root, { + lastIpcObject: network + })); + } + } + } + } + } + + component AccessPoint: QtObject { + required property var lastIpcObject + readonly property string ssid: lastIpcObject.ssid + readonly property string bssid: lastIpcObject.bssid + readonly property int strength: lastIpcObject.strength + readonly property int frequency: lastIpcObject.frequency + readonly property bool active: lastIpcObject.active + } + + Component { + id: apComp + + AccessPoint {} + } +} From aaeac7a5cd1114b958169d7aaceaf0c90e0829d1 Mon Sep 17 00:00:00 2001 From: Benjamin Palko Date: Thu, 24 Jul 2025 11:52:47 -0400 Subject: [PATCH 2/2] add network --- config/Dimensions.qml | 13 ++++- constants/Icons.qml | 4 ++ modules/bar/Bar.qml | 8 ++- modules/bar/components/Network.qml | 78 ++++++++++++++++++++++++++++++ 4 files changed, 99 insertions(+), 4 deletions(-) create mode 100644 modules/bar/components/Network.qml diff --git a/config/Dimensions.qml b/config/Dimensions.qml index 0ab6893..ff30181 100644 --- a/config/Dimensions.qml +++ b/config/Dimensions.qml @@ -12,6 +12,7 @@ Singleton { property Mpris mpris: Mpris {} property Clock clock: Clock {} property Pipewire pipewire: Pipewire {} + property Network network: Network {} property Storage storage: Storage {} property Memory memory: Memory {} property Cpu cpu: Cpu {} @@ -52,6 +53,14 @@ Singleton { property int verticalPadding: 6 } + component Network: QtObject { + property int iconSize: 14 + property int fontSize: 14 + property int height: 30 + property int horizontalPadding: 8 + property int verticalPadding: 6 + } + component Storage: QtObject { property int iconSize: 14 property int fontSize: 14 @@ -74,9 +83,9 @@ Singleton { property int height: 30 property int horizontalPadding: 8 property int verticalPadding: 6 - } + } - component Gpu: QtObject { + component Gpu: QtObject { property int iconSize: 14 property int fontSize: 14 property int height: 30 diff --git a/constants/Icons.qml b/constants/Icons.qml index 9eebe1c..c58b16c 100644 --- a/constants/Icons.qml +++ b/constants/Icons.qml @@ -9,6 +9,10 @@ Singleton { property string gpu: "\u{E66f}" property string hardDrive: "\u{E0f1}" property string memoryStick: "\u{E44a}" + property string wifiOff: "\u{E1af}" + property string wifiLow: "\u{E5fd}" + property string wifiHigh: "\u{E5fc}" + property string wifi: "\u{E1ae}" property string triangle: "\u{E192}" property string triangleDashed: "\u{E642}" } diff --git a/modules/bar/Bar.qml b/modules/bar/Bar.qml index f16330a..f4ec4e0 100644 --- a/modules/bar/Bar.qml +++ b/modules/bar/Bar.qml @@ -104,6 +104,10 @@ Scope { anchors.verticalCenter: parent.verticalCenter } + Network { + anchors.verticalCenter: parent.verticalCenter + } + Storage { anchors.verticalCenter: parent.verticalCenter } @@ -114,9 +118,9 @@ Scope { Cpu { anchors.verticalCenter: parent.verticalCenter - } + } - Gpu { + Gpu { anchors.verticalCenter: parent.verticalCenter } diff --git a/modules/bar/components/Network.qml b/modules/bar/components/Network.qml new file mode 100644 index 0000000..d94a768 --- /dev/null +++ b/modules/bar/components/Network.qml @@ -0,0 +1,78 @@ +import QtQuick +import Quickshell +import "../../../config/" +import "../../../constants/" +import "../../../services/" +import "../../../styled/" +import "../../../utils/" + +StyledLabel { + id: root + + implicitWidth: row.width + implicitHeight: Dimensions.network.height + + Ref { + id: ref + service: NetworkService + } + + Row { + id: row + StyledText { + id: icon + + font.family: Theme.lucide.font.family + font.pixelSize: Dimensions.network.iconSize + font.bold: true + text: Icons.wifiOff + + anchors.verticalCenter: parent.verticalCenter + topPadding: Dimensions.network.verticalPadding + bottomPadding: Dimensions.network.verticalPadding + leftPadding: Dimensions.network.horizontalPadding + + states: [ + State { + name: "high" + when: NetworkService.active?.strength > 50 + PropertyChanges { + icon { + text: Icons.wifi + } + } + }, + State { + name: "medium" + when: NetworkService.active?.strength > 25 + PropertyChanges { + icon { + text: Icons.wifiHigh + } + } + }, + State { + name: "low" + when: NetworkService.active?.strength > 0 + PropertyChanges { + icon { + text: Icons.wifiLow + } + } + } + ] + } + + StyledText { + id: text + anchors.verticalCenter: parent.verticalCenter + topPadding: Dimensions.network.verticalPadding + bottomPadding: Dimensions.network.verticalPadding + rightPadding: Dimensions.network.horizontalPadding + + font.pixelSize: Dimensions.network.fontSize + + text: ` ${(NetworkService.active?.strength ?? 0).toFixed()}%` + } + } +}