mirror of
https://review.haiku-os.org/haiku
synced 2024-11-23 07:18:40 +01:00
PowerStatus: Display unused batteries with a pause symbol.
1. fOnline made sense when APM was the dominant power interface ("online" is "charging" in APM-speak) but it's confusing now that ACPI is the primary system and specifies more granular status. Eliminate fOnline and check specifically for charging or discharging as needed instead. 2. In multi-battery setups batteries that were neither charging nor discharging were shown with the lightning-bolt charging icon due to the lack of granularity in fOnline, now shows a paused icon instead. This solves the first point in #19167. Change-Id: If723b6b9a4695427d09075680a8ef435b3c1ac54 Reviewed-on: https://review.haiku-os.org/c/haiku/+/8456 Reviewed-by: waddlesplash <waddlesplash@gmail.com>
This commit is contained in:
parent
fb993aa063
commit
64854db4af
@ -118,7 +118,6 @@ PowerStatusView::_Init()
|
||||
fShowStatusIcon = true;
|
||||
|
||||
fPercent = 1.0;
|
||||
fOnline = true;
|
||||
fTimeLeft = 0;
|
||||
|
||||
fHasNotifiedLowBattery = false;
|
||||
@ -170,6 +169,7 @@ void
|
||||
PowerStatusView::_DrawBattery(BView* view, BRect rect)
|
||||
{
|
||||
BRect lightningRect = rect;
|
||||
BRect pauseRect = rect;
|
||||
float quarter = floorf((rect.Height() + 1) / 4);
|
||||
rect.top += quarter;
|
||||
rect.bottom -= quarter;
|
||||
@ -180,6 +180,8 @@ PowerStatusView::_DrawBattery(BView* view, BRect rect)
|
||||
rect.left += rect.Width() / 11;
|
||||
lightningRect.left = rect.left;
|
||||
lightningRect.InsetBy(0.0f, 5.0f * rect.Height() / 16);
|
||||
pauseRect.left = rect.left;
|
||||
pauseRect.InsetBy(rect.Width() * 0.1f, rect.Height() * 0.4f);
|
||||
|
||||
if (view->LowColor().IsLight())
|
||||
view->SetHighColor(0, 0, 0);
|
||||
@ -280,7 +282,7 @@ PowerStatusView::_DrawBattery(BView* view, BRect rect)
|
||||
}
|
||||
}
|
||||
|
||||
if (fOnline) {
|
||||
if ((fBatteryInfo.state & BATTERY_CHARGING) != 0) {
|
||||
// When charging, draw a lightning symbol over the battery.
|
||||
view->SetHighColor(255, 255, 0, 180);
|
||||
view->SetDrawingMode(B_OP_ALPHA);
|
||||
@ -295,6 +297,26 @@ PowerStatusView::_DrawBattery(BView* view, BRect rect)
|
||||
};
|
||||
view->FillPolygon(points, 6, lightningRect);
|
||||
|
||||
view->SetDrawingMode(B_OP_OVER);
|
||||
} else if ((fBatteryInfo.state
|
||||
& (BATTERY_CHARGING | BATTERY_DISCHARGING | BATTERY_CRITICAL_STATE)) == 0) {
|
||||
// When a battery is not in use at all, draw a pause symbol over the battery
|
||||
view->SetHighColor(0, 0, 0, 96);
|
||||
view->SetDrawingMode(B_OP_ALPHA);
|
||||
|
||||
static const BPoint points[] = {
|
||||
BPoint(1, 3),
|
||||
BPoint(1, 6),
|
||||
BPoint(8, 6),
|
||||
BPoint(8, 3),
|
||||
|
||||
BPoint(14, 3),
|
||||
BPoint(14, 6),
|
||||
BPoint(22, 6),
|
||||
BPoint(22, 3)
|
||||
};
|
||||
view->FillPolygon(points, 8, pauseRect);
|
||||
|
||||
view->SetDrawingMode(B_OP_OVER);
|
||||
}
|
||||
|
||||
@ -377,7 +399,8 @@ PowerStatusView::_SetLabel(char* buffer, size_t bufferLength)
|
||||
|
||||
const char* open = "";
|
||||
const char* close = "";
|
||||
if (fOnline) {
|
||||
if ((fBatteryInfo.state & BATTERY_DISCHARGING) == 0) {
|
||||
// surround the percentage with () if the battery is not discharging
|
||||
open = "(";
|
||||
close = ")";
|
||||
}
|
||||
@ -403,18 +426,16 @@ PowerStatusView::Update(bool force, bool notify)
|
||||
{
|
||||
double previousPercent = fPercent;
|
||||
time_t previousTimeLeft = fTimeLeft;
|
||||
bool wasOnline = fOnline;
|
||||
bool wasCharging = (fBatteryInfo.state & BATTERY_CHARGING);
|
||||
bool hadBattery = fHasBattery;
|
||||
_GetBatteryInfo(fBatteryID, &fBatteryInfo);
|
||||
fHasBattery = fBatteryInfo.full_capacity > 0;
|
||||
|
||||
if (fBatteryInfo.full_capacity > 0 && fHasBattery) {
|
||||
fPercent = (double)fBatteryInfo.capacity / fBatteryInfo.full_capacity;
|
||||
fOnline = (fBatteryInfo.state & BATTERY_DISCHARGING) == 0;
|
||||
fTimeLeft = fBatteryInfo.time_left;
|
||||
} else {
|
||||
fPercent = 0.0;
|
||||
fOnline = false;
|
||||
fTimeLeft = -1;
|
||||
}
|
||||
|
||||
@ -422,7 +443,6 @@ PowerStatusView::Update(bool force, bool notify)
|
||||
// Just ignore this probe -- it obviously returned invalid values
|
||||
fPercent = previousPercent;
|
||||
fTimeLeft = previousTimeLeft;
|
||||
fOnline = wasOnline;
|
||||
fHasBattery = hadBattery;
|
||||
return;
|
||||
}
|
||||
@ -441,7 +461,8 @@ PowerStatusView::Update(bool force, bool notify)
|
||||
char text[256];
|
||||
const char* open = "";
|
||||
const char* close = "";
|
||||
if (fOnline) {
|
||||
if ((fBatteryInfo.state & BATTERY_DISCHARGING) == 0) {
|
||||
// surround the percentage with () if the battery is not discharging
|
||||
open = "(";
|
||||
close = ")";
|
||||
}
|
||||
@ -498,7 +519,7 @@ PowerStatusView::Update(bool force, bool notify)
|
||||
}
|
||||
}
|
||||
|
||||
if (force || wasOnline != fOnline
|
||||
if (force || wasCharging != (fBatteryInfo.state & BATTERY_CHARGING)
|
||||
|| (fShowTime && fTimeLeft != previousTimeLeft)
|
||||
|| (!fShowTime && fPercent != previousPercent)) {
|
||||
Invalidate();
|
||||
@ -512,13 +533,13 @@ PowerStatusView::Update(bool force, bool notify)
|
||||
|| (fTimeLeft <= kLowBatteryTimeLeft
|
||||
&& previousTimeLeft > kLowBatteryTimeLeft);
|
||||
|
||||
if (!fOnline && notify && fHasBattery
|
||||
if ((fBatteryInfo.state & BATTERY_DISCHARGING) != 0 && notify && fHasBattery
|
||||
&& !fHasNotifiedLowBattery && justTurnedLowBattery) {
|
||||
_NotifyLowBattery();
|
||||
fHasNotifiedLowBattery = true;
|
||||
}
|
||||
|
||||
if (fOnline && fPercent >= kFullBatteryPercentage
|
||||
if ((fBatteryInfo.state & BATTERY_CHARGING) != 0 && fPercent >= kFullBatteryPercentage
|
||||
&& previousPercent < kFullBatteryPercentage) {
|
||||
system_beep("Battery charged");
|
||||
}
|
||||
|
@ -66,7 +66,6 @@ protected:
|
||||
|
||||
double fPercent;
|
||||
time_t fTimeLeft;
|
||||
bool fOnline;
|
||||
bool fHasBattery;
|
||||
|
||||
bool fHasNotifiedLowBattery;
|
||||
|
Loading…
Reference in New Issue
Block a user