feat: battery, refactor

This commit is contained in:
Kat Inskip 2025-12-07 23:37:25 -08:00
parent 9ae22c832f
commit 1ba98534eb
Signed by: kat
GPG key ID: 465E64DECEA8CF0F
15 changed files with 122 additions and 6 deletions

View file

@ -0,0 +1,96 @@
import QtQuick
import QtQuick.Controls
import Quickshell
import Quickshell.Widgets
import Quickshell.Services.UPower
import "root:/DataSources"
Loader {
property UPowerDevice mainBat: UPower.displayDevice
active: mainBat.isLaptopBattery
sourceComponent: batIcon
function findClosestIndex(percent) {
return Math.round(percent/10)
}
property list<string> percentIcons: [
"󰂎",
"󰁺",
"󰁼",
"󰁼",
"󰁽",
"󰁾",
"󰁿",
"󰂀",
"󰂁",
"󰂂",
"󰁹"
]
property string chargingIcon: "󰂄"
function getIcon(percent) {
if (mainBat.timeToEmpty == 0) {
return chargingIcon
} else {
var percentIcon = percentIcons[findClosestIndex(percent)];
return percentIcon
}
}
function getTimeLeft(allSeconds, filling) {
const hours = Math.floor(allSeconds / 3600)
const minutes = Math.floor((allSeconds % 3600) / 60)
const seconds = Math.floor((allSeconds % 3600) / 60) / 60
const fillString = filling ? "full" : "empty"
return `${hours}h${minutes}m${seconds}s remain until ${fillString}`
}
function getTimeLeftT() {
if (mainBat.timeToEmpty == 0) {
return getTimeLeft(mainBat.timeToEmpty, false)
} else if (mainBat.timeToFull == 0) {
return getTimeLeft(mainBat.timeToFull, true)
}
}
function changeRate() {
return `${Math.round(mainBat.changeRate)}W`
}
function energyLeft() {
return `${Math.round(mainBat.energy)}Wh`
}
function getTooltip() {
return `${getTimeLeftT()}, ${energyLeft()}, ${changeRate()}`
}
Component {
id: batIcon
Item {
MarginWrapperManager { margin: 10 }
Text {
color: Stylix.base05
text: `${getIcon(mainBat.percentage)} ${Math.round(mainBat.percentage)} %`
ToolTip {
id: dismissTooltip
visible: false
delay: 500
timeout: 1000
text: getTooltip()
}
HoverHandler {
id: dismissHover
onHoveredChanged: {
dismissTooltip.visible = hovered
}
}
}
}
}
}

View file

@ -33,16 +33,15 @@ Item {
property real clicky property real clicky
id: wrapperPopup id: wrapperPopup
anchor.window: root.QsWindow.window anchor.window: root.QsWindow.window
anchor.rect.y: parentWindow.height anchor.rect.y: parentWindow?.height ?? 0
anchor.rect.x: clicky anchor.rect.x: clicky
implicitWidth: systray.width + 10 implicitWidth: systray.width + 10
implicitHeight: systray.height + 10 implicitHeight: systray?.height + 10
color: "transparent" color: "transparent"
Rectangle { Rectangle {
anchors.fill: parent anchors.fill: parent
color: Stylix.base01 color: Stylix.base01
bottomLeftRadius: 5 radius: 5
bottomRightRadius: 5
SystemTray { SystemTray {
id: systray id: systray
} }

View file

@ -1,11 +1,14 @@
import Quickshell import Quickshell
import Quickshell.Io import Quickshell.Io
import Quickshell.Widgets
import QtQuick import QtQuick
import QtQuick.Layouts import QtQuick.Layouts
import QtQuick.Controls import QtQuick.Controls
import "root:/DataSources" import "root:/DataSources"
import "root:/Components" import "root:/Components"
import "root:/Components/NotificationSystem" import "root:/Components/WorkspaceControl"
import "root:/Components/SystemTray"
import "root:/Components/NotificationArea"
Scope { Scope {
id: root id: root
@ -34,7 +37,13 @@ Scope {
Rectangle { Rectangle {
id: bar id: bar
anchors.fill: parent anchors {
top: parent.top
left: parent.left
bottom: parent.bottom
}
MarginWrapperManager { margin: 10 }
radius: 10 radius: 10
color: Stylix.base00 color: Stylix.base00
@ -54,11 +63,22 @@ Scope {
} }
FocusedWindow {} FocusedWindow {}
} }
}
RowLayout { RowLayout {
anchors.centerIn: parent anchors.centerIn: parent
spacing: 20 spacing: 20
} }
Rectangle {
MarginWrapperManager { margin: 10 }
id: bar3
radius: 10
color: Stylix.base00
anchors {
top: parent.top
right: parent.right
bottom: parent.bottom
}
RowLayout { RowLayout {
anchors { anchors {
@ -71,6 +91,7 @@ Scope {
spacing: 15 spacing: 15
Battery {}
SystemTrayWrapper {} SystemTrayWrapper {}
Clock {} Clock {}
NotificationDisplay {} NotificationDisplay {}