quickshell/modules/bar/Battery.qml

53 lines
1.6 KiB
QML
Raw Normal View History

2025-12-21 20:59:33 +01:00
import Quickshell.Services.UPower
import QtQuick
import Quickshell.Widgets
2025-12-24 15:41:03 +01:00
import "."
import qs
2025-12-21 20:59:33 +01:00
Item {
id: root
implicitWidth: batRow.implicitWidth + 10
implicitHeight: batRow.implicitHeight
Row {
id: batRow
anchors.centerIn: parent
2025-12-24 15:41:03 +01:00
spacing: 5
2025-12-21 20:59:33 +01:00
IconImage {
anchors.verticalCenter: parent.verticalCenter
2025-12-21 20:59:33 +01:00
source: "root:/icons/" + UPower.displayDevice.iconName + ".svg"
width: 12
height: 12
2025-12-21 20:59:33 +01:00
}
Text {
id: batteryText
anchors.verticalCenter: parent.verticalCenter
font.weight: 900
2025-12-21 20:59:33 +01:00
font.family: Appearance.font
font.pixelSize: Appearance.fontSize
color: Colors.foreground
text: Math.round(UPower.displayDevice.percentage * 100) + "%"
}
2025-12-24 15:41:03 +01:00
Text {
id: powerProfile
text: PowerProfile.toString(PowerProfiles.profile)
font.weight: 900
color: Colors.foreground
font.family: Appearance.font
font.pixelSize: Appearance.fontSize
}
}
MouseArea {
acceptedButtons: Qt.LeftButton
cursorShape: Qt.OpenHandCursor
anchors.fill: parent
onClicked: {
const modes = [PowerProfile.PowerSaver, PowerProfile.Balanced, PowerProfile.Performance];
let current = PowerProfiles.profile;
let currentIndex = modes.indexOf(current);
let nextIndex = (currentIndex + 1) % modes.length;
PowerProfiles.profile = modes[nextIndex];
PowerProfiles.profile = profiles[nextIndex];
}
2025-12-21 20:59:33 +01:00
}
}