diff --git a/Modules/Bar/Widgets/Bluetooth.qml b/Modules/Bar/Widgets/Bluetooth.qml index e6f50f0f..e58d5e43 100644 --- a/Modules/Bar/Widgets/Bluetooth.qml +++ b/Modules/Bar/Widgets/Bluetooth.qml @@ -1,27 +1,61 @@ import QtQuick -import QtQuick.Layouts -import QtQuick.Controls import Quickshell -import Quickshell.Wayland import qs.Commons import qs.Services -import qs.Widgets +import qs.Modules.Bar.Extras -NIconButton { +Item { id: root property ShellScreen screen - baseSize: Style.capsuleHeight - applyUiScale: false - density: Settings.data.bar.density - colorBg: Settings.data.bar.showCapsule ? Color.mSurfaceVariant : Color.transparent - colorFg: Color.mOnSurface - colorBorder: Color.transparent - colorBorderHover: Color.transparent - tooltipText: I18n.tr("tooltips.bluetooth-devices") - tooltipDirection: BarService.getTooltipDirection() - icon: BluetoothService.enabled ? "bluetooth" : "bluetooth-off" - onClicked: PanelService.getPanel("bluetoothPanel")?.toggle(this) - onRightClicked: PanelService.getPanel("bluetoothPanel")?.toggle(this) + // Widget properties passed from Bar.qml for per-instance settings + property string widgetId: "" + property string section: "" + property int sectionWidgetIndex: -1 + property int sectionWidgetsCount: 0 + + property var widgetMetadata: BarWidgetRegistry.widgetMetadata[widgetId] + property var widgetSettings: { + if (section && sectionWidgetIndex >= 0) { + var widgets = Settings.data.bar.widgets[section] + if (widgets && sectionWidgetIndex < widgets.length) { + return widgets[sectionWidgetIndex] + } + } + return {} + } + + readonly property bool isBarVertical: Settings.data.bar.position === "left" || Settings.data.bar.position === "right" + readonly property string displayMode: widgetSettings.displayMode !== undefined ? widgetSettings.displayMode : widgetMetadata.displayMode + + implicitWidth: pill.width + implicitHeight: pill.height + + BarPill { + id: pill + + density: Settings.data.bar.density + rightOpen: BarService.getPillDirection(root) + icon: BluetoothService.enabled ? "bluetooth" : "bluetooth-off" + text: { + if (BluetoothService.connectedDevices && BluetoothService.connectedDevices.length > 0) { + const firstDevice = BluetoothService.connectedDevices[0] + return firstDevice.name || firstDevice.deviceName + } + return "" + } + suffix: { + if (BluetoothService.connectedDevices && BluetoothService.connectedDevices.length > 1) { + return ` + ${BluetoothService.connectedDevices.length - 1}` + } + return "" + } + autoHide: false + forceOpen: root.displayMode === "alwaysShow" + forceClose: root.displayMode === "alwaysHide" || BluetoothService.connectedDevices.length === 0 + onClicked: PanelService.getPanel("bluetoothPanel")?.toggle(this) + onRightClicked: PanelService.getPanel("bluetoothPanel")?.toggle(this) + tooltipText: I18n.tr("tooltips.bluetooth-devices") + } } diff --git a/Services/BluetoothService.qml b/Services/BluetoothService.qml index d6c56e79..f6a42743 100644 --- a/Services/BluetoothService.qml +++ b/Services/BluetoothService.qml @@ -21,6 +21,12 @@ Singleton { return dev && (dev.paired || dev.trusted) }) } + readonly property var connectedDevices: { + if (!adapter || !adapter.devices) { + return [] + } + return adapter.devices.values.filter(dev => dev && dev.connected) + } readonly property var allDevicesWithBattery: { if (!adapter || !adapter.devices) {