From d31570fe2f5803396df2fdbdfaee7195b0dded75 Mon Sep 17 00:00:00 2001 From: Keno Goertz Date: Mon, 2 Apr 2018 00:00:16 +0200 Subject: [PATCH] feat(xwindow): Add label-empty Allows for custom text, when window title is empty --- include/modules/xwindow.hpp | 6 ++++++ src/modules/xwindow.cpp | 10 +++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/include/modules/xwindow.hpp b/include/modules/xwindow.hpp index f5030ae7..4378ed5b 100644 --- a/include/modules/xwindow.hpp +++ b/include/modules/xwindow.hpp @@ -30,6 +30,11 @@ namespace modules { */ class xwindow_module : public static_module, public event_handler { public: + enum class state { + NONE, + ACTIVE, + EMPTY + }; explicit xwindow_module(const bar_settings&, string); void update(bool force = false); @@ -43,6 +48,7 @@ namespace modules { connection& m_connection; unique_ptr m_active; + map m_statelabels; label_t m_label; }; } diff --git a/src/modules/xwindow.cpp b/src/modules/xwindow.cpp index e49db956..fbc23af6 100644 --- a/src/modules/xwindow.cpp +++ b/src/modules/xwindow.cpp @@ -77,7 +77,8 @@ namespace modules { m_formatter->add(DEFAULT_FORMAT, TAG_LABEL, {TAG_LABEL}); if (m_formatter->has(TAG_LABEL)) { - m_label = load_optional_label(m_conf, name(), TAG_LABEL, "%title%"); + m_statelabels.emplace(state::ACTIVE, load_optional_label(m_conf, name(), "label", "%title%")); + m_statelabels.emplace(state::EMPTY, load_optional_label(m_conf, name(), "label-empty", "")); } } @@ -118,9 +119,12 @@ namespace modules { m_active = make_unique(m_connection, win); } - if (m_label) { + if (m_active) { + m_label = m_statelabels.at(state::ACTIVE)->clone(); m_label->reset_tokens(); - m_label->replace_token("%title%", m_active ? m_active->title() : ""); + m_label->replace_token("%title%", m_active->title()); + } else { + m_label = m_statelabels.at(state::EMPTY)->clone(); } }