Merge pull request #3028 from bartelsielski/upower-warning_level
Upower warning levelpull/3044/merge
commit
cc084f5f86
|
@ -71,6 +71,7 @@ class UPower : public AModule {
|
||||||
GDBusConnection *login1_connection;
|
GDBusConnection *login1_connection;
|
||||||
std::unique_ptr<UPowerTooltip> upower_tooltip;
|
std::unique_ptr<UPowerTooltip> upower_tooltip;
|
||||||
std::string lastStatus;
|
std::string lastStatus;
|
||||||
|
const char *lastWarningLevel;
|
||||||
bool showAltText;
|
bool showAltText;
|
||||||
bool showIcon = true;
|
bool showIcon = true;
|
||||||
bool upowerRunning;
|
bool upowerRunning;
|
||||||
|
|
|
@ -8,6 +8,17 @@
|
||||||
#include "gtkmm/tooltip.h"
|
#include "gtkmm/tooltip.h"
|
||||||
#include "util/gtk_icon.hpp"
|
#include "util/gtk_icon.hpp"
|
||||||
|
|
||||||
|
static const char* getDeviceWarningLevel(UpDeviceLevel level) {
|
||||||
|
switch (level) {
|
||||||
|
case UP_DEVICE_LEVEL_CRITICAL:
|
||||||
|
return "critical";
|
||||||
|
case UP_DEVICE_LEVEL_LOW:
|
||||||
|
return "low";
|
||||||
|
default:
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
namespace waybar::modules::upower {
|
namespace waybar::modules::upower {
|
||||||
UPower::UPower(const std::string& id, const Json::Value& config)
|
UPower::UPower(const std::string& id, const Json::Value& config)
|
||||||
: AModule(config, "upower", id),
|
: AModule(config, "upower", id),
|
||||||
|
@ -304,11 +315,12 @@ auto UPower::update() -> void {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
UpDeviceKind kind;
|
UpDeviceKind kind = UP_DEVICE_KIND_UNKNOWN;
|
||||||
UpDeviceState state;
|
UpDeviceState state = UP_DEVICE_STATE_UNKNOWN;
|
||||||
double percentage;
|
UpDeviceLevel level = UP_DEVICE_LEVEL_UNKNOWN;
|
||||||
gint64 time_empty;
|
double percentage = 0.0;
|
||||||
gint64 time_full;
|
gint64 time_empty = 0;
|
||||||
|
gint64 time_full = 0;
|
||||||
gchar* icon_name{(char*)'\0'};
|
gchar* icon_name{(char*)'\0'};
|
||||||
std::string percentString{""};
|
std::string percentString{""};
|
||||||
std::string time_format{""};
|
std::string time_format{""};
|
||||||
|
@ -318,7 +330,7 @@ auto UPower::update() -> void {
|
||||||
if (displayDevice) {
|
if (displayDevice) {
|
||||||
g_object_get(displayDevice, "kind", &kind, "state", &state, "percentage", &percentage,
|
g_object_get(displayDevice, "kind", &kind, "state", &state, "percentage", &percentage,
|
||||||
"icon-name", &icon_name, "time-to-empty", &time_empty, "time-to-full", &time_full,
|
"icon-name", &icon_name, "time-to-empty", &time_empty, "time-to-full", &time_full,
|
||||||
NULL);
|
"warning-level", &level, NULL);
|
||||||
/* Every Device which is handled by Upower and which is not
|
/* Every Device which is handled by Upower and which is not
|
||||||
* UP_DEVICE_KIND_UNKNOWN (0) or UP_DEVICE_KIND_LINE_POWER (1) is a Battery
|
* UP_DEVICE_KIND_UNKNOWN (0) or UP_DEVICE_KIND_LINE_POWER (1) is a Battery
|
||||||
*/
|
*/
|
||||||
|
@ -338,6 +350,15 @@ auto UPower::update() -> void {
|
||||||
}
|
}
|
||||||
lastStatus = status;
|
lastStatus = status;
|
||||||
|
|
||||||
|
const char* warning_level = getDeviceWarningLevel(level);
|
||||||
|
if (lastWarningLevel && box_.get_style_context()->has_class(lastWarningLevel)) {
|
||||||
|
box_.get_style_context()->remove_class(lastWarningLevel);
|
||||||
|
}
|
||||||
|
if (warning_level && !box_.get_style_context()->has_class(warning_level)) {
|
||||||
|
box_.get_style_context()->add_class(warning_level);
|
||||||
|
}
|
||||||
|
lastWarningLevel = warning_level;
|
||||||
|
|
||||||
if (devices.size() == 0 && !displayDeviceValid && hideIfEmpty) {
|
if (devices.size() == 0 && !displayDeviceValid && hideIfEmpty) {
|
||||||
event_box_.set_visible(false);
|
event_box_.set_visible(false);
|
||||||
// Call parent update
|
// Call parent update
|
||||||
|
|
Loading…
Reference in New Issue