move stuff into components

This commit is contained in:
Damocles 2026-04-12 00:56:17 +02:00
parent 6370732e4e
commit 14292e6683
17 changed files with 81 additions and 149 deletions

View file

@ -1,12 +1,18 @@
import QtQuick
import QtQuick.Controls
import Quickshell.Services.UPower
import "." as M
Row {
M.BarSection {
id: root
spacing: 4
visible: UPower.displayDevice?.isLaptopBattery ?? false
tooltip: {
const state = root.charging ? "Charging" : "Discharging";
const t = root.charging ? root.dev?.timeToFull : root.dev?.timeToEmpty;
const mins = t ? Math.round(t / 60) : 0;
const timeStr = mins > 0 ? "\n" + Math.floor(mins / 60) + "h " + (mins % 60) + "m " + (root.charging ? "until full" : "remaining") : "";
return state + " \u2014 " + Math.round(root.pct) + "%" + timeStr;
}
readonly property var dev: UPower.displayDevice
readonly property real pct: (dev?.percentage ?? 0) * 100
@ -27,16 +33,4 @@ Row {
color: root.pct < 15 ? M.Theme.base08 : M.Theme.base05
anchors.verticalCenter: parent.verticalCenter
}
HoverHandler { id: hover }
ToolTip {
visible: hover.hovered
text: {
const state = root.charging ? "Charging" : "Discharging";
const t = root.charging ? root.dev?.timeToFull : root.dev?.timeToEmpty;
const mins = t ? Math.round(t / 60) : 0;
const timeStr = mins > 0 ? "\n" + Math.floor(mins / 60) + "h " + (mins % 60) + "m " + (root.charging ? "until full" : "remaining") : "";
return state + " — " + Math.round(root.pct) + "%" + timeStr;
}
}
}