Merge pull request #535 from luleyleo/bluetooth-pill

Display name of connected Bluetooth device in bar pill
This commit is contained in:
Lemmy
2025-10-20 19:46:49 -04:00
committed by GitHub
5 changed files with 102 additions and 17 deletions
+51 -17
View File
@@ -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")
}
}
@@ -122,6 +122,7 @@ Popup {
const widgetSettingsMap = {
"ActiveWindow": "WidgetSettings/ActiveWindowSettings.qml",
"Battery": "WidgetSettings/BatterySettings.qml",
"Bluetooth": "WidgetSettings/BluetoothSettings.qml",
"Brightness": "WidgetSettings/BrightnessSettings.qml",
"Clock": "WidgetSettings/ClockSettings.qml",
"ControlCenter": "WidgetSettings/ControlCenterSettings.qml",
@@ -0,0 +1,40 @@
import QtQuick
import QtQuick.Layouts
import qs.Commons
import qs.Widgets
ColumnLayout {
id: root
spacing: Style.marginM
// Properties to receive data from parent
property var widgetData: null
property var widgetMetadata: null
// Local state
property string valueDisplayMode: widgetData.displayMode !== undefined ? widgetData.displayMode : widgetMetadata.displayMode
function saveSettings() {
var settings = Object.assign({}, widgetData || {})
settings.displayMode = valueDisplayMode
return settings
}
NComboBox {
label: I18n.tr("bar.widget-settings.battery.display-mode.label")
description: I18n.tr("bar.widget-settings.battery.display-mode.description")
minimumWidth: 134
model: [{
"key": "onhover",
"name": I18n.tr("options.display-mode.on-hover")
}, {
"key": "alwaysShow",
"name": I18n.tr("options.display-mode.always-show")
}, {
"key": "alwaysHide",
"name": I18n.tr("options.display-mode.always-hide")
}]
currentKey: root.valueDisplayMode
onSelected: key => root.valueDisplayMode = key
}
}
+4
View File
@@ -53,6 +53,10 @@ Singleton {
"displayMode": "onhover",
"warningThreshold": 30
},
"Bluetooth": {
"allowUserSettings": true,
"displayMode": "onhover"
},
"Brightness": {
"allowUserSettings": true,
"displayMode": "onhover"
+6
View File
@@ -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) {