feat(bar): add home latency indicator widget

This commit is contained in:
tux
2026-08-23 18:17:53 +05:30
parent 3b01362a5a
commit ab15dcf0ac
4 changed files with 64 additions and 1 deletions

1
assets/icons/home.svg Normal file
View File

@@ -0,0 +1 @@
<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path d="M12.0838 3.5C10.1049 3.5 8.40696 4.71031 7.69312 6.43399C7.53464 6.81668 7.09592 6.99844 6.71323 6.83995C6.33053 6.68146 6.14878 6.24275 6.30727 5.86005C7.24515 3.5954 9.47729 2 12.0838 2C14.6904 2 16.9225 3.5954 17.8604 5.86005C18.0189 6.24275 17.8371 6.68146 17.4544 6.83995C17.0717 6.99844 16.633 6.81668 16.4745 6.43399C15.7607 4.71032 14.0627 3.5 12.0838 3.5Z" fill="#000"></path> <path d="M12.0846 6C11.0622 6 10.1973 6.68244 9.92427 7.6182C9.80824 8.01583 9.39183 8.24411 8.9942 8.12808C8.59657 8.01205 8.36829 7.59564 8.48432 7.19801C8.93906 5.63969 10.3777 4.5 12.0846 4.5C13.7914 4.5 15.2301 5.63969 15.6848 7.19801C15.8008 7.59564 15.5725 8.01205 15.1749 8.12808C14.7773 8.24411 14.3609 8.01583 14.2448 7.6182C13.9718 6.68244 13.1069 6 12.0846 6Z" fill="#000"></path> <path d="M13.084 7.75C13.084 8.30228 12.6363 8.75 12.084 8.75C11.5317 8.75 11.084 8.30228 11.084 7.75C11.084 7.19772 11.5317 6.75 12.084 6.75C12.6363 6.75 13.084 7.19772 13.084 7.75Z" fill="#000"></path> <path fill-rule="evenodd" clip-rule="evenodd" d="M3.65131 4.37802C3.4458 4.01839 2.98766 3.89344 2.62802 4.09895C2.26839 4.30445 2.14344 4.76259 2.34895 5.12223L6.13624 11.75H6C4.11438 11.75 3.17157 11.75 2.58579 12.3358C2 12.9216 2 13.8644 2 15.75C2 17.6356 2 18.5784 2.58579 19.1642C3.17157 19.75 4.11438 19.75 6 19.75H18C19.8856 19.75 20.8284 19.75 21.4142 19.1642C22 18.5784 22 17.6356 22 15.75C22 13.8644 22 12.9216 21.4142 12.3358C20.8284 11.75 19.8856 11.75 18 11.75H17.8638L21.6511 5.12223C21.8566 4.76259 21.7316 4.30445 21.372 4.09895C21.0123 3.89344 20.5542 4.01839 20.3487 4.37802L16.3487 11.378L16.1287 11.75H7.88128L7.65131 11.378L3.65131 4.37802ZM6 16.75C6.55228 16.75 7 16.3023 7 15.75C7 15.1977 6.55228 14.75 6 14.75C5.44772 14.75 5 15.1977 5 15.75C5 16.3023 5.44772 16.75 6 16.75ZM10 15.75C10 16.3023 9.55228 16.75 9 16.75C8.44772 16.75 8 16.3023 8 15.75C8 15.1977 8.44772 14.75 9 14.75C9.55228 14.75 10 15.1977 10 15.75ZM14 15C13.5858 15 13.25 15.3358 13.25 15.75C13.25 16.1642 13.5858 16.5 14 16.5H18C18.4142 16.5 18.75 16.1642 18.75 15.75C18.75 15.3358 18.4142 15 18 15H14Z" fill="#000"></path> </g></svg>

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@@ -14,7 +14,7 @@ Singleton {
property var left: [ property var left: [
root.widget("LauncherButton"), root.widget("LauncherButton"),
root.widget("PowerProfileWidget"), root.widget("PowerProfileWidget"),
root.widget("BatteryIndicator"), root.widget("HomeWidget"),
] ]
property var center: [ property var center: [
@@ -24,6 +24,7 @@ Singleton {
] ]
property var right: [ property var right: [
root.widget("BatteryIndicator"),
root.widget("SystemTrayWidget"), root.widget("SystemTrayWidget"),
root.widget("ClockWidget"), root.widget("ClockWidget"),
root.widget("GhostButton") root.widget("GhostButton")

View File

@@ -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
}

50
services/Home.qml Normal file
View File

@@ -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;
}
}
}