summaryrefslogtreecommitdiff
path: root/accounts/gkleen@sif/shell/quickshell/BatteryWidget.qml
diff options
context:
space:
mode:
Diffstat (limited to 'accounts/gkleen@sif/shell/quickshell/BatteryWidget.qml')
-rw-r--r--accounts/gkleen@sif/shell/quickshell/BatteryWidget.qml77
1 files changed, 76 insertions, 1 deletions
diff --git a/accounts/gkleen@sif/shell/quickshell/BatteryWidget.qml b/accounts/gkleen@sif/shell/quickshell/BatteryWidget.qml
index 896440f1..da17df2a 100644
--- a/accounts/gkleen@sif/shell/quickshell/BatteryWidget.qml
+++ b/accounts/gkleen@sif/shell/quickshell/BatteryWidget.qml
@@ -7,7 +7,7 @@ Item {
7 id: root 7 id: root
8 8
9 height: parent.height 9 height: parent.height
10 width: batteryIcon.width 10 width: batteryIcon.width + 8
11 anchors.verticalCenter: parent.verticalCenter 11 anchors.verticalCenter: parent.verticalCenter
12 12
13 property var batteryDevice: Array.from(UPower.devices.values).find(dev => dev.isLaptopBattery) 13 property var batteryDevice: Array.from(UPower.devices.values).find(dev => dev.isLaptopBattery)
@@ -55,7 +55,82 @@ Item {
55 return "#555"; 55 return "#555";
56 } 56 }
57 } 57 }
58 }
59 }
60
61 PopupWindow {
62 id: tooltip
63
64 property bool nextVisible: widgetMouseArea.containsMouse || tooltipMouseArea.containsMouse
65
66 anchor {
67 item: widgetMouseArea
68 edges: Edges.Bottom | Edges.Left
69 }
70 visible: false
71
72 onNextVisibleChanged: hangTimer.restart()
73
74 Timer {
75 id: hangTimer
76 interval: 100
77 onTriggered: tooltip.visible = tooltip.nextVisible
78 }
79
80 implicitWidth: widgetTooltipText.contentWidth + 16
81 implicitHeight: widgetTooltipText.contentHeight + 16
82 color: "black"
83
84 WrapperMouseArea {
85 id: tooltipMouseArea
58 86
87 hoverEnabled: true
88 enabled: true
89
90 anchors.fill: parent
91
92 Item {
93 anchors.fill: parent
94
95 Text {
96 id: widgetTooltipText
97
98 anchors.centerIn: parent
99
100 font.pointSize: 10
101 font.family: "Fira Sans"
102 color: "white"
103
104 text: {
105 const stateStr = UPowerDeviceState.toString(root.batteryDevice.state);
106 var outStr = stateStr;
107 if (root.batteryDevice.state != UPowerDeviceState.FullyCharged)
108 outStr += ` ${Math.round(root.batteryDevice.percentage * 100)}%`;
109
110 function formatTime(t) {
111 var res = "";
112 for (const unit of [{ "s": "h", "v": 3600 }, { "s": "m", "v": 60 }, { "s": "s", "v": 1 }]) {
113 if (t < unit.v)
114 continue;
115 res += Math.floor(t / unit.v) + unit.s;
116 t %= unit.v;
117 }
118 return res;
119 }
120 if (root.batteryDevice.timeToEmpty != 0) {
121 const tStr = formatTime(Math.floor(root.batteryDevice.timeToEmpty / 60) * 60);
122 if (tStr)
123 outStr += " " + tStr;
124 } else if (root.batteryDevice.timeToFull != 0) {
125 const tStr = formatTime(Math.ceil(root.batteryDevice.timeToFull / 60) * 60);
126 if (tStr)
127 outStr += " " + tStr;
128 }
129
130 return outStr;
131 }
132 }
133 }
59 } 134 }
60 } 135 }
61} 136}