From d2187f44e05f6fa93d0ac5e96b72dbd2092e2d16 Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Tue, 25 Oct 2016 07:10:03 +0200 Subject: [PATCH] refactor(drawtypes): Cleanup and fixes --- include/common.hpp | 1 + include/components/x11/connection.hpp | 8 +- include/drawtypes/animation.hpp | 13 ++- include/drawtypes/label.hpp | 72 ++++++++++--- include/drawtypes/progressbar.hpp | 143 +++++++++++++++----------- include/drawtypes/ramp.hpp | 44 +++++--- include/modules/backlight.hpp | 8 +- include/modules/battery.hpp | 13 ++- include/modules/bspwm.hpp | 39 +++---- include/modules/cpu.hpp | 8 +- include/modules/i3.hpp | 8 +- include/modules/memory.hpp | 10 +- include/modules/menu.hpp | 8 +- include/modules/mpd.hpp | 42 ++++---- include/modules/network.hpp | 12 +-- include/modules/volume.hpp | 11 +- include/modules/xbacklight.hpp | 6 +- 17 files changed, 257 insertions(+), 189 deletions(-) diff --git a/include/common.hpp b/include/common.hpp index 30605abd..61a3c541 100644 --- a/include/common.hpp +++ b/include/common.hpp @@ -50,6 +50,7 @@ using namespace std::chrono_literals; using std::string; using std::stringstream; using std::size_t; +using std::move; using std::bind; using std::forward; using std::function; diff --git a/include/components/x11/connection.hpp b/include/components/x11/connection.hpp index 61da6606..993fe733 100644 --- a/include/components/x11/connection.hpp +++ b/include/components/x11/connection.hpp @@ -94,8 +94,9 @@ class connection : public xpp_connection { * Send client message event */ void send_client_message(shared_ptr message, xcb_window_t target, - uint32_t event_mask = 0xFFFFFF, bool propagate = false) { - send_event(propagate, target, event_mask, reinterpret_cast(message.get())); + uint32_t event_mask = 0xFFFFFF, bool propagate = false) const { + const char* data = reinterpret_cast(message.get()); + send_event(propagate, target, event_mask, data); flush(); } @@ -111,8 +112,7 @@ class connection : public xpp_connection { if (target == XCB_NONE) target = root(); auto message = make_client_message(XCB_NONE, target); - send_event(false, target, event, reinterpret_cast(message.get())); - flush(); + send_client_message(message, target, event); } /** diff --git a/include/drawtypes/animation.hpp b/include/drawtypes/animation.hpp index e76dabd7..d80cec6b 100644 --- a/include/drawtypes/animation.hpp +++ b/include/drawtypes/animation.hpp @@ -8,9 +8,6 @@ LEMONBUDDY_NS namespace drawtypes { - class animation; - using animation_t = shared_ptr; - class animation : public non_copyable_mixin { public: explicit animation(int framerate_ms) : m_framerate_ms(framerate_ms) {} @@ -58,7 +55,13 @@ namespace drawtypes { } }; - inline auto get_config_animation( + using animation_t = shared_ptr; + + /** + * Create an animation by loading values + * from the configuration + */ + inline auto load_animation( const config& conf, string section, string name = "animation", bool required = true) { vector vec; vector frames; @@ -72,7 +75,7 @@ namespace drawtypes { for (size_t i = 0; i < frames.size(); i++) vec.emplace_back(forward( - get_optional_config_icon(conf, section, name + "-" + to_string(i), frames[i]))); + load_optional_icon(conf, section, name + "-" + to_string(i), frames[i]))); auto framerate = conf.get(section, name + "-framerate", 1000); diff --git a/include/drawtypes/label.hpp b/include/drawtypes/label.hpp index f12386b0..82f4e890 100644 --- a/include/drawtypes/label.hpp +++ b/include/drawtypes/label.hpp @@ -61,7 +61,7 @@ namespace drawtypes { m_tokenized = string_util::replace_all(m_tokenized, token, replacement); } - void replace_defined_values(label_t label) { + void replace_defined_values(const label_t& label) { if (!label->m_foreground.empty()) m_foreground = label->m_foreground; if (!label->m_background.empty()) @@ -72,43 +72,81 @@ namespace drawtypes { m_overline = label->m_overline; } + void copy_undefined(const label_t& label) { + if (m_foreground.empty() && !label->m_foreground.empty()) + m_foreground = label->m_foreground; + if (m_background.empty() && !label->m_background.empty()) + m_background = label->m_background; + if (m_underline.empty() && !label->m_underline.empty()) + m_underline = label->m_underline; + if (m_overline.empty() && !label->m_overline.empty()) + m_overline = label->m_overline; + if (m_font == 0 && label->m_font != 0) + m_font = label->m_font; + if (m_padding == 0 && label->m_padding != 0) + m_padding = label->m_padding; + if (m_margin == 0 && label->m_margin != 0) + m_margin = label->m_margin; + if (m_maxlen == 0 && label->m_maxlen != 0) { + m_maxlen = label->m_maxlen; + m_ellipsis = label->m_ellipsis; + } + } + private: string m_text, m_tokenized; }; - inline label_t get_config_label(const config& conf, string section, string name = "label", - bool required = true, string def = "") { - string text; - + /** + * Create a label by loading values from the configuration + */ + inline label_t load_label( + const config& conf, string section, string name, bool required = true, string def = "") { name = string_util::ltrim(string_util::rtrim(name, '>'), '<'); + string text; + if (required) text = conf.get(section, name); else text = conf.get(section, name, def); - return label_t{new label(text, conf.get(section, name + "-foreground", ""), + // clang-format off + return label_t{new label_t::element_type(text, + conf.get(section, name + "-foreground", ""), conf.get(section, name + "-background", ""), conf.get(section, name + "-underline", ""), conf.get(section, name + "-overline", ""), - conf.get(section, name + "-font", 0), conf.get(section, name + "-padding", 0), - conf.get(section, name + "-margin", 0), conf.get(section, name + "-maxlen", 0), + conf.get(section, name + "-font", 0), + conf.get(section, name + "-padding", 0), + conf.get(section, name + "-margin", 0), + conf.get(section, name + "-maxlen", 0), conf.get(section, name + "-ellipsis", true))}; + // clang-format on } - inline label_t get_optional_config_label( - const config& conf, string section, string name = "label", string def = "") { - return get_config_label(conf, section, name, false, def); + /** + * Create a label by loading optional values from the configuration + */ + inline label_t load_optional_label( + const config& conf, string section, string name, string def = "") { + return load_label(conf, section, name, false, def); } - inline icon_t get_config_icon(const config& conf, string section, string name = "icon", - bool required = true, string def = "") { - return get_config_label(conf, section, name, required, def); + /** + * Create an icon by loading values from the configuration + */ + inline icon_t load_icon( + const config& conf, string section, string name, bool required = true, string def = "") { + return load_label(conf, section, name, required, def); } - inline icon_t get_optional_config_icon( - const config& conf, string section, string name = "icon", string def = "") { - return get_config_icon(conf, section, name, false, def); + /** + * Create an icon by loading optional values from the configuration + */ + inline icon_t load_optional_icon( + const config& conf, string section, string name, string def = "") { + return load_icon(conf, section, name, false, def); } } diff --git a/include/drawtypes/progressbar.hpp b/include/drawtypes/progressbar.hpp index 59cff9bb..1f99d1e8 100644 --- a/include/drawtypes/progressbar.hpp +++ b/include/drawtypes/progressbar.hpp @@ -5,6 +5,7 @@ #include "components/config.hpp" #include "components/types.hpp" #include "drawtypes/label.hpp" +#include "utils/math.hpp" #include "utils/mixins.hpp" LEMONBUDDY_NS @@ -13,12 +14,10 @@ namespace drawtypes { class progressbar : public non_copyable_mixin { public: explicit progressbar( - const bar_settings& bar, int width, string format, bool lazy_builder_closing) + const bar_settings& bar, int width, string format, bool lazy_builder_closing = true) : m_builder(make_unique(bar, lazy_builder_closing)) , m_format(format) , m_width(width) {} - explicit progressbar(const bar_settings& bar, int width, bool lazy_builder_closing = true) - : progressbar(bar, width, "", lazy_builder_closing) {} void set_fill(icon_t&& fill) { m_fill = forward(fill); @@ -29,6 +28,8 @@ namespace drawtypes { } void set_indicator(icon_t&& indicator) { + if (!m_indicator && indicator.get()) + m_width--; m_indicator = forward(indicator); } @@ -38,54 +39,30 @@ namespace drawtypes { void set_colors(vector&& colors) { m_colors = forward(colors); + + if (m_colors.empty()) + m_colorstep = 1; + else + m_colorstep = m_width / m_colors.size(); } string output(float percentage) { - if (m_colors.empty()) - m_colors.emplace_back(m_fill->m_foreground); + string output{m_format}; - int fill_width = m_width * percentage / 100.0f + 0.5f; - int empty_width = m_width - fill_width; - int color_step = m_width / m_colors.size() + 0.5f; - - auto output = string(m_format); - - if (m_indicator && *m_indicator) { - if (empty_width == 1) - empty_width = 0; - else if (fill_width == 0) - empty_width--; - else - fill_width--; - } - - if (!m_gradient) { - auto idx = static_cast((m_colors.size() - 1) * percentage / 100.0f + 0.5f); - m_fill->m_foreground = m_colors[idx]; - while (fill_width--) { - m_builder->node(m_fill); - } - } else { - int i = 0; - for (auto color : m_colors) { - i += 1; - int j = 0; - - if ((i - 1) * color_step >= fill_width) - break; - - m_fill->m_foreground = color; - - while (j++ < color_step && (i - 1) * color_step + j <= fill_width) - m_builder->node(m_fill); - } - } + // Get fill/empty widths based on percentage + unsigned int perc = math_util::cap(percentage, 0.0f, 100.0f); + unsigned int fill_width = math_util::percentage_to_value(perc, m_width); + unsigned int empty_width = m_width - fill_width; + // Output fill icons + fill(perc, fill_width); output = string_util::replace_all(output, "%fill%", m_builder->flush()); + // Output indicator icon m_builder->node(m_indicator); output = string_util::replace_all(output, "%indicator%", m_builder->flush()); + // Output empty icons while (empty_width--) m_builder->node(m_empty); output = string_util::replace_all(output, "%empty%", m_builder->flush()); @@ -93,10 +70,33 @@ namespace drawtypes { } protected: + void fill(unsigned int perc, unsigned int fill_width) { + if (m_colors.empty()) { + for (size_t i = 0; i < fill_width; i++) { + m_builder->node(m_fill); + } + } else if (m_gradient) { + size_t color = 0; + for (size_t i = 0; i < fill_width; i++) { + if (i % m_colorstep == 0) + m_fill->m_foreground = m_colors[color++]; + m_builder->node(m_fill); + } + } else { + size_t color = math_util::percentage_to_value(perc, m_colors.size() - 1); + m_fill->m_foreground = m_colors[color]; + for (size_t i = 0; i < fill_width; i++) { + m_builder->node(m_fill); + } + } + } + + private: unique_ptr m_builder; vector m_colors; string m_format; unsigned int m_width; + unsigned int m_colorstep = 1; bool m_gradient = false; icon_t m_fill; @@ -106,30 +106,53 @@ namespace drawtypes { using progressbar_t = shared_ptr; - inline auto get_config_bar(const bar_settings& bar, const config& conf, string section, - string name = "bar", bool lazy_builder_closing = true) { - progressbar_t p; - + /** + * Create a progressbar by loading values + * from the configuration + */ + inline auto load_progressbar( + const bar_settings& bar, const config& conf, string section, string name) { + // Remove the start and end tag from the name in case a format tag is passed name = string_util::ltrim(string_util::rtrim(name, '>'), '<'); - auto width = conf.get(section, name + "-width"); - auto format = conf.get(section, name + "-format", "%fill%%indicator%%empty%"); + string format = "%fill%%indicator%%empty%"; + unsigned int width; - if (format.empty()) - p.reset(new progressbar(bar, width, lazy_builder_closing)); - else - p.reset(new progressbar(bar, width, format, lazy_builder_closing)); + if ((format = conf.get(section, name + "-format", format)).empty()) + throw application_error("Invalid format defined at [" + conf.build_path(section, name) + "]"); + if ((width = conf.get(section, name + "-width")) < 1) + throw application_error("Invalid width defined at [" + conf.build_path(section, name) + "]"); - p->set_gradient(conf.get(section, name + "-gradient", true)); - p->set_colors(conf.get_list(section, name + "-foreground", {})); - p->set_indicator(get_config_icon( - conf, section, name + "-indicator", format.find("%indicator%") != string::npos, "")); - p->set_fill( - get_config_icon(conf, section, name + "-fill", format.find("%fill%") != string::npos, "")); - p->set_empty(get_config_icon( - conf, section, name + "-empty", format.find("%empty%") != string::npos, "")); + progressbar_t progressbar{new progressbar_t::element_type(bar, width, format)}; + progressbar->set_gradient(conf.get(section, name + "-gradient", true)); + progressbar->set_colors(conf.get_list(section, name + "-foreground", {})); - return p; + icon_t icon_empty; + icon_t icon_fill; + icon_t icon_indicator; + + if (format.find("%empty%") != string::npos) + icon_empty = load_icon(conf, section, name + "-empty"); + if (format.find("%fill%") != string::npos) + icon_fill = load_icon(conf, section, name + "-fill"); + if (format.find("%indicator%") != string::npos) + icon_indicator = load_icon(conf, section, name + "-indicator"); + + // If a foreground/background color is defined for the indicator + // but not for the empty icon we use the bar's default colors to + // avoid color bleed + if (icon_empty && icon_indicator) { + if (!icon_indicator->m_background.empty() && icon_empty->m_background.empty()) + icon_empty->m_background = bar.background.hex(); + if (!icon_indicator->m_foreground.empty() && icon_empty->m_foreground.empty()) + icon_empty->m_foreground = bar.foreground.hex(); + } + + progressbar->set_empty(move(icon_empty)); + progressbar->set_fill(move(icon_fill)); + progressbar->set_indicator(move(icon_indicator)); + + return progressbar; } } diff --git a/include/drawtypes/ramp.hpp b/include/drawtypes/ramp.hpp index 30d05d32..6b28a0ea 100644 --- a/include/drawtypes/ramp.hpp +++ b/include/drawtypes/ramp.hpp @@ -3,14 +3,12 @@ #include "common.hpp" #include "components/config.hpp" #include "drawtypes/label.hpp" +#include "utils/math.hpp" #include "utils/mixins.hpp" LEMONBUDDY_NS namespace drawtypes { - class ramp; - using ramp_t = shared_ptr; - class ramp : public non_copyable_mixin { public: explicit ramp() = default; @@ -20,28 +18,40 @@ namespace drawtypes { m_icons.emplace_back(forward(icon)); } - icon_t get(int index) { + icon_t get(size_t index) { return m_icons[index]; } icon_t get_by_percentage(float percentage) { - return m_icons[static_cast(percentage * (m_icons.size() - 1) / 100.0f + 0.5f)]; + size_t index = percentage * (m_icons.size() - 1) / 100.0f + 0.5f; + return m_icons[math_util::cap(index, 0, m_icons.size() - 1)]; } operator bool() { - return m_icons.size() > 0; + return !m_icons.empty(); } protected: vector m_icons; }; - inline auto get_config_ramp( - const config& conf, string section, string name = "ramp", bool required = true) { - vector vec; + using ramp_t = shared_ptr; + /** + * Create a ramp by loading values + * from the configuration + */ + inline auto load_ramp(const config& conf, string section, string name, bool required = true) { name = string_util::ltrim(string_util::rtrim(name, '>'), '<'); + icon_t ramp_defaults; + + try { + ramp_defaults = load_icon(conf, section, name); + } catch (const key_error&) { + } + + vector vec; vector icons; if (required) @@ -49,16 +59,16 @@ namespace drawtypes { else icons = conf.get_list(section, name, {}); - auto foreground = conf.get(section, name + "-foreground", ""); - for (int i = 0; i < (int)icons.size(); i++) { - auto ramp = name + "-" + to_string(i); - auto icon = get_optional_config_icon(conf, section, ramp, icons[i]); - if (icon->m_foreground.empty() && !foreground.empty()) - icon->m_foreground = foreground; - vec.emplace_back(std::move(icon)); + for (size_t i = 0; i < icons.size(); i++) { + auto icon = load_optional_icon(conf, section, name + "-" + to_string(i), icons[i]); + + if (ramp_defaults) + icon->copy_undefined(ramp_defaults); + + vec.emplace_back(move(icon)); } - return ramp_t{new ramp(std::move(vec))}; + return ramp_t{new ramp_t::element_type(move(vec))}; } } diff --git a/include/modules/backlight.hpp b/include/modules/backlight.hpp index 4a70dfc0..431cfad5 100644 --- a/include/modules/backlight.hpp +++ b/include/modules/backlight.hpp @@ -1,7 +1,7 @@ #pragma once -#include "config.hpp" #include "components/config.hpp" +#include "config.hpp" #include "drawtypes/label.hpp" #include "drawtypes/progressbar.hpp" #include "drawtypes/ramp.hpp" @@ -37,11 +37,11 @@ namespace modules { m_formatter->add(DEFAULT_FORMAT, TAG_LABEL, {TAG_LABEL, TAG_BAR, TAG_RAMP}); if (m_formatter->has(TAG_LABEL)) - m_label = get_optional_config_label(m_conf, name(), TAG_LABEL, "%percentage%"); + m_label = load_optional_label(m_conf, name(), TAG_LABEL, "%percentage%"); if (m_formatter->has(TAG_BAR)) - m_progressbar = get_config_bar(m_bar, m_conf, name(), TAG_BAR); + m_progressbar = load_progressbar(m_bar, m_conf, name(), TAG_BAR); if (m_formatter->has(TAG_RAMP)) - m_ramp = get_config_ramp(m_conf, name(), TAG_RAMP); + m_ramp = load_ramp(m_conf, name(), TAG_RAMP); // Build path to the file where the current/maximum brightness value is located m_val.filepath(string_util::replace(PATH_BACKLIGHT_VAL, "%card%", card)); diff --git a/include/modules/battery.hpp b/include/modules/battery.hpp index df2156b6..853b30a3 100644 --- a/include/modules/battery.hpp +++ b/include/modules/battery.hpp @@ -49,21 +49,20 @@ namespace modules { FORMAT_FULL, TAG_LABEL_FULL, {TAG_BAR_CAPACITY, TAG_RAMP_CAPACITY, TAG_LABEL_FULL}); if (m_formatter->has(TAG_ANIMATION_CHARGING, FORMAT_CHARGING)) - m_animation_charging = get_config_animation(m_conf, name(), TAG_ANIMATION_CHARGING); + m_animation_charging = load_animation(m_conf, name(), TAG_ANIMATION_CHARGING); if (m_formatter->has(TAG_BAR_CAPACITY)) - m_bar_capacity = get_config_bar(m_bar, m_conf, name(), TAG_BAR_CAPACITY); + m_bar_capacity = load_progressbar(m_bar, m_conf, name(), TAG_BAR_CAPACITY); if (m_formatter->has(TAG_RAMP_CAPACITY)) - m_ramp_capacity = get_config_ramp(m_conf, name(), TAG_RAMP_CAPACITY); + m_ramp_capacity = load_ramp(m_conf, name(), TAG_RAMP_CAPACITY); if (m_formatter->has(TAG_LABEL_CHARGING, FORMAT_CHARGING)) { - m_label_charging = - get_optional_config_label(m_conf, name(), TAG_LABEL_CHARGING, "%percentage%"); + m_label_charging = load_optional_label(m_conf, name(), TAG_LABEL_CHARGING, "%percentage%"); } if (m_formatter->has(TAG_LABEL_DISCHARGING, FORMAT_DISCHARGING)) { m_label_discharging = - get_optional_config_label(m_conf, name(), TAG_LABEL_DISCHARGING, "%percentage%"); + load_optional_label(m_conf, name(), TAG_LABEL_DISCHARGING, "%percentage%"); } if (m_formatter->has(TAG_LABEL_FULL, FORMAT_FULL)) { - m_label_full = get_optional_config_label(m_conf, name(), TAG_LABEL_FULL, "%percentage%"); + m_label_full = load_optional_label(m_conf, name(), TAG_LABEL_FULL, "%percentage%"); } // }}} diff --git a/include/modules/bspwm.hpp b/include/modules/bspwm.hpp index 050a8a14..12f3f6b7 100644 --- a/include/modules/bspwm.hpp +++ b/include/modules/bspwm.hpp @@ -53,32 +53,32 @@ namespace modules { if (m_formatter->has(TAG_LABEL_STATE)) { m_statelabels.insert(make_pair(bspwm_flag::WORKSPACE_ACTIVE, - get_optional_config_label(m_conf, name(), "label-active", DEFAULT_WS_LABEL))); + load_optional_label(m_conf, name(), "label-active", DEFAULT_WS_LABEL))); m_statelabels.insert(make_pair(bspwm_flag::WORKSPACE_OCCUPIED, - get_optional_config_label(m_conf, name(), "label-occupied", DEFAULT_WS_LABEL))); + load_optional_label(m_conf, name(), "label-occupied", DEFAULT_WS_LABEL))); m_statelabels.insert(make_pair(bspwm_flag::WORKSPACE_URGENT, - get_optional_config_label(m_conf, name(), "label-urgent", DEFAULT_WS_LABEL))); + load_optional_label(m_conf, name(), "label-urgent", DEFAULT_WS_LABEL))); m_statelabels.insert(make_pair(bspwm_flag::WORKSPACE_EMPTY, - get_optional_config_label(m_conf, name(), "label-empty", DEFAULT_WS_LABEL))); - m_statelabels.insert(make_pair(bspwm_flag::WORKSPACE_DIMMED, - get_optional_config_label(m_conf, name(), "label-dimmed"))); + load_optional_label(m_conf, name(), "label-empty", DEFAULT_WS_LABEL))); + m_statelabels.insert(make_pair( + bspwm_flag::WORKSPACE_DIMMED, load_optional_label(m_conf, name(), "label-dimmed"))); } if (m_formatter->has(TAG_LABEL_MODE)) { - m_modelabels.insert(make_pair(bspwm_flag::MODE_LAYOUT_MONOCLE, - get_optional_config_label(m_conf, name(), "label-monocle"))); - m_modelabels.insert(make_pair(bspwm_flag::MODE_LAYOUT_TILED, - get_optional_config_label(m_conf, name(), "label-tiled"))); + m_modelabels.insert(make_pair( + bspwm_flag::MODE_LAYOUT_MONOCLE, load_optional_label(m_conf, name(), "label-monocle"))); + m_modelabels.insert(make_pair( + bspwm_flag::MODE_LAYOUT_TILED, load_optional_label(m_conf, name(), "label-tiled"))); m_modelabels.insert(make_pair(bspwm_flag::MODE_STATE_FULLSCREEN, - get_optional_config_label(m_conf, name(), "label-fullscreen"))); + load_optional_label(m_conf, name(), "label-fullscreen"))); m_modelabels.insert(make_pair(bspwm_flag::MODE_STATE_FLOATING, - get_optional_config_label(m_conf, name(), "label-floating"))); - m_modelabels.insert(make_pair(bspwm_flag::MODE_NODE_LOCKED, - get_optional_config_label(m_conf, name(), "label-locked"))); - m_modelabels.insert(make_pair(bspwm_flag::MODE_NODE_STICKY, - get_optional_config_label(m_conf, name(), "label-sticky"))); - m_modelabels.insert(make_pair(bspwm_flag::MODE_NODE_PRIVATE, - get_optional_config_label(m_conf, name(), "label-private"))); + load_optional_label(m_conf, name(), "label-floating"))); + m_modelabels.insert(make_pair( + bspwm_flag::MODE_NODE_LOCKED, load_optional_label(m_conf, name(), "label-locked"))); + m_modelabels.insert(make_pair( + bspwm_flag::MODE_NODE_STICKY, load_optional_label(m_conf, name(), "label-sticky"))); + m_modelabels.insert(make_pair( + bspwm_flag::MODE_NODE_PRIVATE, load_optional_label(m_conf, name(), "label-private"))); } m_icons = iconset_t{new iconset()}; @@ -316,7 +316,8 @@ namespace modules { try { auto ipc = bspwm_util::make_connection(); - auto payload = bspwm_util::make_payload("desktop -f "+ m_monitor +":^"+ cmd.substr(strlen(EVENT_CLICK))); + auto payload = bspwm_util::make_payload( + "desktop -f " + m_monitor + ":^" + cmd.substr(strlen(EVENT_CLICK))); m_log.info("%s: Sending desktop focus command to ipc handler", name()); diff --git a/include/modules/cpu.hpp b/include/modules/cpu.hpp index 1c0df5a4..6d3f56ba 100644 --- a/include/modules/cpu.hpp +++ b/include/modules/cpu.hpp @@ -32,13 +32,13 @@ namespace modules { {TAG_LABEL, TAG_BAR_LOAD, TAG_RAMP_LOAD, TAG_RAMP_LOAD_PER_CORE}); if (m_formatter->has(TAG_BAR_LOAD)) - m_barload = get_config_bar(m_bar, m_conf, name(), TAG_BAR_LOAD); + m_barload = load_progressbar(m_bar, m_conf, name(), TAG_BAR_LOAD); if (m_formatter->has(TAG_RAMP_LOAD)) - m_rampload = get_config_ramp(m_conf, name(), TAG_RAMP_LOAD); + m_rampload = load_ramp(m_conf, name(), TAG_RAMP_LOAD); if (m_formatter->has(TAG_RAMP_LOAD_PER_CORE)) - m_rampload_core = get_config_ramp(m_conf, name(), TAG_RAMP_LOAD_PER_CORE); + m_rampload_core = load_ramp(m_conf, name(), TAG_RAMP_LOAD_PER_CORE); if (m_formatter->has(TAG_LABEL)) - m_label = get_optional_config_label(m_conf, name(), TAG_LABEL, "%percentage%"); + m_label = load_optional_label(m_conf, name(), TAG_LABEL, "%percentage%"); // warmup read_values(); diff --git a/include/modules/i3.hpp b/include/modules/i3.hpp index 303cd827..3f0e1942 100644 --- a/include/modules/i3.hpp +++ b/include/modules/i3.hpp @@ -59,13 +59,13 @@ namespace modules { if (m_formatter->has(TAG_LABEL_STATE)) { m_statelabels.insert(make_pair(i3_flag::WORKSPACE_FOCUSED, - get_optional_config_label(m_conf, name(), "label-focused", DEFAULT_WS_LABEL))); + load_optional_label(m_conf, name(), "label-focused", DEFAULT_WS_LABEL))); m_statelabels.insert(make_pair(i3_flag::WORKSPACE_UNFOCUSED, - get_optional_config_label(m_conf, name(), "label-unfocused", DEFAULT_WS_LABEL))); + load_optional_label(m_conf, name(), "label-unfocused", DEFAULT_WS_LABEL))); m_statelabels.insert(make_pair(i3_flag::WORKSPACE_VISIBLE, - get_optional_config_label(m_conf, name(), "label-visible", DEFAULT_WS_LABEL))); + load_optional_label(m_conf, name(), "label-visible", DEFAULT_WS_LABEL))); m_statelabels.insert(make_pair(i3_flag::WORKSPACE_URGENT, - get_optional_config_label(m_conf, name(), "label-urgent", DEFAULT_WS_LABEL))); + load_optional_label(m_conf, name(), "label-urgent", DEFAULT_WS_LABEL))); } m_icons = iconset_t{new iconset()}; diff --git a/include/modules/memory.hpp b/include/modules/memory.hpp index 5d94cd79..97742dda 100644 --- a/include/modules/memory.hpp +++ b/include/modules/memory.hpp @@ -22,11 +22,11 @@ namespace modules { m_formatter->add(DEFAULT_FORMAT, TAG_LABEL, {TAG_LABEL, TAG_BAR_USED, TAG_BAR_FREE}); if (m_formatter->has(TAG_BAR_USED)) - m_bars[memtype::USED] = get_config_bar(m_bar, m_conf, name(), TAG_BAR_USED); + m_bars[memtype::USED] = load_progressbar(m_bar, m_conf, name(), TAG_BAR_USED); if (m_formatter->has(TAG_BAR_FREE)) - m_bars[memtype::FREE] = get_config_bar(m_bar, m_conf, name(), TAG_BAR_FREE); + m_bars[memtype::FREE] = load_progressbar(m_bar, m_conf, name(), TAG_BAR_FREE); if (m_formatter->has(TAG_LABEL)) - m_label = get_optional_config_label(m_conf, name(), TAG_LABEL, "%percentage_used%"); + m_label = load_optional_label(m_conf, name(), TAG_LABEL, "%percentage_used%"); } bool update() { @@ -93,9 +93,9 @@ namespace modules { } bool build(builder* builder, string tag) const { - if (tag == TAG_BAR_USED) { + if (tag == TAG_BAR_USED) builder->node(m_bars.at(memtype::USED)->output(m_perc.at(memtype::USED))); - } else if (tag == TAG_BAR_FREE) + else if (tag == TAG_BAR_FREE) builder->node(m_bars.at(memtype::FREE)->output(m_perc.at(memtype::FREE))); else if (tag == TAG_LABEL) builder->node(m_label); diff --git a/include/modules/menu.hpp b/include/modules/menu.hpp index 250886c9..c074d550 100644 --- a/include/modules/menu.hpp +++ b/include/modules/menu.hpp @@ -25,11 +25,11 @@ namespace modules { m_formatter->add(DEFAULT_FORMAT, default_format, {TAG_LABEL_TOGGLE, TAG_MENU}); if (m_formatter->has(TAG_LABEL_TOGGLE)) { - m_labelopen = get_config_label(m_conf, name(), "label-open"); - m_labelclose = get_optional_config_label(m_conf, name(), "label-close", "x"); + m_labelopen = load_label(m_conf, name(), "label-open"); + m_labelclose = load_optional_label(m_conf, name(), "label-close", "x"); } - m_labelseparator = get_optional_config_label(m_conf, name(), "label-separator", ""); + m_labelseparator = load_optional_label(m_conf, name(), "label-separator", ""); if (!m_formatter->has(TAG_MENU)) return; @@ -51,7 +51,7 @@ namespace modules { m_log.trace("%s: Creating menu level item %i", name(), m_levels.back()->items.size()); auto item = make_unique(); - item->label = get_config_label(m_conf, name(), item_param); + item->label = load_label(m_conf, name(), item_param); item->exec = m_conf.get(name(), item_param + "-exec", EVENT_MENU_CLOSE); m_levels.back()->items.emplace_back(std::move(item)); } diff --git a/include/modules/mpd.hpp b/include/modules/mpd.hpp index 0d7e1a99..1698d2d4 100644 --- a/include/modules/mpd.hpp +++ b/include/modules/mpd.hpp @@ -34,44 +34,39 @@ namespace modules { m_icons = iconset_t{new iconset()}; if (m_formatter->has(TAG_ICON_PLAY) || m_formatter->has(TAG_TOGGLE)) - m_icons->add("play", get_config_icon(m_conf, name(), TAG_ICON_PLAY)); + m_icons->add("play", load_icon(m_conf, name(), TAG_ICON_PLAY)); if (m_formatter->has(TAG_ICON_PAUSE) || m_formatter->has(TAG_TOGGLE)) - m_icons->add("pause", get_config_icon(m_conf, name(), TAG_ICON_PAUSE)); + m_icons->add("pause", load_icon(m_conf, name(), TAG_ICON_PAUSE)); if (m_formatter->has(TAG_ICON_STOP)) - m_icons->add("stop", get_config_icon(m_conf, name(), TAG_ICON_STOP)); + m_icons->add("stop", load_icon(m_conf, name(), TAG_ICON_STOP)); if (m_formatter->has(TAG_ICON_PREV)) - m_icons->add("prev", get_config_icon(m_conf, name(), TAG_ICON_PREV)); + m_icons->add("prev", load_icon(m_conf, name(), TAG_ICON_PREV)); if (m_formatter->has(TAG_ICON_NEXT)) - m_icons->add("next", get_config_icon(m_conf, name(), TAG_ICON_NEXT)); + m_icons->add("next", load_icon(m_conf, name(), TAG_ICON_NEXT)); if (m_formatter->has(TAG_ICON_SEEKB)) - m_icons->add("seekb", get_config_icon(m_conf, name(), TAG_ICON_SEEKB)); + m_icons->add("seekb", load_icon(m_conf, name(), TAG_ICON_SEEKB)); if (m_formatter->has(TAG_ICON_SEEKF)) - m_icons->add("seekf", get_config_icon(m_conf, name(), TAG_ICON_SEEKF)); + m_icons->add("seekf", load_icon(m_conf, name(), TAG_ICON_SEEKF)); if (m_formatter->has(TAG_ICON_RANDOM)) - m_icons->add("random", get_config_icon(m_conf, name(), TAG_ICON_RANDOM)); + m_icons->add("random", load_icon(m_conf, name(), TAG_ICON_RANDOM)); if (m_formatter->has(TAG_ICON_REPEAT)) - m_icons->add("repeat", get_config_icon(m_conf, name(), TAG_ICON_REPEAT)); + m_icons->add("repeat", load_icon(m_conf, name(), TAG_ICON_REPEAT)); if (m_formatter->has(TAG_ICON_REPEAT_ONE)) - m_icons->add("repeat_one", get_config_icon(m_conf, name(), TAG_ICON_REPEAT_ONE)); + m_icons->add("repeat_one", load_icon(m_conf, name(), TAG_ICON_REPEAT_ONE)); - if (m_formatter->has(TAG_LABEL_SONG)) { - m_label_song = - get_optional_config_label(m_conf, name(), TAG_LABEL_SONG, "%artist% - %title%"); - } - if (m_formatter->has(TAG_LABEL_TIME)) { - m_label_time = - get_optional_config_label(m_conf, name(), TAG_LABEL_TIME, "%elapsed% / %total%"); - } + if (m_formatter->has(TAG_LABEL_SONG)) + m_label_song = load_optional_label(m_conf, name(), TAG_LABEL_SONG, "%artist% - %title%"); + if (m_formatter->has(TAG_LABEL_TIME)) + m_label_time = load_optional_label(m_conf, name(), TAG_LABEL_TIME, "%elapsed% / %total%"); if (m_formatter->has(TAG_ICON_RANDOM) || m_formatter->has(TAG_ICON_REPEAT) || m_formatter->has(TAG_ICON_REPEAT_ONE)) { m_toggle_on_color = m_conf.get(name(), "toggle-on-foreground", ""); m_toggle_off_color = m_conf.get(name(), "toggle-off-foreground", ""); } if (m_formatter->has(TAG_LABEL_OFFLINE, FORMAT_OFFLINE)) - m_label_offline = get_config_label(m_conf, name(), TAG_LABEL_OFFLINE); - if (m_formatter->has(TAG_BAR_PROGRESS)) { - m_bar_progress = get_config_bar(m_bar, m_conf, name(), TAG_BAR_PROGRESS); - } + m_label_offline = load_label(m_conf, name(), TAG_LABEL_OFFLINE); + if (m_formatter->has(TAG_BAR_PROGRESS)) + m_bar_progress = load_progressbar(m_bar, m_conf, name(), TAG_BAR_PROGRESS); // }}} @@ -183,8 +178,7 @@ namespace modules { if (m_label_song) { m_label_song->reset_tokens(); - m_label_song->replace_token( - "%artist%", !artist.empty() ? artist : "untitled artist"); + m_label_song->replace_token("%artist%", !artist.empty() ? artist : "untitled artist"); m_label_song->replace_token("%album%", !album.empty() ? album : "untitled album"); m_label_song->replace_token("%title%", !title.empty() ? title : "untitled track"); } diff --git a/include/modules/network.hpp b/include/modules/network.hpp index 389b5519..52be18ce 100644 --- a/include/modules/network.hpp +++ b/include/modules/network.hpp @@ -32,18 +32,18 @@ namespace modules { // Create elements for format-connected if (m_formatter->has(TAG_RAMP_SIGNAL, FORMAT_CONNECTED)) - m_ramp_signal = get_config_ramp(m_conf, name(), TAG_RAMP_SIGNAL); + m_ramp_signal = load_ramp(m_conf, name(), TAG_RAMP_SIGNAL); if (m_formatter->has(TAG_RAMP_QUALITY, FORMAT_CONNECTED)) - m_ramp_quality = get_config_ramp(m_conf, name(), TAG_RAMP_QUALITY); + m_ramp_quality = load_ramp(m_conf, name(), TAG_RAMP_QUALITY); if (m_formatter->has(TAG_LABEL_CONNECTED, FORMAT_CONNECTED)) { m_label[connection_state::CONNECTED] = - get_optional_config_label(m_conf, name(), TAG_LABEL_CONNECTED, "%ifname% %local_ip%"); + load_optional_label(m_conf, name(), TAG_LABEL_CONNECTED, "%ifname% %local_ip%"); } // Create elements for format-disconnected if (m_formatter->has(TAG_LABEL_DISCONNECTED, FORMAT_DISCONNECTED)) { m_label[connection_state::DISCONNECTED] = - get_optional_config_label(m_conf, name(), TAG_LABEL_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); } @@ -55,10 +55,10 @@ namespace modules { if (m_formatter->has(TAG_LABEL_PACKETLOSS, FORMAT_PACKETLOSS)) { m_label[connection_state::PACKETLOSS] = - get_optional_config_label(m_conf, name(), TAG_LABEL_PACKETLOSS, ""); + load_optional_label(m_conf, name(), TAG_LABEL_PACKETLOSS, ""); } if (m_formatter->has(TAG_ANIMATION_PACKETLOSS, FORMAT_PACKETLOSS)) - m_animation_packetloss = get_config_animation(m_conf, name(), TAG_ANIMATION_PACKETLOSS); + m_animation_packetloss = load_animation(m_conf, name(), TAG_ANIMATION_PACKETLOSS); } // Get an intstance of the network interface diff --git a/include/modules/volume.hpp b/include/modules/volume.hpp index 9e898e3f..44478125 100644 --- a/include/modules/volume.hpp +++ b/include/modules/volume.hpp @@ -87,18 +87,17 @@ namespace modules { FORMAT_MUTED, TAG_LABEL_MUTED, {TAG_RAMP_VOLUME, TAG_LABEL_MUTED, TAG_BAR_VOLUME}); if (m_formatter->has(TAG_BAR_VOLUME)) { - m_bar_volume = get_config_bar(m_bar, m_conf, name(), TAG_BAR_VOLUME); + m_bar_volume = load_progressbar(m_bar, m_conf, name(), TAG_BAR_VOLUME); } if (m_formatter->has(TAG_RAMP_VOLUME)) { - m_ramp_volume = get_config_ramp(m_conf, name(), TAG_RAMP_VOLUME); - m_ramp_headphones = get_config_ramp(m_conf, name(), TAG_RAMP_HEADPHONES, false); + m_ramp_volume = load_ramp(m_conf, name(), TAG_RAMP_VOLUME); + m_ramp_headphones = load_ramp(m_conf, name(), TAG_RAMP_HEADPHONES, false); } if (m_formatter->has(TAG_LABEL_VOLUME, FORMAT_VOLUME)) { - m_label_volume = - get_optional_config_label(m_conf, name(), TAG_LABEL_VOLUME, "%percentage%"); + m_label_volume = load_optional_label(m_conf, name(), TAG_LABEL_VOLUME, "%percentage%"); } if (m_formatter->has(TAG_LABEL_MUTED, FORMAT_MUTED)) { - m_label_muted = get_optional_config_label(m_conf, name(), TAG_LABEL_MUTED, "%percentage%"); + m_label_muted = load_optional_label(m_conf, name(), TAG_LABEL_MUTED, "%percentage%"); } // }}} diff --git a/include/modules/xbacklight.hpp b/include/modules/xbacklight.hpp index 720947fa..ace3d540 100644 --- a/include/modules/xbacklight.hpp +++ b/include/modules/xbacklight.hpp @@ -76,11 +76,11 @@ namespace modules { m_formatter->add(DEFAULT_FORMAT, TAG_LABEL, {TAG_LABEL, TAG_BAR, TAG_RAMP}); if (m_formatter->has(TAG_LABEL)) - m_label = get_optional_config_label(m_conf, name(), TAG_LABEL, "%percentage%"); + m_label = load_optional_label(m_conf, name(), TAG_LABEL, "%percentage%"); if (m_formatter->has(TAG_BAR)) - m_progressbar = get_config_bar(m_bar, m_conf, name(), TAG_BAR); + m_progressbar = load_progressbar(m_bar, m_conf, name(), TAG_BAR); if (m_formatter->has(TAG_RAMP)) - m_ramp = get_config_ramp(m_conf, name(), TAG_RAMP); + m_ramp = load_ramp(m_conf, name(), TAG_RAMP); // Trigger the initial draw event update();