diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2025-09-10 15:57:26 +0200 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2025-09-10 15:57:26 +0200 |
commit | d20393e077b8d97b18f4a224ddcb20caf6dac23b (patch) | |
tree | 337a8630deecdb50a2c879754e6b34b71575bbe0 /accounts/gkleen@sif/shell/quickshell/BatteryWidget.qml | |
parent | 9fab3828698199718a3d2f2faf8826f77d9258f7 (diff) | |
download | nixos-d20393e077b8d97b18f4a224ddcb20caf6dac23b.tar nixos-d20393e077b8d97b18f4a224ddcb20caf6dac23b.tar.gz nixos-d20393e077b8d97b18f4a224ddcb20caf6dac23b.tar.bz2 nixos-d20393e077b8d97b18f4a224ddcb20caf6dac23b.tar.xz nixos-d20393e077b8d97b18f4a224ddcb20caf6dac23b.zip |
...
Diffstat (limited to 'accounts/gkleen@sif/shell/quickshell/BatteryWidget.qml')
-rw-r--r-- | accounts/gkleen@sif/shell/quickshell/BatteryWidget.qml | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/accounts/gkleen@sif/shell/quickshell/BatteryWidget.qml b/accounts/gkleen@sif/shell/quickshell/BatteryWidget.qml new file mode 100644 index 00000000..896440f1 --- /dev/null +++ b/accounts/gkleen@sif/shell/quickshell/BatteryWidget.qml | |||
@@ -0,0 +1,61 @@ | |||
1 | import QtQuick | ||
2 | import Quickshell | ||
3 | import Quickshell.Widgets | ||
4 | import Quickshell.Services.UPower | ||
5 | |||
6 | Item { | ||
7 | id: root | ||
8 | |||
9 | height: parent.height | ||
10 | width: batteryIcon.width | ||
11 | anchors.verticalCenter: parent.verticalCenter | ||
12 | |||
13 | property var batteryDevice: Array.from(UPower.devices.values).find(dev => dev.isLaptopBattery) | ||
14 | |||
15 | WrapperMouseArea { | ||
16 | id: widgetMouseArea | ||
17 | |||
18 | anchors.fill: parent | ||
19 | |||
20 | hoverEnabled: true | ||
21 | |||
22 | Item { | ||
23 | anchors.fill: parent | ||
24 | |||
25 | MaterialDesignIcon { | ||
26 | id: batteryIcon | ||
27 | |||
28 | implicitSize: 14 | ||
29 | anchors.centerIn: parent | ||
30 | |||
31 | icon: { | ||
32 | if (!root.batteryDevice?.ready) | ||
33 | return "battery-unknown"; | ||
34 | |||
35 | if (root.batteryDevice.state == UPowerDeviceState.FullyCharged) | ||
36 | return "power-plug-battery"; | ||
37 | |||
38 | const perdec = 10 * Math.max(1, Math.ceil(root.batteryDevice.percentage * 10)); | ||
39 | if (root.batteryDevice.state == UPowerDeviceState.Charging) | ||
40 | return `battery-charging-${perdec}`; | ||
41 | if (perdec == 100) | ||
42 | return "battery"; | ||
43 | return `battery-${perdec}`; | ||
44 | } | ||
45 | color: { | ||
46 | if (!root.batteryDevice?.ready) | ||
47 | return "#555"; | ||
48 | |||
49 | if (root.batteryDevice.state != UPowerDeviceState.FullyCharged && root.batteryDevice.state != UPowerDeviceState.Charging && root.batteryDevice.timeToEmpty < 20 * 60) | ||
50 | return "#f2201f"; | ||
51 | if (root.batteryDevice.state != UPowerDeviceState.FullyCharged && root.batteryDevice.state != UPowerDeviceState.Charging && root.batteryDevice.timeToEmpty < 40 * 60) | ||
52 | return "#f28a21"; | ||
53 | if (root.batteryDevice.state != UPowerDeviceState.FullyCharged) | ||
54 | return "#fff"; | ||
55 | return "#555"; | ||
56 | } | ||
57 | } | ||
58 | |||
59 | } | ||
60 | } | ||
61 | } | ||