add available devices and fix formatting/icons
This commit is contained in:
parent
622604ad08
commit
0bbb032823
6 changed files with 105 additions and 34 deletions
49
modules/bar/components/bluetooth/AvailableDevice.qml
Normal file
49
modules/bar/components/bluetooth/AvailableDevice.qml
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
pragma ComponentBehavior: Bound
|
||||
|
||||
import qs.config
|
||||
import qs.widgets
|
||||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import Quickshell
|
||||
import Quickshell.Bluetooth
|
||||
import Quickshell.Widgets
|
||||
|
||||
StyledLabel {
|
||||
id: root
|
||||
required property BluetoothDevice modelData
|
||||
|
||||
RowLayout {
|
||||
id: row
|
||||
|
||||
spacing: 8
|
||||
|
||||
Loader {
|
||||
active: root.modelData?.icon != undefined
|
||||
sourceComponent: IconImage {
|
||||
implicitSize: 22
|
||||
source: Quickshell.iconPath(root.modelData.icon, "device-support-unknown-symbolic")
|
||||
}
|
||||
}
|
||||
|
||||
StyledText {
|
||||
text: root.modelData.deviceName
|
||||
}
|
||||
|
||||
StyledButton {
|
||||
Layout.alignment: Qt.AlignRight
|
||||
hoverEnabled: !root.modelData.pairing
|
||||
color: containsMouse ? Theme.palette.primary : Theme.palette.base200
|
||||
content: StyledText {
|
||||
text: 'Pair'
|
||||
font.pixelSize: 12
|
||||
}
|
||||
onClicked: {
|
||||
if (!hoverEnabled) {
|
||||
return;
|
||||
}
|
||||
root.modelData.trusted = true;
|
||||
root.modelData.pair();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -22,17 +22,31 @@ StyledPopupWindow {
|
|||
color: Theme.palette.base200
|
||||
radius: 8
|
||||
Layout.fillWidth: true
|
||||
RowLayout {
|
||||
RowLayout {
|
||||
StyledText {
|
||||
text: "Bluetooth"
|
||||
text: "Enabled"
|
||||
}
|
||||
|
||||
Switch {
|
||||
Layout.alignment: Qt.AlignRight
|
||||
checked: Bluetooth.defaultAdapter.enabled
|
||||
onClicked: Bluetooth.defaultAdapter.enabled = checked
|
||||
}
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
Layout.alignment: Qt.AlignRight
|
||||
StyledText {
|
||||
text: "Scan"
|
||||
}
|
||||
|
||||
Switch {
|
||||
checked: Bluetooth.defaultAdapter.discovering
|
||||
onClicked: Bluetooth.defaultAdapter.discovering = true;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
WrapperRectangle {
|
||||
|
|
@ -76,10 +90,12 @@ StyledPopupWindow {
|
|||
text: "Available Devices"
|
||||
}
|
||||
|
||||
DeviceList {
|
||||
devices: Bluetooth.availableDevices
|
||||
onDeviceActivated: device => {
|
||||
device.pair();
|
||||
ColumnLayout {
|
||||
Repeater {
|
||||
model: Bluetooth.availableDevices
|
||||
delegate: AvailableDevice {
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import Quickshell.Bluetooth
|
|||
import Quickshell.Widgets
|
||||
|
||||
StyledLabel {
|
||||
id: device
|
||||
id: root
|
||||
required property BluetoothDevice modelData
|
||||
|
||||
RowLayout {
|
||||
|
|
@ -19,19 +19,19 @@ StyledLabel {
|
|||
spacing: 8
|
||||
|
||||
Loader {
|
||||
active: modelData.icon != undefined
|
||||
active: root.modelData?.icon != undefined
|
||||
sourceComponent: IconImage {
|
||||
implicitSize: 18
|
||||
source: Quickshell.iconPath(modelData.icon)
|
||||
implicitSize: 22
|
||||
source: Quickshell.iconPath(root.modelData.icon, "device-support-unknown-symbolic")
|
||||
}
|
||||
}
|
||||
|
||||
StyledText {
|
||||
text: device.modelData.deviceName
|
||||
text: root.modelData.deviceName
|
||||
}
|
||||
|
||||
Loader {
|
||||
active: device.modelData.batteryAvailable
|
||||
active: root.modelData.batteryAvailable
|
||||
sourceComponent: RowLayout {
|
||||
StyledText {
|
||||
id: icon
|
||||
|
|
@ -42,11 +42,11 @@ StyledLabel {
|
|||
states: [
|
||||
State {
|
||||
name: "full"
|
||||
when: device.modelData.battery > 0.66
|
||||
when: root.modelData.battery > 0.66
|
||||
},
|
||||
State {
|
||||
name: "medium"
|
||||
when: device.modelData.battery > 0.33
|
||||
when: root.modelData.battery > 0.33
|
||||
PropertyChanges {
|
||||
icon {
|
||||
text: Icons.batteryFull
|
||||
|
|
@ -55,7 +55,7 @@ StyledLabel {
|
|||
},
|
||||
State {
|
||||
name: "low"
|
||||
when: device.modelData.battery > 0.10
|
||||
when: root.modelData.battery > 0.10
|
||||
PropertyChanges {
|
||||
icon {
|
||||
text: Icons.batteryFull
|
||||
|
|
@ -64,7 +64,7 @@ StyledLabel {
|
|||
},
|
||||
State {
|
||||
name: "critical"
|
||||
when: device.modelData.battery > 0.10
|
||||
when: root.modelData.battery > 0.10
|
||||
PropertyChanges {
|
||||
icon {
|
||||
text: Icons.batteryWarning
|
||||
|
|
@ -82,12 +82,13 @@ StyledLabel {
|
|||
color: containsMouse ? Theme.palette.error : Theme.palette.base200
|
||||
content: StyledText {
|
||||
text: 'Disconnect'
|
||||
font.pixelSize: 12
|
||||
}
|
||||
onClicked: {
|
||||
if (modelData.state != BluetoothDeviceState.Connected) {
|
||||
if (root.modelData.state != BluetoothDeviceState.Connected) {
|
||||
return;
|
||||
}
|
||||
modelData.disconnect();
|
||||
root.modelData.connected = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import Quickshell.Bluetooth
|
|||
import Quickshell.Widgets
|
||||
|
||||
StyledLabel {
|
||||
id: device
|
||||
id: root
|
||||
required property BluetoothDevice modelData
|
||||
|
||||
RowLayout {
|
||||
|
|
@ -18,44 +18,46 @@ StyledLabel {
|
|||
spacing: 8
|
||||
|
||||
Loader {
|
||||
active: modelData.icon != undefined
|
||||
active: root.modelData?.icon != undefined
|
||||
sourceComponent: IconImage {
|
||||
implicitSize: 18
|
||||
source: Quickshell.iconPath(device.modelData.icon)
|
||||
implicitSize: 22
|
||||
source: Quickshell.iconPath(root.modelData.icon, "device-support-unknown-symbolic")
|
||||
}
|
||||
}
|
||||
|
||||
StyledText {
|
||||
text: device.modelData.deviceName
|
||||
text: root.modelData.deviceName
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
Layout.alignment: Qt.AlignRight
|
||||
StyledButton {
|
||||
hoverEnabled: device.modelData.state == BluetoothDeviceState.Disconnected
|
||||
color: containsMouse ? Theme.palette.info : Theme.palette.base200
|
||||
hoverEnabled: root.modelData.state == BluetoothDeviceState.Disconnected
|
||||
color: containsMouse ? Theme.palette.primary : Theme.palette.base200
|
||||
content: StyledText {
|
||||
text: 'Connect'
|
||||
font.pixelSize: 12
|
||||
}
|
||||
onClicked: {
|
||||
if (!hoverEnabled) {
|
||||
return;
|
||||
}
|
||||
device.modelData.connect();
|
||||
root.modelData.connect();
|
||||
}
|
||||
}
|
||||
|
||||
StyledButton {
|
||||
hoverEnabled: device.modelData.state == BluetoothDeviceState.Disconnected
|
||||
hoverEnabled: root.modelData.state == BluetoothDeviceState.Disconnected
|
||||
color: containsMouse ? Theme.palette.error : Theme.palette.base200
|
||||
content: StyledText {
|
||||
text: 'Unpair'
|
||||
font.pixelSize: 12
|
||||
}
|
||||
onClicked: {
|
||||
if (!hoverEnabled) {
|
||||
return;
|
||||
}
|
||||
device.modelData.forget();
|
||||
root.modelData.forget();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
pragma Singleton
|
||||
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Bluetooth
|
||||
|
||||
|
|
@ -7,9 +8,9 @@ Singleton {
|
|||
id: root
|
||||
|
||||
property BluetoothAdapter defaultAdapter: Bluetooth.defaultAdapter
|
||||
property list<BluetoothDevice> connectedDevices: defaultAdapter.devices.values.filter(device => device.connected)
|
||||
property list<BluetoothDevice> pairedDevices: defaultAdapter.devices.values.filter(device => device.paired && !device.connected)
|
||||
property list<BluetoothDevice> availableDevices: defaultAdapter.devices.values.filter(device => !device.paired)
|
||||
property list<BluetoothDevice> connectedDevices: defaultAdapter?.devices.values.filter(device => device.state == BluetoothDeviceState.Connected)
|
||||
property list<BluetoothDevice> pairedDevices: defaultAdapter?.devices.values.filter(device => device.bonded && device.state == BluetoothDeviceState.Disconnected)
|
||||
property list<BluetoothDevice> availableDevices: defaultAdapter?.devices.values.filter(device => !device.bonded && device.deviceName != "")
|
||||
|
||||
function isConnected(BluetoothDevice: device) {
|
||||
return device.state == BluetoothDeviceState.Connected;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
//@ pragma IconTheme WhiteSur-dark
|
||||
|
||||
import Quickshell
|
||||
import "modules"
|
||||
import "modules/bar"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue