From 8db3e79919ba835266c1d23ded23a8388236be60 Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Fri, 25 Nov 2016 08:42:31 +0100 Subject: [PATCH] refactor(clang-format): Apply fixes --- include/adapters/alsa.hpp | 2 +- include/adapters/net.hpp | 1 + include/common.hpp | 2 +- include/components/bar.hpp | 3 +- include/components/builder.hpp | 28 +++---- include/components/command_line.hpp | 6 +- include/components/config.hpp | 2 +- include/components/controller.hpp | 4 +- include/components/ipc.hpp | 2 +- include/debug.hpp | 7 +- include/drawtypes/animation.hpp | 3 +- include/drawtypes/label.hpp | 12 +-- include/modules/fs.hpp | 3 +- include/modules/mpd.hpp | 2 +- include/modules/xbacklight.hpp | 5 +- include/utils/file.hpp | 3 +- include/utils/inotify.hpp | 2 +- include/utils/math.hpp | 3 +- include/utils/socket.hpp | 5 +- include/utils/string.hpp | 4 +- include/utils/throttle.hpp | 5 +- include/x11/connection.hpp | 5 +- include/x11/graphics.hpp | 3 +- src/adapters/alsa.cpp | 30 +++----- src/adapters/net.cpp | 10 +-- src/components/command_line.cpp | 2 +- src/components/controller.cpp | 9 ++- src/drawtypes/label.cpp | 4 +- src/main.cpp | 115 ++++++++++++++++------------ src/modules/meta/base.cpp | 2 +- src/modules/mpd.cpp | 6 +- src/modules/network.cpp | 13 ++-- src/modules/volume.cpp | 28 +++---- src/utils/string.cpp | 7 +- src/x11/graphics.cpp | 3 +- src/x11/randr.cpp | 2 +- src/x11/tray.cpp | 5 +- src/x11/window.cpp | 2 +- src/x11/wm.cpp | 19 ++--- src/x11/xembed.cpp | 3 +- src/x11/xutils.cpp | 2 +- 41 files changed, 185 insertions(+), 189 deletions(-) diff --git a/include/adapters/alsa.hpp b/include/adapters/alsa.hpp index 01f8c230..d5dc2c76 100644 --- a/include/adapters/alsa.hpp +++ b/include/adapters/alsa.hpp @@ -1,9 +1,9 @@ #pragma once #include +#include #include #include -#include #include diff --git a/include/adapters/net.hpp b/include/adapters/net.hpp index d1ee8bbb..4cd57a93 100644 --- a/include/adapters/net.hpp +++ b/include/adapters/net.hpp @@ -1,6 +1,7 @@ #pragma once #include + #include #include #include diff --git a/include/common.hpp b/include/common.hpp index f986d625..2ad4cb7d 100644 --- a/include/common.hpp +++ b/include/common.hpp @@ -18,7 +18,7 @@ namespace polybar { \ inline namespace v2_0_0 { #define POLYBAR_NS_END \ - } \ + } \ } #define POLYBAR_NS_PATH "polybar::v2_0_0" diff --git a/include/components/bar.hpp b/include/components/bar.hpp index 2f27e785..b188d0b7 100644 --- a/include/components/bar.hpp +++ b/include/components/bar.hpp @@ -19,8 +19,7 @@ class renderer; class bar : public xpp::event::sink { public: - explicit bar(connection& conn, const config& config, const logger& logger, - unique_ptr tray_manager); + explicit bar(connection& conn, const config& config, const logger& logger, unique_ptr tray_manager); ~bar(); void bootstrap(bool nodraw = false); diff --git a/include/components/builder.hpp b/include/components/builder.hpp index b13cc8a3..67d97804 100644 --- a/include/components/builder.hpp +++ b/include/components/builder.hpp @@ -69,23 +69,23 @@ class builder { 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 + // 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_colors{ - // clang-format off - {syntaxtag::B, ""}, - {syntaxtag::F, ""}, - {syntaxtag::u, ""}, - {syntaxtag::o, ""}, - // clang-format on + // clang-format off + {syntaxtag::B, ""}, + {syntaxtag::F, ""}, + {syntaxtag::u, ""}, + {syntaxtag::o, ""}, + // clang-format on }; uint8_t m_attributes{static_cast(attribute::NONE)}; diff --git a/include/components/command_line.hpp b/include/components/command_line.hpp index 8036bf4a..2eb7f311 100644 --- a/include/components/command_line.hpp +++ b/include/components/command_line.hpp @@ -23,8 +23,7 @@ namespace command_line { string token; const choices values; - explicit option( - string flag, string flag_long, string desc, string token = "", const choices c = {}) + 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) {} }; @@ -33,8 +32,7 @@ namespace command_line { class parser { public: - explicit parser(const string& synopsis, const options& opts) - : m_synopsis(synopsis), m_opts(opts) {} + explicit parser(const string& synopsis, const options& opts) : m_synopsis(synopsis), m_opts(opts) {} void usage() const; diff --git a/include/components/config.hpp b/include/components/config.hpp index d6a6e998..2af60566 100644 --- a/include/components/config.hpp +++ b/include/components/config.hpp @@ -1,7 +1,7 @@ #pragma once -#include #include +#include #include #include diff --git a/include/components/controller.hpp b/include/components/controller.hpp index 96bf5f39..731c84aa 100644 --- a/include/components/controller.hpp +++ b/include/components/controller.hpp @@ -35,7 +35,9 @@ class controller { ~controller(); void bootstrap(bool writeback = false, bool dump_wmname = false); - bool run(); + + void run(); + bool completed(); protected: void install_sigmask(); diff --git a/include/components/ipc.hpp b/include/components/ipc.hpp index c8e18b38..c12c10c3 100644 --- a/include/components/ipc.hpp +++ b/include/components/ipc.hpp @@ -2,8 +2,8 @@ #include "common.hpp" #include "components/logger.hpp" -#include "utils/functional.hpp" #include "utils/concurrency.hpp" +#include "utils/functional.hpp" POLYBAR_NS diff --git a/include/debug.hpp b/include/debug.hpp index 9d38b0b9..d4b7436a 100644 --- a/include/debug.hpp +++ b/include/debug.hpp @@ -1,17 +1,16 @@ #ifdef DEBUG #pragma once -#include #include +#include template void benchmark_execution_speed(const T& expr) noexcept { 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; + std::cout << "execution speed: " << std::chrono::duration_cast(finish - start).count() + << "ms" << std::endl; } template diff --git a/include/drawtypes/animation.hpp b/include/drawtypes/animation.hpp index f39acfb1..b2ef98da 100644 --- a/include/drawtypes/animation.hpp +++ b/include/drawtypes/animation.hpp @@ -38,8 +38,7 @@ namespace drawtypes { using animation_t = shared_ptr; - animation_t load_animation( - const config& conf, string section, string name = "animation", bool required = true); + animation_t load_animation(const config& conf, string section, string name = "animation", bool required = true); } POLYBAR_NS_END diff --git a/include/drawtypes/label.hpp b/include/drawtypes/label.hpp index c04808de..6a6ad764 100644 --- a/include/drawtypes/label.hpp +++ b/include/drawtypes/label.hpp @@ -39,9 +39,8 @@ namespace drawtypes { bool m_ellipsis = true; explicit label(string text, int font) : m_font(font), m_text(text), m_tokenized(m_text) {} - explicit label(string text, string foreground = "", string background = "", - string underline = "", string overline = "", int font = 0, int padding = 0, int margin = 0, - size_t maxlen = 0, bool ellipsis = true, + explicit label(string text, string foreground = "", string background = "", string underline = "", + string overline = "", int font = 0, int padding = 0, int margin = 0, size_t maxlen = 0, bool ellipsis = true, const vector& bound = {}) : m_foreground(foreground) , m_background(background) @@ -68,16 +67,13 @@ namespace drawtypes { private: string m_text, m_tokenized; const vector m_token_bounds; - }; - label_t load_label( - const config& conf, string section, string name, bool required = true, string def = ""); + label_t load_label(const config& conf, string section, string name, bool required = true, string def = ""); label_t load_optional_label(const config& conf, string section, string name, string def = ""); - icon_t load_icon( - const config& conf, string section, string name, bool required = true, string def = ""); + icon_t load_icon(const config& conf, string section, string name, bool required = true, string def = ""); icon_t load_optional_icon(const config& conf, string section, string name, string def = ""); } diff --git a/include/modules/fs.hpp b/include/modules/fs.hpp index bf814b35..58e3047f 100644 --- a/include/modules/fs.hpp +++ b/include/modules/fs.hpp @@ -27,8 +27,7 @@ namespace modules { string percentage_free_s; string percentage_used_s; - explicit fs_mount(const string& mountpoint, bool mounted = false) - : mountpoint(mountpoint), mounted(mounted) {} + explicit fs_mount(const string& mountpoint, bool mounted = false) : mountpoint(mountpoint), mounted(mounted) {} }; using fs_mount_t = unique_ptr; diff --git a/include/modules/mpd.hpp b/include/modules/mpd.hpp index d99cbeb1..f6a6f781 100644 --- a/include/modules/mpd.hpp +++ b/include/modules/mpd.hpp @@ -1,7 +1,7 @@ #pragma once -#include #include +#include #include "adapters/mpd.hpp" #include "modules/meta/event_module.hpp" diff --git a/include/modules/xbacklight.hpp b/include/modules/xbacklight.hpp index de079126..917fd740 100644 --- a/include/modules/xbacklight.hpp +++ b/include/modules/xbacklight.hpp @@ -1,9 +1,9 @@ #pragma once #include "components/config.hpp" -#include "x11/randr.hpp" #include "config.hpp" #include "modules/meta/static_module.hpp" +#include "x11/randr.hpp" POLYBAR_NS @@ -23,8 +23,7 @@ namespace modules { * * TODO: Implement backlight configuring using scroll events */ - class xbacklight_module : public static_module, - public xpp::event::sink { + class xbacklight_module : public static_module, public xpp::event::sink { public: using static_module::static_module; diff --git a/include/utils/file.hpp b/include/utils/file.hpp index 84391f4e..95ee5c18 100644 --- a/include/utils/file.hpp +++ b/include/utils/file.hpp @@ -10,8 +10,7 @@ namespace file_util { */ class file_ptr { public: - explicit file_ptr(const string& path, const string& mode = "a+") - : m_path(string(path)), m_mode(string(mode)) { + explicit file_ptr(const string& path, const string& mode = "a+") : m_path(string(path)), m_mode(string(mode)) { m_ptr = fopen(m_path.c_str(), m_mode.c_str()); } diff --git a/include/utils/inotify.hpp b/include/utils/inotify.hpp index a7edfbf4..e018d5f4 100644 --- a/include/utils/inotify.hpp +++ b/include/utils/inotify.hpp @@ -1,7 +1,7 @@ #pragma once -#include #include +#include #include #include "common.hpp" diff --git a/include/utils/math.hpp b/include/utils/math.hpp index d11dec85..4d6dbed4 100644 --- a/include/utils/math.hpp +++ b/include/utils/math.hpp @@ -48,7 +48,8 @@ namespace math_util { template ReturnType percentage_to_value(ValueType percentage, ValueType min_value, ValueType max_value) { if (std::is_integral()) - return cap(percentage * (max_value - min_value) / 100.0f + 0.5f, 0, max_value - min_value) + min_value; + return cap(percentage * (max_value - min_value) / 100.0f + 0.5f, 0, max_value - min_value) + + min_value; else return cap(percentage * (max_value - min_value) / 100.0f, 0.0f, max_value - min_value) + min_value; } diff --git a/include/utils/socket.hpp b/include/utils/socket.hpp index 61bad83d..1a0573b7 100644 --- a/include/utils/socket.hpp +++ b/include/utils/socket.hpp @@ -36,9 +36,8 @@ namespace socket_util { * conn->receive(...); * @endcode */ - auto make_unix_connection = [](string&& path) -> unique_ptr { - return make_unique(forward(path)); - }; + auto make_unix_connection = []( + string&& path) -> unique_ptr { return make_unique(forward(path)); }; } POLYBAR_NS_END diff --git a/include/utils/string.hpp b/include/utils/string.hpp index 39954a5c..f900fcbb 100644 --- a/include/utils/string.hpp +++ b/include/utils/string.hpp @@ -18,8 +18,8 @@ namespace string_util { bool compare(const string& s1, const string& s2); string replace(const string& haystack, string needle, string repl, size_t start = 0, size_t end = string::npos); string replace_all(const string& haystack, string needle, string repl, size_t start = 0, size_t end = string::npos); - string replace_all_bounded(const string& haystack, string needle, string replacement, - size_t min, size_t max, size_t start = 0, size_t end = string::npos); + string replace_all_bounded(const string& haystack, string needle, string replacement, size_t min, size_t max, + size_t start = 0, size_t end = string::npos); string squeeze(const string& haystack, char needle); string strip(const string& haystack, char needle); string strip_trailing_newline(const string& haystack); diff --git a/include/utils/throttle.hpp b/include/utils/throttle.hpp index d4b69e55..46b5b611 100644 --- a/include/utils/throttle.hpp +++ b/include/utils/throttle.hpp @@ -1,7 +1,7 @@ #pragma once -#include #include +#include #include "common.hpp" #include "components/logger.hpp" @@ -41,8 +41,7 @@ namespace throttle_util { /** * Construct throttler */ - explicit event_throttler(int limit, timewindow timewindow) - : m_limit(limit), m_timewindow(timewindow) {} + explicit event_throttler(int limit, timewindow timewindow) : m_limit(limit), m_timewindow(timewindow) {} /** * Check if event is allowed to pass diff --git a/include/x11/connection.hpp b/include/x11/connection.hpp index b453cb48..b429ba82 100644 --- a/include/x11/connection.hpp +++ b/include/x11/connection.hpp @@ -3,9 +3,9 @@ #include #include #include +#include #include #include -#include #include "common.hpp" #include "utils/memory.hpp" @@ -63,8 +63,7 @@ class connection : public xpp_connection { xcb_screen_t* screen(); - shared_ptr make_client_message( - xcb_atom_t type, xcb_window_t target) const; + shared_ptr make_client_message(xcb_atom_t type, xcb_window_t target) const; void send_client_message(shared_ptr message, xcb_window_t target, uint32_t event_mask = 0xFFFFFF, bool propagate = false) const; diff --git a/include/x11/graphics.hpp b/include/x11/graphics.hpp index fc7bb358..134b8e84 100644 --- a/include/x11/graphics.hpp +++ b/include/x11/graphics.hpp @@ -18,7 +18,8 @@ namespace graphics_util { xcb_pixmap_t pixmap{0}; }; - bool create_window(connection& conn, xcb_window_t* win, int16_t x = 0, int16_t y = 0, uint16_t w = 1, uint16_t h = 1, xcb_window_t root = 0); + bool create_window(connection& conn, xcb_window_t* win, int16_t x = 0, int16_t y = 0, uint16_t w = 1, uint16_t h = 1, + xcb_window_t root = 0); bool create_pixmap(connection& conn, xcb_drawable_t dst, uint16_t w, uint16_t h, xcb_pixmap_t* pixmap); bool create_pixmap(connection& conn, xcb_drawable_t dst, uint16_t w, uint16_t h, uint8_t d, xcb_pixmap_t* pixmap); bool create_gc(connection& conn, xcb_drawable_t drawable, xcb_gcontext_t* gc); diff --git a/src/adapters/alsa.cpp b/src/adapters/alsa.cpp index 3c35c888..b850be3b 100644 --- a/src/adapters/alsa.cpp +++ b/src/adapters/alsa.cpp @@ -16,8 +16,7 @@ alsa_ctl_interface::alsa_ctl_interface(int numid) : m_numid(numid) { snd_ctl_elem_info_set_id(m_info, m_id); if ((err = snd_ctl_open(&m_ctl, ALSA_SOUNDCARD, SND_CTL_NONBLOCK | SND_CTL_READONLY)) < 0) - throw_exception( - "Could not open control '" + string{ALSA_SOUNDCARD} + "'", err); + throw_exception("Could not open control '" + string{ALSA_SOUNDCARD} + "'", err); if ((err = snd_ctl_elem_info(m_ctl, m_info)) < 0) throw_exception("Could not get control datal", err); @@ -29,12 +28,10 @@ alsa_ctl_interface::alsa_ctl_interface(int numid) : m_numid(numid) { if ((err = snd_hctl_load(m_hctl)) < 0) throw_exception("Failed to load hctl", err); if ((m_elem = snd_hctl_find_elem(m_hctl, m_id)) == nullptr) - throw alsa_ctl_interface_error( - "Could not find control with id " + to_string(snd_ctl_elem_id_get_numid(m_id))); + throw alsa_ctl_interface_error("Could not find control with id " + to_string(snd_ctl_elem_id_get_numid(m_id))); if ((err = snd_ctl_subscribe_events(m_ctl, 1)) < 0) - throw alsa_ctl_interface_error( - "Could not subscribe to events: " + to_string(snd_ctl_elem_id_get_numid(m_id))); + throw alsa_ctl_interface_error("Could not subscribe to events: " + to_string(snd_ctl_elem_id_get_numid(m_id))); } alsa_ctl_interface::~alsa_ctl_interface() { @@ -158,10 +155,8 @@ int alsa_mixer::get_volume() { snd_mixer_selem_get_playback_volume_range(m_mixerelement, &vol_min, &vol_max); for (int i = 0; i <= SND_MIXER_SCHN_LAST; i++) { - if (snd_mixer_selem_has_playback_channel( - m_mixerelement, static_cast(i))) { - snd_mixer_selem_get_playback_volume( - m_mixerelement, static_cast(i), &vol); + if (snd_mixer_selem_has_playback_channel(m_mixerelement, static_cast(i))) { + snd_mixer_selem_get_playback_volume(m_mixerelement, static_cast(i), &vol); vol_total += vol; chan_n++; } @@ -178,10 +173,8 @@ int alsa_mixer::get_normalized_volume() { snd_mixer_selem_get_playback_dB_range(m_mixerelement, &vol_min, &vol_max); for (int i = 0; i <= SND_MIXER_SCHN_LAST; i++) { - if (snd_mixer_selem_has_playback_channel( - m_mixerelement, static_cast(i))) { - snd_mixer_selem_get_playback_dB( - m_mixerelement, static_cast(i), &vol); + if (snd_mixer_selem_has_playback_channel(m_mixerelement, static_cast(i))) { + snd_mixer_selem_get_playback_dB(m_mixerelement, static_cast(i), &vol); vol_total += vol; chan_n++; } @@ -207,7 +200,8 @@ void alsa_mixer::set_volume(float percentage) { long vol_min, vol_max; snd_mixer_selem_get_playback_volume_range(m_mixerelement, &vol_min, &vol_max); - snd_mixer_selem_set_playback_volume_all(m_mixerelement, math_util::percentage_to_value(percentage, vol_min, vol_max)); + snd_mixer_selem_set_playback_volume_all( + m_mixerelement, math_util::percentage_to_value(percentage, vol_min, vol_max)); } void alsa_mixer::set_normalized_volume(float percentage) { @@ -251,11 +245,9 @@ bool alsa_mixer::is_muted() { std::lock_guard guard(m_lock); int state = 0; for (int i = 0; i <= SND_MIXER_SCHN_LAST; i++) { - if (snd_mixer_selem_has_playback_channel( - m_mixerelement, static_cast(i))) { + if (snd_mixer_selem_has_playback_channel(m_mixerelement, static_cast(i))) { int state_ = 0; - snd_mixer_selem_get_playback_switch( - m_mixerelement, static_cast(i), &state_); + snd_mixer_selem_get_playback_switch(m_mixerelement, static_cast(i), &state_); state = state || state_; } } diff --git a/src/adapters/net.cpp b/src/adapters/net.cpp index ee4fe0e6..c1ee5019 100644 --- a/src/adapters/net.cpp +++ b/src/adapters/net.cpp @@ -1,6 +1,11 @@ #include "adapters/net.hpp" +#include +#include +#include #include +#include +#include #include #include @@ -10,11 +15,6 @@ #include #include #include -#include -#include -#include -#include -#include #ifdef inline #undef inline diff --git a/src/components/command_line.cpp b/src/components/command_line.cpp index 9e02ea81..b238e63f 100644 --- a/src/components/command_line.cpp +++ b/src/components/command_line.cpp @@ -1,6 +1,6 @@ +#include #include #include -#include #include "components/command_line.hpp" diff --git a/src/components/controller.cpp b/src/components/controller.cpp index 183d85ba..7b4283a4 100644 --- a/src/components/controller.cpp +++ b/src/components/controller.cpp @@ -163,7 +163,7 @@ void controller::bootstrap(bool writeback, bool dump_wmname) { /** * Launch the controller */ -bool controller::run() { +void controller::run() { assert(!m_connection.connection_has_error()); m_log.info("Starting application"); @@ -201,8 +201,13 @@ bool controller::run() { uninstall_confwatch(); m_running = false; +} - return !m_reload; +/** + * Get completion state + */ +bool controller::completed() { + return !m_running && !m_reload; } /** diff --git a/src/drawtypes/label.cpp b/src/drawtypes/label.cpp index b78500bd..6bce8127 100644 --- a/src/drawtypes/label.cpp +++ b/src/drawtypes/label.cpp @@ -12,8 +12,8 @@ namespace drawtypes { } label_t label::clone() { - return label_t{new label(m_text, m_foreground, m_background, m_underline, m_overline, m_font, - m_padding, m_margin, m_maxlen, m_ellipsis, m_token_bounds)}; + return label_t{new label(m_text, m_foreground, m_background, m_underline, m_overline, m_font, m_padding, m_margin, + m_maxlen, m_ellipsis, m_token_bounds)}; } void label::reset_tokens() { diff --git a/src/main.cpp b/src/main.cpp index 8518ec62..a89eacfa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,26 +14,16 @@ using namespace polybar; +struct exit_success {}; +struct exit_failure {}; + int main(int argc, char** argv) { - XInitThreads(); - - logger& logger{configure_logger(loglevel::WARNING).create()}; - - //================================================== - // Connect to X server - //================================================== - xcb_connection_t* connection; - - if ((connection = xutils::get_connection()) == nullptr) { - logger.err("A connection to X could not be established... "); - return EXIT_FAILURE; - } - - int xfd = xcb_get_file_descriptor(connection); + uint8_t exit_code{EXIT_SUCCESS}; + stateflag quit{false}; // clang-format off const command_line::options opts{ - command_line::option{"-h", "--help", "Show help options"}, + command_line::option{"-h", "--help", "Show help options"}, command_line::option{"-v", "--version", "Print version information"}, command_line::option{"-l", "--log", "Set the logging verbosity (default: WARNING)", "LEVEL", {"warning", "info", "trace"}}, command_line::option{"-q", "--quiet", "Be quiet (will override -l)"}, @@ -45,36 +35,46 @@ int main(int argc, char** argv) { }; // clang-format on - stateflag terminate{false}; + logger& logger{configure_logger(loglevel::WARNING).create()}; - while (!terminate) { + //================================================== + // Connect to X server + //================================================== + XInitThreads(); + + xcb_connection_t* connection{nullptr}; + + if ((connection = xutils::get_connection()) == nullptr) { + logger.err("A connection to X could not be established... "); + throw exit_failure{}; + } + + int xfd{xcb_get_file_descriptor(connection)}; + + while (!quit) { try { //================================================== // Parse command line arguments //================================================== + vector args(argv + 1, argv + argc); cliparser cli{configure_cliparser(argv[0], opts).create()}; - - vector args; - for (int i = 1; i < argc; i++) { - args.emplace_back(argv[i]); - } - cli.process_input(args); - if (cli.has("quiet")) + if (cli.has("quiet")) { logger.verbosity(loglevel::ERROR); - else if (cli.has("log")) + } else if (cli.has("log")) { logger.verbosity(cli.get("log")); + } if (cli.has("help")) { cli.usage(); - return EXIT_SUCCESS; + throw exit_success{}; } else if (cli.has("version")) { print_build_info(version_details(args)); - return EXIT_SUCCESS; + throw exit_success{}; } else if (args.empty() || args[0][0] == '-') { cli.usage(); - return EXIT_FAILURE; + throw exit_failure{}; } //================================================== @@ -82,21 +82,22 @@ int main(int argc, char** argv) { //================================================== config& conf{configure_config().create()}; - if (cli.has("config")) + if (cli.has("config")) { conf.load(cli.get("config"), args[0]); - else if (env_util::has("XDG_CONFIG_HOME")) + } else if (env_util::has("XDG_CONFIG_HOME")) { conf.load(env_util::get("XDG_CONFIG_HOME") + "/polybar/config", args[0]); - else if (env_util::has("HOME")) + } else if (env_util::has("HOME")) { conf.load(env_util::get("HOME") + "/.config/polybar/config", args[0]); - else + } else { throw application_error("Define configuration using --config=PATH"); + } //================================================== // Dump requested data //================================================== if (cli.has("dump")) { std::cout << conf.get(conf.bar_section(), cli.get("dump")) << std::endl; - return EXIT_SUCCESS; + throw exit_success{}; } //================================================== @@ -104,31 +105,49 @@ int main(int argc, char** argv) { //================================================== inotify_util::watch_t watch; - if (cli.has("reload")) + if (cli.has("reload")) { watch = inotify_util::make_watch(conf.filepath()); + } //================================================== - // Create controller and run application + // Create controller //================================================== - auto app = configure_controller(watch).create>(); + auto ctrl = configure_controller(watch).create>(); - app->bootstrap(cli.has("stdout"), cli.has("print-wmname")); + ctrl->bootstrap(cli.has("stdout"), cli.has("print-wmname")); - if (cli.has("print-wmname")) - break; + if (cli.has("print-wmname")) { + throw exit_success{}; + } - if ((terminate = app->run()) == false) + //================================================== + // Run application + //================================================== + ctrl->run(); + + if (ctrl->completed()) { + quit = true; + } else { logger.info("Reloading application..."); - - } catch (const std::exception& err) { + } + } catch (const exit_success& term) { + exit_code = EXIT_SUCCESS; + quit = true; + } catch (const exit_failure& term) { + exit_code = EXIT_FAILURE; + quit = true; + } catch (const exception& err) { logger.err(err.what()); - return EXIT_FAILURE; + exit_code = EXIT_FAILURE; + quit = true; } - }; + } + + logger.trace("Close connection to X server"); + xcb_disconnect(connection); + close(xfd); logger.info("Reached end of application..."); - close(xfd); - - return EXIT_SUCCESS; + return exit_code; } diff --git a/src/modules/meta/base.cpp b/src/modules/meta/base.cpp index 88426b5b..73751c88 100644 --- a/src/modules/meta/base.cpp +++ b/src/modules/meta/base.cpp @@ -1,5 +1,5 @@ -#include "components/builder.hpp" #include "modules/meta/base.hpp" +#include "components/builder.hpp" POLYBAR_NS diff --git a/src/modules/mpd.cpp b/src/modules/mpd.cpp index 201ac2e1..8cae5897 100644 --- a/src/modules/mpd.cpp +++ b/src/modules/mpd.cpp @@ -24,9 +24,9 @@ namespace modules { // Add formats and elements {{{ m_formatter->add(FORMAT_ONLINE, TAG_LABEL_SONG, - {TAG_BAR_PROGRESS, TAG_TOGGLE, TAG_TOGGLE_STOP, TAG_LABEL_SONG, TAG_LABEL_TIME, TAG_ICON_RANDOM, TAG_ICON_REPEAT, - TAG_ICON_REPEAT_ONE, TAG_ICON_PREV, TAG_ICON_STOP, TAG_ICON_PLAY, TAG_ICON_PAUSE, TAG_ICON_NEXT, - TAG_ICON_SEEKB, TAG_ICON_SEEKF}); + {TAG_BAR_PROGRESS, TAG_TOGGLE, TAG_TOGGLE_STOP, TAG_LABEL_SONG, TAG_LABEL_TIME, TAG_ICON_RANDOM, + TAG_ICON_REPEAT, TAG_ICON_REPEAT_ONE, TAG_ICON_PREV, TAG_ICON_STOP, TAG_ICON_PLAY, TAG_ICON_PAUSE, + TAG_ICON_NEXT, TAG_ICON_SEEKB, TAG_ICON_SEEKF}); m_formatter->add(FORMAT_OFFLINE, "", {TAG_LABEL_OFFLINE}); diff --git a/src/modules/network.cpp b/src/modules/network.cpp index 6d06454d..2f85c0ba 100644 --- a/src/modules/network.cpp +++ b/src/modules/network.cpp @@ -25,8 +25,7 @@ namespace modules { m_interval = chrono::duration(m_conf.get(name(), "interval", 1)); // Add formats - m_formatter->add(FORMAT_CONNECTED, TAG_LABEL_CONNECTED, - {TAG_RAMP_SIGNAL, TAG_RAMP_QUALITY, TAG_LABEL_CONNECTED}); + m_formatter->add(FORMAT_CONNECTED, TAG_LABEL_CONNECTED, {TAG_RAMP_SIGNAL, TAG_RAMP_QUALITY, TAG_LABEL_CONNECTED}); m_formatter->add(FORMAT_DISCONNECTED, TAG_LABEL_DISCONNECTED, {TAG_LABEL_DISCONNECTED}); // Create elements for format-connected @@ -41,8 +40,7 @@ namespace modules { // Create elements for format-disconnected if (m_formatter->has(TAG_LABEL_DISCONNECTED, FORMAT_DISCONNECTED)) { - m_label[connection_state::DISCONNECTED] = - load_optional_label(m_conf, name(), TAG_LABEL_DISCONNECTED, ""); + m_label[connection_state::DISCONNECTED] = load_optional_label(m_conf, name(), TAG_LABEL_DISCONNECTED, ""); m_label[connection_state::DISCONNECTED]->reset_tokens(); m_label[connection_state::DISCONNECTED]->replace_token("%ifname%", m_interface); } @@ -53,8 +51,7 @@ namespace modules { {TAG_ANIMATION_PACKETLOSS, TAG_LABEL_PACKETLOSS, TAG_LABEL_CONNECTED}); if (m_formatter->has(TAG_LABEL_PACKETLOSS, FORMAT_PACKETLOSS)) { - m_label[connection_state::PACKETLOSS] = - load_optional_label(m_conf, name(), TAG_LABEL_PACKETLOSS, ""); + m_label[connection_state::PACKETLOSS] = load_optional_label(m_conf, name(), TAG_LABEL_PACKETLOSS, ""); } if (m_formatter->has(TAG_ANIMATION_PACKETLOSS, FORMAT_PACKETLOSS)) m_animation_packetloss = load_animation(m_conf, name(), TAG_ANIMATION_PACKETLOSS); @@ -77,8 +74,8 @@ namespace modules { } bool network_module::update() { - net::network* network = m_wireless ? static_cast(m_wireless.get()) - : static_cast(m_wired.get()); + net::network* network = + m_wireless ? static_cast(m_wireless.get()) : static_cast(m_wired.get()); if (!network->query(m_accumulate)) { m_log.warn("%s: Failed to query interface '%s'", name(), m_interface); diff --git a/src/modules/volume.cpp b/src/modules/volume.cpp index 6874616c..00c2bdc1 100644 --- a/src/modules/volume.cpp +++ b/src/modules/volume.cpp @@ -52,10 +52,8 @@ namespace modules { } // Add formats and elements - m_formatter->add( - FORMAT_VOLUME, TAG_LABEL_VOLUME, {TAG_RAMP_VOLUME, TAG_LABEL_VOLUME, TAG_BAR_VOLUME}); - m_formatter->add( - FORMAT_MUTED, TAG_LABEL_MUTED, {TAG_RAMP_VOLUME, TAG_LABEL_MUTED, TAG_BAR_VOLUME}); + m_formatter->add(FORMAT_VOLUME, TAG_LABEL_VOLUME, {TAG_RAMP_VOLUME, TAG_LABEL_VOLUME, TAG_BAR_VOLUME}); + m_formatter->add(FORMAT_MUTED, TAG_LABEL_MUTED, {TAG_RAMP_VOLUME, TAG_LABEL_MUTED, TAG_BAR_VOLUME}); if (m_formatter->has(TAG_BAR_VOLUME)) m_bar_volume = load_progressbar(m_bar, m_conf, name(), TAG_BAR_VOLUME); @@ -108,19 +106,19 @@ namespace modules { m_headphones = false; if (m_mixers[mixer::MASTER]) { - m_volume = m_volume * (m_mapped ? m_mixers[mixer::MASTER]->get_normalized_volume() / 100.0f : - m_mixers[mixer::MASTER]->get_volume() / 100.0f); + m_volume = m_volume * (m_mapped ? m_mixers[mixer::MASTER]->get_normalized_volume() / 100.0f + : m_mixers[mixer::MASTER]->get_volume() / 100.0f); m_muted = m_muted || m_mixers[mixer::MASTER]->is_muted(); } if (m_controls[control::HEADPHONE] && m_controls[control::HEADPHONE]->test_device_plugged()) { m_headphones = true; - m_volume = m_volume * (m_mapped ? m_mixers[mixer::HEADPHONE]->get_normalized_volume() / 100.0f : - m_mixers[mixer::HEADPHONE]->get_volume() / 100.0f); + m_volume = m_volume * (m_mapped ? m_mixers[mixer::HEADPHONE]->get_normalized_volume() / 100.0f + : m_mixers[mixer::HEADPHONE]->get_volume() / 100.0f); m_muted = m_muted || m_mixers[mixer::HEADPHONE]->is_muted(); } else if (m_mixers[mixer::SPEAKER]) { - m_volume = m_volume * (m_mapped ? m_mixers[mixer::SPEAKER]->get_normalized_volume() / 100.0f : - m_mixers[mixer::SPEAKER]->get_volume() / 100.0f); + m_volume = m_volume * (m_mapped ? m_mixers[mixer::SPEAKER]->get_normalized_volume() / 100.0f + : m_mixers[mixer::SPEAKER]->get_volume() / 100.0f); m_muted = m_muted || m_mixers[mixer::SPEAKER]->is_muted(); } @@ -193,15 +191,13 @@ namespace modules { } } else if (cmd.compare(0, strlen(EVENT_VOLUME_UP), EVENT_VOLUME_UP) == 0) { for (auto&& mixer : mixers) { - m_mapped ? - mixer->set_normalized_volume(math_util::cap(mixer->get_normalized_volume() + 5, 0, 100)) : - mixer->set_volume(math_util::cap(mixer->get_volume() + 5, 0, 100)); + m_mapped ? mixer->set_normalized_volume(math_util::cap(mixer->get_normalized_volume() + 5, 0, 100)) + : mixer->set_volume(math_util::cap(mixer->get_volume() + 5, 0, 100)); } } else if (cmd.compare(0, strlen(EVENT_VOLUME_DOWN), EVENT_VOLUME_DOWN) == 0) { for (auto&& mixer : mixers) { - m_mapped ? - mixer->set_normalized_volume(math_util::cap(mixer->get_normalized_volume() - 5, 0, 100)) : - mixer->set_volume(math_util::cap(mixer->get_volume() - 5, 0, 100)); + m_mapped ? mixer->set_normalized_volume(math_util::cap(mixer->get_normalized_volume() - 5, 0, 100)) + : mixer->set_volume(math_util::cap(mixer->get_volume() - 5, 0, 100)); } } else { return false; diff --git a/src/utils/string.cpp b/src/utils/string.cpp index 46a98153..e5d3490e 100644 --- a/src/utils/string.cpp +++ b/src/utils/string.cpp @@ -81,12 +81,11 @@ namespace string_util { /** * Replace all occurrences with bounded replacement */ - string replace_all_bounded(const string& haystack, string needle, string replacement, - size_t min, size_t max, size_t start, size_t end) { + string replace_all_bounded( + const string& haystack, string needle, string replacement, size_t min, size_t max, size_t start, size_t end) { if (max != 0 && replacement.length() > max) { replacement = replacement.erase(max); - } - else if (min != 0 && replacement.length() < min) { + } else if (min != 0 && replacement.length() < min) { replacement.insert(0, min - replacement.length(), ' '); } return replace_all(haystack, needle, replacement, start, end); diff --git a/src/x11/graphics.cpp b/src/x11/graphics.cpp index c5f5f564..0f96f2c3 100644 --- a/src/x11/graphics.cpp +++ b/src/x11/graphics.cpp @@ -12,7 +12,8 @@ namespace graphics_util { /** * Create a basic window */ - bool create_window(connection& conn, xcb_window_t* win, int16_t x, int16_t y, uint16_t w, uint16_t h, xcb_window_t root) { + bool create_window( + connection& conn, xcb_window_t* win, int16_t x, int16_t y, uint16_t w, uint16_t h, xcb_window_t root) { if (!root) { root = conn.screen()->root; } diff --git a/src/x11/randr.cpp b/src/x11/randr.cpp index e003091f..acfbd255 100644 --- a/src/x11/randr.cpp +++ b/src/x11/randr.cpp @@ -1,6 +1,6 @@ #include "x11/randr.hpp" -#include "x11/connection.hpp" #include "utils/string.hpp" +#include "x11/connection.hpp" POLYBAR_NS diff --git a/src/x11/tray.cpp b/src/x11/tray.cpp index af97a8a0..3ce25c2b 100644 --- a/src/x11/tray.cpp +++ b/src/x11/tray.cpp @@ -489,14 +489,15 @@ void tray_manager::query_atom() { // {{{ void tray_manager::create_window() { // {{{ m_log.trace("tray: Create tray window"); + // clang-format off auto win = winspec(m_connection, m_tray) << cw_size(calculate_w(), calculate_h()) << cw_pos(calculate_x(calculate_w()), calculate_y()) << cw_class(XCB_WINDOW_CLASS_INPUT_OUTPUT) << cw_params_backing_store(XCB_BACKING_STORE_WHEN_MAPPED) << cw_params_event_mask(XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | XCB_EVENT_MASK_STRUCTURE_NOTIFY) - << cw_params_override_redirect(true) - ; + << cw_params_override_redirect(true); + // clang-format on if (!m_opts.transparent) { win << cw_params_back_pixel(m_opts.background); diff --git a/src/x11/window.cpp b/src/x11/window.cpp index 44e41c9e..11b92686 100644 --- a/src/x11/window.cpp +++ b/src/x11/window.cpp @@ -5,8 +5,8 @@ #include "x11/window.hpp" #include "x11/xutils.hpp" -#include "x11/color.hpp" #include "components/types.hpp" +#include "x11/color.hpp" POLYBAR_NS diff --git a/src/x11/wm.cpp b/src/x11/wm.cpp index 07e3db7d..63d56e78 100644 --- a/src/x11/wm.cpp +++ b/src/x11/wm.cpp @@ -1,8 +1,8 @@ #include #include "x11/atoms.hpp" -#include "x11/wm.hpp" #include "x11/connection.hpp" +#include "x11/wm.hpp" POLYBAR_NS @@ -17,13 +17,12 @@ namespace wm_util { } void set_windowtype(connection& conn, xcb_window_t win, vector types) { - conn.change_property(XCB_PROP_MODE_REPLACE, win, _NET_WM_WINDOW_TYPE, XCB_ATOM_ATOM, 32, - types.size(), types.data()); + conn.change_property( + XCB_PROP_MODE_REPLACE, win, _NET_WM_WINDOW_TYPE, XCB_ATOM_ATOM, 32, types.size(), types.data()); } void set_wmstate(connection& conn, xcb_window_t win, vector states) { - conn.change_property( - XCB_PROP_MODE_REPLACE, win, _NET_WM_STATE, XCB_ATOM_ATOM, 32, states.size(), states.data()); + conn.change_property(XCB_PROP_MODE_REPLACE, win, _NET_WM_STATE, XCB_ATOM_ATOM, 32, states.size(), states.data()); } void set_wmpid(connection& conn, xcb_window_t win, pid_t pid) { @@ -33,18 +32,16 @@ namespace wm_util { void set_wmdesktop(connection& conn, xcb_window_t win, uint32_t desktop) { const uint32_t value_list[1]{desktop}; - conn.change_property( - XCB_PROP_MODE_REPLACE, win, _NET_WM_DESKTOP, XCB_ATOM_CARDINAL, 32, 1, value_list); + conn.change_property(XCB_PROP_MODE_REPLACE, win, _NET_WM_DESKTOP, XCB_ATOM_CARDINAL, 32, 1, value_list); } void set_trayorientation(connection& conn, xcb_window_t win, uint32_t orientation) { - conn.change_property(XCB_PROP_MODE_REPLACE, win, _NET_SYSTEM_TRAY_ORIENTATION, - _NET_SYSTEM_TRAY_ORIENTATION, 32, 1, &orientation); + conn.change_property( + XCB_PROP_MODE_REPLACE, win, _NET_SYSTEM_TRAY_ORIENTATION, _NET_SYSTEM_TRAY_ORIENTATION, 32, 1, &orientation); } void set_trayvisual(connection& conn, xcb_window_t win, xcb_visualid_t visual) { - conn.change_property( - XCB_PROP_MODE_REPLACE, win, _NET_SYSTEM_TRAY_VISUAL, XCB_ATOM_VISUALID, 32, 1, &visual); + conn.change_property(XCB_PROP_MODE_REPLACE, win, _NET_SYSTEM_TRAY_VISUAL, XCB_ATOM_VISUALID, 32, 1, &visual); } } diff --git a/src/x11/xembed.cpp b/src/x11/xembed.cpp index cbf0425c..2b8f69b7 100644 --- a/src/x11/xembed.cpp +++ b/src/x11/xembed.cpp @@ -27,8 +27,7 @@ namespace xembed { /** * Send _XEMBED messages */ - void send_message( - connection& conn, xcb_window_t target, long message, long d1, long d2, long d3) { + void send_message(connection& conn, xcb_window_t target, long message, long d1, long d2, long d3) { auto msg = conn.make_client_message(_XEMBED, target); msg->data.data32[0] = XCB_CURRENT_TIME; msg->data.data32[1] = message; diff --git a/src/x11/xutils.cpp b/src/x11/xutils.cpp index 99b72bd5..bc5ecc41 100644 --- a/src/x11/xutils.cpp +++ b/src/x11/xutils.cpp @@ -1,5 +1,5 @@ -#include "x11/atoms.hpp" #include "x11/xutils.hpp" +#include "x11/atoms.hpp" #include "x11/connection.hpp" #include "x11/xlib.hpp"