LockScreen: Added a battery indicator
- relocated lockscreen to its own directory
This commit is contained in:
parent
049dd5d771
commit
b1a6804fea
3 changed files with 95 additions and 5 deletions
75
Widgets/LockScreen/BatteryCharge.qml
Normal file
75
Widgets/LockScreen/BatteryCharge.qml
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Services.UPower
|
||||
import QtQuick.Layouts
|
||||
import qs.Components
|
||||
import qs.Settings
|
||||
|
||||
Item {
|
||||
// Test mode
|
||||
property bool testMode: false
|
||||
property int testPercent: 49
|
||||
property bool testCharging: true
|
||||
|
||||
property var battery: UPower.displayDevice
|
||||
property bool isReady: testMode ? true : (battery && battery.ready && battery.isLaptopBattery && battery.isPresent)
|
||||
property real percent: testMode ? testPercent : (isReady ? (battery.percentage * 100) : 0)
|
||||
property bool charging: testMode ? testCharging : (isReady ? battery.state === UPowerDeviceState.Charging : false)
|
||||
property bool show: isReady && percent > 0
|
||||
|
||||
width: row.width
|
||||
height: row.height
|
||||
visible: testMode || (isReady && battery.isLaptopBattery)
|
||||
|
||||
// Choose icon based on charge and charging state
|
||||
function batteryIcon() {
|
||||
if (!show)
|
||||
return "";
|
||||
|
||||
if (charging)
|
||||
return "battery_android_bolt";
|
||||
|
||||
if (percent >= 95)
|
||||
return "battery_android_full";
|
||||
|
||||
// Hardcoded battery symbols
|
||||
if (percent >= 85)
|
||||
return "battery_android_6";
|
||||
if (percent >= 70)
|
||||
return "battery_android_5";
|
||||
if (percent >= 55)
|
||||
return "battery_android_4";
|
||||
if (percent >= 40)
|
||||
return "battery_android_3";
|
||||
if (percent >= 25)
|
||||
return "battery_android_2";
|
||||
if (percent >= 10)
|
||||
return "battery_android_1";
|
||||
if (percent >= 0)
|
||||
return "battery_android_0";
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
id: row
|
||||
spacing: 6
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
|
||||
Text {
|
||||
text: batteryIcon()
|
||||
font.family: "Material Symbols Outlined"
|
||||
font.pixelSize: 28
|
||||
color: charging ? Theme.accentPrimary : Theme.textSecondary
|
||||
verticalAlignment: Text.AlignVBottom
|
||||
}
|
||||
|
||||
Text {
|
||||
text: Math.round(percent) + "%"
|
||||
font.family: Theme.fontFamily
|
||||
font.pixelSize: 18
|
||||
color: Theme.textSecondary
|
||||
verticalAlignment: Text.AlignVBottom
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue