mirror of
https://github.com/scorpion-26/gBar.git
synced 2024-11-21 18:52:49 +00:00
Add a warning color when battery is low
The threshold is controlled via BatteryWarnThreshold and the color via battery-warning
This commit is contained in:
parent
e717e0e7ad
commit
12d1c59ef0
5 changed files with 27 additions and 9 deletions
|
@ -231,7 +231,11 @@ highlight {
|
||||||
}
|
}
|
||||||
|
|
||||||
.battery-charging {
|
.battery-charging {
|
||||||
color: $orange
|
color: $orange;
|
||||||
|
}
|
||||||
|
|
||||||
|
.battery-warning {
|
||||||
|
color: $red;
|
||||||
}
|
}
|
||||||
|
|
||||||
.network-data-text {
|
.network-data-text {
|
||||||
|
|
|
@ -39,6 +39,9 @@ ExitCommand: killall Hyprland
|
||||||
# The folder, where the battery sensors reside
|
# The folder, where the battery sensors reside
|
||||||
BatteryFolder: /sys/class/power_supply/BAT1
|
BatteryFolder: /sys/class/power_supply/BAT1
|
||||||
|
|
||||||
|
# Threshold, when the battery is considered low and a different color (as specified by the 'battery-warning' CSS property) is applied
|
||||||
|
BatteryWarnThreshold: 20
|
||||||
|
|
||||||
# The partition to monitor with disk sensor
|
# The partition to monitor with disk sensor
|
||||||
DiskPartition: /
|
DiskPartition: /
|
||||||
|
|
||||||
|
|
25
src/Bar.cpp
25
src/Bar.cpp
|
@ -107,6 +107,20 @@ namespace Bar
|
||||||
batteryText->RemoveClass("battery-charging");
|
batteryText->RemoveClass("battery-charging");
|
||||||
wasCharging = false;
|
wasCharging = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add warning if color falls below threshold
|
||||||
|
if (!isCharging && percentage * 100 <= Config::Get().batteryWarnThreshold)
|
||||||
|
{
|
||||||
|
sensor.AddClass("battery-warning");
|
||||||
|
if (batteryText)
|
||||||
|
batteryText->AddClass("battery-warning");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sensor.RemoveClass("battery-warning");
|
||||||
|
if (batteryText)
|
||||||
|
batteryText->RemoveClass("battery-warning");
|
||||||
|
}
|
||||||
return TimerResult::Ok;
|
return TimerResult::Ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -417,8 +431,7 @@ namespace Bar
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void WidgetSensor(Widget& parent, TimerCallback<Sensor>&& callback, const std::string& sensorName, Text*& textPtr,
|
void WidgetSensor(Widget& parent, TimerCallback<Sensor>&& callback, const std::string& sensorName, Text*& textPtr, Side side)
|
||||||
Side side)
|
|
||||||
{
|
{
|
||||||
auto eventBox = Widget::Create<EventBox>();
|
auto eventBox = Widget::Create<EventBox>();
|
||||||
Utils::SetTransform(*eventBox, {-1, false, SideToAlignment(side)});
|
Utils::SetTransform(*eventBox, {-1, false, SideToAlignment(side)});
|
||||||
|
@ -571,12 +584,8 @@ namespace Bar
|
||||||
box->AddClass("widget");
|
box->AddClass("widget");
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case AudioType::Input:
|
case AudioType::Input: box->AddClass("mic"); break;
|
||||||
box->AddClass("mic");
|
case AudioType::Output: box->AddClass("audio"); break;
|
||||||
break;
|
|
||||||
case AudioType::Output:
|
|
||||||
box->AddClass("audio");
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::SetTransform(*box, {-1, false, SideToAlignment(side)});
|
Utils::SetTransform(*box, {-1, false, SideToAlignment(side)});
|
||||||
|
|
|
@ -294,6 +294,7 @@ void Config::Load(const std::string& overrideConfigLocation)
|
||||||
AddConfigVar("AudioScrollSpeed", config.audioScrollSpeed, lineView, foundProperty);
|
AddConfigVar("AudioScrollSpeed", config.audioScrollSpeed, lineView, foundProperty);
|
||||||
AddConfigVar("SensorSize", config.sensorSize, lineView, foundProperty);
|
AddConfigVar("SensorSize", config.sensorSize, lineView, foundProperty);
|
||||||
AddConfigVar("NetworkIconSize", config.networkIconSize, lineView, foundProperty);
|
AddConfigVar("NetworkIconSize", config.networkIconSize, lineView, foundProperty);
|
||||||
|
AddConfigVar("BatteryWarnThreshold", config.batteryWarnThreshold, lineView, foundProperty);
|
||||||
|
|
||||||
AddConfigVar("AudioMinVolume", config.audioMinVolume, lineView, foundProperty);
|
AddConfigVar("AudioMinVolume", config.audioMinVolume, lineView, foundProperty);
|
||||||
AddConfigVar("AudioMaxVolume", config.audioMaxVolume, lineView, foundProperty);
|
AddConfigVar("AudioMaxVolume", config.audioMaxVolume, lineView, foundProperty);
|
||||||
|
|
|
@ -78,6 +78,7 @@ public:
|
||||||
uint32_t numWorkspaces = 9; // How many workspaces to display
|
uint32_t numWorkspaces = 9; // How many workspaces to display
|
||||||
uint32_t sensorSize = 24; // The size of the circular sensors
|
uint32_t sensorSize = 24; // The size of the circular sensors
|
||||||
uint32_t networkIconSize = 24; // The size of the two network arrows
|
uint32_t networkIconSize = 24; // The size of the two network arrows
|
||||||
|
uint32_t batteryWarnThreshold = 20; // Threshold for color change when on battery
|
||||||
|
|
||||||
char location = 'T'; // The Location of the bar. Can be L,R,T,B
|
char location = 'T'; // The Location of the bar. Can be L,R,T,B
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue