From c6d85b2b9209dbe853f67b3613ee9a01d2850627 Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Sun, 20 Nov 2016 23:04:31 +0100 Subject: [PATCH] refactor: Optimize build --- cmake/build/core.cmake | 23 +- cmake/build/summary.cmake | 93 +-- include/adapters/alsa.hpp | 6 +- include/adapters/mpd.hpp | 13 +- include/adapters/net.hpp | 3 + include/common.hpp | 69 +-- include/components/bar.hpp | 37 +- include/components/config.hpp | 10 +- include/components/controller.hpp | 27 +- include/components/eventloop.hpp | 5 +- include/components/ipc.hpp | 2 + include/components/logger.hpp | 4 +- include/components/parser.hpp | 1 - include/components/signals.hpp | 14 +- include/config.hpp.cmake | 40 +- include/debug.hpp | 1 + include/drawtypes/animation.hpp | 4 + include/modules/backlight.hpp | 2 +- include/modules/battery.hpp | 4 +- include/modules/bspwm.hpp | 2 +- include/modules/counter.hpp | 2 +- include/modules/cpu.hpp | 2 +- include/modules/date.hpp | 2 +- include/modules/fs.hpp | 2 +- include/modules/i3.hpp | 2 +- include/modules/ipc.hpp | 2 +- include/modules/memory.hpp | 2 +- include/modules/menu.hpp | 2 +- include/modules/meta.hpp | 558 ------------------ include/modules/meta/base.hpp | 171 ++++++ include/modules/meta/base.inl | 185 ++++++ include/modules/meta/event_module.hpp | 23 + include/modules/meta/event_module.inl | 51 ++ include/modules/meta/inotify_module.hpp | 27 + include/modules/meta/inotify_module.inl | 96 +++ include/modules/meta/static_module.hpp | 21 + include/modules/meta/static_module.inl | 15 + include/modules/meta/timer_module.hpp | 28 + include/modules/meta/timer_module.inl | 35 ++ include/modules/mpd.hpp | 7 +- include/modules/network.hpp | 2 +- include/modules/script.hpp | 8 +- include/modules/temperature.hpp | 2 +- include/modules/text.hpp | 2 +- include/modules/unsupported.hpp | 3 +- include/modules/volume.hpp | 10 +- include/modules/xbacklight.hpp | 10 +- include/modules/xwindow.hpp | 6 +- include/utils/command.hpp | 5 +- .../utils/{threading.hpp => concurrency.hpp} | 13 +- include/utils/env.hpp | 12 + include/utils/factory.hpp | 25 + include/utils/functional.hpp | 12 + include/utils/scope.hpp | 2 + include/utils/throttle.hpp | 3 + include/utils/time.hpp | 23 + include/x11/connection.hpp | 24 +- include/x11/damage.hpp | 9 + include/x11/events.hpp | 61 ++ include/x11/{fontmanager.hpp => fonts.hpp} | 29 +- include/x11/icccm.hpp | 1 - include/x11/randr.hpp | 25 +- include/x11/render.hpp | 9 + include/x11/tray.hpp | 7 +- include/x11/types.hpp | 111 +--- include/x11/window.hpp | 129 ---- include/x11/winspec.hpp | 151 +++++ include/x11/wm.hpp | 5 +- include/x11/xresources.hpp | 11 +- src/CMakeLists.txt | 113 ++-- src/adapters/alsa.cpp | 26 +- src/adapters/mpd.cpp | 12 +- src/components/bar.cpp | 42 +- src/components/command_line.cpp | 1 + src/components/config.cpp | 12 +- src/components/controller.cpp | 26 +- src/components/eventloop.cpp | 7 +- src/components/ipc.cpp | 1 + src/components/logger.cpp | 2 + src/components/parser.cpp | 3 + src/components/signals.cpp | 31 +- src/drawtypes/progressbar.cpp | 3 + src/main.cpp | 15 +- src/modules/backlight.cpp | 7 + src/modules/battery.cpp | 10 +- src/modules/bspwm.cpp | 6 + src/modules/counter.cpp | 6 + src/modules/cpu.cpp | 7 + src/modules/date.cpp | 6 + src/modules/fs.cpp | 9 +- src/modules/i3.cpp | 6 + src/modules/ipc.cpp | 7 + src/modules/memory.cpp | 7 + src/modules/menu.cpp | 6 + src/modules/meta/base.cpp | 97 +++ src/modules/meta/inotify_module.cpp | 104 ++++ src/modules/mpd.cpp | 6 + src/modules/network.cpp | 10 +- src/modules/script.cpp | 8 +- src/modules/temperature.cpp | 6 + src/modules/text.cpp | 6 + src/modules/volume.cpp | 39 +- src/modules/xbacklight.cpp | 15 +- src/modules/xwindow.cpp | 8 +- src/utils/bspwm.cpp | 3 +- src/utils/command.cpp | 8 +- src/utils/env.cpp | 18 + src/utils/inotify.cpp | 2 + src/utils/process.cpp | 1 + src/utils/socket.cpp | 5 +- src/utils/throttle.cpp | 4 +- src/x11/connection.cpp | 24 +- src/x11/{fontmanager.cpp => fonts.cpp} | 64 +- src/x11/randr.cpp | 14 + src/x11/tray.cpp | 11 +- src/x11/window.cpp | 1 + src/x11/wm.cpp | 1 + src/x11/xresources.cpp | 24 + tests/CMakeLists.txt | 18 +- tests/unit_tests/components/command_line.cpp | 4 +- tests/unit_tests/components/di.cpp | 6 +- tests/unit_tests/components/logger.cpp | 13 - tests/unit_tests/utils/string.cpp | 2 +- tests/unit_tests/x11/color.cpp | 31 +- tests/unit_tests/x11/connection.cpp | 8 +- tests/unit_tests/x11/window.cpp | 25 - tests/unit_tests/x11/winspec.cpp | 33 ++ 127 files changed, 1962 insertions(+), 1331 deletions(-) delete mode 100644 include/modules/meta.hpp create mode 100644 include/modules/meta/base.hpp create mode 100644 include/modules/meta/base.inl create mode 100644 include/modules/meta/event_module.hpp create mode 100644 include/modules/meta/event_module.inl create mode 100644 include/modules/meta/inotify_module.hpp create mode 100644 include/modules/meta/inotify_module.inl create mode 100644 include/modules/meta/static_module.hpp create mode 100644 include/modules/meta/static_module.inl create mode 100644 include/modules/meta/timer_module.hpp create mode 100644 include/modules/meta/timer_module.inl rename include/utils/{threading.hpp => concurrency.hpp} (82%) create mode 100644 include/utils/env.hpp create mode 100644 include/utils/factory.hpp create mode 100644 include/utils/functional.hpp create mode 100644 include/utils/time.hpp create mode 100644 include/x11/damage.hpp create mode 100644 include/x11/events.hpp rename include/x11/{fontmanager.hpp => fonts.hpp} (69%) create mode 100644 include/x11/render.hpp create mode 100644 include/x11/winspec.hpp create mode 100644 src/modules/meta/base.cpp create mode 100644 src/modules/meta/inotify_module.cpp create mode 100644 src/utils/env.cpp rename src/x11/{fontmanager.cpp => fonts.cpp} (71%) delete mode 100644 tests/unit_tests/components/logger.cpp delete mode 100644 tests/unit_tests/x11/window.cpp create mode 100644 tests/unit_tests/x11/winspec.cpp diff --git a/cmake/build/core.cmake b/cmake/build/core.cmake index 23e012fe..76a6cb3d 100644 --- a/cmake/build/core.cmake +++ b/cmake/build/core.cmake @@ -1,7 +1,6 @@ # # Core setup # - set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) @@ -15,25 +14,27 @@ if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Release") endif() -# Generic compiler flags +# Compiler flags set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") - -# Debug specific compiler flags +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic-errors") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-stack-protector") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffunction-sections -fdata-sections") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g2") -set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pedantic") -set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pedantic-errors") -# Release specific compiler flags -set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3") +# Linker flags +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") +set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -s") -# Compiler specific flags -if("${CMAKE_CXX_COMPILER_ID}" STREQUAL Clang) +# Check compiler +if(${CMAKE_CXX_COMPILER_ID} STREQUAL Clang) message_colored(STATUS "Using supported compiler ${CMAKE_CXX_COMPILER_ID}" 32) -elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL GNU) +elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL GNU) message_colored(STATUS "Using supported compiler ${CMAKE_CXX_COMPILER_ID}" 32) else() message_colored(WARNING "Using unsupported compiler ${CMAKE_CXX_COMPILER_ID} !" 31) diff --git a/cmake/build/summary.cmake b/cmake/build/summary.cmake index 3d455f72..da8cd7da 100644 --- a/cmake/build/summary.cmake +++ b/cmake/build/summary.cmake @@ -2,14 +2,23 @@ # Output build summary # -message(STATUS "---------------------------") -message(STATUS " Build type: ${CMAKE_BUILD_TYPE}") +function(colored_option message_level text var color_on color_off) + string(ASCII 27 esc) + if(${var}) + message(${message_level} "${esc}[${color_on}m${text}${esc}[0m") + else() + message(${message_level} "${esc}[${color_off}m${text}${esc}[0m") + endif() +endfunction() + +message(STATUS "--------------------------") +message_colored(STATUS " Build type: ${CMAKE_BUILD_TYPE}" "32;1") message(STATUS " Compiler C: ${CMAKE_C_COMPILER}") message(STATUS " Compiler C++: ${CMAKE_CXX_COMPILER}") message(STATUS " Compiler flags: ${CMAKE_CXX_FLAGS}") if(CMAKE_BUILD_TYPE STREQUAL "Debug") - message(STATUS " + debug flags:: ${CMAKE_CXX_FLAGS_DEBUG}") + message(STATUS " debug flags: ${CMAKE_CXX_FLAGS_DEBUG}") if(NOT DEFINED ${DEBUG_LOGGER}) set(DEBUG_LOGGER ON) endif() @@ -17,50 +26,52 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug") set(ENABLE_CCACHE ON) endif() elseif(CMAKE_BUILD_TYPE STREQUAL "Release") - message(STATUS " + release flags:: ${CMAKE_CXX_FLAGS_RELEASE}") + message(STATUS " release: ${CMAKE_CXX_FLAGS_RELEASE}") elseif(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel") - message(STATUS " + minsizerel flags:: ${CMAKE_CXX_FLAGS_MINSIZEREL}") + message(STATUS " minsizerel: ${CMAKE_CXX_FLAGS_MINSIZEREL}") elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") - message(STATUS " + relwithdebinfo flags:: ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") + message(STATUS " relwithdebinfo: ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") endif() +message(STATUS " Linker flags: ${CMAKE_EXE_LINKER_FLAGS}") + if(CXXLIB_CLANG) - message(STATUS " Linking C++ library: libc++") + message(STATUS " C++ library: libc++") elseif(CXXLIB_GCC) - message(STATUS " Linking C++ library: libstdc++") + message(STATUS " C++ library: libstdc++") else() - message(STATUS " Linking C++ library: system default") + message(STATUS " C++ library: system default") endif() -message(STATUS "--------------------------------------------") -message(STATUS " Build testsuite ${BUILD_TESTS}") -message(STATUS " Enable debug logger ${DEBUG_LOGGER}") -message(STATUS " Enable extra tracing ${VERBOSE_TRACELOG}") -message(STATUS " Enable ccache support ${ENABLE_CCACHE}") -message(STATUS "--------------------------------------------") -message(STATUS " Enable alsa support ${ENABLE_ALSA}") -message(STATUS " Enable i3 support ${ENABLE_I3}") -message(STATUS " Enable mpd support ${ENABLE_MPD}") -message(STATUS " Enable network support ${ENABLE_NETWORK}") -message(STATUS "--------------------------------------------") -message(STATUS " Enable X RandR ${ENABLE_RANDR_EXT}") -message(STATUS " Enable X Render ${ENABLE_RENDER_EXT}") -message(STATUS " Enable X Damage ${ENABLE_DAMAGE_EXT}") -message(STATUS "--------------------------------------------") -message(STATUS " ALSA_SOUNDCARD ${SETTING_ALSA_SOUNDCARD}") -message(STATUS " BSPWM_SOCKET_PATH ${SETTING_BSPWM_SOCKET_PATH}") -message(STATUS " BSPWM_STATUS_PREFIX ${SETTING_BSPWM_STATUS_PREFIX}") -message(STATUS " CONNECTION_TEST_IP ${SETTING_CONNECTION_TEST_IP}") -message(STATUS " PATH_ADAPTER_STATUS ${SETTING_PATH_ADAPTER_STATUS}") -message(STATUS " PATH_BACKLIGHT_VAL ${SETTING_PATH_BACKLIGHT_VAL}") -message(STATUS " PATH_BACKLIGHT_MAX ${SETTING_PATH_BACKLIGHT_MAX}") -message(STATUS " PATH_BATTERY_CAPACITY ${SETTING_PATH_BATTERY_CAPACITY}") -message(STATUS " PATH_BATTERY_CAPACITY_MAX ${SETTING_PATH_BATTERY_CAPACITY_MAX}") -message(STATUS " PATH_BATTERY_CAPACITY_PERC ${SETTING_PATH_BATTERY_CAPACITY_PERC}") -message(STATUS " PATH_BATTERY_VOLTAGE ${SETTING_PATH_BATTERY_VOLTAGE}") -message(STATUS " PATH_BATTERY_RATE ${SETTING_PATH_BATTERY_RATE}") -message(STATUS " PATH_CPU_INFO ${SETTING_PATH_CPU_INFO}") -message(STATUS " PATH_MEMORY_INFO ${SETTING_PATH_MEMORY_INFO}") -message(STATUS " PATH_MESSAGING_FIFO ${SETTING_PATH_MESSAGING_FIFO}") -message(STATUS " PATH_TEMPERATURE_INFO ${SETTING_PATH_TEMPERATURE_INFO}") -message(STATUS "--------------------------------------------") +message(STATUS "--------------------------") +colored_option(STATUS " Build testsuite ${BUILD_TESTS}" BUILD_TESTS "32;1" "37;2") +colored_option(STATUS " Debug logging ${DEBUG_LOGGER}" DEBUG_LOGGER "32;1" "37;2") +colored_option(STATUS " Verbose tracing ${VERBOSE_TRACELOG}" VERBOSE_TRACELOG "32;1" "37;2") +colored_option(STATUS " Enable ccache ${ENABLE_CCACHE}" ENABLE_CCACHE "32;1" "37;2") +message(STATUS "--------------------------") +colored_option(STATUS " Enable alsa ${ENABLE_ALSA}" ENABLE_ALSA "32;1" "37;2") +colored_option(STATUS " Enable i3 ${ENABLE_I3}" ENABLE_I3 "32;1" "37;2") +colored_option(STATUS " Enable mpd ${ENABLE_MPD}" ENABLE_MPD "32;1" "37;2") +colored_option(STATUS " Enable network ${ENABLE_NETWORK}" ENABLE_NETWORK "32;1" "37;2") +message(STATUS "--------------------------") +colored_option(STATUS " Enable X RandR ${ENABLE_RANDR_EXT}" ENABLE_RANDR_EXT "32;1" "37;2") +colored_option(STATUS " Enable X Render ${ENABLE_RENDER_EXT}" ENABLE_RENDER_EXT "32;1" "37;2") +colored_option(STATUS " Enable X Damage ${ENABLE_DAMAGE_EXT}" ENABLE_DAMAGE_EXT "32;1" "37;2") +message(STATUS "--------------------------") +# message(STATUS " ALSA_SOUNDCARD ${SETTING_ALSA_SOUNDCARD}") +# message(STATUS " BSPWM_SOCKET_PATH ${SETTING_BSPWM_SOCKET_PATH}") +# message(STATUS " BSPWM_STATUS_PREFIX ${SETTING_BSPWM_STATUS_PREFIX}") +# message(STATUS " CONNECTION_TEST_IP ${SETTING_CONNECTION_TEST_IP}") +# message(STATUS " PATH_ADAPTER_STATUS ${SETTING_PATH_ADAPTER_STATUS}") +# message(STATUS " PATH_BACKLIGHT_VAL ${SETTING_PATH_BACKLIGHT_VAL}") +# message(STATUS " PATH_BACKLIGHT_MAX ${SETTING_PATH_BACKLIGHT_MAX}") +# message(STATUS " PATH_BATTERY_CAPACITY ${SETTING_PATH_BATTERY_CAPACITY}") +# message(STATUS " PATH_BATTERY_CAPACITY_MAX ${SETTING_PATH_BATTERY_CAPACITY_MAX}") +# message(STATUS " PATH_BATTERY_CAPACITY_PERC ${SETTING_PATH_BATTERY_CAPACITY_PERC}") +# message(STATUS " PATH_BATTERY_VOLTAGE ${SETTING_PATH_BATTERY_VOLTAGE}") +# message(STATUS " PATH_BATTERY_RATE ${SETTING_PATH_BATTERY_RATE}") +# message(STATUS " PATH_CPU_INFO ${SETTING_PATH_CPU_INFO}") +# message(STATUS " PATH_MEMORY_INFO ${SETTING_PATH_MEMORY_INFO}") +# message(STATUS " PATH_MESSAGING_FIFO ${SETTING_PATH_MESSAGING_FIFO}") +# message(STATUS " PATH_TEMPERATURE_INFO ${SETTING_PATH_TEMPERATURE_INFO}") +# message(STATUS "--------------------------") diff --git a/include/adapters/alsa.hpp b/include/adapters/alsa.hpp index 02fc8c9a..01f8c230 100644 --- a/include/adapters/alsa.hpp +++ b/include/adapters/alsa.hpp @@ -9,7 +9,7 @@ #include "common.hpp" #include "config.hpp" -#include "utils/threading.hpp" +#include "utils/concurrency.hpp" #define MAX_LINEAR_DB_SCALE 24 @@ -42,7 +42,7 @@ class alsa_ctl_interface { private: int m_numid = 0; - threading_util::spin_lock m_lock; + concurrency_util::spin_lock m_lock; snd_hctl_t* m_hctl = nullptr; snd_hctl_elem_t* m_elem = nullptr; @@ -77,7 +77,7 @@ class alsa_mixer { private: string m_name; - threading_util::spin_lock m_lock; + concurrency_util::spin_lock m_lock; snd_mixer_t* m_hardwaremixer = nullptr; snd_mixer_elem_t* m_mixerelement = nullptr; diff --git a/include/adapters/mpd.hpp b/include/adapters/mpd.hpp index 0195a6cd..43b29f9a 100644 --- a/include/adapters/mpd.hpp +++ b/include/adapters/mpd.hpp @@ -3,14 +3,16 @@ #include #include #include -#include -#include #include "common.hpp" -#include "components/logger.hpp" POLYBAR_NS +// fwd +class logger; + +namespace chrono = std::chrono; + namespace mpd { DEFINE_ERROR(mpd_exception); DEFINE_CHILD_ERROR(client_error, mpd_exception); @@ -72,9 +74,8 @@ namespace mpd { class mpdstatus; class mpdconnection { public: - explicit mpdconnection(const logger& logger, string host, unsigned int port = 6600, - string password = "", unsigned int timeout = 15) - : m_log(logger), m_host(host), m_port(port), m_password(password), m_timeout(timeout) {} + explicit mpdconnection( + const logger& logger, string host, unsigned int port = 6600, string password = "", unsigned int timeout = 15); void connect(); void disconnect(); diff --git a/include/adapters/net.hpp b/include/adapters/net.hpp index a49d8a8e..d1ee8bbb 100644 --- a/include/adapters/net.hpp +++ b/include/adapters/net.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include @@ -13,6 +14,8 @@ POLYBAR_NS +namespace chrono = std::chrono; + namespace net { DEFINE_ERROR(network_error); diff --git a/include/common.hpp b/include/common.hpp index d40762a3..98a5cb6d 100644 --- a/include/common.hpp +++ b/include/common.hpp @@ -4,18 +4,13 @@ #define BOOST_DI_CFG_DIAGNOSTICS_LEVEL 2 #endif -#include #include -#include #include #include -#include #include -#include #include #include #include -#include #include #include "config.hpp" @@ -28,8 +23,19 @@ } #define POLYBAR_NS_PATH "polybar::v2_0_0" +#ifndef PIPE_READ #define PIPE_READ 0 +#endif +#ifndef PIPE_WRITE #define PIPE_WRITE 1 +#endif + +#ifndef STDOUT_FILENO +#define STDOUT_FILENO 1 +#endif +#ifndef STDERR_FILENO +#define STDERR_FILENO 2 +#endif #ifdef DEBUG #include "debug.hpp" @@ -42,12 +48,8 @@ POLYBAR_NS //================================================== namespace di = boost::di; -namespace chrono = std::chrono; -namespace this_thread = std::this_thread; namespace placeholders = std::placeholders; -using namespace std::chrono_literals; - using std::string; using std::stringstream; using std::size_t; @@ -66,36 +68,8 @@ using std::map; using std::vector; using std::to_string; using std::strerror; -using std::getenv; -using std::thread; using std::exception; -using boost::optional; - -using stateflag = std::atomic; - -//================================================== -// Instance factory -//================================================== - -namespace factory { - template - unique_ptr generic_instance(Deps... deps) { - return make_unique(deps...); - } - - template - shared_ptr generic_singleton(Deps... deps) { - static auto instance = make_shared(deps...); - return instance; - } -} - -struct null_deleter { - template - void operator()(T*) const {} -}; - //================================================== // Errors and exceptions //================================================== @@ -121,25 +95,4 @@ class system_error : public application_error { } #define DEFINE_ERROR(error) DEFINE_CHILD_ERROR(error, application_error) -//================================================== -// Various tools and helpers functions -//================================================== - -auto has_env = [](const char* var) { return getenv(var) != nullptr; }; -auto read_env = [](const char* var, string&& fallback = "") { - const char* value{getenv(var)}; - return value != nullptr ? value : fallback; -}; - -template -auto time_execution(const T& expr) noexcept { - auto start = std::chrono::high_resolution_clock::now(); - expr(); - auto finish = std::chrono::high_resolution_clock::now(); - return std::chrono::duration_cast(finish - start).count(); -} - -template -using callback = function; - POLYBAR_NS_END diff --git a/include/components/bar.hpp b/include/components/bar.hpp index 85465838..7f7e1136 100644 --- a/include/components/bar.hpp +++ b/include/components/bar.hpp @@ -4,11 +4,10 @@ #include "components/config.hpp" #include "components/logger.hpp" #include "components/types.hpp" -#include "utils/threading.hpp" +#include "utils/concurrency.hpp" #include "utils/throttle.hpp" #include "x11/connection.hpp" -#include "x11/fontmanager.hpp" -#include "x11/tray.hpp" +#include "x11/events.hpp" #include "x11/types.hpp" #include "x11/window.hpp" @@ -16,17 +15,12 @@ POLYBAR_NS // fwd class tray_manager; +class font_manager; class bar : public xpp::event::sink { public: - explicit bar(connection& conn, const config& config, const logger& logger, unique_ptr fontmanager, - unique_ptr tray_manager) - : m_connection(conn) - , m_conf(config) - , m_log(logger) - , m_fontmanager(forward(fontmanager)) - , m_tray(forward(tray_manager)) {} - + explicit bar(connection& conn, const config& config, const logger& logger, unique_ptr font_manager, + unique_ptr tray_manager); ~bar(); void bootstrap(bool nodraw = false); @@ -79,10 +73,10 @@ class bar : public xpp::event::sink m_fontmanager; + unique_ptr m_fontmanager; unique_ptr m_tray; - threading_util::spin_lock m_lock; + concurrency_util::spin_lock m_lock; throttle_util::throttle_t m_throttler; xcb_screen_t* m_screen; @@ -115,21 +109,6 @@ class bar : public xpp::event::sink> - di::injector configure_bar() { - // clang-format off - return di::make_injector( - configure_connection(), - configure_config(), - configure_logger(), - configure_fontmanager(), - configure_tray_manager()); - // clang-format on - } -} +di::injector> configure_bar(); POLYBAR_NS_END diff --git a/include/components/config.hpp b/include/components/config.hpp index df296740..41696670 100644 --- a/include/components/config.hpp +++ b/include/components/config.hpp @@ -1,11 +1,13 @@ #pragma once +#include #include #include #include #include "common.hpp" #include "components/logger.hpp" +#include "utils/env.hpp" #include "utils/string.hpp" #include "x11/xresources.hpp" @@ -78,7 +80,7 @@ class config { template vector get_list(string section, string key) const { vector vec; - optional value; + boost::optional value; while ((value = m_ptree.get_optional(build_path(section, key) + "-" + to_string(vec.size()))) != boost::none) { auto str_val = m_ptree.get(build_path(section, key) + "-" + to_string(vec.size())); @@ -98,7 +100,7 @@ class config { template vector get_list(string section, string key, vector default_value) const { vector vec; - optional value; + boost::optional value; while ((value = m_ptree.get_optional(build_path(section, key) + "-" + to_string(vec.size()))) != boost::none) { auto str_val = m_ptree.get(build_path(section, key) + "-" + to_string(vec.size())); @@ -173,8 +175,8 @@ class config { var.erase(pos); } - if (has_env(var.c_str())) - return boost::lexical_cast(read_env(var.c_str())); + if (env_util::has(var.c_str())) + return boost::lexical_cast(env_util::get(var.c_str())); return fallback; } diff --git a/include/components/controller.hpp b/include/components/controller.hpp index c3ba179d..96bf5f39 100644 --- a/include/components/controller.hpp +++ b/include/components/controller.hpp @@ -1,7 +1,6 @@ #pragma once #include "common.hpp" -#include "components/bar.hpp" #include "components/config.hpp" #include "components/eventloop.hpp" #include "components/ipc.hpp" @@ -14,6 +13,14 @@ POLYBAR_NS +// fwd decl {{{ + +class bar; + +// }}} + +using watch_t = inotify_util::watch_t; + class controller { public: explicit controller(connection& conn, const logger& logger, const config& config, unique_ptr eventloop, @@ -72,22 +79,6 @@ class controller { bool m_writeback{false}; }; -namespace { - /** - * Configure injection module - */ - template > - di::injector configure_controller(inotify_util::watch_t& confwatch) { - // clang-format off - return di::make_injector( - di::bind<>().to(confwatch), - configure_connection(), - configure_logger(), - configure_config(), - configure_eventloop(), - configure_bar()); - // clang-format on - } -} +di::injector> configure_controller(watch_t& confwatch); POLYBAR_NS_END diff --git a/include/components/eventloop.hpp b/include/components/eventloop.hpp index 6fc5e2cb..0096a5d2 100644 --- a/include/components/eventloop.hpp +++ b/include/components/eventloop.hpp @@ -1,10 +1,11 @@ #pragma once #include +#include #include "common.hpp" #include "components/logger.hpp" -#include "modules/meta.hpp" +#include "modules/meta/base.hpp" POLYBAR_NS @@ -30,7 +31,7 @@ class eventloop { ~eventloop() noexcept; bool enqueue(const entry_t& i); - void run(chrono::duration timeframe, int limit); + void run(std::chrono::duration timeframe, int limit); void stop(); void set_update_cb(callback<>&& cb); diff --git a/include/components/ipc.hpp b/include/components/ipc.hpp index e4a6d8d7..40c1560a 100644 --- a/include/components/ipc.hpp +++ b/include/components/ipc.hpp @@ -2,6 +2,8 @@ #include "common.hpp" #include "components/logger.hpp" +#include "utils/functional.hpp" +#include "utils/concurrency.hpp" POLYBAR_NS diff --git a/include/components/logger.hpp b/include/components/logger.hpp index 9afb969a..aafee342 100644 --- a/include/components/logger.hpp +++ b/include/components/logger.hpp @@ -3,6 +3,7 @@ #include #include "common.hpp" +#include "utils/factory.hpp" POLYBAR_NS @@ -22,7 +23,6 @@ class logger { explicit logger(string level_name) : logger(parse_loglevel_name(level_name)) {} void verbosity(loglevel level); - void verbosity(string level); /** @@ -159,7 +159,7 @@ namespace { */ template di::injector configure_logger(loglevel level = loglevel::NONE) { - auto instance = factory::generic_singleton(level); + auto instance = factory_util::generic_singleton(level); return di::make_injector(di::bind<>().to(instance)); } } diff --git a/include/components/parser.hpp b/include/components/parser.hpp index 17d7853b..959ad4a9 100644 --- a/include/components/parser.hpp +++ b/include/components/parser.hpp @@ -2,7 +2,6 @@ #include "common.hpp" #include "components/signals.hpp" -#include "components/types.hpp" POLYBAR_NS diff --git a/include/components/signals.hpp b/include/components/signals.hpp index ad43fd49..4e545b37 100644 --- a/include/components/signals.hpp +++ b/include/components/signals.hpp @@ -1,10 +1,22 @@ #pragma once #include "common.hpp" -#include "components/types.hpp" + +#include "utils/functional.hpp" POLYBAR_NS +// fwd decl {{{ + +enum class mousebtn; +enum class syntaxtag; +enum class alignment; +enum class attribute; +enum class gc; +class color; + +// }}} + /** * @TODO: Allow multiple signal handlers */ diff --git a/include/config.hpp.cmake b/include/config.hpp.cmake index 005754c1..5488a666 100644 --- a/include/config.hpp.cmake +++ b/include/config.hpp.cmake @@ -1,6 +1,7 @@ #pragma once #include +#include #include "version.hpp" @@ -21,7 +22,7 @@ #ifdef DEBUG #cmakedefine01 DRAW_CLICKABLE_AREA_HINTS -#cmakedefine DRAW_CLICKABLE_AREA_HINTS_OFFSET_Y @DRAW_CLICKABLE_AREA_HINTS_OFFSET_Y@ +#cmakedefine DRAW_CLICKABLE_AREA_HINTS_OFFSET_Y @DRAW_CLICKABLE_AREA_HINTS_OFFSET_Y @ #ifndef DRAW_CLICKABLE_AREA_HINTS_OFFSET_Y #define DRAW_CLICKABLE_AREA_HINTS_OFFSET_Y 0 #endif @@ -46,16 +47,31 @@ #define PATH_MESSAGING_FIFO "@SETTING_PATH_MESSAGING_FIFO@" #define PATH_TEMPERATURE_INFO "@SETTING_PATH_TEMPERATURE_INFO@" -auto print_build_info = []() { - // clang-format off - std::cout << APP_NAME << " " << GIT_TAG - << "\n\n" - << "Built with: " - << (ENABLE_ALSA ? "+" : "-") << "alsa " - << (ENABLE_I3 ? "+" : "-") << "i3 " - << (ENABLE_MPD ? "+" : "-") << "mpd " - << (ENABLE_NETWORK ? "+" : "-") << "network " - << "\n\n" +auto version_details = [](const std::vector& args) { + for (auto&& arg : args) { + if (arg.compare(0, 3, "-vv") == 0) + return true; + } + return false; +}; + +// clang-format off +auto print_build_info = [](bool extended = false) { + std::cout << APP_NAME << " " << GIT_TAG << " " << "\n" + << "\n" + << "Features: " + << (ENABLE_ALSA ? "+" : "-") << "alsa " + << (ENABLE_I3 ? "+" : "-") << "i3 " + << (ENABLE_MPD ? "+" : "-") << "mpd " + << (ENABLE_NETWORK ? "+" : "-") << "network " + << "\n"; + if (!extended) + return; + std::cout << "\n" + << "Build type: @CMAKE_BUILD_TYPE@" << "\n" + << "Compiler flags: @CMAKE_CXX_FLAGS@" << "\n" + << "Linker flags: @CMAKE_EXE_LINKER_FLAGS@" << "\n" + << "\n" << "ALSA_SOUNDCARD " << ALSA_SOUNDCARD << "\n" << "BSPWM_SOCKET_PATH " << BSPWM_SOCKET_PATH << "\n" << "BSPWM_STATUS_PREFIX " << BSPWM_STATUS_PREFIX << "\n" @@ -73,7 +89,7 @@ auto print_build_info = []() { << "PATH_CPU_INFO " << PATH_CPU_INFO << "\n" << "PATH_MEMORY_INFO " << PATH_MEMORY_INFO << "\n" << "PATH_TEMPERATURE_INFO " << PATH_TEMPERATURE_INFO << "\n"; - // clang-format on }; +// clang-format on // vim:ft=cpp diff --git a/include/debug.hpp b/include/debug.hpp index 4bc644b1..9d38b0b9 100644 --- a/include/debug.hpp +++ b/include/debug.hpp @@ -2,6 +2,7 @@ #pragma once #include +#include template void benchmark_execution_speed(const T& expr) noexcept { diff --git a/include/drawtypes/animation.hpp b/include/drawtypes/animation.hpp index 4f573ff6..f39acfb1 100644 --- a/include/drawtypes/animation.hpp +++ b/include/drawtypes/animation.hpp @@ -1,5 +1,7 @@ #pragma once +#include + #include "common.hpp" #include "components/config.hpp" #include "drawtypes/label.hpp" @@ -7,6 +9,8 @@ POLYBAR_NS +namespace chrono = std::chrono; + namespace drawtypes { class animation : public non_copyable_mixin { public: diff --git a/include/modules/backlight.hpp b/include/modules/backlight.hpp index be727d1b..4fa543d9 100644 --- a/include/modules/backlight.hpp +++ b/include/modules/backlight.hpp @@ -2,7 +2,7 @@ #include "components/config.hpp" #include "config.hpp" -#include "modules/meta.hpp" +#include "modules/meta/inotify_module.hpp" POLYBAR_NS diff --git a/include/modules/battery.hpp b/include/modules/battery.hpp index c89b8d0a..fd75dcbe 100644 --- a/include/modules/battery.hpp +++ b/include/modules/battery.hpp @@ -2,7 +2,7 @@ #include "common.hpp" #include "config.hpp" -#include "modules/meta.hpp" +#include "modules/meta/inotify_module.hpp" POLYBAR_NS @@ -67,7 +67,7 @@ namespace modules { map m_valuepath; std::atomic m_percentage{0}; int m_fullat{100}; - interval_t m_interval; + chrono::duration m_interval; chrono::system_clock::time_point m_lastpoll; string m_timeformat; int m_unchanged{SKIP_N_UNCHANGED}; diff --git a/include/modules/bspwm.hpp b/include/modules/bspwm.hpp index 8b8faa02..1c91a2d1 100644 --- a/include/modules/bspwm.hpp +++ b/include/modules/bspwm.hpp @@ -1,6 +1,6 @@ #pragma once -#include "modules/meta.hpp" +#include "modules/meta/event_module.hpp" #include "utils/bspwm.hpp" POLYBAR_NS diff --git a/include/modules/counter.hpp b/include/modules/counter.hpp index 87711d0a..71606734 100644 --- a/include/modules/counter.hpp +++ b/include/modules/counter.hpp @@ -1,6 +1,6 @@ #pragma once -#include "modules/meta.hpp" +#include "modules/meta/timer_module.hpp" POLYBAR_NS diff --git a/include/modules/cpu.hpp b/include/modules/cpu.hpp index da5e8711..bfff1c32 100644 --- a/include/modules/cpu.hpp +++ b/include/modules/cpu.hpp @@ -3,7 +3,7 @@ #include #include "config.hpp" -#include "modules/meta.hpp" +#include "modules/meta/timer_module.hpp" POLYBAR_NS diff --git a/include/modules/date.hpp b/include/modules/date.hpp index 72953e1a..8a6eaa28 100644 --- a/include/modules/date.hpp +++ b/include/modules/date.hpp @@ -1,6 +1,6 @@ #pragma once -#include "modules/meta.hpp" +#include "modules/meta/timer_module.hpp" POLYBAR_NS diff --git a/include/modules/fs.hpp b/include/modules/fs.hpp index c2ae7210..bf814b35 100644 --- a/include/modules/fs.hpp +++ b/include/modules/fs.hpp @@ -2,7 +2,7 @@ #include "components/config.hpp" #include "config.hpp" -#include "modules/meta.hpp" +#include "modules/meta/timer_module.hpp" POLYBAR_NS diff --git a/include/modules/i3.hpp b/include/modules/i3.hpp index 079b3bf0..0e55ae5a 100644 --- a/include/modules/i3.hpp +++ b/include/modules/i3.hpp @@ -4,7 +4,7 @@ #include "components/config.hpp" #include "config.hpp" -#include "modules/meta.hpp" +#include "modules/meta/event_module.hpp" #include "utils/i3.hpp" #include "utils/io.hpp" diff --git a/include/modules/ipc.hpp b/include/modules/ipc.hpp index 03e5f438..152cbd36 100644 --- a/include/modules/ipc.hpp +++ b/include/modules/ipc.hpp @@ -1,6 +1,6 @@ #pragma once -#include "modules/meta.hpp" +#include "modules/meta/static_module.hpp" #include "utils/command.hpp" POLYBAR_NS diff --git a/include/modules/memory.hpp b/include/modules/memory.hpp index ddbe85ee..f17e2dbd 100644 --- a/include/modules/memory.hpp +++ b/include/modules/memory.hpp @@ -3,7 +3,7 @@ #include #include "config.hpp" -#include "modules/meta.hpp" +#include "modules/meta/timer_module.hpp" POLYBAR_NS diff --git a/include/modules/menu.hpp b/include/modules/menu.hpp index c0a8ffee..fe372338 100644 --- a/include/modules/menu.hpp +++ b/include/modules/menu.hpp @@ -1,6 +1,6 @@ #pragma once -#include "modules/meta.hpp" +#include "modules/meta/static_module.hpp" POLYBAR_NS diff --git a/include/modules/meta.hpp b/include/modules/meta.hpp deleted file mode 100644 index 75026ade..00000000 --- a/include/modules/meta.hpp +++ /dev/null @@ -1,558 +0,0 @@ -#pragma once - -#include -#include -#include - -#include "common.hpp" -#include "components/builder.hpp" -#include "components/config.hpp" -#include "components/logger.hpp" -#include "utils/inotify.hpp" -#include "utils/string.hpp" -#include "utils/threading.hpp" - -POLYBAR_NS - -#define DEFAULT_FORMAT "format" - -#define DEFINE_MODULE(name, type) struct name : public type -#define CONST_MOD(name) static_cast(*this) -#define CAST_MOD(name) static_cast(this) - -// fwd decl -namespace drawtypes { - class label; - using label_t = shared_ptr