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(); } }