feat(volume): Optional event handling #84

This commit is contained in:
Michael Carlberg 2017-04-02 18:12:07 +02:00
parent 68beb8d744
commit 02833b7871
3 changed files with 13 additions and 8 deletions

View File

@ -154,6 +154,8 @@ namespace modules {
vector<thread> m_threads;
thread m_mainthread;
bool m_handle_events{true};
private:
atomic<bool> m_enabled{true};
atomic<bool> m_changed{true};

View File

@ -17,7 +17,8 @@ namespace modules {
, m_conf(config::make())
, m_name("module/" + name)
, m_builder(make_unique<builder>(bar))
, m_formatter(make_unique<module_formatter>(m_conf, m_name)) {}
, m_formatter(make_unique<module_formatter>(m_conf, m_name))
, m_handle_events(m_conf.get(m_name, "handle-events", true)) {}
template <typename Impl>
module<Impl>::~module() noexcept {

View File

@ -189,9 +189,11 @@ namespace modules {
// 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_builder->cmd(mousebtn::SCROLL_DOWN, EVENT_VOLUME_DOWN);
if (m_handle_events) {
m_builder->cmd(mousebtn::LEFT, EVENT_TOGGLE_MUTE);
m_builder->cmd(mousebtn::SCROLL_UP, EVENT_VOLUME_UP);
m_builder->cmd(mousebtn::SCROLL_DOWN, EVENT_VOLUME_DOWN);
}
m_builder->append(output);
@ -216,11 +218,11 @@ namespace modules {
}
bool volume_module::input(string&& cmd) {
if (cmd.compare(0, 3, EVENT_PREFIX) != 0) {
if (!m_handle_events) {
return false;
}
if (!m_mixer[mixer::MASTER]) {
} else if (cmd.compare(0, 3, EVENT_PREFIX) != 0) {
return false;
} else if (!m_mixer[mixer::MASTER]) {
return false;
}