functional bluetooth module
This commit is contained in:
109
Bar/Bluetooth.qml
Normal file
109
Bar/Bluetooth.qml
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
import QtQuick
|
||||||
|
import QtQuick.Layouts
|
||||||
|
import Quickshell
|
||||||
|
import Quickshell.Hyprland
|
||||||
|
|
||||||
|
import "../Color.js" as Colors
|
||||||
|
import "../Components/"
|
||||||
|
import "../Services/"
|
||||||
|
|
||||||
|
Container {
|
||||||
|
id: root
|
||||||
|
|
||||||
|
required property HyprlandMonitor monitor
|
||||||
|
property bool opened: false
|
||||||
|
|
||||||
|
animOffset: 200
|
||||||
|
boxColor: Colors.peach
|
||||||
|
boxHeight: 25
|
||||||
|
boxWidth: 33
|
||||||
|
defaultItem: icon
|
||||||
|
exclusiveMonitor: root.monitor
|
||||||
|
exclusiveToScreen: true
|
||||||
|
forceHidden: !(BluetoothManager.getConnected())
|
||||||
|
|
||||||
|
states: [
|
||||||
|
State {
|
||||||
|
name: "hovered"
|
||||||
|
when: root.hovered == true && root.opened == false
|
||||||
|
|
||||||
|
PropertyChanges {
|
||||||
|
root.boxHeight: 28
|
||||||
|
root.boxWidth: 35
|
||||||
|
}
|
||||||
|
},
|
||||||
|
State {
|
||||||
|
name: "opened"
|
||||||
|
when: root.opened == true && root.hovered == true
|
||||||
|
|
||||||
|
PropertyChanges {
|
||||||
|
root.boxHeight: 300
|
||||||
|
root.boxWidth: 350
|
||||||
|
}
|
||||||
|
|
||||||
|
StateChangeScript {
|
||||||
|
script: {
|
||||||
|
stack.replace(deviceList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
hover.onHoveredChanged: {
|
||||||
|
if (hover.hovered == false) {
|
||||||
|
root.opened = false;
|
||||||
|
if (root.state != "icon") {
|
||||||
|
root.stack.replace(icon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tap.onTapped: {
|
||||||
|
root.opened = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Component {
|
||||||
|
id: icon
|
||||||
|
|
||||||
|
StyledText {
|
||||||
|
property string component: "icon"
|
||||||
|
|
||||||
|
horizontalAlignment: Qt.AlignCenter
|
||||||
|
propo: true
|
||||||
|
text: ""
|
||||||
|
verticalAlignment: Qt.AlignVCenter
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Component {
|
||||||
|
id: deviceList
|
||||||
|
|
||||||
|
Column {
|
||||||
|
property string component: "deviceList"
|
||||||
|
|
||||||
|
spacing: 3
|
||||||
|
|
||||||
|
Repeater {
|
||||||
|
delegate: devicePlaque
|
||||||
|
model: BluetoothManager.getConnectedDevicesList()
|
||||||
|
}
|
||||||
|
|
||||||
|
Component {
|
||||||
|
id: devicePlaque
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
id: devicePlaqueRoot
|
||||||
|
|
||||||
|
required property var modelData
|
||||||
|
|
||||||
|
color: Colors.surface1
|
||||||
|
implicitHeight: 10
|
||||||
|
|
||||||
|
anchors {
|
||||||
|
left: parent.left
|
||||||
|
right: parent.right
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,6 +20,17 @@ Singleton {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getConnectedDevicesList() {
|
||||||
|
let devicesList = getDevicesList();
|
||||||
|
let connectedList = [];
|
||||||
|
for (let device of devicesList) {
|
||||||
|
if (device.connected == true) {
|
||||||
|
connectedList.push(device);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return connectedList;
|
||||||
|
}
|
||||||
|
|
||||||
function getDevicesList() {
|
function getDevicesList() {
|
||||||
return root.defaultAdapter.devices.values;
|
return root.defaultAdapter.devices.values;
|
||||||
}
|
}
|
||||||
@@ -41,29 +52,4 @@ Singleton {
|
|||||||
|
|
||||||
return icons[name] || "";
|
return icons[name] || "";
|
||||||
}
|
}
|
||||||
|
|
||||||
function pairTrustConnect(device) {
|
|
||||||
device.pair();
|
|
||||||
device.trusted = true;
|
|
||||||
device.connect();
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleDiscover() {
|
|
||||||
if (defaultAdapter.discovering == true) {
|
|
||||||
defaultAdapter.discovering = false;
|
|
||||||
} else {
|
|
||||||
defaultAdapter.discovering = true;
|
|
||||||
discoveringTimeout.running = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Timer {
|
|
||||||
id: discoveringTimeout
|
|
||||||
|
|
||||||
interval: 15000
|
|
||||||
repeat: false
|
|
||||||
running: false
|
|
||||||
|
|
||||||
onTriggered: defaultAdapter.discovering = false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user