From ab15dcf0acbbf2c993947000f4eb2256508752d0 Mon Sep 17 00:00:00 2001 From: tux Date: Sun, 23 Aug 2026 18:17:53 +0530 Subject: [PATCH] feat(bar): add home latency indicator widget --- assets/icons/home.svg | 1 + config/BarLayout.qml | 3 ++- modules/bar/HomeWidget.qml | 11 +++++++++ services/Home.qml | 50 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 assets/icons/home.svg create mode 100644 modules/bar/HomeWidget.qml create mode 100644 services/Home.qml diff --git a/assets/icons/home.svg b/assets/icons/home.svg new file mode 100644 index 0000000..f9a1252 --- /dev/null +++ b/assets/icons/home.svg @@ -0,0 +1 @@ + diff --git a/config/BarLayout.qml b/config/BarLayout.qml index 20fd5fb..51888d3 100644 --- a/config/BarLayout.qml +++ b/config/BarLayout.qml @@ -14,7 +14,7 @@ Singleton { property var left: [ root.widget("LauncherButton"), root.widget("PowerProfileWidget"), - root.widget("BatteryIndicator"), + root.widget("HomeWidget"), ] property var center: [ @@ -24,6 +24,7 @@ Singleton { ] property var right: [ + root.widget("BatteryIndicator"), root.widget("SystemTrayWidget"), root.widget("ClockWidget"), root.widget("GhostButton") diff --git a/modules/bar/HomeWidget.qml b/modules/bar/HomeWidget.qml new file mode 100644 index 0000000..560ab89 --- /dev/null +++ b/modules/bar/HomeWidget.qml @@ -0,0 +1,11 @@ +pragma ComponentBehavior: Bound + +import qs.ui +import qs.services + +BarButton { + hoverHighlight: false + pointerCursor: false + label: Home.latency >= 0 ? `${Home.latency} ms` : "NA" + iconSource: Home.icon +} diff --git a/services/Home.qml b/services/Home.qml new file mode 100644 index 0000000..f9d652d --- /dev/null +++ b/services/Home.qml @@ -0,0 +1,50 @@ +pragma Singleton + +import QtQuick +import Quickshell +import Quickshell.Io + +Singleton { + id: root + + property string host: "100.64.0.3" + property int interval: 5000 + + // Round-trip time in ms; -1 means unknown/unreachable. + property int latency: -1 + property bool replied: false + + readonly property url icon: `${Quickshell.shellPath("assets")}/icons/home.svg` + + function ping(): void { + proc.command = ["ping", "-c", "1", "-W", "2", root.host]; + root.replied = false; + proc.running = true; + } + + Timer { + interval: root.interval + running: true + repeat: true + triggeredOnStart: true + onTriggered: root.ping() + } + + Process { + id: proc + + stdout: SplitParser { + onRead: line => { + const match = line.match(/time[=<]([\d.]+)\s*ms/); + if (match) { + root.latency = Math.round(parseFloat(match[1])); + root.replied = true; + } + } + } + onExited: { + if (!root.replied) + root.latency = -1; + } + } +}