From 8cc885c31669f590f057660711cae5ae6701499b Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Wed, 11 Jan 2017 03:07:28 +0100 Subject: [PATCH] refactor: Cleanup --- include/adapters/alsa/control.hpp | 1 + include/adapters/alsa/generic.hpp | 1 + include/adapters/alsa/mixer.hpp | 1 + include/adapters/net.hpp | 6 +- include/common.hpp | 3 +- include/components/bar.hpp | 1 + include/components/command_line.hpp | 13 +- include/components/config.hpp | 1 + include/components/controller.hpp | 1 + include/components/ipc.hpp | 9 +- include/debug.hpp | 9 +- include/modules/backlight.hpp | 2 +- include/modules/cpu.hpp | 2 +- include/modules/fs.hpp | 2 +- include/modules/github.hpp | 2 +- include/modules/i3.hpp | 2 +- include/modules/memory.hpp | 2 +- include/modules/temperature.hpp | 2 +- include/modules/volume.hpp | 2 +- include/modules/xbacklight.hpp | 2 +- include/settings.hpp | 107 +++++++ .../{config.hpp.cmake => settings.hpp.cmake} | 73 ++--- include/utils/bspwm.hpp | 2 +- include/utils/file.hpp | 4 +- include/x11/extensions/all.hpp | 2 +- include/x11/extensions/composite.hpp | 2 +- include/x11/extensions/damage.hpp | 2 +- include/x11/extensions/fwd.hpp | 2 +- include/x11/extensions/randr.hpp | 2 +- include/x11/extensions/render.hpp | 2 +- include/x11/extensions/sync.hpp | 2 +- include/x11/extensions/xkb.hpp | 2 +- src/CMakeLists.txt | 4 +- src/adapters/net.cpp | 6 +- src/components/command_line.cpp | 302 +++++++++--------- src/components/ipc.cpp | 4 +- src/components/parser.cpp | 2 + src/components/renderer.cpp | 2 + src/main.cpp | 4 +- src/modules/battery.cpp | 3 +- src/utils/http.cpp | 2 +- src/utils/i3.cpp | 2 +- 42 files changed, 353 insertions(+), 244 deletions(-) create mode 100644 include/settings.hpp rename include/{config.hpp.cmake => settings.hpp.cmake} (52%) diff --git a/include/adapters/alsa/control.hpp b/include/adapters/alsa/control.hpp index dcb4d7fd..5641b134 100644 --- a/include/adapters/alsa/control.hpp +++ b/include/adapters/alsa/control.hpp @@ -3,6 +3,7 @@ #include #include "common.hpp" +#include "settings.hpp" // fwd struct _snd_ctl; diff --git a/include/adapters/alsa/generic.hpp b/include/adapters/alsa/generic.hpp index a070b34a..4595c2e4 100644 --- a/include/adapters/alsa/generic.hpp +++ b/include/adapters/alsa/generic.hpp @@ -39,6 +39,7 @@ #endif #include "common.hpp" +#include "settings.hpp" #include "errors.hpp" POLYBAR_NS diff --git a/include/adapters/alsa/mixer.hpp b/include/adapters/alsa/mixer.hpp index 2f7cc958..5bb256e9 100644 --- a/include/adapters/alsa/mixer.hpp +++ b/include/adapters/alsa/mixer.hpp @@ -3,6 +3,7 @@ #include #include "common.hpp" +#include "settings.hpp" // fwd struct _snd_mixer; diff --git a/include/adapters/net.hpp b/include/adapters/net.hpp index 3dc9a823..445d57bf 100644 --- a/include/adapters/net.hpp +++ b/include/adapters/net.hpp @@ -11,14 +11,12 @@ #endif #include "common.hpp" -#include "config.hpp" +#include "settings.hpp" #include "errors.hpp" #include "utils/math.hpp" POLYBAR_NS -namespace chrono = std::chrono; - class file_descriptor; namespace net { @@ -45,7 +43,7 @@ namespace net { struct link_activity { bytes_t transmitted{0}; bytes_t received{0}; - chrono::system_clock::time_point time; + std::chrono::system_clock::time_point time; }; struct link_status { diff --git a/include/common.hpp b/include/common.hpp index 3dcbda39..dccf431e 100644 --- a/include/common.hpp +++ b/include/common.hpp @@ -2,8 +2,7 @@ #include #include - -#include "config.hpp" +#include #define POLYBAR_NS \ namespace polybar { \ diff --git a/include/components/bar.hpp b/include/components/bar.hpp index d925345c..feeebc09 100644 --- a/include/components/bar.hpp +++ b/include/components/bar.hpp @@ -4,6 +4,7 @@ #include #include "common.hpp" +#include "settings.hpp" #include "components/types.hpp" #include "errors.hpp" #include "events/signal_fwd.hpp" diff --git a/include/components/command_line.hpp b/include/components/command_line.hpp index 40f4e2e0..8a1db054 100644 --- a/include/components/command_line.hpp +++ b/include/components/command_line.hpp @@ -4,7 +4,6 @@ #include "common.hpp" #include "errors.hpp" -#include "utils/factory.hpp" POLYBAR_NS @@ -27,8 +26,12 @@ namespace command_line { string token; const choices values; - explicit option(string flag, string flag_long, string desc, string token = "", const choices c = {}) - : flag(flag), flag_long(flag_long), desc(desc), token(token), values(c) {} + explicit option(string&& flag, string&& flag_long, string&& desc, string&& token = "", const choices&& c = {}) + : flag(forward(flag)) + , flag_long(forward(flag_long)) + , desc(forward(desc)) + , token(forward(token)) + , values(forward(c)) {} }; // }}} @@ -67,8 +70,4 @@ namespace command_line { // }}} } -using cliparser = command_line::parser; -using clioption = command_line::option; -using clioptions = command_line::options; - POLYBAR_NS_END diff --git a/include/components/config.hpp b/include/components/config.hpp index ea79b218..6ffa0d2c 100644 --- a/include/components/config.hpp +++ b/include/components/config.hpp @@ -1,4 +1,5 @@ #pragma once + #include #include "common.hpp" diff --git a/include/components/controller.hpp b/include/components/controller.hpp index f03f2c58..d1896de5 100644 --- a/include/components/controller.hpp +++ b/include/components/controller.hpp @@ -4,6 +4,7 @@ #include #include "common.hpp" +#include "settings.hpp" #include "events/signal_fwd.hpp" #include "events/signal_receiver.hpp" #include "events/types.hpp" diff --git a/include/components/ipc.hpp b/include/components/ipc.hpp index 39ac30b8..ba97a039 100644 --- a/include/components/ipc.hpp +++ b/include/components/ipc.hpp @@ -1,14 +1,15 @@ #pragma once #include "common.hpp" -#include "components/logger.hpp" -#include "events/signal_emitter.hpp" +#include "settings.hpp" #include "utils/concurrency.hpp" -#include "utils/functional.hpp" -#include "utils/file.hpp" POLYBAR_NS +class file_descriptor; +class logger; +class signal_emitter; + /** * Message types */ diff --git a/include/debug.hpp b/include/debug.hpp index 59892f56..2ccd9258 100644 --- a/include/debug.hpp +++ b/include/debug.hpp @@ -5,7 +5,7 @@ #endif #include -#include +#include #include "common.hpp" @@ -23,7 +23,7 @@ namespace debug_util { explicit scope_timer() : m_start(clock_t::now()) {} ~scope_timer() { - std::cout << std::chrono::duration_cast(clock_t::now() - m_start).count() << "ms" << std::endl; + printf("%lums\n", std::chrono::duration_cast(clock_t::now() - m_start).count()); } private: @@ -39,13 +39,12 @@ namespace debug_util { auto start = std::chrono::high_resolution_clock::now(); expr(); auto finish = std::chrono::high_resolution_clock::now(); - std::cout << "execution speed: " << std::chrono::duration_cast(finish - start).count() - << "ms" << std::endl; + printf("execution speed: %lums\n", std::chrono::duration_cast(finish - start).count()); } template void memory_usage(const T& object) noexcept { - std::cout << "memory usage: " << sizeof(object) << "b" << std::endl; + printf("memory usage: %lub\n", sizeof(object)); } } diff --git a/include/modules/backlight.hpp b/include/modules/backlight.hpp index 22df3e9d..ecbc6897 100644 --- a/include/modules/backlight.hpp +++ b/include/modules/backlight.hpp @@ -1,7 +1,7 @@ #pragma once #include "components/config.hpp" -#include "config.hpp" +#include "settings.hpp" #include "modules/meta/inotify_module.hpp" POLYBAR_NS diff --git a/include/modules/cpu.hpp b/include/modules/cpu.hpp index 22eda610..f301ff76 100644 --- a/include/modules/cpu.hpp +++ b/include/modules/cpu.hpp @@ -1,6 +1,6 @@ #pragma once -#include "config.hpp" +#include "settings.hpp" #include "modules/meta/timer_module.hpp" POLYBAR_NS diff --git a/include/modules/fs.hpp b/include/modules/fs.hpp index 45cbc1e3..7134c852 100644 --- a/include/modules/fs.hpp +++ b/include/modules/fs.hpp @@ -1,7 +1,7 @@ #pragma once #include "components/config.hpp" -#include "config.hpp" +#include "settings.hpp" #include "modules/meta/timer_module.hpp" POLYBAR_NS diff --git a/include/modules/github.hpp b/include/modules/github.hpp index 945c68bf..84db9107 100644 --- a/include/modules/github.hpp +++ b/include/modules/github.hpp @@ -1,6 +1,6 @@ #pragma once -#include "config.hpp" +#include "settings.hpp" #include "modules/meta/timer_module.hpp" #include "utils/http.hpp" diff --git a/include/modules/i3.hpp b/include/modules/i3.hpp index bfb296e6..55cd500c 100644 --- a/include/modules/i3.hpp +++ b/include/modules/i3.hpp @@ -3,7 +3,7 @@ #include #include "components/config.hpp" -#include "config.hpp" +#include "settings.hpp" #include "modules/meta/event_module.hpp" #include "modules/meta/input_handler.hpp" #include "utils/i3.hpp" diff --git a/include/modules/memory.hpp b/include/modules/memory.hpp index d01ca343..3ddc27dd 100644 --- a/include/modules/memory.hpp +++ b/include/modules/memory.hpp @@ -1,6 +1,6 @@ #pragma once -#include "config.hpp" +#include "settings.hpp" #include "modules/meta/timer_module.hpp" POLYBAR_NS diff --git a/include/modules/temperature.hpp b/include/modules/temperature.hpp index 7a9b1045..75ee57f8 100644 --- a/include/modules/temperature.hpp +++ b/include/modules/temperature.hpp @@ -2,7 +2,7 @@ #include -#include "config.hpp" +#include "settings.hpp" #include "modules/meta/timer_module.hpp" POLYBAR_NS diff --git a/include/modules/volume.hpp b/include/modules/volume.hpp index 21dc7cdd..8c86665f 100644 --- a/include/modules/volume.hpp +++ b/include/modules/volume.hpp @@ -1,6 +1,6 @@ #pragma once -#include "config.hpp" +#include "settings.hpp" #include "modules/meta/event_module.hpp" #include "modules/meta/input_handler.hpp" diff --git a/include/modules/xbacklight.hpp b/include/modules/xbacklight.hpp index 11db3e94..12c0d118 100644 --- a/include/modules/xbacklight.hpp +++ b/include/modules/xbacklight.hpp @@ -1,7 +1,7 @@ #pragma once #include "components/config.hpp" -#include "config.hpp" +#include "settings.hpp" #include "modules/meta/event_handler.hpp" #include "modules/meta/input_handler.hpp" #include "modules/meta/static_module.hpp" diff --git a/include/settings.hpp b/include/settings.hpp new file mode 100644 index 00000000..9865db7e --- /dev/null +++ b/include/settings.hpp @@ -0,0 +1,107 @@ +#pragma once + +#include +#include +#include + +#include "version.hpp" + +#define APP_NAME "polybar" +#define APP_VERSION "2.4.8-9-gc1aa331-git" +#ifndef APP_VERSION +#define APP_VERSION GIT_TAG +#endif +#define BASE_PATH "/home/jaagr/.local/var/github/jaagr/polybar" + +#define ENABLE_ALSA 1 +#define ENABLE_MPD 1 +#define ENABLE_NETWORK 1 +#define ENABLE_I3 1 +#define ENABLE_CURL 1 + +#define WITH_XRANDR 1 +#define WITH_XRENDER 0 +#define WITH_XDAMAGE 0 +#define WITH_XSYNC 0 +#define WITH_XCOMPOSITE 0 +#define WITH_XKB 1 +#define XPP_EXTENSION_LIST xpp::randr::extension, xpp::xkb::extension + +/* #undef DEBUG_LOGGER */ +/* #undef VERBOSE_TRACELOG */ +/* #undef DEBUG_HINTS */ + +static const size_t EVENT_SIZE{64UL}; + +static const int SIGN_PRIORITY_CONTROLLER{1}; +static const int SIGN_PRIORITY_SCREEN{2}; +static const int SIGN_PRIORITY_BAR{3}; +static const int SIGN_PRIORITY_RENDERER{4}; +static const int SIGN_PRIORITY_TRAY{5}; + +static const int SINK_PRIORITY_BAR{1}; +static const int SINK_PRIORITY_SCREEN{2}; +static const int SINK_PRIORITY_TRAY{3}; +static const int SINK_PRIORITY_MODULE{4}; + +#ifdef DEBUG_HINTS +static const int DEBUG_HINTS_OFFSET_X{0}; +static const int DEBUG_HINTS_OFFSET_Y{0}; +#endif + +static constexpr const char* ALSA_SOUNDCARD{"default"}; +static constexpr const char* BSPWM_SOCKET_PATH{"/tmp/bspwm_0_0-socket"}; +static constexpr const char* BSPWM_STATUS_PREFIX{"W"}; +static constexpr const char* CONNECTION_TEST_IP{"8.8.8.8"}; +static constexpr const char* PATH_ADAPTER{"/sys/class/power_supply/%adapter%"}; +static constexpr const char* PATH_BACKLIGHT_MAX{"/sys/class/backlight/%card%/max_brightness"}; +static constexpr const char* PATH_BACKLIGHT_VAL{"/sys/class/backlight/%card%/brightness"}; +static constexpr const char* PATH_BATTERY{"/sys/class/power_supply/%battery%"}; +static constexpr const char* PATH_CPU_INFO{"/proc/stat"}; +static constexpr const char* PATH_MEMORY_INFO{"/proc/meminfo"}; +static constexpr const char* PATH_MESSAGING_FIFO{"/tmp/polybar_mqueue.%pid%"}; +static constexpr const char* PATH_TEMPERATURE_INFO{"/sys/class/thermal/thermal_zone%zone%/temp"}; + +static constexpr const char* BUILDER_SPACE_TOKEN{"%__"}; + +const 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 +const auto print_build_info = [](bool extended = false) { + printf("%s %s\n\n", APP_NAME, APP_VERSION); + printf("Features: %calsa %ccurl %ci3 %cmpd %cnetwork\n", + (ENABLE_ALSA ? '+' : '-'), + (ENABLE_CURL ? '+' : '-'), + (ENABLE_I3 ? '+' : '-'), + (ENABLE_MPD ? '+' : '-'), + (ENABLE_NETWORK ? '+' : '-')); + if (extended) { + printf("\n"); + printf("Build type: RelWithDebInfo\n"); + printf("Compiler: /usr/bin/c++\n"); + printf("Compiler flags: -Wall -Wextra -Werror -O2 -pedantic -pedantic-errors\n"); + printf("Linker flags: \n"); + printf("\n"); + printf("ALSA_SOUNDCARD %s\n", ALSA_SOUNDCARD); + printf("BSPWM_SOCKET_PATH %s\n", BSPWM_SOCKET_PATH); + printf("BSPWM_STATUS_PREFIX %s\n", BSPWM_STATUS_PREFIX); + printf("BUILDER_SPACE_TOKEN %s\n", BUILDER_SPACE_TOKEN); + printf("CONNECTION_TEST_IP %s\n", CONNECTION_TEST_IP); + printf("PATH_ADAPTER %s\n", PATH_ADAPTER); + printf("PATH_BACKLIGHT_MAX %s\n", PATH_BACKLIGHT_MAX); + printf("PATH_BACKLIGHT_VAL %s\n", PATH_BACKLIGHT_VAL); + printf("PATH_BATTERY %s\n", PATH_BATTERY); + printf("PATH_CPU_INFO %s\n", PATH_CPU_INFO); + printf("PATH_MEMORY_INFO %s\n", PATH_MEMORY_INFO); + printf("PATH_TEMPERATURE_INFO %s\n", PATH_TEMPERATURE_INFO); + } +}; +// clang-format on + +// vim:ft=cpp diff --git a/include/config.hpp.cmake b/include/settings.hpp.cmake similarity index 52% rename from include/config.hpp.cmake rename to include/settings.hpp.cmake index 726d56a5..65a38cfb 100644 --- a/include/config.hpp.cmake +++ b/include/settings.hpp.cmake @@ -1,6 +1,7 @@ #pragma once -#include +#include +#include #include #include "version.hpp" @@ -30,7 +31,7 @@ #cmakedefine VERBOSE_TRACELOG #cmakedefine DEBUG_HINTS -static const size_t EVENT_SIZE{64U}; +static const size_t EVENT_SIZE{64UL}; static const int SIGN_PRIORITY_CONTROLLER{1}; static const int SIGN_PRIORITY_SCREEN{2}; @@ -44,12 +45,8 @@ 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@"}; @@ -67,7 +64,7 @@ static constexpr const char* PATH_TEMPERATURE_INFO{"@SETTING_PATH_TEMPERATURE_IN static constexpr const char* BUILDER_SPACE_TOKEN{"%__"}; -auto version_details = [](const std::vector& args) { +const auto version_details = [](const std::vector& args) { for (auto&& arg : args) { if (arg.compare(0, 3, "-vv") == 0) return true; @@ -76,36 +73,34 @@ auto version_details = [](const std::vector& args) { }; // clang-format off -auto print_build_info = [](bool extended = false) { - std::cout << APP_NAME << " " << APP_VERSION << " " << "\n" - << "\n" - << "Features: " - << (ENABLE_ALSA ? "+" : "-") << "alsa " - << (ENABLE_CURL ? "+" : "-") << "curl " - << (ENABLE_I3 ? "+" : "-") << "i3 " - << (ENABLE_MPD ? "+" : "-") << "mpd " - << (ENABLE_NETWORK ? "+" : "-") << "network " - << "\n"; - if (!extended) - return; - std::cout << "\n" - << "Build type: @CMAKE_BUILD_TYPE@" << "\n" - << "Compiler: @CMAKE_CXX_COMPILER@" << "\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" - << "BUILDER_SPACE_TOKEN " << BUILDER_SPACE_TOKEN << "\n" - << "CONNECTION_TEST_IP " << CONNECTION_TEST_IP << "\n" - << "PATH_ADAPTER " << PATH_ADAPTER << "\n" - << "PATH_BACKLIGHT_MAX " << PATH_BACKLIGHT_MAX << "\n" - << "PATH_BACKLIGHT_VAL " << PATH_BACKLIGHT_VAL << "\n" - << "PATH_BATTERY " << PATH_BATTERY << "\n" - << "PATH_CPU_INFO " << PATH_CPU_INFO << "\n" - << "PATH_MEMORY_INFO " << PATH_MEMORY_INFO << "\n" - << "PATH_TEMPERATURE_INFO " << PATH_TEMPERATURE_INFO << "\n"; +const auto print_build_info = [](bool extended = false) { + printf("%s %s\n\n", APP_NAME, APP_VERSION); + printf("Features: %calsa %ccurl %ci3 %cmpd %cnetwork\n", + (ENABLE_ALSA ? '+' : '-'), + (ENABLE_CURL ? '+' : '-'), + (ENABLE_I3 ? '+' : '-'), + (ENABLE_MPD ? '+' : '-'), + (ENABLE_NETWORK ? '+' : '-')); + if (extended) { + printf("\n"); + printf("Build type: @CMAKE_BUILD_TYPE@\n"); + printf("Compiler: @CMAKE_CXX_COMPILER@\n"); + printf("Compiler flags: @CMAKE_CXX_FLAGS@\n"); + printf("Linker flags: @CMAKE_EXE_LINKER_FLAGS@\n"); + printf("\n"); + printf("ALSA_SOUNDCARD %s\n", ALSA_SOUNDCARD); + printf("BSPWM_SOCKET_PATH %s\n", BSPWM_SOCKET_PATH); + printf("BSPWM_STATUS_PREFIX %s\n", BSPWM_STATUS_PREFIX); + printf("BUILDER_SPACE_TOKEN %s\n", BUILDER_SPACE_TOKEN); + printf("CONNECTION_TEST_IP %s\n", CONNECTION_TEST_IP); + printf("PATH_ADAPTER %s\n", PATH_ADAPTER); + printf("PATH_BACKLIGHT_MAX %s\n", PATH_BACKLIGHT_MAX); + printf("PATH_BACKLIGHT_VAL %s\n", PATH_BACKLIGHT_VAL); + printf("PATH_BATTERY %s\n", PATH_BATTERY); + printf("PATH_CPU_INFO %s\n", PATH_CPU_INFO); + printf("PATH_MEMORY_INFO %s\n", PATH_MEMORY_INFO); + printf("PATH_TEMPERATURE_INFO %s\n", PATH_TEMPERATURE_INFO); + } }; // clang-format on diff --git a/include/utils/bspwm.hpp b/include/utils/bspwm.hpp index cf0223a1..075e2566 100644 --- a/include/utils/bspwm.hpp +++ b/include/utils/bspwm.hpp @@ -4,7 +4,7 @@ #include #include "common.hpp" -#include "config.hpp" +#include "settings.hpp" #include "utils/socket.hpp" #include "utils/string.hpp" #include "x11/extensions/randr.hpp" diff --git a/include/utils/file.hpp b/include/utils/file.hpp index dafbff41..2ca2ff47 100644 --- a/include/utils/file.hpp +++ b/include/utils/file.hpp @@ -1,5 +1,7 @@ #pragma once +#include + #include "common.hpp" #include "utils/factory.hpp" @@ -75,7 +77,7 @@ class fd_streambuf : public std::streambuf { char m_in[BUFSIZ - 1]{}; }; -template +template class fd_stream : public StreamType { public: using type = fd_stream; diff --git a/include/x11/extensions/all.hpp b/include/x11/extensions/all.hpp index 0d42bcda..a805192f 100644 --- a/include/x11/extensions/all.hpp +++ b/include/x11/extensions/all.hpp @@ -1,6 +1,6 @@ #pragma once -#include "config.hpp" +#include "settings.hpp" #if WITH_XDAMAGE #include "x11/extensions/damage.hpp" diff --git a/include/x11/extensions/composite.hpp b/include/x11/extensions/composite.hpp index d44e7cc7..6922d5db 100644 --- a/include/x11/extensions/composite.hpp +++ b/include/x11/extensions/composite.hpp @@ -1,6 +1,6 @@ #pragma once -#include "config.hpp" +#include "settings.hpp" #if not WITH_XCOMPOSITE #error "X Composite extension is disabled..." diff --git a/include/x11/extensions/damage.hpp b/include/x11/extensions/damage.hpp index c0c654ea..0041b474 100644 --- a/include/x11/extensions/damage.hpp +++ b/include/x11/extensions/damage.hpp @@ -1,6 +1,6 @@ #pragma once -#include "config.hpp" +#include "settings.hpp" #if not WITH_XDAMAGE #error "X Damage extension is disabled..." diff --git a/include/x11/extensions/fwd.hpp b/include/x11/extensions/fwd.hpp index 93be9778..0d3f5023 100644 --- a/include/x11/extensions/fwd.hpp +++ b/include/x11/extensions/fwd.hpp @@ -1,6 +1,6 @@ #pragma once -#include "config.hpp" +#include "settings.hpp" namespace xpp { #if WITH_XDAMAGE diff --git a/include/x11/extensions/randr.hpp b/include/x11/extensions/randr.hpp index f8aeb091..5e8d5bcc 100644 --- a/include/x11/extensions/randr.hpp +++ b/include/x11/extensions/randr.hpp @@ -1,6 +1,6 @@ #pragma once -#include "config.hpp" +#include "settings.hpp" #if not WITH_XRANDR #error "X RandR extension is disabled..." diff --git a/include/x11/extensions/render.hpp b/include/x11/extensions/render.hpp index 56727428..4b85469f 100644 --- a/include/x11/extensions/render.hpp +++ b/include/x11/extensions/render.hpp @@ -1,6 +1,6 @@ #pragma once -#include "config.hpp" +#include "settings.hpp" #if not WITH_XRENDER #error "X Render extension is disabled..." diff --git a/include/x11/extensions/sync.hpp b/include/x11/extensions/sync.hpp index 3a8e8697..024e7606 100644 --- a/include/x11/extensions/sync.hpp +++ b/include/x11/extensions/sync.hpp @@ -1,6 +1,6 @@ #pragma once -#include "config.hpp" +#include "settings.hpp" #if not WITH_XSYNC #error "X Sync extension is disabled..." diff --git a/include/x11/extensions/xkb.hpp b/include/x11/extensions/xkb.hpp index 3b2c3651..ab5caa56 100644 --- a/include/x11/extensions/xkb.hpp +++ b/include/x11/extensions/xkb.hpp @@ -2,7 +2,7 @@ #include -#include "config.hpp" +#include "settings.hpp" #if not WITH_XKB #error "X xkb extension is disabled..." diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e285dc34..431a9d98 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -161,6 +161,6 @@ execute_process(COMMAND git describe --tags --dirty=-git OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET) configure_file( - ${PROJECT_SOURCE_DIR}/include/config.hpp.cmake - ${CMAKE_SOURCE_DIR}/include/config.hpp + ${PROJECT_SOURCE_DIR}/include/settings.hpp.cmake + ${CMAKE_SOURCE_DIR}/include/settings.hpp ESCAPE_QUOTES @ONLY) diff --git a/src/adapters/net.cpp b/src/adapters/net.cpp index 75f6c5fa..6ad353e4 100644 --- a/src/adapters/net.cpp +++ b/src/adapters/net.cpp @@ -22,7 +22,7 @@ #endif #include "common.hpp" -#include "config.hpp" +#include "settings.hpp" #include "utils/command.hpp" #include "utils/file.hpp" #include "utils/string.hpp" @@ -67,7 +67,7 @@ namespace net { m_status.previous = m_status.current; m_status.current.transmitted = 0; m_status.current.received = 0; - m_status.current.time = chrono::system_clock::now(); + m_status.current.time = std::chrono::system_clock::now(); for (auto ifa = ifaddr; ifa != nullptr; ifa = ifa->ifa_next) { if (ifa->ifa_addr == nullptr) { @@ -183,7 +183,7 @@ namespace net { */ string network::format_speedrate(float bytes_diff, int minwidth) const { const auto duration = m_status.current.time - m_status.previous.time; - float time_diff = chrono::duration_cast(duration).count(); + float time_diff = std::chrono::duration_cast(duration).count(); float speedrate = bytes_diff / (time_diff ? time_diff : 1); vector suffixes{"GB", "MB"}; diff --git a/src/components/command_line.cpp b/src/components/command_line.cpp index e7134503..1a753d0e 100644 --- a/src/components/command_line.cpp +++ b/src/components/command_line.cpp @@ -1,179 +1,179 @@ #include -#include -#include -#include #include "components/command_line.hpp" +#include "utils/factory.hpp" POLYBAR_NS -/** - * Create instance - */ -cliparser::make_type cliparser::make(string&& scriptname, const clioptions&& opts) { - return factory_util::unique( - "Usage: " + scriptname + " bar_name [OPTION...]", forward(opts)); -} - -/** - * Construct parser - */ -cliparser::parser(string&& synopsis, const options&& opts) - : m_synopsis(forward(synopsis)), m_opts(forward(opts)) {} - -/** - * Print application usage message - */ -void cliparser::usage() const { - std::cout << m_synopsis << "\n\n"; - - // get the length of the longest string in the flag column - // which is used to align the description fields - size_t maxlen{0}; - - for (const auto& m_opt : m_opts) { - size_t len{m_opt.flag_long.length() + m_opt.flag.length() + 4}; - maxlen = len > maxlen ? len : maxlen; +namespace command_line { + /** + * Create instance + */ + parser::make_type parser::make(string&& scriptname, const options&& opts) { + return factory_util::unique( + "Usage: " + scriptname + " bar_name [OPTION...]", forward(opts)); } - for (auto& opt : m_opts) { - size_t pad = maxlen - opt.flag_long.length() - opt.token.length(); + /** + * Construct parser + */ + parser::parser(string&& synopsis, const options&& opts) + : m_synopsis(forward(synopsis)), m_opts(forward(opts)) {} - std::cout << " " << opt.flag << ", " << opt.flag_long; + /** + * Print application usage message + */ + void parser::usage() const { + printf("%s\n\n", m_synopsis.c_str()); - if (!opt.token.empty()) { - std::cout << "=" << opt.token; - pad--; + // get the length of the longest string in the flag column + // which is used to align the description fields + size_t maxlen{0}; + + for (const auto& m_opt : m_opts) { + size_t len{m_opt.flag_long.length() + m_opt.flag.length() + 4}; + maxlen = len > maxlen ? len : maxlen; } - // output the list with accepted values - if (!opt.values.empty()) { - std::cout << std::setw(pad + opt.desc.length()) << std::setfill(' ') << opt.desc << '\n'; + for (auto& opt : m_opts) { + size_t pad = maxlen - opt.flag_long.length() - opt.token.length(); - pad = pad + opt.flag_long.length() + opt.token.length() + 7; + printf(" %s, %s", opt.flag.c_str(), opt.flag_long.c_str()); - std::cout << string(pad, ' ') << opt.token << " is one of: "; - - for (auto& v : opt.values) { - std::cout << v << (v != opt.values.back() ? ", " : ""); + if (!opt.token.empty()) { + printf("=%s", opt.token.c_str()); + pad--; } - } else { - std::cout << std::setw(pad + opt.desc.length()) << std::setfill(' ') << opt.desc; - } - std::cout << '\n'; - } + // output the list with accepted values + if (!opt.values.empty()) { + printf("%*s\n", static_cast(pad + opt.desc.length()), opt.desc.c_str()); - std::cout << std::endl; -} + pad = pad + opt.flag_long.length() + opt.token.length() + 7; -/** - * Process input values - */ -void cliparser::process_input(const vector& values) { - for (size_t i = 0; i < values.size(); i++) { - parse(values[i], values.size() > i + 1 ? values[i + 1] : ""); - } -} + printf("%*c%s is one of: ", static_cast(pad), ' ', opt.token.c_str()); -/** - * Test if the passed option was provided - */ -bool cliparser::has(const string& option) const { - return m_optvalues.find(option) != m_optvalues.end(); -} - -/** - * Gets the value defined for given option - */ -string cliparser::get(string opt) const { - if (has(forward(opt))) { - return m_optvalues.find(opt)->second; - } - return ""; -} - -/** - * Compare option value with given string - */ -bool cliparser::compare(string opt, const string& val) const { - return get(move(opt)) == val; -} - -/** - * Compare option with its short version - */ -auto cliparser::is_short(const string& option, const string& opt_short) const { - return option.compare(0, opt_short.length(), opt_short) == 0; -} - -/** - * Compare option with its long version - */ -auto cliparser::is_long(const string& option, const string& opt_long) const { - return option.compare(0, opt_long.length(), opt_long) == 0; -} - -/** - * Compare option with both versions - */ -auto cliparser::is(const string& option, string opt_short, string opt_long) const { - return is_short(option, move(opt_short)) || is_long(option, move(opt_long)); -} - -/** - * Parse option value - */ -auto cliparser::parse_value(string input, const string& input_next, choices values) const { - string opt = move(input); - size_t pos; - string value; - - if (input_next.empty() && opt.compare(0, 2, "--") != 0) { - throw value_error("Missing value for " + opt); - } else if ((pos = opt.find('=')) == string::npos && opt.compare(0, 2, "--") == 0) { - throw value_error("Missing value for " + opt); - } else if (pos == string::npos && !input_next.empty()) { - value = input_next; - } else { - value = opt.substr(pos + 1); - opt = opt.substr(0, pos); - } - - if (!values.empty() && std::find(values.begin(), values.end(), value) == values.end()) { - throw value_error("Invalid value '" + value + "' for argument " + string{opt}); - } - - return value; -} - -/** - * Parse and validate passed arguments and flags - */ -void cliparser::parse(const string& input, const string& input_next) { - if (m_skipnext) { - m_skipnext = false; - if (!input_next.empty()) { - return; - } - } - - for (auto&& opt : m_opts) { - if (is(input, opt.flag, opt.flag_long)) { - if (opt.token.empty()) { - m_optvalues.insert(make_pair(opt.flag_long.substr(2), "")); + for (auto& v : opt.values) { + printf("%s%s", v.c_str(), v != opt.values.back() ? ", " : ""); + } } else { - auto value = parse_value(input, input_next, opt.values); - m_skipnext = (value == input_next); - m_optvalues.insert(make_pair(opt.flag_long.substr(2), value)); + printf("%*s", static_cast(pad + opt.desc.length()), opt.desc.c_str()); } - return; + printf("\n"); + } + + printf("\n"); + } + + /** + * Process input values + */ + void parser::process_input(const vector& values) { + for (size_t i = 0; i < values.size(); i++) { + parse(values[i], values.size() > i + 1 ? values[i + 1] : ""); } } - if (input.compare(0, 1, "-") == 0) { - throw argument_error("Unrecognized option " + input); + /** + * Test if the passed option was provided + */ + bool parser::has(const string& option) const { + return m_optvalues.find(option) != m_optvalues.end(); + } + + /** + * Gets the value defined for given option + */ + string parser::get(string opt) const { + if (has(forward(opt))) { + return m_optvalues.find(opt)->second; + } + return ""; + } + + /** + * Compare option value with given string + */ + bool parser::compare(string opt, const string& val) const { + return get(move(opt)) == val; + } + + /** + * Compare option with its short version + */ + auto parser::is_short(const string& option, const string& opt_short) const { + return option.compare(0, opt_short.length(), opt_short) == 0; + } + + /** + * Compare option with its long version + */ + auto parser::is_long(const string& option, const string& opt_long) const { + return option.compare(0, opt_long.length(), opt_long) == 0; + } + + /** + * Compare option with both versions + */ + auto parser::is(const string& option, string opt_short, string opt_long) const { + return is_short(option, move(opt_short)) || is_long(option, move(opt_long)); + } + + /** + * Parse option value + */ + auto parser::parse_value(string input, const string& input_next, choices values) const { + string opt = move(input); + size_t pos; + string value; + + if (input_next.empty() && opt.compare(0, 2, "--") != 0) { + throw value_error("Undefined argument for option " + opt); + } else if ((pos = opt.find('=')) == string::npos && opt.compare(0, 2, "--") == 0) { + throw value_error("Undefined argument for option " + opt); + } else if (pos == string::npos && !input_next.empty()) { + value = input_next; + } else { + value = opt.substr(pos + 1); + opt = opt.substr(0, pos); + } + + if (!values.empty() && std::find(values.begin(), values.end(), value) == values.end()) { + throw value_error("Invalid argument for option " + opt); + } + + return value; + } + + /** + * Parse and validate passed arguments and flags + */ + void parser::parse(const string& input, const string& input_next) { + if (m_skipnext) { + m_skipnext = false; + if (!input_next.empty()) { + return; + } + } + + for (auto&& opt : m_opts) { + if (is(input, opt.flag, opt.flag_long)) { + if (opt.token.empty()) { + m_optvalues.insert(make_pair(opt.flag_long.substr(2), "")); + } else { + auto value = parse_value(input, input_next, opt.values); + m_skipnext = (value == input_next); + m_optvalues.insert(make_pair(opt.flag_long.substr(2), value)); + } + + return; + } + } + + if (input.compare(0, 1, "-") == 0) { + throw argument_error("Unrecognized option " + input); + } } } diff --git a/src/components/ipc.cpp b/src/components/ipc.cpp index c075b83e..9cd8b5df 100644 --- a/src/components/ipc.cpp +++ b/src/components/ipc.cpp @@ -1,14 +1,12 @@ #include #include -#include #include "components/ipc.hpp" -#include "config.hpp" +#include "components/logger.hpp" #include "events/signal.hpp" #include "events/signal_emitter.hpp" #include "utils/factory.hpp" #include "utils/file.hpp" -#include "utils/io.hpp" #include "utils/string.hpp" POLYBAR_NS diff --git a/src/components/parser.cpp b/src/components/parser.cpp index 562140e8..94756f94 100644 --- a/src/components/parser.cpp +++ b/src/components/parser.cpp @@ -5,6 +5,8 @@ #include "events/signal.hpp" #include "events/signal_emitter.hpp" #include "utils/color.hpp" +#include "utils/factory.hpp" +#include "utils/file.hpp" #include "utils/math.hpp" #include "utils/memory.hpp" #include "utils/string.hpp" diff --git a/src/components/renderer.cpp b/src/components/renderer.cpp index ceeccdd8..1f3b4522 100644 --- a/src/components/renderer.cpp +++ b/src/components/renderer.cpp @@ -4,6 +4,8 @@ #include "events/signal.hpp" #include "events/signal_emitter.hpp" #include "events/signal_receiver.hpp" +#include "utils/factory.hpp" +#include "utils/file.hpp" #include "x11/connection.hpp" #include "x11/draw.hpp" #include "x11/extensions/all.hpp" diff --git a/src/main.cpp b/src/main.cpp index 49be8a23..44d2bf34 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,7 +9,7 @@ #include "components/logger.hpp" #include "components/parser.hpp" #include "components/renderer.hpp" -#include "config.hpp" +#include "settings.hpp" #include "utils/env.hpp" #include "utils/file.hpp" #include "utils/inotify.hpp" @@ -47,7 +47,7 @@ int main(int argc, char** argv) { string scriptname{argv[0]}; vector args{argv + 1, argv + argc}; - cliparser::make_type cli{cliparser::make(move(scriptname), move(opts))}; + command_line::parser::make_type cli{command_line::parser::make(move(scriptname), move(opts))}; cli->process_input(args); if (cli->has("quiet")) { diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp index a5b0e410..87613ce8 100644 --- a/src/modules/battery.cpp +++ b/src/modules/battery.cpp @@ -36,7 +36,8 @@ namespace modules { if (file_util::exists((m_fstate = path_adapter + "online"))) { m_state_reader = make_unique([=] { return file_util::contents(m_fstate).compare(0, 1, "1") == 0; }); } else if (file_util::exists((m_fstate = path_battery + "status"))) { - m_state_reader = make_unique([=] { return file_util::contents(m_fstate).compare(0, 8, "Charging") == 0; }); + m_state_reader = + make_unique([=] { return file_util::contents(m_fstate).compare(0, 8, "Charging") == 0; }); } else { throw module_error("No suitable way to get current charge state"); } diff --git a/src/utils/http.cpp b/src/utils/http.cpp index 6e590f10..2bd3fe95 100644 --- a/src/utils/http.cpp +++ b/src/utils/http.cpp @@ -1,10 +1,10 @@ #include #include #include -#include #include #include "errors.hpp" +#include "settings.hpp" #include "utils/http.hpp" POLYBAR_NS diff --git a/src/utils/i3.cpp b/src/utils/i3.cpp index 19993ee1..3c32d099 100644 --- a/src/utils/i3.cpp +++ b/src/utils/i3.cpp @@ -2,7 +2,7 @@ #include #include "common.hpp" -#include "config.hpp" +#include "settings.hpp" #include "utils/i3.hpp" #include "utils/socket.hpp" #include "utils/string.hpp"