2026-02-06 13:56:41 +01:00
|
|
|
pragma ComponentBehavior: Bound
|
|
|
|
|
import Quickshell.Networking
|
|
|
|
|
import QtQuick
|
|
|
|
|
import QtQuick.Layouts
|
|
|
|
|
import qs.reusables
|
|
|
|
|
import qs.settings
|
|
|
|
|
import qs
|
|
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
|
id: root
|
|
|
|
|
// This is the background of the entire bar/module
|
|
|
|
|
// You might want to make this transparent if you only want the "pills" to show
|
|
|
|
|
implicitHeight: Settings.config.barHeight - 10
|
2026-02-06 14:29:25 +01:00
|
|
|
implicitWidth: mainLayout.implicitWidth + 20
|
|
|
|
|
color: Colors.surfaceContainer
|
|
|
|
|
radius: implicitHeight / 2
|
2026-02-06 13:56:41 +01:00
|
|
|
|
|
|
|
|
// --- Logic Functions ---
|
|
|
|
|
function getIcon(device) {
|
|
|
|
|
if (device.type === DeviceType.Wifi) {
|
|
|
|
|
for (var i = 0; i < device.networks.values.length; i++) {
|
|
|
|
|
var net = device.networks.values[i];
|
|
|
|
|
if (net.connected) {
|
|
|
|
|
if (net.signalStrength <= 0.20)
|
2026-02-09 20:12:22 +01:00
|
|
|
return "\uf0b0";
|
|
|
|
|
//signa_wifi_0_bar
|
2026-02-06 13:56:41 +01:00
|
|
|
if (net.signalStrength <= 0.40)
|
2026-02-09 20:12:22 +01:00
|
|
|
return "\uebe4";
|
|
|
|
|
//network_wifi_1_bar
|
2026-02-06 13:56:41 +01:00
|
|
|
if (net.signalStrength <= 0.60)
|
2026-02-09 20:12:22 +01:00
|
|
|
return "\uebd6";
|
|
|
|
|
//network_wifi_2_bar
|
2026-02-06 13:56:41 +01:00
|
|
|
if (net.signalStrength <= 0.80)
|
2026-02-09 20:12:22 +01:00
|
|
|
return "\uebe1";
|
|
|
|
|
//network_wifi_3_bar
|
|
|
|
|
if (net.signalStrength >= 0.80)
|
|
|
|
|
return "\ue1d8";
|
|
|
|
|
// signal_wifi_4_bar
|
2026-02-06 13:56:41 +01:00
|
|
|
}
|
|
|
|
|
}
|
2026-02-09 20:47:15 +01:00
|
|
|
return "\ue1d8";
|
2026-02-06 13:56:41 +01:00
|
|
|
} else if (device.connected) {
|
|
|
|
|
return "settings_ethernet";
|
|
|
|
|
}
|
2026-02-09 20:47:15 +01:00
|
|
|
return "\ue1da";
|
|
|
|
|
// signal_wifi_off
|
2026-02-06 13:56:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getStatus(device) {
|
|
|
|
|
if (device.type === DeviceType.Wifi) {
|
|
|
|
|
for (var i = 0; i < device.networks.values.length; i++) {
|
|
|
|
|
var net = device.networks.values[i];
|
|
|
|
|
if (net.connected) {
|
|
|
|
|
return net.name;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return "Disconnected";
|
|
|
|
|
}
|
|
|
|
|
return device.connected ? "Connected" : "Disconnected";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- Main Layout ---
|
|
|
|
|
RowLayout {
|
|
|
|
|
id: mainLayout
|
2026-02-06 14:29:25 +01:00
|
|
|
anchors.centerIn: parent
|
2026-02-06 13:56:41 +01:00
|
|
|
spacing: 10 // Space between multiple device pills (if you have ethernet + wifi)
|
|
|
|
|
|
|
|
|
|
Repeater {
|
|
|
|
|
id: netRepeater
|
|
|
|
|
model: Networking.devices
|
|
|
|
|
|
2026-02-06 14:29:25 +01:00
|
|
|
delegate: RowLayout {
|
|
|
|
|
id: innerContent
|
|
|
|
|
required property var modelData
|
|
|
|
|
// THIS fixes the centering issue:
|
|
|
|
|
spacing: 8
|
2026-02-06 13:56:41 +01:00
|
|
|
|
2026-02-06 14:29:25 +01:00
|
|
|
CustomIcon {
|
|
|
|
|
id: netIcon
|
|
|
|
|
Layout.alignment: Qt.AlignVCenter
|
|
|
|
|
text: root.getIcon(innerContent.modelData)
|
|
|
|
|
}
|
2026-02-06 13:56:41 +01:00
|
|
|
|
2026-02-06 14:29:25 +01:00
|
|
|
CustomText {
|
|
|
|
|
id: netText
|
|
|
|
|
Layout.topMargin: 1
|
|
|
|
|
Layout.alignment: Qt.AlignVCenter
|
|
|
|
|
text: root.getStatus(innerContent.modelData)
|
|
|
|
|
// Ensures the text font aligns vertically within its own line-height
|
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
2026-02-06 13:56:41 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|