diff options
Diffstat (limited to 'accounts/gkleen@sif/shell/quickshell/BatteryWidget.qml')
| -rw-r--r-- | accounts/gkleen@sif/shell/quickshell/BatteryWidget.qml | 71 |
1 files changed, 70 insertions, 1 deletions
diff --git a/accounts/gkleen@sif/shell/quickshell/BatteryWidget.qml b/accounts/gkleen@sif/shell/quickshell/BatteryWidget.qml index 896440f1..fd031627 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,76 @@ 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" | ||
| 58 | 83 | ||
| 84 | WrapperMouseArea { | ||
| 85 | id: tooltipMouseArea | ||
| 86 | |||
| 87 | hoverEnabled: true | ||
| 88 | enabled: true | ||
| 89 | |||
| 90 | anchors.centerIn: parent | ||
| 91 | |||
| 92 | Text { | ||
| 93 | id: widgetTooltipText | ||
| 94 | |||
| 95 | font.pointSize: 10 | ||
| 96 | font.family: "Fira Sans" | ||
| 97 | color: "white" | ||
| 98 | |||
| 99 | text: { | ||
| 100 | const stateStr = UPowerDeviceState.toString(root.batteryDevice.state); | ||
| 101 | var outStr = stateStr; | ||
| 102 | if (root.batteryDevice.state != UPowerDeviceState.FullyCharged) | ||
| 103 | outStr += ` ${Math.round(root.batteryDevice.percentage * 100)}%`; | ||
| 104 | |||
| 105 | function formatTime(t) { | ||
| 106 | var res = ""; | ||
| 107 | for (const unit of [{ "s": "h", "v": 3600 }, { "s": "m", "v": 60 }, { "s": "s", "v": 1 }]) { | ||
| 108 | if (t < unit.v) | ||
| 109 | continue; | ||
| 110 | res += Math.floor(t / unit.v) + unit.s; | ||
| 111 | t %= unit.v; | ||
| 112 | } | ||
| 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 | |||
| 125 | return outStr; | ||
| 126 | } | ||
| 127 | } | ||
| 59 | } | 128 | } |
| 60 | } | 129 | } |
| 61 | } | 130 | } |
