feat: added graphs to battery hover windows

This commit is contained in:
Honney
2026-09-02 14:54:00 +02:00
parent 510cbb0cec
commit f9c14c84b4
2 changed files with 90 additions and 23 deletions
@@ -4,6 +4,7 @@ import Quickshell
import Quickshell.Services.UPower
Item {
id: root
property bool available: UPower.displayDevice.isLaptopBattery
property real percentage: UPower.displayDevice.percentage*100
property string state: UPowerDeviceState.toString(UPower.displayDevice.state)
@@ -18,4 +19,38 @@ Item {
property real energy_rate_formated: Math.round(energy_rate*10)/10
property bool healthSupported: UPower.displayDevice.healthSupported
property real health: healthSupported ? UPower.displayDevice.healthPercentage : NaN
property int _maxHistory: 60*60
property var percentageHistory: [{time: Date.now() - _maxHistory*1000, value: 0}, {time: Date.now(), value: 0}]
property var energyHistory: [{time: Date.now() - _maxHistory*1000, value: 0}, {time: Date.now(), value: 0}]
property var usageHistory: [{time: Date.now() - _maxHistory*1000, value: 0}, {time: Date.now(), value: 0}]
Timer {
id: statsTimer
interval: 1000
repeat: true
running: true
onTriggered: {
var now = Date.now()
// Creating percentage History
var pHist = root.percentageHistory
pHist.push({time: now, value: percentage})
if (pHist.length > root._maxHistory) pHist.shift()
root.percentageHistory = pHist
// Creating percentage History
var eHist = root.energyHistory
eHist.push({time: now, value: percentage})
if (eHist.length > root._maxHistory) eHist.shift()
root.energyHistory = eHist
// Creating percentage History
var uHist = root.usageHistory
uHist.push({time: now, value: percentage})
if (uHist.length > root._maxHistory) uHist.shift()
root.usageHistory = uHist
}
}
}
+50 -18
View File
@@ -126,14 +126,6 @@ MouseArea {
Column {
spacing: parent.spacing
Text {
text: "percentage: " + BatteryState.percentage + "%"
wrapMode: Text.WordWrap
color: Colors.primary
anchors.horizontalCenter: parent.horizontalCenter
font.pixelSize: Config.font_size_tiny(bar.height)
font.family: Config.font
}
Text {
text: "State: " + BatteryState.state
wrapMode: Text.WordWrap
@@ -142,14 +134,62 @@ MouseArea {
font.pixelSize: Config.font_size_tiny(bar.height)
font.family: Config.font
}
Column {
width: parent.width
spacing: 2
Text {
text: "energy: " + Math.round(BatteryState.energy*10)/10 + " W"
wrapMode: Text.WordWrap
text: "percentage: " + BatteryState.percentage + "%"
color: Colors.primary
anchors.horizontalCenter: parent.horizontalCenter
font.pixelSize: Config.font_size_tiny(bar.height)
font.family: Config.font
}
Sparkline {
values: BatteryState.percentageHistory
lineColor: Colors.primary
width: parent.width
windowMs: BatteryState._maxHistory * 1000
}
}
Column {
width: parent.width
spacing: 2
Text {
text: "energy: " + Math.round(BatteryState.energy*10)/10 + " W"
color: Colors.primary
anchors.horizontalCenter: parent.horizontalCenter
font.pixelSize: Config.font_size_tiny(bar.height)
font.family: Config.font
}
Sparkline {
values: BatteryState.energyHistory
lineColor: Colors.primary
width: parent.width
windowMs: BatteryState._maxHistory * 1000
}
}
Column {
width: parent.width
spacing: 2
Text {
text: "Usage: " + BatteryState.energy_rate_formated + " W"
color: Colors.primary
anchors.horizontalCenter: parent.horizontalCenter
font.pixelSize: Config.font_size_tiny(bar.height)
font.family: Config.font
}
Sparkline {
values: BatteryState.usageHistory
lineColor: Colors.primary
width: parent.width
windowMs: BatteryState._maxHistory * 1000
}
}
Text {
text: (
BatteryState.hour_to_empty > 0 ? "Remaining: " + BatteryState.hour_to_empty + "h " + BatteryState.min_to_empty + "min" :
@@ -161,14 +201,6 @@ MouseArea {
font.pixelSize: Config.font_size_tiny(bar.height)
font.family: Config.font
}
Text {
text: "Usage: " + BatteryState.energy_rate_formated + " W"
wrapMode: Text.WordWrap
color: Colors.primary
anchors.horizontalCenter: parent.horizontalCenter
font.pixelSize: Config.font_size_tiny(bar.height)
font.family: Config.font
}
Text {
text: "Health: " + BatteryState.health + " %"
visible: BatteryState.healthSupported