From b9f9092bbe28382a2636af4eb62c26ac595deed7 Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Mon, 26 Dec 2016 10:37:14 +0100 Subject: [PATCH] refactor: Cleanup --- include/components/builder.hpp | 50 +++++++++++----------------------- include/components/screen.hpp | 4 +-- include/config.hpp.cmake | 8 ++++-- include/utils/inotify.hpp | 14 ++++------ src/components/bar.cpp | 2 +- src/components/builder.cpp | 19 ++++++++++++- src/modules/xworkspaces.cpp | 3 -- src/utils/inotify.cpp | 14 ++++------ 8 files changed, 53 insertions(+), 61 deletions(-) diff --git a/include/components/builder.hpp b/include/components/builder.hpp index 3b919cbc..721768fc 100644 --- a/include/components/builder.hpp +++ b/include/components/builder.hpp @@ -3,9 +3,6 @@ #include #include "common.hpp" -#include "components/config.hpp" -#include "components/types.hpp" -#include "config.hpp" POLYBAR_NS @@ -13,10 +10,6 @@ using std::map; #define DEFAULT_SPACING -1 -#ifndef BUILDER_SPACE_TOKEN -#define BUILDER_SPACE_TOKEN "%__" -#endif - // fwd decl namespace drawtypes { class label; @@ -24,12 +17,18 @@ namespace drawtypes { using icon = label; using icon_t = label_t; } - using namespace drawtypes; +enum class alignment : uint8_t; +enum class attribute : uint8_t; +enum class edge : uint8_t; +enum class syntaxtag : uint8_t; +enum class mousebtn : uint8_t; +struct bar_settings; + class builder { public: - explicit builder(const bar_settings bar) : m_bar(bar) {} + explicit builder(const bar_settings& bar); string flush(); void append(const string& text); @@ -71,34 +70,17 @@ class builder { void tag_close(attribute attr); private: - const bar_settings m_bar; - string m_output{}; + const bar_settings& m_bar; + string m_output; - map m_tags{ - // clang-format off - {syntaxtag::A, 0}, - {syntaxtag::B, 0}, - {syntaxtag::F, 0}, - {syntaxtag::T, 0}, - {syntaxtag::u, 0}, - {syntaxtag::o, 0}, - // clang-format on - }; + map m_tags; + map m_colors; - map m_colors{ - // clang-format off - {syntaxtag::B, ""}, - {syntaxtag::F, ""}, - {syntaxtag::u, ""}, - {syntaxtag::o, ""}, - // clang-format on - }; + uint8_t m_attributes; + uint8_t m_fontindex; - uint8_t m_attributes{static_cast(attribute::NONE)}; - uint8_t m_fontindex{1}; - - string m_background{}; - string m_foreground{}; + string m_background; + string m_foreground; }; POLYBAR_NS_END diff --git a/include/components/screen.hpp b/include/components/screen.hpp index b92b6f8d..9f06bcfd 100644 --- a/include/components/screen.hpp +++ b/include/components/screen.hpp @@ -46,9 +46,7 @@ class screen : public xpp::event::sink { xcb_window_t m_proxy{XCB_NONE}; vector m_monitors; - struct size m_size { - 0U, 0U - }; + struct size m_size {0U, 0U}; bool m_sigraised{false}; }; diff --git a/include/config.hpp.cmake b/include/config.hpp.cmake index 2f2b6683..726d56a5 100644 --- a/include/config.hpp.cmake +++ b/include/config.hpp.cmake @@ -44,8 +44,12 @@ static const int SINK_PRIORITY_TRAY{3}; static const int SINK_PRIORITY_MODULE{4}; #ifdef DEBUG_HINTS -static const int DEBUG_HINTS_OFFSET_X{@DEBUG_HINTS_OFFSET_X@}; -static const int DEBUG_HINTS_OFFSET_Y{@DEBUG_HINTS_OFFSET_Y@}; +static const int DEBUG_HINTS_OFFSET_X { + @DEBUG_HINTS_OFFSET_X@ +}; +static const int DEBUG_HINTS_OFFSET_Y { + @DEBUG_HINTS_OFFSET_Y@ +}; #endif static constexpr const char* ALSA_SOUNDCARD{"@SETTING_ALSA_SOUNDCARD@"}; diff --git a/include/utils/inotify.hpp b/include/utils/inotify.hpp index b423143e..9a964eb7 100644 --- a/include/utils/inotify.hpp +++ b/include/utils/inotify.hpp @@ -24,22 +24,20 @@ class inotify_watch { void attach(int mask = IN_MODIFY); void remove(bool force = false); - bool poll(int wait_ms = 1000); - unique_ptr get_event(); - bool await_match(); + bool poll(int wait_ms = 1000) const; + unique_ptr get_event() const; + bool await_match() const; const string path() const; int get_file_descriptor() const; protected: string m_path; - int m_fd = -1; - int m_wd = -1; - int m_mask = 0; + int m_fd{-1}; + int m_wd{-1}; + int m_mask{0}; }; namespace inotify_util { - bool match(const inotify_event* evt, int mask); - template decltype(auto) make_watch(Args&&... args) { return factory_util::unique(forward(args)...); diff --git a/src/components/bar.cpp b/src/components/bar.cpp index 0c23ced5..aca0a601 100644 --- a/src/components/bar.cpp +++ b/src/components/bar.cpp @@ -720,7 +720,7 @@ bool bar::on(const sig_ui::tick&) { bool bar::on(const sig_ui::dim_window& sig) { m_opts.dimmed = *sig.data() != 1.0; - wm_util::set_wm_window_opacity(m_connection, m_opts.window, *sig.data() * 0xFFFFFFFF); + set_wm_window_opacity(m_connection, m_opts.window, *sig.data() * 0xFFFFFFFF); m_connection.flush(); return false; } diff --git a/src/components/builder.cpp b/src/components/builder.cpp index c50491f1..1d654660 100644 --- a/src/components/builder.cpp +++ b/src/components/builder.cpp @@ -1,7 +1,7 @@ #include #include "components/builder.hpp" - +#include "components/types.hpp" #include "drawtypes/label.hpp" #include "utils/math.hpp" #include "utils/string.hpp" @@ -9,6 +9,23 @@ POLYBAR_NS +#ifndef BUILDER_SPACE_TOKEN +#define BUILDER_SPACE_TOKEN "%__" +#endif + +builder::builder(const bar_settings& bar) : m_bar(bar), m_attributes{static_cast(attribute::NONE)} { + m_tags[syntaxtag::A] = 0; + m_tags[syntaxtag::B] = 0; + m_tags[syntaxtag::F] = 0; + m_tags[syntaxtag::T] = 0; + m_tags[syntaxtag::u] = 0; + m_tags[syntaxtag::o] = 0; + m_colors[syntaxtag::B] = ""; + m_colors[syntaxtag::F] = ""; + m_colors[syntaxtag::u] = ""; + m_colors[syntaxtag::o] = ""; +} + /** * Flush contents of the builder and return built string * diff --git a/src/modules/xworkspaces.cpp b/src/modules/xworkspaces.cpp index 7ae70f39..d6216aeb 100644 --- a/src/modules/xworkspaces.cpp +++ b/src/modules/xworkspaces.cpp @@ -74,9 +74,6 @@ namespace modules { m_icons->add(vec[0], factory_util::shared