68 lines
2.2 KiB
QML
68 lines
2.2 KiB
QML
import QtQuick
|
|
import Quickshell.Bluetooth
|
|
import qs.config
|
|
import qs.components
|
|
import qs.services
|
|
|
|
// Right section: the bluetooth button. The device list lives in
|
|
// BluetoothPanel.qml as a separate layer surface.
|
|
Item {
|
|
id: root
|
|
|
|
required property var bar
|
|
|
|
readonly property BluetoothAdapter adapter: Bluetooth.defaultAdapter
|
|
readonly property bool adapterOn: root.adapter ? root.adapter.enabled : false
|
|
|
|
readonly property var connected: root.adapter ? root.adapter.devices.values.filter(d => d.connected) : []
|
|
|
|
// The first connected device that reports a battery. With a headset paired
|
|
// that is the one number worth carrying on the panel; the rest are a click
|
|
// away.
|
|
readonly property var batteryDevice: root.connected.find(d => d.batteryAvailable) ?? null
|
|
|
|
// Machines without a bluetooth radio get no button at all.
|
|
visible: Config.showBluetooth && root.adapter !== null
|
|
|
|
implicitWidth: button.implicitWidth
|
|
|
|
PanelButton {
|
|
id: button
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
height: root.height - Theme.spacing
|
|
minContentWidth: Theme.iconSize
|
|
active: panel.visible
|
|
activeColor: Theme.accent
|
|
|
|
onClicked: Session.toggle("bluetooth", panel.screenName)
|
|
|
|
Row {
|
|
spacing: Theme.spacing
|
|
|
|
BluetoothGlyph {
|
|
size: Theme.iconSize
|
|
struck: !root.adapterOn
|
|
color: button.active ? Theme.background : !root.adapterOn ? Theme.textDim : root.connected.length > 0 ? Theme.accent : Theme.text
|
|
}
|
|
|
|
Text {
|
|
height: Theme.iconSize
|
|
verticalAlignment: Text.AlignVCenter
|
|
visible: root.batteryDevice !== null
|
|
text: root.batteryDevice ? Math.round(root.batteryDevice.battery * 100) + "%" : ""
|
|
color: button.active ? Theme.background : root.batteryDevice && root.batteryDevice.battery <= 0.2 ? Theme.danger : Theme.textDim
|
|
font.family: Theme.fontFamily
|
|
font.pixelSize: Theme.fontSizeSmall
|
|
font.bold: true
|
|
}
|
|
}
|
|
}
|
|
|
|
BluetoothPanel {
|
|
id: panel
|
|
|
|
bar: root.bar
|
|
}
|
|
}
|