From aabe05a7ea61e6c48cf2901d812b56656d58ee5a Mon Sep 17 00:00:00 2001 From: Ly-sec Date: Sun, 17 Aug 2025 11:44:13 +0200 Subject: [PATCH] Add Battery indicator to LockScreen --- Modules/LockScreen/LockScreen.qml | 62 +++++++++++++++++++++++++++++++ README.md | 33 ++++++++-------- 2 files changed, 79 insertions(+), 16 deletions(-) diff --git a/Modules/LockScreen/LockScreen.qml b/Modules/LockScreen/LockScreen.qml index d932fb9..2d75c25 100644 --- a/Modules/LockScreen/LockScreen.qml +++ b/Modules/LockScreen/LockScreen.qml @@ -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 + } + } } } diff --git a/README.md b/README.md index 4a53b0a..06fbd0e 100644 --- a/README.md +++ b/README.md @@ -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