From edcc78483cb0d6df64d8701ef462c7126e6559b7 Mon Sep 17 00:00:00 2001 From: Damocles Date: Tue, 14 Apr 2026 00:58:24 +0200 Subject: [PATCH] network/bluetooth menus: add radio toggle header, fix contentWidth --- modules/BluetoothMenu.qml | 94 +++++++++++++++++++++++++++++++++---- modules/NetworkMenu.qml | 98 +++++++++++++++++++++++++++++++++------ 2 files changed, 170 insertions(+), 22 deletions(-) diff --git a/modules/BluetoothMenu.qml b/modules/BluetoothMenu.qml index 0c2cfdb..1eb9d5f 100644 --- a/modules/BluetoothMenu.qml +++ b/modules/BluetoothMenu.qml @@ -10,15 +10,19 @@ M.HoverPanel { contentWidth: 250 property var _devices: [] + property bool _btEnabled: true property Process _scanner: Process { id: scanner running: true - command: ["sh", "-c", "bluetoothctl devices Paired 2>/dev/null | while read -r _ mac name; do " + "info=$(bluetoothctl info \"$mac\" 2>/dev/null); " + "conn=$(echo \"$info\" | grep -c 'Connected: yes'); " + "bat=$(echo \"$info\" | awk -F'[(): ]' '/Battery Percentage/{for(i=1;i<=NF;i++) if($i+0==$i && $i!=\"\") print $i}'); " + "echo \"$mac:$conn:${bat:-}:$name\"; " + "done"] + command: ["sh", "-c", "bluetoothctl show 2>/dev/null | awk '/Powered:/{print $2; exit}';" + "echo '---DEVICES---';" + "bluetoothctl devices Paired 2>/dev/null | while read -r _ mac name; do " + "info=$(bluetoothctl info \"$mac\" 2>/dev/null); " + "conn=$(echo \"$info\" | grep -c 'Connected: yes'); " + "bat=$(echo \"$info\" | awk -F'[(): ]' '/Battery Percentage/{for(i=1;i<=NF;i++) if($i+0==$i && $i!=\"\") print $i}'); " + "echo \"$mac:$conn:${bat:-}:$name\"; " + "done"] stdout: StdioCollector { onStreamFinished: { + const sections = text.split("---DEVICES---"); + menuWindow._btEnabled = (sections[0] || "").trim() === "yes"; + const devs = []; - for (const line of text.trim().split("\n")) { + for (const line of (sections[1] || "").trim().split("\n")) { if (!line) continue; const i1 = line.indexOf(":"); @@ -27,10 +31,10 @@ M.HoverPanel { if (i3 < 0) continue; devs.push({ - mac: line.slice(0, i1), - connected: line.slice(i1 + 1, i2) === "1", - battery: parseInt(line.slice(i2 + 1, i3)) || -1, - name: line.slice(i3 + 1) + "mac": line.slice(0, i1), + "connected": line.slice(i1 + 1, i2) === "1", + "battery": parseInt(line.slice(i2 + 1, i3)) || -1, + "name": line.slice(i3 + 1) }); } devs.sort((a, b) => { @@ -43,6 +47,14 @@ M.HoverPanel { } } + property Process _powerProc: Process { + id: powerProc + property string _action: "" + command: ["bluetoothctl", "power", _action] + onRunningChanged: if (!running) + scanner.running = true + } + property Process _toggleProc: Process { id: toggleProc property string action: "" @@ -52,6 +64,70 @@ M.HoverPanel { scanner.running = true } + // Bluetooth radio toggle header + Item { + width: menuWindow.contentWidth + height: 36 + + Rectangle { + anchors.fill: parent + anchors.leftMargin: 4 + anchors.rightMargin: 4 + color: btHeaderArea.containsMouse ? M.Theme.base02 : "transparent" + radius: M.Theme.radius + } + + Text { + id: btHeaderIcon + anchors.left: parent.left + anchors.leftMargin: 12 + anchors.verticalCenter: parent.verticalCenter + text: "\uF294" + color: menuWindow._btEnabled ? menuWindow.accentColor : M.Theme.base04 + font.pixelSize: M.Theme.fontSize + 1 + font.family: M.Theme.iconFontFamily + } + + Text { + anchors.left: btHeaderIcon.right + anchors.leftMargin: 8 + anchors.verticalCenter: parent.verticalCenter + text: "Bluetooth" + color: menuWindow._btEnabled ? M.Theme.base05 : M.Theme.base04 + font.pixelSize: M.Theme.fontSize + font.family: M.Theme.fontFamily + font.bold: true + } + + Text { + anchors.right: parent.right + anchors.rightMargin: 12 + anchors.verticalCenter: parent.verticalCenter + text: "\uF011" + color: menuWindow._btEnabled ? menuWindow.accentColor : M.Theme.base04 + font.pixelSize: M.Theme.fontSize + font.family: M.Theme.iconFontFamily + } + + MouseArea { + id: btHeaderArea + anchors.fill: parent + hoverEnabled: true + cursorShape: Qt.PointingHandCursor + onClicked: { + powerProc._action = menuWindow._btEnabled ? "off" : "on"; + powerProc.running = true; + } + } + } + + Rectangle { + width: menuWindow.contentWidth - 16 + height: 1 + anchors.horizontalCenter: parent.horizontalCenter + color: M.Theme.base03 + } + Repeater { model: menuWindow._devices @@ -60,7 +136,7 @@ M.HoverPanel { required property var modelData required property int index - width: menuWindow.panelWidth + width: menuWindow.contentWidth height: 32 Rectangle { @@ -125,11 +201,11 @@ M.HoverPanel { Text { visible: menuWindow._devices.length === 0 - width: menuWindow.panelWidth + width: menuWindow.contentWidth height: 32 horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter - text: "No paired devices" + text: menuWindow._btEnabled ? "No paired devices" : "Bluetooth is off" color: M.Theme.base04 font.pixelSize: M.Theme.fontSize font.family: M.Theme.fontFamily diff --git a/modules/NetworkMenu.qml b/modules/NetworkMenu.qml index 4f8e128..a2798d8 100644 --- a/modules/NetworkMenu.qml +++ b/modules/NetworkMenu.qml @@ -10,18 +10,21 @@ M.HoverPanel { contentWidth: 250 property var _networks: [] + property bool _wifiEnabled: true property Process _scanner: Process { id: scanner running: true - command: ["sh", "-c", "echo '---CONNS---';" + "nmcli -t -f NAME,UUID,TYPE,ACTIVE connection show 2>/dev/null;" + "echo '---WIFI---';" + "nmcli -t -f SSID,SIGNAL device wifi list --rescan no 2>/dev/null"] + command: ["sh", "-c", "echo '---RADIO---';" + "nmcli radio wifi 2>/dev/null;" + "echo '---CONNS---';" + "nmcli -t -f NAME,UUID,TYPE,ACTIVE connection show 2>/dev/null;" + "echo '---WIFI---';" + "nmcli -t -f SSID,SIGNAL device wifi list --rescan no 2>/dev/null"] stdout: StdioCollector { onStreamFinished: { + const radioSection = text.split("---CONNS---")[0].split("---RADIO---")[1] || ""; + menuWindow._wifiEnabled = radioSection.trim() === "enabled"; + const sections = text.split("---WIFI---"); const connLines = (sections[0] || "").split("---CONNS---")[1] || ""; const wifiLines = sections[1] || ""; - // Visible SSIDs with signal const visible = {}; for (const l of wifiLines.trim().split("\n")) { if (!l) @@ -32,7 +35,6 @@ M.HoverPanel { visible[ssid] = parseInt(parts[1]) || 0; } - // Saved connections — filter: show wired always, wifi only if visible const nets = []; for (const l of connLines.trim().split("\n")) { if (!l) @@ -48,15 +50,14 @@ M.HoverPanel { continue; nets.push({ - name: name, - uuid: uuid, - isWifi: isWifi, - active: active, - signal: isWifi ? (visible[name] || 0) : -1 + "name": name, + "uuid": uuid, + "isWifi": isWifi, + "active": active, + "signal": isWifi ? (visible[name] || 0) : -1 }); } - // Active first, then by signal (wifi) or name nets.sort((a, b) => { if (a.active !== b.active) return a.active ? -1 : 1; @@ -70,6 +71,14 @@ M.HoverPanel { } } + property Process _radioProc: Process { + id: radioProc + property string _state: "" + command: ["nmcli", "radio", "wifi", _state] + onRunningChanged: if (!running) + scanner.running = true + } + property Process _connectProc: Process { id: connectProc property string uuid: "" @@ -86,6 +95,70 @@ M.HoverPanel { scanner.running = true } + // Wi-Fi radio toggle header + Item { + width: menuWindow.contentWidth + height: 36 + + Rectangle { + anchors.fill: parent + anchors.leftMargin: 4 + anchors.rightMargin: 4 + color: headerArea.containsMouse ? M.Theme.base02 : "transparent" + radius: M.Theme.radius + } + + Text { + id: wifiHeaderIcon + anchors.left: parent.left + anchors.leftMargin: 12 + anchors.verticalCenter: parent.verticalCenter + text: "\uF1EB" + color: menuWindow._wifiEnabled ? menuWindow.accentColor : M.Theme.base04 + font.pixelSize: M.Theme.fontSize + 1 + font.family: M.Theme.iconFontFamily + } + + Text { + anchors.left: wifiHeaderIcon.right + anchors.leftMargin: 8 + anchors.verticalCenter: parent.verticalCenter + text: "Wi-Fi" + color: menuWindow._wifiEnabled ? M.Theme.base05 : M.Theme.base04 + font.pixelSize: M.Theme.fontSize + font.family: M.Theme.fontFamily + font.bold: true + } + + Text { + anchors.right: parent.right + anchors.rightMargin: 12 + anchors.verticalCenter: parent.verticalCenter + text: "\uF011" + color: menuWindow._wifiEnabled ? menuWindow.accentColor : M.Theme.base04 + font.pixelSize: M.Theme.fontSize + font.family: M.Theme.iconFontFamily + } + + MouseArea { + id: headerArea + anchors.fill: parent + hoverEnabled: true + cursorShape: Qt.PointingHandCursor + onClicked: { + radioProc._state = menuWindow._wifiEnabled ? "off" : "on"; + radioProc.running = true; + } + } + } + + Rectangle { + width: menuWindow.contentWidth - 16 + height: 1 + anchors.horizontalCenter: parent.horizontalCenter + color: M.Theme.base03 + } + Repeater { model: menuWindow._networks @@ -94,7 +167,7 @@ M.HoverPanel { required property var modelData required property int index - width: menuWindow.panelWidth + width: menuWindow.contentWidth height: 32 Rectangle { @@ -161,14 +234,13 @@ M.HoverPanel { } } - // Empty state Text { visible: menuWindow._networks.length === 0 - width: menuWindow.panelWidth + width: menuWindow.contentWidth height: 32 horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter - text: "No networks available" + text: menuWindow._wifiEnabled ? "No networks available" : "Wi-Fi is off" color: M.Theme.base04 font.pixelSize: M.Theme.fontSize font.family: M.Theme.fontFamily