mirror of
https://github.com/polybar/polybar.git
synced 2024-11-18 13:55:11 -05:00
feat(xwindow): Add label-empty
Allows for custom text, when window title is empty
This commit is contained in:
parent
8f75e685cc
commit
d31570fe2f
2 changed files with 13 additions and 3 deletions
|
@ -30,6 +30,11 @@ namespace modules {
|
|||
*/
|
||||
class xwindow_module : public static_module<xwindow_module>, public event_handler<evt::property_notify> {
|
||||
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<active_window> m_active;
|
||||
map<state, label_t> m_statelabels;
|
||||
label_t m_label;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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<active_window>(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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue