Add Battery indicator to LockScreen

This commit is contained in:
Ly-sec 2025-08-17 11:44:13 +02:00
parent a722712913
commit aabe05a7ea
2 changed files with 79 additions and 16 deletions

View file

@ -5,6 +5,7 @@ import QtQuick.Effects
import Quickshell
import Quickshell.Wayland
import Quickshell.Services.Pam
import Quickshell.Services.UPower
import Quickshell.Io
import Quickshell.Widgets
import qs.Commons
@ -91,6 +92,46 @@ WlSessionLock {
}
WlSessionLockSurface {
// Battery indicator component
Item {
id: batteryIndicator
// Import UPower for battery data
property var battery: UPower.displayDevice
property bool isReady: battery && battery.ready && battery.isLaptopBattery && battery.isPresent
property real percent: isReady ? (battery.percentage * 100) : 0
property bool charging: isReady ? battery.state === UPowerDeviceState.Charging : false
property bool batteryVisible: isReady && percent > 0
// Choose icon based on charge and charging state
function getIcon() {
if (!batteryVisible)
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"
}
}
// Wallpaper image
Image {
id: lockBgImage
@ -354,6 +395,27 @@ WlSessionLock {
font.weight: Font.Bold
Layout.fillWidth: true
}
// Battery indicator
Row {
spacing: Style.marginSmall * scaling
visible: batteryIndicator.batteryVisible
Text {
text: batteryIndicator.getIcon()
font.family: "Material Symbols Outlined"
font.pointSize: Style.fontSizeMedium
color: batteryIndicator.charging ? Color.mPrimary : Color.mOnSurface
}
Text {
text: Math.round(batteryIndicator.percent) + "%"
color: Color.mOnSurface
font.family: "DejaVu Sans Mono"
font.pointSize: Style.fontSizeMedium
font.weight: Font.Bold
}
}
}
}

View file

@ -64,6 +64,23 @@ A sleek, minimal, and thoughtfully crafted desktop shell for Wayland using **Qui
---
## Dependencies
### Required
- `quickshell-git` - Core shell framework
- `material-symbols-git` - Icon font for UI elements
- `xdg-desktop-portal-gnome` - Desktop integration (or alternative portal)
### Optional
- `swww` - Wallpaper animations and effects
- `matugen` - Material You color scheme generation
- `cava` - Audio visualizer component
- `gpu-screen-recorder` - Screen recording functionality
---
## Quick Start
### Installation
@ -174,22 +191,6 @@ layer-rule {
---
## Dependencies
### Required
- `quickshell-git` - Core shell framework
- `material-symbols-git` - Icon font for UI elements
- `xdg-desktop-portal-gnome` - Desktop integration (or alternative portal)
### Optional
- `swww` - Wallpaper animations and effects
- `matugen` - Material You color scheme generation
- `cava` - Audio visualizer component
- `gpu-screen-recorder` - Screen recording functionality
---
## Development