From 38545155219fabf1dd23deb8bb2e02731cd912ab Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Mon, 5 Dec 2016 05:32:10 +0100 Subject: [PATCH] fix: Wrap format pre/suffix within cmd --- include/components/builder.hpp | 2 +- src/components/builder.cpp | 6 ++++-- src/modules/ipc.cpp | 7 ++++++- src/modules/script.cpp | 6 +++++- src/modules/text.cpp | 7 ++++++- src/modules/volume.cpp | 16 ++++++++-------- src/modules/xbacklight.cpp | 15 ++++++++------- 7 files changed, 38 insertions(+), 21 deletions(-) diff --git a/include/components/builder.hpp b/include/components/builder.hpp index 3a41d382..d9533286 100644 --- a/include/components/builder.hpp +++ b/include/components/builder.hpp @@ -55,7 +55,7 @@ class builder { void underline(const string& color = ""); void underline_close(); void cmd(mousebtn index, string action, bool condition = true); - void cmd_close(); + void cmd_close(bool condition = true); protected: string background_hex(); diff --git a/src/components/builder.cpp b/src/components/builder.cpp index 7bcc81d6..c1b29af3 100644 --- a/src/components/builder.cpp +++ b/src/components/builder.cpp @@ -503,8 +503,10 @@ void builder::cmd(mousebtn index, string action, bool condition) { /** * Close command tag */ -void builder::cmd_close() { - tag_close(syntaxtag::A); +void builder::cmd_close(bool condition) { + if (condition) { + tag_close(syntaxtag::A); + } } /** diff --git a/src/modules/ipc.cpp b/src/modules/ipc.cpp index 19291fdb..10797ddd 100644 --- a/src/modules/ipc.cpp +++ b/src/modules/ipc.cpp @@ -39,6 +39,11 @@ namespace modules { * Wrap the output with defined mouse actions */ string ipc_module::get_output() { + // Get the module output early so that + // the format prefix/suffix also gets wrapper + // with the cmd handlers + string output{module::get_output()}; + if (!m_actions[mousebtn::LEFT].empty()) { m_builder->cmd(mousebtn::LEFT, m_actions[mousebtn::LEFT]); } @@ -55,7 +60,7 @@ namespace modules { m_builder->cmd(mousebtn::SCROLL_DOWN, m_actions[mousebtn::SCROLL_DOWN]); } - m_builder->append(module::get_output()); + m_builder->append(output); return m_builder->flush(); } diff --git a/src/modules/script.cpp b/src/modules/script.cpp index 8447ef50..8d0ce162 100644 --- a/src/modules/script.cpp +++ b/src/modules/script.cpp @@ -123,13 +123,17 @@ namespace modules { m_output += m_ellipsis ? "..." : ""; } + auto counter_str = to_string(m_counter); + string output{module::get_output()}; + OUTPUT_ACTION(mousebtn::LEFT); OUTPUT_ACTION(mousebtn::MIDDLE); OUTPUT_ACTION(mousebtn::RIGHT); OUTPUT_ACTION(mousebtn::SCROLL_UP); OUTPUT_ACTION(mousebtn::SCROLL_DOWN); - m_builder->append(module::get_output()); + + m_builder->append(output); return m_builder->flush(); } diff --git a/src/modules/text.cpp b/src/modules/text.cpp index 6f661ffb..42e0c8e4 100644 --- a/src/modules/text.cpp +++ b/src/modules/text.cpp @@ -25,6 +25,11 @@ namespace modules { } string text_module::get_output() { + // Get the module output early so that + // the format prefix/suffix also gets wrapper + // with the cmd handlers + string output{module::get_output()}; + auto click_left = m_conf.get(name(), "click-left", ""); auto click_middle = m_conf.get(name(), "click-middle", ""); auto click_right = m_conf.get(name(), "click-right", ""); @@ -47,7 +52,7 @@ namespace modules { m_builder->cmd(mousebtn::SCROLL_DOWN, scroll_down); } - m_builder->append(module::get_output()); + m_builder->append(output); return m_builder->flush(); } diff --git a/src/modules/volume.cpp b/src/modules/volume.cpp index 7974f598..8615c2c3 100644 --- a/src/modules/volume.cpp +++ b/src/modules/volume.cpp @@ -174,16 +174,16 @@ namespace modules { } string volume_module::get_output() { + // Get the module output early so that + // the format prefix/suffix also gets wrapper + // with the cmd handlers + string output{module::get_output()}; + m_builder->cmd(mousebtn::LEFT, EVENT_TOGGLE_MUTE); + m_builder->cmd(mousebtn::SCROLL_UP, EVENT_VOLUME_UP, !m_muted && m_volume < 100); + m_builder->cmd(mousebtn::SCROLL_DOWN, EVENT_VOLUME_DOWN, !m_muted && m_volume > 0); - if (!m_muted && m_volume < 100) { - m_builder->cmd(mousebtn::SCROLL_UP, EVENT_VOLUME_UP); - } - if (!m_muted && m_volume > 0) { - m_builder->cmd(mousebtn::SCROLL_DOWN, EVENT_VOLUME_DOWN); - } - - m_builder->append(module::get_output()); + m_builder->append(output); return m_builder->flush(); } diff --git a/src/modules/xbacklight.cpp b/src/modules/xbacklight.cpp index 1dcd085b..061e66ca 100644 --- a/src/modules/xbacklight.cpp +++ b/src/modules/xbacklight.cpp @@ -137,14 +137,15 @@ namespace modules { * Generate the module output */ string xbacklight_module::get_output() { - if (m_scroll && m_percentage < 100) { - m_builder->cmd(mousebtn::SCROLL_UP, EVENT_SCROLLUP); - } - if (m_scroll && m_percentage > 0) { - m_builder->cmd(mousebtn::SCROLL_DOWN, EVENT_SCROLLDOWN); - } + // Get the module output early so that + // the format prefix/suffix also gets wrapper + // with the cmd handlers + string output{module::get_output()}; - m_builder->append(static_module::get_output()); + m_builder->cmd(mousebtn::SCROLL_UP, EVENT_SCROLLUP, m_scroll && m_percentage < 100); + m_builder->cmd(mousebtn::SCROLL_DOWN, EVENT_SCROLLDOWN, m_scroll && m_percentage > 0); + + m_builder->append(output); return m_builder->flush(); }