forked from Shinonome/dots-hyprland
bluetooth: use quickshell's service
This commit is contained in:
@@ -2,6 +2,7 @@ import "./weather"
|
|||||||
import QtQuick
|
import QtQuick
|
||||||
import QtQuick.Layouts
|
import QtQuick.Layouts
|
||||||
import Quickshell
|
import Quickshell
|
||||||
|
import Quickshell.Bluetooth
|
||||||
import Quickshell.Services.UPower
|
import Quickshell.Services.UPower
|
||||||
import qs
|
import qs
|
||||||
import qs.services
|
import qs.services
|
||||||
@@ -306,7 +307,10 @@ Item { // Bar content region
|
|||||||
color: rightSidebarButton.colText
|
color: rightSidebarButton.colText
|
||||||
}
|
}
|
||||||
MaterialSymbol {
|
MaterialSymbol {
|
||||||
text: Bluetooth.bluetoothConnected ? "bluetooth_connected" : Bluetooth.bluetoothEnabled ? "bluetooth" : "bluetooth_disabled"
|
readonly property bool bluetoothEnabled: Bluetooth.defaultAdapter.enabled
|
||||||
|
readonly property BluetoothDevice bluetoothDevice: Bluetooth.defaultAdapter.devices.values.find(device => device.connected)
|
||||||
|
readonly property bool bluetoothConnected: bluetoothDevice !== undefined
|
||||||
|
text: bluetoothConnected ? "bluetooth_connected" : bluetoothEnabled ? "bluetooth" : "bluetooth_disabled"
|
||||||
iconSize: Appearance.font.pixelSize.larger
|
iconSize: Appearance.font.pixelSize.larger
|
||||||
color: rightSidebarButton.colText
|
color: rightSidebarButton.colText
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,36 +1,30 @@
|
|||||||
import qs
|
import qs
|
||||||
import qs.services
|
|
||||||
import qs.modules.common
|
import qs.modules.common
|
||||||
import qs.modules.common.widgets
|
import qs.modules.common.widgets
|
||||||
import qs.modules.common.functions
|
import qs.modules.common.functions
|
||||||
import QtQuick
|
import QtQuick
|
||||||
import Quickshell
|
import Quickshell
|
||||||
|
import Quickshell.Bluetooth
|
||||||
import Quickshell.Io
|
import Quickshell.Io
|
||||||
import Quickshell.Hyprland
|
import Quickshell.Hyprland
|
||||||
|
|
||||||
QuickToggleButton {
|
QuickToggleButton {
|
||||||
toggled: Bluetooth.bluetoothEnabled
|
id: root
|
||||||
buttonIcon: Bluetooth.bluetoothConnected ? "bluetooth_connected" : Bluetooth.bluetoothEnabled ? "bluetooth" : "bluetooth_disabled"
|
readonly property bool bluetoothEnabled: Bluetooth.defaultAdapter.enabled
|
||||||
|
readonly property BluetoothDevice bluetoothDevice: Bluetooth.defaultAdapter.devices.values.find(device => device.connected)
|
||||||
|
readonly property bool bluetoothConnected: bluetoothDevice !== undefined
|
||||||
|
toggled: bluetoothEnabled
|
||||||
|
buttonIcon: bluetoothConnected ? "bluetooth_connected" : bluetoothEnabled ? "bluetooth" : "bluetooth_disabled"
|
||||||
onClicked: {
|
onClicked: {
|
||||||
toggleBluetooth.running = true
|
Bluetooth.defaultAdapter.enabled = !Bluetooth.defaultAdapter.enabled
|
||||||
}
|
}
|
||||||
altAction: () => {
|
altAction: () => {
|
||||||
Quickshell.execDetached(["bash", "-c", `${Config.options.apps.bluetooth}`])
|
Quickshell.execDetached(["bash", "-c", `${Config.options.apps.bluetooth}`])
|
||||||
GlobalStates.sidebarRightOpen = false
|
GlobalStates.sidebarRightOpen = false
|
||||||
}
|
}
|
||||||
Process {
|
|
||||||
id: toggleBluetooth
|
|
||||||
command: ["bash", "-c", `bluetoothctl power ${Bluetooth.bluetoothEnabled ? "off" : "on"}`]
|
|
||||||
onRunningChanged: {
|
|
||||||
if(!running) {
|
|
||||||
Bluetooth.update()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
StyledToolTip {
|
StyledToolTip {
|
||||||
content: Translation.tr("%1 | Right-click to configure").arg(
|
content: Translation.tr("%1 | Right-click to configure").arg(
|
||||||
(Bluetooth.bluetoothEnabled && Bluetooth.bluetoothDeviceName.length > 0) ?
|
(bluetoothDevice?.name.length > 0) ?
|
||||||
Bluetooth.bluetoothDeviceName : Translation.tr("Bluetooth"))
|
bluetoothDevice.name : Translation.tr("Bluetooth"))
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import QtQuick
|
import QtQuick
|
||||||
import QtQuick.Layouts
|
import QtQuick.Layouts
|
||||||
import Quickshell
|
import Quickshell
|
||||||
|
import Quickshell.Bluetooth
|
||||||
import Quickshell.Services.UPower
|
import Quickshell.Services.UPower
|
||||||
import qs
|
import qs
|
||||||
import qs.services
|
import qs.services
|
||||||
@@ -284,7 +285,10 @@ Item { // Bar content region
|
|||||||
color: rightSidebarButton.colText
|
color: rightSidebarButton.colText
|
||||||
}
|
}
|
||||||
MaterialSymbol {
|
MaterialSymbol {
|
||||||
text: Bluetooth.bluetoothConnected ? "bluetooth_connected" : Bluetooth.bluetoothEnabled ? "bluetooth" : "bluetooth_disabled"
|
readonly property bool bluetoothEnabled: Bluetooth.defaultAdapter.enabled
|
||||||
|
readonly property BluetoothDevice bluetoothDevice: Bluetooth.defaultAdapter.devices.values.find(device => device.connected)
|
||||||
|
readonly property bool bluetoothConnected: bluetoothDevice !== undefined
|
||||||
|
text: bluetoothConnected ? "bluetooth_connected" : bluetoothEnabled ? "bluetooth" : "bluetooth_disabled"
|
||||||
iconSize: Appearance.font.pixelSize.larger
|
iconSize: Appearance.font.pixelSize.larger
|
||||||
color: rightSidebarButton.colText
|
color: rightSidebarButton.colText
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,73 +0,0 @@
|
|||||||
pragma Singleton
|
|
||||||
pragma ComponentBehavior: Bound
|
|
||||||
|
|
||||||
import Quickshell;
|
|
||||||
import Quickshell.Io;
|
|
||||||
import QtQuick;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Basic polled Bluetooth state.
|
|
||||||
*/
|
|
||||||
Singleton {
|
|
||||||
id: root
|
|
||||||
|
|
||||||
property int updateInterval: 1000
|
|
||||||
property string bluetoothDeviceName: ""
|
|
||||||
property string bluetoothDeviceAddress: ""
|
|
||||||
property bool bluetoothEnabled: false
|
|
||||||
property bool bluetoothConnected: false
|
|
||||||
|
|
||||||
function update() {
|
|
||||||
updateBluetoothDevice.running = true
|
|
||||||
updateBluetoothStatus.running = true
|
|
||||||
updateBluetoothEnabled.running = true
|
|
||||||
}
|
|
||||||
|
|
||||||
Timer {
|
|
||||||
interval: 10
|
|
||||||
running: true
|
|
||||||
repeat: true
|
|
||||||
onTriggered: {
|
|
||||||
update()
|
|
||||||
interval = root.updateInterval
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if Bluetooth is enabled (controller powered on)
|
|
||||||
Process {
|
|
||||||
id: updateBluetoothEnabled
|
|
||||||
command: ["sh", "-c", "bluetoothctl show | grep -q 'Powered: yes' && echo 1 || echo 0"]
|
|
||||||
running: true
|
|
||||||
stdout: SplitParser {
|
|
||||||
onRead: data => {
|
|
||||||
root.bluetoothEnabled = (parseInt(data) === 1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the name and address of the first connected Bluetooth device
|
|
||||||
Process {
|
|
||||||
id: updateBluetoothDevice
|
|
||||||
command: ["sh", "-c", "bluetoothctl info | awk -F': ' '/Name: /{name=$2} /Device /{addr=$2} END{print name \":\" addr}'"]
|
|
||||||
running: true
|
|
||||||
stdout: SplitParser {
|
|
||||||
onRead: data => {
|
|
||||||
let parts = data.split(":")
|
|
||||||
root.bluetoothDeviceName = parts[0] || ""
|
|
||||||
root.bluetoothDeviceAddress = parts[1] || ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if any device is connected
|
|
||||||
Process {
|
|
||||||
id: updateBluetoothStatus
|
|
||||||
command: ["sh", "-c", "bluetoothctl info | grep -q 'Connected: yes' && echo 1 || echo 0"]
|
|
||||||
running: true
|
|
||||||
stdout: SplitParser {
|
|
||||||
onRead: data => {
|
|
||||||
root.bluetoothConnected = (parseInt(data) === 1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user