From 05effad18bf12fb0de92369003703a263872b39e Mon Sep 17 00:00:00 2001 From: Erik Reider <35975961+ErikReider@users.noreply.github.com> Date: Sat, 19 Mar 2022 19:22:00 +0100 Subject: [PATCH] Added CSS status classes --- include/modules/upower/upower.hpp | 3 +++ man/waybar-upower.5.scd | 7 +++++++ src/modules/upower/upower.cpp | 27 +++++++++++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/include/modules/upower/upower.hpp b/include/modules/upower/upower.hpp index c73a0728..7907027b 100644 --- a/include/modules/upower/upower.hpp +++ b/include/modules/upower/upower.hpp @@ -37,6 +37,8 @@ class UPower : public AModule { void removeDevices(); bool show_tooltip_callback(int, int, bool, const Glib::RefPtr &tooltip); + const std::string getDeviceStatus(UpDeviceState &state); + Gtk::Box box_; Gtk::Image icon_; Gtk::Label label_; @@ -54,6 +56,7 @@ class UPower : public AModule { guint login1_id; GDBusConnection *login1_connection; UPowerTooltip *upower_tooltip; + std::string lastStatus; }; } // namespace waybar::modules::upower diff --git a/man/waybar-upower.5.scd b/man/waybar-upower.5.scd index b16bca14..94ba8660 100644 --- a/man/waybar-upower.5.scd +++ b/man/waybar-upower.5.scd @@ -43,3 +43,10 @@ compatible devices in the tooltip. } ``` + +# STYLE + +- *#upower* +- *#upower.charging* +- *#upower.discharging* +- *#upower.unknown-status* diff --git a/src/modules/upower/upower.cpp b/src/modules/upower/upower.cpp index aef874b9..0cbe0107 100644 --- a/src/modules/upower/upower.cpp +++ b/src/modules/upower/upower.cpp @@ -198,6 +198,21 @@ bool UPower::show_tooltip_callback(int, int, bool, const Glib::RefPtr void { std::lock_guard guard(m_Mutex); @@ -230,6 +245,18 @@ auto UPower::update() -> void { uint tooltipCount = 0; + // CSS status class + const std::string status = getDeviceStatus(state); + // Remove last status if it exists + if (!lastStatus.empty() && box_.get_style_context()->has_class(lastStatus)) { + box_.get_style_context()->remove_class(lastStatus); + } + // Add the new status class to the Box + if (!box_.get_style_context()->has_class(status)) { + box_.get_style_context()->add_class(status); + } + lastStatus = status; + if (devices.size() == 0 && !displayDeviceValid && hideIfEmpty) { event_box_.set_visible(false); goto update;