dwm: Only initialize and use tags if label is used

Check the formatter for the tags label, and if it doesn't exist, there's no need
to initialize the tags array or listen to tag change events. Also, check to see
if tags are being used before trying to update them from the
on_monitor_focus_change function.
This commit is contained in:
Mihir Lad 2020-07-23 16:49:55 -04:00
parent b6c2dc0dee
commit 339d059441

View File

@ -70,6 +70,7 @@ namespace modules {
update_monitor_ref();
m_focused_client_id = m_bar_mon->clients.selected;
if (m_formatter->has(TAG_LABEL_TAGS)) {
// Initialize tags array
auto tags = m_ipc->get_tags();
for (dwmipc::Tag& t : *tags) {
@ -79,6 +80,11 @@ namespace modules {
m_tags.emplace_back(t.tag_name, t.bit_mask, state, move(label));
}
// This event is for keeping track of the tag states
m_ipc->on_tag_change = [this](const dwmipc::TagChangeEvent& ev) { this->on_tag_change(ev); };
m_ipc->subscribe(dwmipc::Event::TAG_CHANGE);
}
if (m_floating_label) {
update_floating_label();
}
@ -131,10 +137,6 @@ namespace modules {
this->on_monitor_focus_change(ev);
};
m_ipc->subscribe(dwmipc::Event::MONITOR_FOCUS_CHANGE);
// This event is for keeping track of the tag states
m_ipc->on_tag_change = [this](const dwmipc::TagChangeEvent& ev) { this->on_tag_change(ev); };
m_ipc->subscribe(dwmipc::Event::TAG_CHANGE);
} catch (const dwmipc::IPCError& err) {
throw module_error(err.what());
}
@ -430,8 +432,10 @@ namespace modules {
void dwm_module::on_monitor_focus_change(const dwmipc::MonitorFocusChangeEvent& ev) {
m_active_mon = &m_monitors->at(ev.new_mon_num);
if (m_formatter->has(TAG_LABEL_TAGS)) {
update_tag_labels();
}
}
void dwm_module::on_tag_change(const dwmipc::TagChangeEvent& ev) {
auto& mon = m_monitors->at(ev.monitor_num);