From e06316c80b04c58638616094f1dda9ad27393914 Mon Sep 17 00:00:00 2001 From: Erik Reider <35975961+ErikReider@users.noreply.github.com> Date: Sun, 20 Mar 2022 00:36:53 +0100 Subject: [PATCH] Only set label text if string doesn't only contain spaces --- src/modules/upower/upower.cpp | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/modules/upower/upower.cpp b/src/modules/upower/upower.cpp index c5c51d9e..9e4b8ee1 100644 --- a/src/modules/upower/upower.cpp +++ b/src/modules/upower/upower.cpp @@ -2,6 +2,7 @@ #include +#include #include #include "gtkmm/icontheme.h" @@ -312,9 +313,30 @@ auto UPower::update() -> void { } // Label format - label_.set_markup(fmt::format(showAltText ? format_alt : format, - fmt::arg("percentage", percentString), - fmt::arg("time", time_format))); + std::string time_format = ""; + switch (state) { + case UP_DEVICE_STATE_CHARGING: + case UP_DEVICE_STATE_PENDING_CHARGE: + time_format = timeToString(time_full); + break; + case UP_DEVICE_STATE_DISCHARGING: + case UP_DEVICE_STATE_PENDING_DISCHARGE: + time_format = timeToString(time_empty); + break; + default: + break; + } + std::string label_format = fmt::format(showAltText ? format_alt : format, + fmt::arg("percentage", percentString), + fmt::arg("time", time_format)); + // Only set the label text if it doesn't only contain spaces + bool onlySpaces = true; + for (auto& character : label_format) { + if (character == ' ') continue; + onlySpaces = false; + break; + } + label_.set_markup(onlySpaces ? "" : label_format); // Set icon if (!Gtk::IconTheme::get_default()->has_icon(icon_name)) {