add Bluetooth to quickshell bar
This commit is contained in:
63
roles/quickshell/files/bar/BluetoothControl.qml
Normal file
63
roles/quickshell/files/bar/BluetoothControl.qml
Normal file
@ -0,0 +1,63 @@
|
||||
import Quickshell.Bluetooth
|
||||
import QtQuick
|
||||
import "../components"
|
||||
|
||||
Item {
|
||||
id: root
|
||||
implicitWidth: chip.implicitWidth + 10
|
||||
implicitHeight: 24
|
||||
|
||||
signal clickedLeft
|
||||
|
||||
readonly property var adapter: Bluetooth.defaultAdapter
|
||||
readonly property bool powered: adapter?.enabled ?? false
|
||||
readonly property var connectedDevices:
|
||||
Bluetooth.devices.values.filter(d => d.connected)
|
||||
|
||||
// \uf293 = FA bluetooth-b (on), \uf294 = FA bluetooth (off / no connection)
|
||||
readonly property string btIcon: root.powered ? "\uf293" : "\uf294"
|
||||
|
||||
function label() {
|
||||
const n = root.connectedDevices.length
|
||||
if (n === 0) return ""
|
||||
if (n === 1) {
|
||||
const name = root.connectedDevices[0].name || ""
|
||||
return name.length > 16 ? name.substring(0, 15) + "…" : name
|
||||
}
|
||||
return n + " devices"
|
||||
}
|
||||
|
||||
Row {
|
||||
id: chip
|
||||
anchors.centerIn: parent
|
||||
spacing: 5
|
||||
|
||||
Text {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
text: root.btIcon
|
||||
font.family: "JetBrainsMono Nerd Font Mono"
|
||||
font.pixelSize: 14
|
||||
color: (root.powered && root.connectedDevices.length > 0) ? Theme.text : Theme.textDim
|
||||
}
|
||||
Text {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
text: root.label()
|
||||
font.pixelSize: 11
|
||||
color: Theme.textDim
|
||||
visible: text !== ""
|
||||
}
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: mouse => {
|
||||
if (mouse.button === Qt.RightButton) {
|
||||
if (root.adapter) root.adapter.enabled = !root.adapter.enabled
|
||||
} else {
|
||||
root.clickedLeft()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user