Files
att_menu/modules/BluetoothDeviceEntry.qml
T
2026-07-26 21:16:55 +02:00

118 lines
3.3 KiB
QML

import QtQuick
import Quickshell.Bluetooth
import qs.config
import qs.components
// One known device in the bluetooth menu.
Rectangle {
id: root
required property BluetoothDevice device
property bool selected: false
signal activated
signal entered
readonly property bool busy: root.device.state === BluetoothDeviceState.Connecting || root.device.state === BluetoothDeviceState.Disconnecting || root.device.pairing
readonly property string status: {
if (root.device.pairing)
return "Pairing…";
switch (root.device.state) {
case BluetoothDeviceState.Connecting:
return "Connecting…";
case BluetoothDeviceState.Disconnecting:
return "Disconnecting…";
case BluetoothDeviceState.Connected:
return "Connected";
default:
return root.device.blocked ? "Blocked" : "Not connected";
}
}
implicitHeight: 40
radius: Theme.radius
color: root.selected ? Theme.surfaceActive : "transparent"
Behavior on color {
ColorAnimation {
duration: Theme.animDuration
easing.type: Theme.animEasing
}
}
AppIcon {
id: icon
anchors {
left: parent.left
leftMargin: Theme.padding
verticalCenter: parent.verticalCenter
}
// BlueZ reports a freedesktop icon name for the device class
// ("audio-headset", "input-mouse", …); the lettered tile covers the
// classes a theme happens to be missing.
icon: root.device.icon
fallbackLabel: root.device.name
size: 24
opacity: root.device.connected ? 1 : 0.65
}
Column {
anchors {
left: icon.right
right: battery.left
leftMargin: Theme.padding * 2
rightMargin: Theme.padding
verticalCenter: parent.verticalCenter
}
spacing: 1
Text {
width: parent.width
elide: Text.ElideRight
text: root.device.name || root.device.deviceName || root.device.address
color: Theme.text
font.family: Theme.fontFamily
font.pixelSize: Theme.fontSize
}
Text {
width: parent.width
elide: Text.ElideRight
text: root.status
color: root.device.connected ? Theme.accent : Theme.textDim
font.family: Theme.fontFamily
font.pixelSize: Theme.fontSizeSmall
}
}
// Battery is only published by devices that report it, and only while they
// are connected.
Text {
id: battery
anchors {
right: parent.right
rightMargin: Theme.padding * 2
verticalCenter: parent.verticalCenter
}
visible: root.device.batteryAvailable
width: visible ? implicitWidth : 0
text: Math.round(root.device.battery * 100) + "%"
color: root.device.battery <= 0.2 ? Theme.danger : Theme.textDim
font.family: Theme.fontFamily
font.pixelSize: Theme.fontSizeSmall
font.bold: true
}
MouseArea {
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: root.activated()
onEntered: root.entered()
}
}