From 97fa7052fe9aad3434efb31d3f74a15e007bedbf Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Fri, 23 Dec 2016 15:54:06 +0100 Subject: [PATCH] refactor(clang-tidy): Apply fixes --- include/components/logger.hpp | 2 +- include/modules/ipc.hpp | 1 + include/modules/menu.hpp | 1 + include/modules/meta/event_module.hpp | 10 +-- include/modules/meta/inotify_module.hpp | 10 +-- include/modules/meta/static_module.hpp | 1 + include/modules/mpd.hpp | 82 ++++++++++++------------- include/modules/text.hpp | 1 + src/modules/mpd.cpp | 8 +-- src/modules/xbacklight.cpp | 3 - src/modules/xkeyboard.cpp | 2 - src/modules/xwindow.cpp | 3 - src/modules/xworkspaces.cpp | 2 - src/utils/concurrency.cpp | 3 +- src/x11/fonts.cpp | 4 +- 15 files changed, 60 insertions(+), 73 deletions(-) diff --git a/include/components/logger.hpp b/include/components/logger.hpp index d9c37f49..6fdec973 100644 --- a/include/components/logger.hpp +++ b/include/components/logger.hpp @@ -82,7 +82,7 @@ class logger { /** * Convert string */ - const char* convert(string arg) const; + const char* convert(string arg) const; // NOLINT /** * Convert thread id diff --git a/include/modules/ipc.hpp b/include/modules/ipc.hpp index b5622a0b..ca463430 100644 --- a/include/modules/ipc.hpp +++ b/include/modules/ipc.hpp @@ -28,6 +28,7 @@ namespace modules { public: explicit ipc_module(const bar_settings&, string); + void update() {} string get_output(); bool build(builder* builder, const string& tag) const; void on_message(const ipc_hook& message); diff --git a/include/modules/menu.hpp b/include/modules/menu.hpp index a73376f8..ad7cc6d5 100644 --- a/include/modules/menu.hpp +++ b/include/modules/menu.hpp @@ -21,6 +21,7 @@ namespace modules { explicit menu_module(const bar_settings&, string); bool build(builder* builder, const string& tag) const; + void update() {} protected: bool on(const input_event_t& evt); diff --git a/include/modules/meta/event_module.hpp b/include/modules/meta/event_module.hpp index d40c92df..bf051bc6 100644 --- a/include/modules/meta/event_module.hpp +++ b/include/modules/meta/event_module.hpp @@ -17,13 +17,9 @@ namespace modules { protected: void runner() { try { - // Warm up module output and - // send broadcast before entering - // the update loop - if (this->running()) { - CAST_MOD(Impl)->update(); - CAST_MOD(Impl)->broadcast(); - } + // Warm up the module output before entering the loop + CAST_MOD(Impl)->update(); + CAST_MOD(Impl)->broadcast(); while (this->running()) { CAST_MOD(Impl)->idle(); diff --git a/include/modules/meta/inotify_module.hpp b/include/modules/meta/inotify_module.hpp index 36149170..2c95535f 100644 --- a/include/modules/meta/inotify_module.hpp +++ b/include/modules/meta/inotify_module.hpp @@ -18,13 +18,9 @@ namespace modules { protected: void runner() { try { - // Warm up module output and - // send broadcast before entering - // the update loop - if (this->running()) { - CAST_MOD(Impl)->on_event(nullptr); - CAST_MOD(Impl)->broadcast(); - } + // Warm up module output before entering the loop + CAST_MOD(Impl)->on_event(nullptr); + CAST_MOD(Impl)->broadcast(); while (this->running()) { CAST_MOD(Impl)->poll_events(); diff --git a/include/modules/meta/static_module.hpp b/include/modules/meta/static_module.hpp index f926c934..f22da3b1 100644 --- a/include/modules/meta/static_module.hpp +++ b/include/modules/meta/static_module.hpp @@ -11,6 +11,7 @@ namespace modules { using module::module; void start() { + CAST_MOD(Impl)->update(); CAST_MOD(Impl)->broadcast(); } diff --git a/include/modules/mpd.hpp b/include/modules/mpd.hpp index a93c5815..487f2e90 100644 --- a/include/modules/mpd.hpp +++ b/include/modules/mpd.hpp @@ -30,35 +30,49 @@ namespace modules { bool on(const input_event_t& evt); private: - static constexpr auto FORMAT_ONLINE = "format-online"; - static constexpr auto TAG_BAR_PROGRESS = ""; - static constexpr auto TAG_TOGGLE = ""; - static constexpr auto TAG_TOGGLE_STOP = ""; - static constexpr auto TAG_LABEL_SONG = ""; - static constexpr auto TAG_LABEL_TIME = ""; - static constexpr auto TAG_ICON_RANDOM = ""; - static constexpr auto TAG_ICON_REPEAT = ""; - static constexpr auto TAG_ICON_REPEAT_ONE = ""; - static constexpr auto TAG_ICON_PREV = ""; - static constexpr auto TAG_ICON_STOP = ""; - static constexpr auto TAG_ICON_PLAY = ""; - static constexpr auto TAG_ICON_PAUSE = ""; - static constexpr auto TAG_ICON_NEXT = ""; - static constexpr auto TAG_ICON_SEEKB = ""; - static constexpr auto TAG_ICON_SEEKF = ""; + static constexpr const char* FORMAT_ONLINE{"format-online"}; + static constexpr const char* TAG_BAR_PROGRESS{""}; + static constexpr const char* TAG_TOGGLE{""}; + static constexpr const char* TAG_TOGGLE_STOP{""}; + static constexpr const char* TAG_LABEL_SONG{""}; + static constexpr const char* TAG_LABEL_TIME{""}; + static constexpr const char* TAG_ICON_RANDOM{""}; + static constexpr const char* TAG_ICON_REPEAT{""}; + static constexpr const char* TAG_ICON_REPEAT_ONE{""}; + static constexpr const char* TAG_ICON_PREV{""}; + static constexpr const char* TAG_ICON_STOP{""}; + static constexpr const char* TAG_ICON_PLAY{""}; + static constexpr const char* TAG_ICON_PAUSE{""}; + static constexpr const char* TAG_ICON_NEXT{""}; + static constexpr const char* TAG_ICON_SEEKB{""}; + static constexpr const char* TAG_ICON_SEEKF{""}; - static constexpr auto FORMAT_OFFLINE = "format-offline"; - static constexpr auto TAG_LABEL_OFFLINE = ""; + static constexpr const char* FORMAT_OFFLINE{"format-offline"}; + static constexpr const char* TAG_LABEL_OFFLINE{""}; - static constexpr auto EVENT_PLAY = "mpdplay"; - static constexpr auto EVENT_PAUSE = "mpdpause"; - static constexpr auto EVENT_STOP = "mpdstop"; - static constexpr auto EVENT_PREV = "mpdprev"; - static constexpr auto EVENT_NEXT = "mpdnext"; - static constexpr auto EVENT_REPEAT = "mpdrepeat"; - static constexpr auto EVENT_REPEAT_ONE = "mpdrepeatone"; - static constexpr auto EVENT_RANDOM = "mpdrandom"; - static constexpr auto EVENT_SEEK = "mpdseek"; + static constexpr const char* EVENT_PLAY{"mpdplay"}; + static constexpr const char* EVENT_PAUSE{"mpdpause"}; + static constexpr const char* EVENT_STOP{"mpdstop"}; + static constexpr const char* EVENT_PREV{"mpdprev"}; + static constexpr const char* EVENT_NEXT{"mpdnext"}; + static constexpr const char* EVENT_REPEAT{"mpdrepeat"}; + static constexpr const char* EVENT_REPEAT_ONE{"mpdrepeatone"}; + static constexpr const char* EVENT_RANDOM{"mpdrandom"}; + static constexpr const char* EVENT_SEEK{"mpdseek"}; + + unique_ptr m_mpd; + unique_ptr m_status; + + string m_host{"127.0.0.1"}; + string m_pass; + unsigned int m_port{6600U}; + + chrono::system_clock::time_point m_lastsync{}; + float m_synctime{1.0f}; + + // This flag is used to let thru a broadcast once every time + // the connection state changes + mpd::connection_state m_statebroadcasted{mpd::connection_state::NONE}; progressbar_t m_bar_progress; iconset_t m_icons; @@ -66,22 +80,8 @@ namespace modules { label_t m_label_time; label_t m_label_offline; - unique_ptr m_mpd; - unique_ptr m_status; - - string m_host = "127.0.0.1"; - string m_pass = ""; - unsigned int m_port = 6600; - string m_toggle_on_color; string m_toggle_off_color; - - chrono::system_clock::time_point m_lastsync; - float m_synctime = 1.0f; - - // This flag is used to let thru a broadcast once every time - // the connection state changes - mpd::connection_state m_statebroadcasted; }; } diff --git a/include/modules/text.hpp b/include/modules/text.hpp index bb0ce695..6a6ab901 100644 --- a/include/modules/text.hpp +++ b/include/modules/text.hpp @@ -9,6 +9,7 @@ namespace modules { public: explicit text_module(const bar_settings&, string); + void update() {} string get_format() const; string get_output(); }; diff --git a/src/modules/mpd.cpp b/src/modules/mpd.cpp index fd7bec59..1a3724be 100644 --- a/src/modules/mpd.cpp +++ b/src/modules/mpd.cpp @@ -15,10 +15,10 @@ namespace modules { template class module; mpd_module::mpd_module(const bar_settings& bar, string name_) : event_module(bar, move(name_)) { - m_host = m_conf.get(name(), "host", m_host); - m_port = m_conf.get(name(), "port", m_port); - m_pass = m_conf.get(name(), "password", m_pass); - m_synctime = m_conf.get(name(), "interval", m_synctime); + m_host = m_conf.get(name(), "host", m_host); + m_port = m_conf.get(name(), "port", m_port); + m_pass = m_conf.get(name(), "password", m_pass); + m_synctime = m_conf.get(name(), "interval", m_synctime); // Add formats and elements {{{ diff --git a/src/modules/xbacklight.cpp b/src/modules/xbacklight.cpp index 6a1887e6..cec84c72 100644 --- a/src/modules/xbacklight.cpp +++ b/src/modules/xbacklight.cpp @@ -68,9 +68,6 @@ namespace modules { if (m_formatter->has(TAG_RAMP)) { m_ramp = load_ramp(m_conf, name(), TAG_RAMP); } - - // Trigger the initial draw event - update(); } /** diff --git a/src/modules/xkeyboard.cpp b/src/modules/xkeyboard.cpp index 359af3cc..1a02a348 100644 --- a/src/modules/xkeyboard.cpp +++ b/src/modules/xkeyboard.cpp @@ -39,8 +39,6 @@ namespace modules { // Create keyboard object query_keyboard(); - - update(); } /** diff --git a/src/modules/xwindow.cpp b/src/modules/xwindow.cpp index be4c56a4..8e998cd4 100644 --- a/src/modules/xwindow.cpp +++ b/src/modules/xwindow.cpp @@ -80,9 +80,6 @@ namespace modules { if (m_formatter->has(TAG_LABEL)) { m_label = load_optional_label(m_conf, name(), TAG_LABEL, "%title%"); } - - // Trigger the initial draw event - update(); } /** diff --git a/src/modules/xworkspaces.cpp b/src/modules/xworkspaces.cpp index ea2dd19a..f0ffcc65 100644 --- a/src/modules/xworkspaces.cpp +++ b/src/modules/xworkspaces.cpp @@ -75,8 +75,6 @@ namespace modules { } } - update(); - // Make sure we get notified when root properties change window{m_connection, m_connection.root()}.ensure_event_mask(XCB_EVENT_MASK_PROPERTY_CHANGE); } diff --git a/src/utils/concurrency.cpp b/src/utils/concurrency.cpp index dad1612a..058aa5c5 100644 --- a/src/utils/concurrency.cpp +++ b/src/utils/concurrency.cpp @@ -8,8 +8,9 @@ namespace concurrency_util { static mutex mtx; static map ids; std::lock_guard lock(mtx); - if (ids.find(id) == ids.end()) + if (ids.find(id) == ids.end()) { ids[id] = idx++; + } return ids[id]; } } diff --git a/src/x11/fonts.cpp b/src/x11/fonts.cpp index 1bfd4d62..ac597aa3 100644 --- a/src/x11/fonts.cpp +++ b/src/x11/fonts.cpp @@ -72,9 +72,9 @@ bool font_manager::load(const string& name, uint8_t fontindex, int8_t offset_y) return false; } else if (fontindex == 0) { fontindex = m_fonts.size(); - m_logger.trace("font_manager: Assign font '%s' to index '%d'", name.c_str(), fontindex); + m_logger.trace("font_manager: Assign font '%s' to index '%u'", name, fontindex); } else { - m_logger.trace("font_manager: Add font '%s' to index '%i'", name, fontindex); + m_logger.trace("font_manager: Add font '%s' to index '%u'", name, fontindex); } shared_ptr font{new font_ref{}, font_ref::deleter};