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 <[email protected]>
This commit is contained in:
@@ -118,7 +118,6 @@ PowerStatusView::_Init()
|
|||||||
fShowStatusIcon = true;
|
fShowStatusIcon = true;
|
||||||
|
|
||||||
fPercent = 1.0;
|
fPercent = 1.0;
|
||||||
fOnline = true;
|
|
||||||
fTimeLeft = 0;
|
fTimeLeft = 0;
|
||||||
|
|
||||||
fHasNotifiedLowBattery = false;
|
fHasNotifiedLowBattery = false;
|
||||||
@@ -170,6 +169,7 @@ void
|
|||||||
PowerStatusView::_DrawBattery(BView* view, BRect rect)
|
PowerStatusView::_DrawBattery(BView* view, BRect rect)
|
||||||
{
|
{
|
||||||
BRect lightningRect = rect;
|
BRect lightningRect = rect;
|
||||||
|
BRect pauseRect = rect;
|
||||||
float quarter = floorf((rect.Height() + 1) / 4);
|
float quarter = floorf((rect.Height() + 1) / 4);
|
||||||
rect.top += quarter;
|
rect.top += quarter;
|
||||||
rect.bottom -= quarter;
|
rect.bottom -= quarter;
|
||||||
@@ -180,6 +180,8 @@ PowerStatusView::_DrawBattery(BView* view, BRect rect)
|
|||||||
rect.left += rect.Width() / 11;
|
rect.left += rect.Width() / 11;
|
||||||
lightningRect.left = rect.left;
|
lightningRect.left = rect.left;
|
||||||
lightningRect.InsetBy(0.0f, 5.0f * rect.Height() / 16);
|
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())
|
if (view->LowColor().IsLight())
|
||||||
view->SetHighColor(0, 0, 0);
|
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.
|
// When charging, draw a lightning symbol over the battery.
|
||||||
view->SetHighColor(255, 255, 0, 180);
|
view->SetHighColor(255, 255, 0, 180);
|
||||||
view->SetDrawingMode(B_OP_ALPHA);
|
view->SetDrawingMode(B_OP_ALPHA);
|
||||||
@@ -295,6 +297,26 @@ PowerStatusView::_DrawBattery(BView* view, BRect rect)
|
|||||||
};
|
};
|
||||||
view->FillPolygon(points, 6, lightningRect);
|
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);
|
view->SetDrawingMode(B_OP_OVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -377,7 +399,8 @@ PowerStatusView::_SetLabel(char* buffer, size_t bufferLength)
|
|||||||
|
|
||||||
const char* open = "";
|
const char* open = "";
|
||||||
const char* close = "";
|
const char* close = "";
|
||||||
if (fOnline) {
|
if ((fBatteryInfo.state & BATTERY_DISCHARGING) == 0) {
|
||||||
|
// surround the percentage with () if the battery is not discharging
|
||||||
open = "(";
|
open = "(";
|
||||||
close = ")";
|
close = ")";
|
||||||
}
|
}
|
||||||
@@ -403,18 +426,16 @@ PowerStatusView::Update(bool force, bool notify)
|
|||||||
{
|
{
|
||||||
double previousPercent = fPercent;
|
double previousPercent = fPercent;
|
||||||
time_t previousTimeLeft = fTimeLeft;
|
time_t previousTimeLeft = fTimeLeft;
|
||||||
bool wasOnline = fOnline;
|
bool wasCharging = (fBatteryInfo.state & BATTERY_CHARGING);
|
||||||
bool hadBattery = fHasBattery;
|
bool hadBattery = fHasBattery;
|
||||||
_GetBatteryInfo(fBatteryID, &fBatteryInfo);
|
_GetBatteryInfo(fBatteryID, &fBatteryInfo);
|
||||||
fHasBattery = fBatteryInfo.full_capacity > 0;
|
fHasBattery = fBatteryInfo.full_capacity > 0;
|
||||||
|
|
||||||
if (fBatteryInfo.full_capacity > 0 && fHasBattery) {
|
if (fBatteryInfo.full_capacity > 0 && fHasBattery) {
|
||||||
fPercent = (double)fBatteryInfo.capacity / fBatteryInfo.full_capacity;
|
fPercent = (double)fBatteryInfo.capacity / fBatteryInfo.full_capacity;
|
||||||
fOnline = (fBatteryInfo.state & BATTERY_DISCHARGING) == 0;
|
|
||||||
fTimeLeft = fBatteryInfo.time_left;
|
fTimeLeft = fBatteryInfo.time_left;
|
||||||
} else {
|
} else {
|
||||||
fPercent = 0.0;
|
fPercent = 0.0;
|
||||||
fOnline = false;
|
|
||||||
fTimeLeft = -1;
|
fTimeLeft = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -422,7 +443,6 @@ PowerStatusView::Update(bool force, bool notify)
|
|||||||
// Just ignore this probe -- it obviously returned invalid values
|
// Just ignore this probe -- it obviously returned invalid values
|
||||||
fPercent = previousPercent;
|
fPercent = previousPercent;
|
||||||
fTimeLeft = previousTimeLeft;
|
fTimeLeft = previousTimeLeft;
|
||||||
fOnline = wasOnline;
|
|
||||||
fHasBattery = hadBattery;
|
fHasBattery = hadBattery;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -441,7 +461,8 @@ PowerStatusView::Update(bool force, bool notify)
|
|||||||
char text[256];
|
char text[256];
|
||||||
const char* open = "";
|
const char* open = "";
|
||||||
const char* close = "";
|
const char* close = "";
|
||||||
if (fOnline) {
|
if ((fBatteryInfo.state & BATTERY_DISCHARGING) == 0) {
|
||||||
|
// surround the percentage with () if the battery is not discharging
|
||||||
open = "(";
|
open = "(";
|
||||||
close = ")";
|
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 && fTimeLeft != previousTimeLeft)
|
||||||
|| (!fShowTime && fPercent != previousPercent)) {
|
|| (!fShowTime && fPercent != previousPercent)) {
|
||||||
Invalidate();
|
Invalidate();
|
||||||
@@ -512,13 +533,13 @@ PowerStatusView::Update(bool force, bool notify)
|
|||||||
|| (fTimeLeft <= kLowBatteryTimeLeft
|
|| (fTimeLeft <= kLowBatteryTimeLeft
|
||||||
&& previousTimeLeft > kLowBatteryTimeLeft);
|
&& previousTimeLeft > kLowBatteryTimeLeft);
|
||||||
|
|
||||||
if (!fOnline && notify && fHasBattery
|
if ((fBatteryInfo.state & BATTERY_DISCHARGING) != 0 && notify && fHasBattery
|
||||||
&& !fHasNotifiedLowBattery && justTurnedLowBattery) {
|
&& !fHasNotifiedLowBattery && justTurnedLowBattery) {
|
||||||
_NotifyLowBattery();
|
_NotifyLowBattery();
|
||||||
fHasNotifiedLowBattery = true;
|
fHasNotifiedLowBattery = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fOnline && fPercent >= kFullBatteryPercentage
|
if ((fBatteryInfo.state & BATTERY_CHARGING) != 0 && fPercent >= kFullBatteryPercentage
|
||||||
&& previousPercent < kFullBatteryPercentage) {
|
&& previousPercent < kFullBatteryPercentage) {
|
||||||
system_beep("Battery charged");
|
system_beep("Battery charged");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,7 +66,6 @@ protected:
|
|||||||
|
|
||||||
double fPercent;
|
double fPercent;
|
||||||
time_t fTimeLeft;
|
time_t fTimeLeft;
|
||||||
bool fOnline;
|
|
||||||
bool fHasBattery;
|
bool fHasBattery;
|
||||||
|
|
||||||
bool fHasNotifiedLowBattery;
|
bool fHasNotifiedLowBattery;
|
||||||
|
|||||||
Reference in New Issue
Block a user