From dacf36b9816369ae7218c525fa37fe5c6cbf6cde Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Sat, 14 Jan 2017 00:27:29 +0100 Subject: [PATCH] refactor(ipc): Cleanup --- include/modules/ipc.hpp | 6 +++--- src/ipc.cpp | 2 +- src/modules/ipc.cpp | 18 +++++++++--------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/include/modules/ipc.hpp b/include/modules/ipc.hpp index 09312ccf..21b1c9b8 100644 --- a/include/modules/ipc.hpp +++ b/include/modules/ipc.hpp @@ -35,11 +35,11 @@ namespace modules { void on_message(const string& message); private: - static constexpr auto TAG_OUTPUT = ""; + static constexpr const char* TAG_OUTPUT{""}; vector> m_hooks; - string m_output; - size_t m_initial{0_z}; map m_actions; + string m_output; + size_t m_initial; }; } diff --git a/src/ipc.cpp b/src/ipc.cpp index c44a42a6..6b13b217 100644 --- a/src/ipc.cpp +++ b/src/ipc.cpp @@ -115,7 +115,7 @@ int main(int argc, char** argv) { } else if (!pid || pid == handle_pid) { string payload{ipc_type + ':' + ipc_payload}; file_descriptor fd(handle, O_WRONLY); - if (write(fd, payload.c_str(), payload.size()) == -1) { + if (write(fd, payload.c_str(), payload.size()) != -1) { log("Successfully wrote \"" + payload + "\" to \"" + handle + "\""); } else { log(E_WRITE, "Failed to write \"" + payload + "\" to \"" + handle + "\" (err: " + std::strerror(errno) + ")"); diff --git a/src/modules/ipc.cpp b/src/modules/ipc.cpp index d1ce3348..e653a26e 100644 --- a/src/modules/ipc.cpp +++ b/src/modules/ipc.cpp @@ -23,18 +23,18 @@ namespace modules { throw module_error("No hooks defined"); } - if ((m_initial = m_conf.get(name(), "initial", m_initial)) && m_initial > m_hooks.size()) { + if ((m_initial = m_conf.get(name(), "initial", 0_z)) && m_initial > m_hooks.size()) { throw module_error("Initial hook out of bounds (defined: " + to_string(m_hooks.size()) + ")"); } - m_actions[mousebtn::LEFT] = m_conf.get(name(), "click-left", ""s); - m_actions[mousebtn::MIDDLE] = m_conf.get(name(), "click-middle", ""s); - m_actions[mousebtn::RIGHT] = m_conf.get(name(), "click-right", ""s); - m_actions[mousebtn::SCROLL_UP] = m_conf.get(name(), "scroll-up", ""s); - m_actions[mousebtn::SCROLL_DOWN] = m_conf.get(name(), "scroll-down", ""s); - m_actions[mousebtn::DOUBLE_LEFT] = m_conf.get(name(), "double-click-left", ""s); - m_actions[mousebtn::DOUBLE_MIDDLE] = m_conf.get(name(), "double-click-middle", ""s); - m_actions[mousebtn::DOUBLE_RIGHT] = m_conf.get(name(), "double-click-right", ""s); + m_actions.emplace(make_pair(mousebtn::LEFT, m_conf.get(name(), "click-left", ""s))); + m_actions.emplace(make_pair(mousebtn::MIDDLE, m_conf.get(name(), "click-middle", ""s))); + m_actions.emplace(make_pair(mousebtn::RIGHT, m_conf.get(name(), "click-right", ""s))); + m_actions.emplace(make_pair(mousebtn::SCROLL_UP, m_conf.get(name(), "scroll-up", ""s))); + m_actions.emplace(make_pair(mousebtn::SCROLL_DOWN, m_conf.get(name(), "scroll-down", ""s))); + m_actions.emplace(make_pair(mousebtn::DOUBLE_LEFT, m_conf.get(name(), "double-click-left", ""s))); + m_actions.emplace(make_pair(mousebtn::DOUBLE_MIDDLE, m_conf.get(name(), "double-click-middle", ""s))); + m_actions.emplace(make_pair(mousebtn::DOUBLE_RIGHT, m_conf.get(name(), "double-click-right", ""s))); m_formatter->add(DEFAULT_FORMAT, TAG_OUTPUT, {TAG_OUTPUT}); }