nosignal-shell/modules/bar/components/StatusIcons.qml
Kaj 81b8ff31d8
config: enable/disable status icons (#243)
* Adds ability to disable/enable status icons

Improves the hover calculations so that it's not hardcoded. This should make it easier to add/remove status icons.
Also adds an optional audio status icon.

* status: move config to barconfig

* fixes

* fix merge

* loader icons

* fix audio popout

---------

Co-authored-by: Kaj Giesbers <kajgiesbers@gmail.com>
Co-authored-by: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>
2025-07-26 14:16:52 +10:00

179 lines
5.5 KiB
QML

pragma ComponentBehavior: Bound
import qs.widgets
import qs.services
import qs.utils
import qs.config
import Quickshell
import Quickshell.Bluetooth
import Quickshell.Services.UPower
import QtQuick
import QtQuick.Layouts
Item {
id: root
property color colour: Colours.palette.m3secondary
readonly property list<var> hoverAreas: [
{
name: "audio",
item: audioIcon,
enabled: Config.bar.status.showAudio
},
{
name: "network",
item: networkIcon,
enabled: Config.bar.status.showNetwork
},
{
name: "bluetooth",
item: bluetoothGroup,
enabled: Config.bar.status.showBluetooth
},
{
name: "battery",
item: batteryIcon,
enabled: Config.bar.status.showBattery
}
]
clip: true
implicitWidth: iconColumn.implicitWidth
implicitHeight: iconColumn.implicitHeight
ColumnLayout {
id: iconColumn
anchors.horizontalCenter: parent.horizontalCenter
spacing: Appearance.spacing.smaller / 2
// Audio icon
Loader {
id: audioIcon
asynchronous: true
active: Config.bar.status.showAudio
visible: active
sourceComponent: MaterialIcon {
animate: true
text: Audio.muted ? "volume_off" : Audio.volume >= 0.66 ? "volume_up" : Audio.volume >= 0.33 ? "volume_down" : "volume_mute"
color: root.colour
}
}
// Network icon
Loader {
id: networkIcon
asynchronous: true
active: Config.bar.status.showNetwork
visible: active
sourceComponent: MaterialIcon {
animate: true
text: Network.active ? Icons.getNetworkIcon(Network.active.strength ?? 0) : "wifi_off"
color: root.colour
}
}
// Bluetooth section (grouped for hover area)
Loader {
id: bluetoothGroup
asynchronous: true
active: Config.bar.status.showBluetooth
visible: active
sourceComponent: ColumnLayout {
spacing: Appearance.spacing.smaller / 2
// Bluetooth icon
MaterialIcon {
animate: true
text: Bluetooth.defaultAdapter?.enabled ? "bluetooth" : "bluetooth_disabled"
color: root.colour
}
// Connected bluetooth devices
Repeater {
model: ScriptModel {
values: Bluetooth.devices.values.filter(d => d.state !== BluetoothDeviceState.Disconnected)
}
MaterialIcon {
id: device
required property BluetoothDevice modelData
animate: true
text: Icons.getBluetoothIcon(modelData.icon)
color: root.colour
fill: 1
SequentialAnimation on opacity {
running: device.modelData.state !== BluetoothDeviceState.Connected
alwaysRunToEnd: true
loops: Animation.Infinite
Anim {
from: 1
to: 0
easing.bezierCurve: Appearance.anim.curves.standardAccel
}
Anim {
from: 0
to: 1
easing.bezierCurve: Appearance.anim.curves.standardDecel
}
}
}
}
}
}
// Battery icon
Loader {
id: batteryIcon
asynchronous: true
active: Config.bar.status.showBattery
visible: active
sourceComponent: MaterialIcon {
animate: true
text: {
if (!UPower.displayDevice.isLaptopBattery) {
if (PowerProfiles.profile === PowerProfile.PowerSaver)
return "energy_savings_leaf";
if (PowerProfiles.profile === PowerProfile.Performance)
return "rocket_launch";
return "balance";
}
const perc = UPower.displayDevice.percentage;
const charging = !UPower.onBattery;
if (perc === 1)
return charging ? "battery_charging_full" : "battery_full";
let level = Math.floor(perc * 7);
if (charging && (level === 4 || level === 1))
level--;
return charging ? `battery_charging_${(level + 3) * 10}` : `battery_${level}_bar`;
}
color: !UPower.onBattery || UPower.displayDevice.percentage > 0.2 ? root.colour : Colours.palette.m3error
fill: 1
}
}
}
Behavior on implicitHeight {
Anim {}
}
component Anim: NumberAnimation {
duration: Appearance.anim.durations.large
easing.type: Easing.BezierSpline
easing.bezierCurve: Appearance.anim.curves.emphasized
}
}