From b74f3c7aaa9ebcc9052f2fd43bc98b6d82482e5a Mon Sep 17 00:00:00 2001 From: Prokhor40 Date: Fri, 2 Dec 2022 18:08:56 +0300 Subject: [PATCH] hide mdp/pulseaudio/sndio if text 'resolves' to be empty. --- src/modules/mpd/mpd.cpp | 21 ++++++++++++++++----- src/modules/pulseaudio.cpp | 10 ++++++++-- src/modules/sndio.cpp | 9 ++++++++- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/modules/mpd/mpd.cpp b/src/modules/mpd/mpd.cpp index 99ba2be..bc8809b 100644 --- a/src/modules/mpd/mpd.cpp +++ b/src/modules/mpd/mpd.cpp @@ -96,7 +96,13 @@ void waybar::modules::MPD::setLabel() { auto format = config_["format-disconnected"].isString() ? config_["format-disconnected"].asString() : "disconnected"; - label_.set_markup(format); + if(format.empty()) { + label_.set_markup(format); + label_.show(); + } else { + label_.hide(); + } + if (tooltipEnabled()) { std::string tooltip_format; @@ -107,9 +113,8 @@ void waybar::modules::MPD::setLabel() { label_.set_tooltip_text(tooltip_format); } return; - } else { - label_.get_style_context()->remove_class("disconnected"); } + label_.get_style_context()->remove_class("disconnected"); auto format = format_; Glib::ustring artist, album_artist, album, title; @@ -169,7 +174,7 @@ void waybar::modules::MPD::setLabel() { if (config_["title-len"].isInt()) title = title.substr(0, config_["title-len"].asInt()); try { - label_.set_markup(fmt::format( + auto text = fmt::format( format, fmt::arg("artist", artist.raw()), fmt::arg("albumArtist", album_artist.raw()), fmt::arg("album", album.raw()), fmt::arg("title", title.raw()), fmt::arg("date", date), fmt::arg("volume", volume), fmt::arg("elapsedTime", elapsedTime), @@ -177,7 +182,13 @@ void waybar::modules::MPD::setLabel() { fmt::arg("queueLength", queue_length), fmt::arg("stateIcon", stateIcon), fmt::arg("consumeIcon", consumeIcon), fmt::arg("randomIcon", randomIcon), fmt::arg("repeatIcon", repeatIcon), fmt::arg("singleIcon", singleIcon), - fmt::arg("filename", filename))); + fmt::arg("filename", filename)); + if(text.empty()) { + label_.hide(); + } else { + label_.show(); + label_.set_markup(text); + } } catch (fmt::format_error const& e) { spdlog::warn("mpd: format error: {}", e.what()); } diff --git a/src/modules/pulseaudio.cpp b/src/modules/pulseaudio.cpp index 4ba88de..8c70436 100644 --- a/src/modules/pulseaudio.cpp +++ b/src/modules/pulseaudio.cpp @@ -295,10 +295,16 @@ auto waybar::modules::Pulseaudio::update() -> void { } } format_source = fmt::format(format_source, fmt::arg("volume", source_volume_)); - label_.set_markup(fmt::format( + auto text = fmt::format( format, fmt::arg("desc", desc_), fmt::arg("volume", volume_), fmt::arg("format_source", format_source), fmt::arg("source_volume", source_volume_), - fmt::arg("source_desc", source_desc_), fmt::arg("icon", getIcon(volume_, getPulseIcon())))); + fmt::arg("source_desc", source_desc_), fmt::arg("icon", getIcon(volume_, getPulseIcon()))); + if(text.empty()) { + label_.hide(); + } else { + label_.set_markup(text); + label_.show(); + } getState(volume_); if (tooltipEnabled()) { diff --git a/src/modules/sndio.cpp b/src/modules/sndio.cpp index 92a8d3d..08331fc 100644 --- a/src/modules/sndio.cpp +++ b/src/modules/sndio.cpp @@ -110,7 +110,14 @@ auto Sndio::update() -> void { label_.get_style_context()->remove_class("muted"); } - label_.set_markup(fmt::format(format, fmt::arg("volume", vol), fmt::arg("raw_value", volume_))); + auto text = fmt::format(format, fmt::arg("volume", vol), fmt::arg("raw_value", volume_)); + if(text.empty()) { + label_.hide(); + } else { + label_.set_markup(text); + label_.show(); + } + ALabel::update(); }