diff --git a/include/modules/dwm.hpp b/include/modules/dwm.hpp index d081d3ec..ff108d26 100644 --- a/include/modules/dwm.hpp +++ b/include/modules/dwm.hpp @@ -67,6 +67,7 @@ namespace modules { shared_ptr> m_monitors; unsigned int m_active_mon_num = 0; unsigned int m_bar_mon = 0; + unsigned int m_focused_client_id = 0; std::unordered_map m_state_labels; vector m_tags; diff --git a/src/modules/dwm.cpp b/src/modules/dwm.cpp index ea80bba4..4cdb7652 100644 --- a/src/modules/dwm.cpp +++ b/src/modules/dwm.cpp @@ -111,19 +111,28 @@ namespace modules { return; } + m_focused_client_id = ev.new_win_id; m_title_label->reset_tokens(); - if (ev.new_win_id != 0) { - auto focused_client = m_ipc->get_client(ev.new_win_id); + if (m_focused_client_id != 0) { + auto focused_client = m_ipc->get_client(m_focused_client_id); m_title_label->replace_token("%title%", focused_client->name); } else { m_title_label->replace_token("%title%", ""); } }; + m_ipc->on_focused_title_change = [this](const dwmipc::FocusedTitleChangeEvent& ev) { + if (ev.monitor_num == m_bar_mon && ev.client_window_id == m_focused_client_id) { + m_title_label->reset_tokens(); + m_title_label->replace_token("%title%", ev.new_name); + } + }; + m_ipc->subscribe(dwmipc::Event::LAYOUT_CHANGE); m_ipc->subscribe(dwmipc::Event::CLIENT_FOCUS_CHANGE); m_ipc->subscribe(dwmipc::Event::TAG_CHANGE); m_ipc->subscribe(dwmipc::Event::MONITOR_FOCUS_CHANGE); + m_ipc->subscribe(dwmipc::Event::FOCUSED_TITLE_CHANGE); } catch (const dwmipc::IPCError& err) { throw module_error(err.what()); }