From 02833b787171a238266552871af485bdae6f20f1 Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Sun, 2 Apr 2017 18:12:07 +0200 Subject: [PATCH] feat(volume): Optional event handling #84 --- include/modules/meta/base.hpp | 2 ++ include/modules/meta/base.inl | 3 ++- src/modules/volume.cpp | 16 +++++++++------- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/include/modules/meta/base.hpp b/include/modules/meta/base.hpp index ca4dae42..2659ce11 100644 --- a/include/modules/meta/base.hpp +++ b/include/modules/meta/base.hpp @@ -154,6 +154,8 @@ namespace modules { vector m_threads; thread m_mainthread; + bool m_handle_events{true}; + private: atomic m_enabled{true}; atomic m_changed{true}; diff --git a/include/modules/meta/base.inl b/include/modules/meta/base.inl index efc35b19..2be51ccb 100644 --- a/include/modules/meta/base.inl +++ b/include/modules/meta/base.inl @@ -17,7 +17,8 @@ namespace modules { , m_conf(config::make()) , m_name("module/" + name) , m_builder(make_unique(bar)) - , m_formatter(make_unique(m_conf, m_name)) {} + , m_formatter(make_unique(m_conf, m_name)) + , m_handle_events(m_conf.get(m_name, "handle-events", true)) {} template module::~module() noexcept { diff --git a/src/modules/volume.cpp b/src/modules/volume.cpp index 5ad0a116..1ce45df6 100644 --- a/src/modules/volume.cpp +++ b/src/modules/volume.cpp @@ -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; }