mirror of
https://review.haiku-os.org/haiku
synced 2024-11-23 07:18:40 +01:00
PowerStatus: Fix issues with (dis)connecting batteries while running
1. Fixed stale data and invalid percent/time remaining being displayed after a battery is removed from the system. 2. Added display of a red X over damaged/missing batteries in the Battery Info view. This fixes the last point in bug #19167. Change-Id: I968829895fc814011b2c88bafe0b62a159b46d5a Reviewed-on: https://review.haiku-os.org/c/haiku/+/8496 Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org> Reviewed-by: waddlesplash <waddlesplash@gmail.com>
This commit is contained in:
parent
89264cfe2e
commit
b54510c378
@ -97,6 +97,13 @@ Battery::UpdateBatteryInfo()
|
||||
|| info.capacity < 0)
|
||||
return B_BAD_DATA;
|
||||
|
||||
if ((fCachedInfo.capacity == 0 && info.capacity > 0)
|
||||
|| (fCachedInfo.capacity > 0 && info.capacity == 0)) {
|
||||
// if capacity went from zero to non-zero or vice-versa, we likely just had a battery
|
||||
// connected or disconnected from the system so refresh the full fExtendedBatteryInfo
|
||||
GetExtendedBatteryInfo(&fExtendedBatteryInfo);
|
||||
}
|
||||
|
||||
fCachedInfo = info;
|
||||
return B_OK;
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ BatteryInfoView::_GetTextForLine(size_t line)
|
||||
&& fBatteryExtendedInfo.oem_info[0] == '\0')
|
||||
string = B_TRANSLATE("Empty battery slot");
|
||||
else if ((fBatteryInfo.state & BATTERY_CRITICAL_STATE) != 0)
|
||||
string = B_TRANSLATE("Damaged battery");
|
||||
string = B_TRANSLATE("Damaged or missing battery");
|
||||
else
|
||||
string = B_TRANSLATE("Battery unused");
|
||||
break;
|
||||
|
@ -317,6 +317,29 @@ PowerStatusView::_DrawBattery(BView* view, BRect rect)
|
||||
};
|
||||
view->FillPolygon(points, 8, pauseRect);
|
||||
|
||||
view->SetDrawingMode(B_OP_OVER);
|
||||
} else if ((fBatteryInfo.state & BATTERY_CRITICAL_STATE) != 0) {
|
||||
// When a battery is damaged or missing, draw an X over it
|
||||
view->SetHighColor(200, 0, 0, 96);
|
||||
view->SetDrawingMode(B_OP_ALPHA);
|
||||
|
||||
static const BPoint points[] = {
|
||||
BPoint(1, 1),
|
||||
BPoint(1, 2),
|
||||
BPoint(20, 6),
|
||||
BPoint(22, 6),
|
||||
BPoint(22, 5),
|
||||
BPoint(3, 1),
|
||||
|
||||
BPoint(20, 1),
|
||||
BPoint(1, 5),
|
||||
BPoint(1, 6),
|
||||
BPoint(3, 6),
|
||||
BPoint(22, 2),
|
||||
BPoint(22, 1)
|
||||
};
|
||||
view->FillPolygon(points, 12, lightningRect);
|
||||
|
||||
view->SetDrawingMode(B_OP_OVER);
|
||||
}
|
||||
|
||||
@ -429,7 +452,7 @@ PowerStatusView::Update(bool force, bool notify)
|
||||
bool wasCharging = (fBatteryInfo.state & BATTERY_CHARGING);
|
||||
bool hadBattery = fHasBattery;
|
||||
_GetBatteryInfo(fBatteryID, &fBatteryInfo);
|
||||
fHasBattery = fBatteryInfo.full_capacity > 0;
|
||||
fHasBattery = fBatteryInfo.full_capacity > 0 && fBatteryInfo.state != BATTERY_CRITICAL_STATE;
|
||||
|
||||
if (fBatteryInfo.full_capacity > 0 && fHasBattery) {
|
||||
fPercent = (double)fBatteryInfo.capacity / fBatteryInfo.full_capacity;
|
||||
@ -605,7 +628,12 @@ PowerStatusView::_GetBatteryInfo(int batteryID, battery_info* batteryInfo)
|
||||
*batteryInfo = info;
|
||||
first = false;
|
||||
} else {
|
||||
batteryInfo->state |= info.state;
|
||||
if ((batteryInfo->state & BATTERY_CRITICAL_STATE) == 0) {
|
||||
// don't propagate CRITICAL_STATE to the aggregate battery.
|
||||
// one battery charging means "the system is charging" but one battery having
|
||||
// been removed does not mean "the system has no battery"
|
||||
batteryInfo->state |= info.state;
|
||||
}
|
||||
batteryInfo->capacity += info.capacity;
|
||||
batteryInfo->full_capacity += info.full_capacity;
|
||||
batteryInfo->current_rate += info.current_rate;
|
||||
|
Loading…
Reference in New Issue
Block a user