quickshell-toki-night/modules/bar/modules/StatusIcons.qml

166 lines
5.2 KiB
QML

import Quickshell
import Quickshell.Services.UPower
import QtQuick
import QtQuick.Layouts
import qs.services
import qs.config
import qs.custom
import qs.util
import qs.modules.bar
Container {
id: root
implicitWidth: layout.width + 20
RowLayout {
id: layout
anchors.centerIn: parent
spacing: 10
MaterialIcon {
id: network
objectName: "network"
Layout.alignment: Qt.AlignVCenter
text: Network.active ? Icons.getNetworkIcon(Network.active.strength ?? 0) : "wifi_off"
color: text !== "wifi_off" ? Config.colors.secondary : Config.colors.tertiary
animate: (from, to) => from === "wifi_off" || to === "wifi_off"
MouseArea {
anchors.fill: parent
onClicked: Network.toggleWifi()
}
}
/* MaterialIcon { */
/* id: bluetooth */
/* objectName: "bluetooth" */
/* anchors.verticalCenter: parent.verticalCenter */
/* animate: true */
/* text: Bluetooth.powered ? "bluetooth" : "bluetooth_disabled" */
/* } */
/* Row { */
/* id: devices */
/* objectName: "devices" */
/* anchors.verticalCenter: parent.verticalCenter */
/* Repeater { */
/* id: repeater */
/* model: ScriptModel { */
/* values: Bluetooth.devices.filter(d => d.connected) */
/* } */
/* MaterialIcon { */
/* required property Bluetooth.Device modelData */
/* animate: true */
/* text: Icons.getBluetoothIcon(modelData.icon) */
/* fill: 1 */
/* } */
/* } */
/* } */
MaterialIcon {
id: idleinhibit
objectName: "idleinhibit"
Layout.alignment: Qt.AlignVCenter
text: Idle.inhibit ? "visibility" : "visibility_off"
color: text === "visibility" ? Config.colors.secondary : Config.colors.tertiary
fill: Idle.inhibit ? 1 : 0
animate: true
MouseArea {
anchors.fill: parent
onClicked: Idle.inhibit = !Idle.inhibit
}
}
MaterialIcon {
id: battery
objectName: "battery"
Layout.alignment: Qt.AlignVCenter
Layout.leftMargin: hasBattery ? -2 : 0
Layout.topMargin: hasBattery ? 0.5 : 2
readonly property bool hasBattery: UPower.displayDevice.isLaptopBattery
readonly property real percentage: UPower.displayDevice.percentage
readonly property bool charging: !UPower.onBattery && batteryText.text !== "100"
readonly property bool warning: UPower.onBattery && percentage < Config.services.batteryWarning + 0.01
text: {
if (!hasBattery) {
if (PowerProfiles.profile === PowerProfile.PowerSaver)
return "energy_savings_leaf";
if (PowerProfiles.profile === PowerProfile.Performance)
return "rocket_launch";
return "balance";
}
return `battery_android_full`;
}
fill: 1
font.pointSize: hasBattery ? 18 : Config.font.size.normal
grade: 50
font.weight: 100
color: !hasBattery ? Config.colors.secondary :
warning ? Config.colors.errorBg :
batteryText.text === "100" ? Config.colors.battery :
Color.mute(Config.colors.battery, 0.6, 1.5)
CustomRect {
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.topMargin: 9
anchors.bottomMargin: 9
anchors.leftMargin: 3
width: (battery.width - 7) * battery.percentage
radius: 2
visible: battery.hasBattery
color: battery.warning ? Config.colors.batteryWarning : Config.colors.battery
}
Row {
anchors.centerIn: parent
anchors.horizontalCenterOffset: battery.charging ? width / 20 : -width / 15
visible: battery.hasBattery
spacing: -1
CustomText {
id: batteryText
anchors.verticalCenter: parent.verticalCenter
anchors.verticalCenterOffset: 0.5
text: Math.floor(battery.percentage * 100)
color: battery.warning ? Config.colors.batteryWarning : Config.colors.bg
font.family: Config.font.family.mono
font.pointSize: 6
font.weight: 800
}
MaterialIcon {
anchors.verticalCenter: parent.verticalCenter
visible: battery.charging
text: "bolt"
fill: 1
color: Config.colors.bg
font.pointSize: 7
font.weight: 300
}
}
}
}
}