Compare commits

...
2 Commits
Author SHA1 Message Date
Hannes 0fad9baa5b fix: hide not given stats 2026-09-02 15:08:26 +02:00
Honney f9c14c84b4 feat: added graphs to battery hover windows 2026-09-02 14:54:00 +02:00
2 changed files with 101 additions and 24 deletions
+42 -1
View File
@@ -4,7 +4,8 @@ import Quickshell
import Quickshell.Services.UPower
Item {
property bool available: UPower.displayDevice.isLaptopBattery
id: root
property bool available: UPower.displayDevice.isPresent
property real percentage: UPower.displayDevice.percentage*100
property string state: UPowerDeviceState.toString(UPower.displayDevice.state)
property bool charging: state == "Charging"
@@ -18,4 +19,44 @@ 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 percentageHistoryExists: true
property var energyHistory: [{time: Date.now() - _maxHistory*1000, value: 0}, {time: Date.now(), value: 0}]
property var energyHistoryExists: true
property var usageHistory: [{time: Date.now() - _maxHistory*1000, value: 0}, {time: Date.now(), value: 0}]
property var usageHistoryExists: true
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()
percentageHistoryExists = pHist.some(item => item.value !== 0 && item.value !== undefined)
root.percentageHistory = pHist
// Creating percentage History
var eHist = root.energyHistory
eHist.push({time: now, value: energy_formated})
if (eHist.length > root._maxHistory) eHist.shift()
energyHistoryExists = eHist.some(item => item.value !== 0 && item.value !== undefined)
root.energyHistory = eHist
// Creating percentage History
var uHist = root.usageHistory
uHist.push({time: now, value: energy_rate_formated})
if (uHist.length > root._maxHistory) uHist.shift()
usageHistoryExists = uHist.some(item => item.value !== 0 && item.value !== undefined)
root.usageHistory = uHist
}
}
}
+59 -23
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,13 +134,65 @@ MouseArea {
font.pixelSize: Config.font_size_tiny(bar.height)
font.family: Config.font
}
Text {
text: "energy: " + Math.round(BatteryState.energy*10)/10 + " W"
wrapMode: Text.WordWrap
color: Colors.primary
anchors.horizontalCenter: parent.horizontalCenter
font.pixelSize: Config.font_size_tiny(bar.height)
font.family: Config.font
Column {
width: parent.width
spacing: 2
visible: BatteryState.percentageHistoryExists
Text {
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
visible: BatteryState.energyHistoryExists
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
visible: BatteryState.usageHistoryExists
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: (
@@ -161,14 +205,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