mirror of
https://github.com/scorpion-26/gBar.git
synced 2024-11-21 18:52:49 +00:00
Add battery charging indication
This commit is contained in:
parent
74f8df49f3
commit
6e71e8a4f3
5 changed files with 44 additions and 0 deletions
|
@ -198,6 +198,10 @@ highlight {
|
|||
font-size: 16px;
|
||||
}
|
||||
|
||||
.battery-charging {
|
||||
color: #ffb86c;
|
||||
}
|
||||
|
||||
.network-data-text {
|
||||
color: #50fa7b;
|
||||
font-size: 16px;
|
||||
|
|
|
@ -229,11 +229,16 @@ highlight {
|
|||
background-color: $inactive;
|
||||
font-size: $textsize;
|
||||
}
|
||||
|
||||
.battery-data-text {
|
||||
color: $pink;
|
||||
font-size: $textsize;
|
||||
}
|
||||
|
||||
.battery-charging {
|
||||
color: $orange
|
||||
}
|
||||
|
||||
.network-data-text {
|
||||
color: $green;
|
||||
font-size: $textsize;
|
||||
|
|
15
src/Bar.cpp
15
src/Bar.cpp
|
@ -42,6 +42,7 @@ namespace Bar
|
|||
}
|
||||
|
||||
static Text* batteryText;
|
||||
static bool wasCharging = false;
|
||||
static TimerResult UpdateBattery(Sensor& sensor)
|
||||
{
|
||||
double percentage = System::GetBatteryPercentage();
|
||||
|
@ -56,6 +57,20 @@ namespace Bar
|
|||
batteryText->SetText(text);
|
||||
}
|
||||
sensor.SetValue(percentage);
|
||||
|
||||
bool isCharging = System::IsBatteryCharging();
|
||||
if (isCharging && !wasCharging && sensor.Get() != nullptr)
|
||||
{
|
||||
sensor.AddClass("battery-charging");
|
||||
batteryText->AddClass("battery-charging");
|
||||
wasCharging = true;
|
||||
}
|
||||
else if (!isCharging && wasCharging)
|
||||
{
|
||||
sensor.RemoveClass("battery-charging");
|
||||
batteryText->RemoveClass("battery-charging");
|
||||
wasCharging = false;
|
||||
}
|
||||
return TimerResult::Ok;
|
||||
}
|
||||
|
||||
|
|
|
@ -89,6 +89,25 @@ namespace System
|
|||
return temp;
|
||||
}
|
||||
|
||||
bool IsBatteryCharging()
|
||||
{
|
||||
std::ifstream batteryStatus(Config::Get().batteryFolder + "/status");
|
||||
if (batteryStatus.is_open())
|
||||
{
|
||||
std::string status;
|
||||
std::getline(batteryStatus, status);
|
||||
if (status == "Charging" || status == "Full")
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
double GetBatteryPercentage()
|
||||
{
|
||||
std::ifstream fullChargeFile(Config::Get().batteryFolder + "/charge_full");
|
||||
|
|
|
@ -11,6 +11,7 @@ namespace System
|
|||
// Tctl
|
||||
double GetCPUTemp();
|
||||
|
||||
bool IsBatteryCharging();
|
||||
double GetBatteryPercentage();
|
||||
|
||||
struct RAMInfo
|
||||
|
|
Loading…
Reference in a new issue