From e4f35d7ca09d7194cb79086b77241959cdfa9e37 Mon Sep 17 00:00:00 2001 From: Alexis Date: Thu, 16 Aug 2018 17:09:51 +0200 Subject: [PATCH] fea(custom): add max-length config --- resources/config | 1 + src/modules/custom.cpp | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/resources/config b/resources/config index cadaf897..2069499a 100644 --- a/resources/config +++ b/resources/config @@ -39,6 +39,7 @@ }, "custom/spotify": { "format": " {}", + "max-length": 40, "exec": "$HOME/.bin/mediaplayer.sh" } } diff --git a/src/modules/custom.cpp b/src/modules/custom.cpp index 7beb10b5..1b28115a 100644 --- a/src/modules/custom.cpp +++ b/src/modules/custom.cpp @@ -7,6 +7,10 @@ waybar::modules::Custom::Custom(const std::string &name, Json::Value config) if (!config_["exec"]) { throw std::runtime_error(name_ + " has no exec path."); } + if (config_["max-length"]) { + label_.set_max_width_chars(config_["max-length"].asUInt()); + label_.set_ellipsize(Pango::EllipsizeMode::ELLIPSIZE_END); + } uint32_t interval = config_["interval"] ? config_["inveral"].asUInt() : 30; thread_ = [this, interval] { Glib::signal_idle().connect_once(sigc::mem_fun(*this, &Custom::update)); @@ -42,7 +46,9 @@ auto waybar::modules::Custom::update() -> void } else { label_.set_name("custom-" + name_); auto format = config_["format"] ? config_["format"].asString() : "{}"; - label_.set_text(fmt::format(format, output)); + auto str = fmt::format(format, output); + label_.set_text(str); + label_.set_tooltip_text(str); label_.show(); } }