diff options
Diffstat (limited to 'accounts/gkleen@sif/shell/quickshell/BatteryWidget.qml')
-rw-r--r-- | accounts/gkleen@sif/shell/quickshell/BatteryWidget.qml | 72 |
1 files changed, 39 insertions, 33 deletions
diff --git a/accounts/gkleen@sif/shell/quickshell/BatteryWidget.qml b/accounts/gkleen@sif/shell/quickshell/BatteryWidget.qml index fd031627..da17df2a 100644 --- a/accounts/gkleen@sif/shell/quickshell/BatteryWidget.qml +++ b/accounts/gkleen@sif/shell/quickshell/BatteryWidget.qml | |||
@@ -87,42 +87,48 @@ Item { | |||
87 | hoverEnabled: true | 87 | hoverEnabled: true |
88 | enabled: true | 88 | enabled: true |
89 | 89 | ||
90 | anchors.centerIn: parent | 90 | anchors.fill: parent |
91 | |||
92 | Text { | ||
93 | id: widgetTooltipText | ||
94 | |||
95 | font.pointSize: 10 | ||
96 | font.family: "Fira Sans" | ||
97 | color: "white" | ||
98 | 91 | ||
99 | text: { | 92 | Item { |
100 | const stateStr = UPowerDeviceState.toString(root.batteryDevice.state); | 93 | anchors.fill: parent |
101 | var outStr = stateStr; | 94 | |
102 | if (root.batteryDevice.state != UPowerDeviceState.FullyCharged) | 95 | Text { |
103 | outStr += ` ${Math.round(root.batteryDevice.percentage * 100)}%`; | 96 | id: widgetTooltipText |
104 | 97 | ||
105 | function formatTime(t) { | 98 | anchors.centerIn: parent |
106 | var res = ""; | 99 | |
107 | for (const unit of [{ "s": "h", "v": 3600 }, { "s": "m", "v": 60 }, { "s": "s", "v": 1 }]) { | 100 | font.pointSize: 10 |
108 | if (t < unit.v) | 101 | font.family: "Fira Sans" |
109 | continue; | 102 | color: "white" |
110 | res += Math.floor(t / unit.v) + unit.s; | 103 | |
111 | t %= unit.v; | 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; | ||
112 | } | 128 | } |
113 | return res; | ||
114 | } | ||
115 | if (root.batteryDevice.timeToEmpty != 0) { | ||
116 | const tStr = formatTime(Math.floor(root.batteryDevice.timeToEmpty / 60) * 60); | ||
117 | if (tStr) | ||
118 | outStr += " " + tStr; | ||
119 | } else if (root.batteryDevice.timeToFull != 0) { | ||
120 | const tStr = formatTime(Math.ceil(root.batteryDevice.timeToFull / 60) * 60); | ||
121 | if (tStr) | ||
122 | outStr += " " + tStr; | ||
123 | } | ||
124 | 129 | ||
125 | return outStr; | 130 | return outStr; |
131 | } | ||
126 | } | 132 | } |
127 | } | 133 | } |
128 | } | 134 | } |