refactor(drawtypes): Cleanup and fixes

This commit is contained in:
Michael Carlberg 2016-10-25 07:10:03 +02:00
parent a0f0fc8723
commit d2187f44e0
17 changed files with 257 additions and 189 deletions

View File

@ -50,6 +50,7 @@ using namespace std::chrono_literals;
using std::string; using std::string;
using std::stringstream; using std::stringstream;
using std::size_t; using std::size_t;
using std::move;
using std::bind; using std::bind;
using std::forward; using std::forward;
using std::function; using std::function;

View File

@ -94,8 +94,9 @@ class connection : public xpp_connection {
* Send client message event * Send client message event
*/ */
void send_client_message(shared_ptr<xcb_client_message_event_t> message, xcb_window_t target, void send_client_message(shared_ptr<xcb_client_message_event_t> message, xcb_window_t target,
uint32_t event_mask = 0xFFFFFF, bool propagate = false) { uint32_t event_mask = 0xFFFFFF, bool propagate = false) const {
send_event(propagate, target, event_mask, reinterpret_cast<char*>(message.get())); const char* data = reinterpret_cast<decltype(data)>(message.get());
send_event(propagate, target, event_mask, data);
flush(); flush();
} }
@ -111,8 +112,7 @@ class connection : public xpp_connection {
if (target == XCB_NONE) if (target == XCB_NONE)
target = root(); target = root();
auto message = make_client_message(XCB_NONE, target); auto message = make_client_message(XCB_NONE, target);
send_event(false, target, event, reinterpret_cast<char*>(message.get())); send_client_message(message, target, event);
flush();
} }
/** /**

View File

@ -8,9 +8,6 @@
LEMONBUDDY_NS LEMONBUDDY_NS
namespace drawtypes { namespace drawtypes {
class animation;
using animation_t = shared_ptr<animation>;
class animation : public non_copyable_mixin<animation> { class animation : public non_copyable_mixin<animation> {
public: public:
explicit animation(int framerate_ms) : m_framerate_ms(framerate_ms) {} 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<animation>;
/**
* Create an animation by loading values
* from the configuration
*/
inline auto load_animation(
const config& conf, string section, string name = "animation", bool required = true) { const config& conf, string section, string name = "animation", bool required = true) {
vector<icon_t> vec; vector<icon_t> vec;
vector<string> frames; vector<string> frames;
@ -72,7 +75,7 @@ namespace drawtypes {
for (size_t i = 0; i < frames.size(); i++) for (size_t i = 0; i < frames.size(); i++)
vec.emplace_back(forward<icon_t>( vec.emplace_back(forward<icon_t>(
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<int>(section, name + "-framerate", 1000); auto framerate = conf.get<int>(section, name + "-framerate", 1000);

View File

@ -61,7 +61,7 @@ namespace drawtypes {
m_tokenized = string_util::replace_all(m_tokenized, token, replacement); 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()) if (!label->m_foreground.empty())
m_foreground = label->m_foreground; m_foreground = label->m_foreground;
if (!label->m_background.empty()) if (!label->m_background.empty())
@ -72,43 +72,81 @@ namespace drawtypes {
m_overline = label->m_overline; 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: private:
string m_text, m_tokenized; string m_text, m_tokenized;
}; };
inline label_t get_config_label(const config& conf, string section, string name = "label", /**
bool required = true, string def = "") { * Create a label by loading values from the configuration
string text; */
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, '>'), '<'); name = string_util::ltrim(string_util::rtrim(name, '>'), '<');
string text;
if (required) if (required)
text = conf.get<string>(section, name); text = conf.get<string>(section, name);
else else
text = conf.get<string>(section, name, def); text = conf.get<string>(section, name, def);
return label_t{new label(text, conf.get<string>(section, name + "-foreground", ""), // clang-format off
return label_t{new label_t::element_type(text,
conf.get<string>(section, name + "-foreground", ""),
conf.get<string>(section, name + "-background", ""), conf.get<string>(section, name + "-background", ""),
conf.get<string>(section, name + "-underline", ""), conf.get<string>(section, name + "-underline", ""),
conf.get<string>(section, name + "-overline", ""), conf.get<string>(section, name + "-overline", ""),
conf.get<int>(section, name + "-font", 0), conf.get<int>(section, name + "-padding", 0), conf.get<int>(section, name + "-font", 0),
conf.get<int>(section, name + "-margin", 0), conf.get<size_t>(section, name + "-maxlen", 0), conf.get<int>(section, name + "-padding", 0),
conf.get<int>(section, name + "-margin", 0),
conf.get<size_t>(section, name + "-maxlen", 0),
conf.get<bool>(section, name + "-ellipsis", true))}; conf.get<bool>(section, name + "-ellipsis", true))};
// clang-format on
} }
inline label_t get_optional_config_label( /**
const config& conf, string section, string name = "label", string def = "") { * Create a label by loading optional values from the configuration
return get_config_label(conf, section, name, false, def); */
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 = "") { * Create an icon by loading values from the configuration
return get_config_label(conf, section, name, required, def); */
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 = "") { * Create an icon by loading optional values from the configuration
return get_config_icon(conf, section, name, false, def); */
inline icon_t load_optional_icon(
const config& conf, string section, string name, string def = "") {
return load_icon(conf, section, name, false, def);
} }
} }

View File

@ -5,6 +5,7 @@
#include "components/config.hpp" #include "components/config.hpp"
#include "components/types.hpp" #include "components/types.hpp"
#include "drawtypes/label.hpp" #include "drawtypes/label.hpp"
#include "utils/math.hpp"
#include "utils/mixins.hpp" #include "utils/mixins.hpp"
LEMONBUDDY_NS LEMONBUDDY_NS
@ -13,12 +14,10 @@ namespace drawtypes {
class progressbar : public non_copyable_mixin<progressbar> { class progressbar : public non_copyable_mixin<progressbar> {
public: public:
explicit progressbar( 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<builder>(bar, lazy_builder_closing)) : m_builder(make_unique<builder>(bar, lazy_builder_closing))
, m_format(format) , m_format(format)
, m_width(width) {} , m_width(width) {}
explicit progressbar(const bar_settings& bar, int width, bool lazy_builder_closing = true)
: progressbar(bar, width, "<fill><indicator><empty>", lazy_builder_closing) {}
void set_fill(icon_t&& fill) { void set_fill(icon_t&& fill) {
m_fill = forward<decltype(fill)>(fill); m_fill = forward<decltype(fill)>(fill);
@ -29,6 +28,8 @@ namespace drawtypes {
} }
void set_indicator(icon_t&& indicator) { void set_indicator(icon_t&& indicator) {
if (!m_indicator && indicator.get())
m_width--;
m_indicator = forward<decltype(indicator)>(indicator); m_indicator = forward<decltype(indicator)>(indicator);
} }
@ -38,54 +39,30 @@ namespace drawtypes {
void set_colors(vector<string>&& colors) { void set_colors(vector<string>&& colors) {
m_colors = forward<decltype(colors)>(colors); m_colors = forward<decltype(colors)>(colors);
if (m_colors.empty())
m_colorstep = 1;
else
m_colorstep = m_width / m_colors.size();
} }
string output(float percentage) { string output(float percentage) {
if (m_colors.empty()) string output{m_format};
m_colors.emplace_back(m_fill->m_foreground);
int fill_width = m_width * percentage / 100.0f + 0.5f; // Get fill/empty widths based on percentage
int empty_width = m_width - fill_width; unsigned int perc = math_util::cap(percentage, 0.0f, 100.0f);
int color_step = m_width / m_colors.size() + 0.5f; unsigned int fill_width = math_util::percentage_to_value(perc, m_width);
unsigned int empty_width = m_width - fill_width;
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<int>((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);
}
}
// Output fill icons
fill(perc, fill_width);
output = string_util::replace_all(output, "%fill%", m_builder->flush()); output = string_util::replace_all(output, "%fill%", m_builder->flush());
// Output indicator icon
m_builder->node(m_indicator); m_builder->node(m_indicator);
output = string_util::replace_all(output, "%indicator%", m_builder->flush()); output = string_util::replace_all(output, "%indicator%", m_builder->flush());
// Output empty icons
while (empty_width--) m_builder->node(m_empty); while (empty_width--) m_builder->node(m_empty);
output = string_util::replace_all(output, "%empty%", m_builder->flush()); output = string_util::replace_all(output, "%empty%", m_builder->flush());
@ -93,10 +70,33 @@ namespace drawtypes {
} }
protected: 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<size_t>(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<builder> m_builder; unique_ptr<builder> m_builder;
vector<string> m_colors; vector<string> m_colors;
string m_format; string m_format;
unsigned int m_width; unsigned int m_width;
unsigned int m_colorstep = 1;
bool m_gradient = false; bool m_gradient = false;
icon_t m_fill; icon_t m_fill;
@ -106,30 +106,53 @@ namespace drawtypes {
using progressbar_t = shared_ptr<progressbar>; using progressbar_t = shared_ptr<progressbar>;
inline auto get_config_bar(const bar_settings& bar, const config& conf, string section, /**
string name = "bar", bool lazy_builder_closing = true) { * Create a progressbar by loading values
progressbar_t p; * 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, '>'), '<'); name = string_util::ltrim(string_util::rtrim(name, '>'), '<');
auto width = conf.get<int>(section, name + "-width"); string format = "%fill%%indicator%%empty%";
auto format = conf.get<string>(section, name + "-format", "%fill%%indicator%%empty%"); unsigned int width;
if (format.empty()) if ((format = conf.get<decltype(format)>(section, name + "-format", format)).empty())
p.reset(new progressbar(bar, width, lazy_builder_closing)); throw application_error("Invalid format defined at [" + conf.build_path(section, name) + "]");
else if ((width = conf.get<decltype(width)>(section, name + "-width")) < 1)
p.reset(new progressbar(bar, width, format, lazy_builder_closing)); throw application_error("Invalid width defined at [" + conf.build_path(section, name) + "]");
p->set_gradient(conf.get<bool>(section, name + "-gradient", true)); progressbar_t progressbar{new progressbar_t::element_type(bar, width, format)};
p->set_colors(conf.get_list<string>(section, name + "-foreground", {})); progressbar->set_gradient(conf.get<bool>(section, name + "-gradient", true));
p->set_indicator(get_config_icon( progressbar->set_colors(conf.get_list<string>(section, name + "-foreground", {}));
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, ""));
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;
} }
} }

View File

@ -3,14 +3,12 @@
#include "common.hpp" #include "common.hpp"
#include "components/config.hpp" #include "components/config.hpp"
#include "drawtypes/label.hpp" #include "drawtypes/label.hpp"
#include "utils/math.hpp"
#include "utils/mixins.hpp" #include "utils/mixins.hpp"
LEMONBUDDY_NS LEMONBUDDY_NS
namespace drawtypes { namespace drawtypes {
class ramp;
using ramp_t = shared_ptr<ramp>;
class ramp : public non_copyable_mixin<ramp> { class ramp : public non_copyable_mixin<ramp> {
public: public:
explicit ramp() = default; explicit ramp() = default;
@ -20,28 +18,40 @@ namespace drawtypes {
m_icons.emplace_back(forward<decltype(icon)>(icon)); m_icons.emplace_back(forward<decltype(icon)>(icon));
} }
icon_t get(int index) { icon_t get(size_t index) {
return m_icons[index]; return m_icons[index];
} }
icon_t get_by_percentage(float percentage) { icon_t get_by_percentage(float percentage) {
return m_icons[static_cast<int>(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<size_t>(index, 0, m_icons.size() - 1)];
} }
operator bool() { operator bool() {
return m_icons.size() > 0; return !m_icons.empty();
} }
protected: protected:
vector<icon_t> m_icons; vector<icon_t> m_icons;
}; };
inline auto get_config_ramp( using ramp_t = shared_ptr<ramp>;
const config& conf, string section, string name = "ramp", bool required = true) {
vector<icon_t> vec;
/**
* 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, '>'), '<'); 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<icon_t> vec;
vector<string> icons; vector<string> icons;
if (required) if (required)
@ -49,16 +59,16 @@ namespace drawtypes {
else else
icons = conf.get_list<string>(section, name, {}); icons = conf.get_list<string>(section, name, {});
auto foreground = conf.get<string>(section, name + "-foreground", ""); for (size_t i = 0; i < icons.size(); i++) {
for (int i = 0; i < (int)icons.size(); i++) { auto icon = load_optional_icon(conf, section, name + "-" + to_string(i), icons[i]);
auto ramp = name + "-" + to_string(i);
auto icon = get_optional_config_icon(conf, section, ramp, icons[i]); if (ramp_defaults)
if (icon->m_foreground.empty() && !foreground.empty()) icon->copy_undefined(ramp_defaults);
icon->m_foreground = foreground;
vec.emplace_back(std::move(icon)); vec.emplace_back(move(icon));
} }
return ramp_t{new ramp(std::move(vec))}; return ramp_t{new ramp_t::element_type(move(vec))};
} }
} }

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include "config.hpp"
#include "components/config.hpp" #include "components/config.hpp"
#include "config.hpp"
#include "drawtypes/label.hpp" #include "drawtypes/label.hpp"
#include "drawtypes/progressbar.hpp" #include "drawtypes/progressbar.hpp"
#include "drawtypes/ramp.hpp" #include "drawtypes/ramp.hpp"
@ -37,11 +37,11 @@ namespace modules {
m_formatter->add(DEFAULT_FORMAT, TAG_LABEL, {TAG_LABEL, TAG_BAR, TAG_RAMP}); m_formatter->add(DEFAULT_FORMAT, TAG_LABEL, {TAG_LABEL, TAG_BAR, TAG_RAMP});
if (m_formatter->has(TAG_LABEL)) 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)) 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)) 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 // Build path to the file where the current/maximum brightness value is located
m_val.filepath(string_util::replace(PATH_BACKLIGHT_VAL, "%card%", card)); m_val.filepath(string_util::replace(PATH_BACKLIGHT_VAL, "%card%", card));

View File

@ -49,21 +49,20 @@ namespace modules {
FORMAT_FULL, TAG_LABEL_FULL, {TAG_BAR_CAPACITY, TAG_RAMP_CAPACITY, TAG_LABEL_FULL}); FORMAT_FULL, TAG_LABEL_FULL, {TAG_BAR_CAPACITY, TAG_RAMP_CAPACITY, TAG_LABEL_FULL});
if (m_formatter->has(TAG_ANIMATION_CHARGING, FORMAT_CHARGING)) 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)) 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)) 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)) { if (m_formatter->has(TAG_LABEL_CHARGING, FORMAT_CHARGING)) {
m_label_charging = m_label_charging = load_optional_label(m_conf, name(), TAG_LABEL_CHARGING, "%percentage%");
get_optional_config_label(m_conf, name(), TAG_LABEL_CHARGING, "%percentage%");
} }
if (m_formatter->has(TAG_LABEL_DISCHARGING, FORMAT_DISCHARGING)) { if (m_formatter->has(TAG_LABEL_DISCHARGING, FORMAT_DISCHARGING)) {
m_label_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)) { 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%");
} }
// }}} // }}}

View File

@ -53,32 +53,32 @@ namespace modules {
if (m_formatter->has(TAG_LABEL_STATE)) { if (m_formatter->has(TAG_LABEL_STATE)) {
m_statelabels.insert(make_pair(bspwm_flag::WORKSPACE_ACTIVE, 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, 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, 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, m_statelabels.insert(make_pair(bspwm_flag::WORKSPACE_EMPTY,
get_optional_config_label(m_conf, name(), "label-empty", DEFAULT_WS_LABEL))); load_optional_label(m_conf, name(), "label-empty", DEFAULT_WS_LABEL)));
m_statelabels.insert(make_pair(bspwm_flag::WORKSPACE_DIMMED, m_statelabels.insert(make_pair(
get_optional_config_label(m_conf, name(), "label-dimmed"))); bspwm_flag::WORKSPACE_DIMMED, load_optional_label(m_conf, name(), "label-dimmed")));
} }
if (m_formatter->has(TAG_LABEL_MODE)) { if (m_formatter->has(TAG_LABEL_MODE)) {
m_modelabels.insert(make_pair(bspwm_flag::MODE_LAYOUT_MONOCLE, m_modelabels.insert(make_pair(
get_optional_config_label(m_conf, name(), "label-monocle"))); bspwm_flag::MODE_LAYOUT_MONOCLE, load_optional_label(m_conf, name(), "label-monocle")));
m_modelabels.insert(make_pair(bspwm_flag::MODE_LAYOUT_TILED, m_modelabels.insert(make_pair(
get_optional_config_label(m_conf, name(), "label-tiled"))); bspwm_flag::MODE_LAYOUT_TILED, load_optional_label(m_conf, name(), "label-tiled")));
m_modelabels.insert(make_pair(bspwm_flag::MODE_STATE_FULLSCREEN, 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, m_modelabels.insert(make_pair(bspwm_flag::MODE_STATE_FLOATING,
get_optional_config_label(m_conf, name(), "label-floating"))); load_optional_label(m_conf, name(), "label-floating")));
m_modelabels.insert(make_pair(bspwm_flag::MODE_NODE_LOCKED, m_modelabels.insert(make_pair(
get_optional_config_label(m_conf, name(), "label-locked"))); bspwm_flag::MODE_NODE_LOCKED, load_optional_label(m_conf, name(), "label-locked")));
m_modelabels.insert(make_pair(bspwm_flag::MODE_NODE_STICKY, m_modelabels.insert(make_pair(
get_optional_config_label(m_conf, name(), "label-sticky"))); bspwm_flag::MODE_NODE_STICKY, load_optional_label(m_conf, name(), "label-sticky")));
m_modelabels.insert(make_pair(bspwm_flag::MODE_NODE_PRIVATE, m_modelabels.insert(make_pair(
get_optional_config_label(m_conf, name(), "label-private"))); bspwm_flag::MODE_NODE_PRIVATE, load_optional_label(m_conf, name(), "label-private")));
} }
m_icons = iconset_t{new iconset()}; m_icons = iconset_t{new iconset()};
@ -316,7 +316,8 @@ namespace modules {
try { try {
auto ipc = bspwm_util::make_connection(); 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()); m_log.info("%s: Sending desktop focus command to ipc handler", name());

View File

@ -32,13 +32,13 @@ namespace modules {
{TAG_LABEL, TAG_BAR_LOAD, TAG_RAMP_LOAD, TAG_RAMP_LOAD_PER_CORE}); {TAG_LABEL, TAG_BAR_LOAD, TAG_RAMP_LOAD, TAG_RAMP_LOAD_PER_CORE});
if (m_formatter->has(TAG_BAR_LOAD)) 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)) 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)) 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)) 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 // warmup
read_values(); read_values();

View File

@ -59,13 +59,13 @@ namespace modules {
if (m_formatter->has(TAG_LABEL_STATE)) { if (m_formatter->has(TAG_LABEL_STATE)) {
m_statelabels.insert(make_pair(i3_flag::WORKSPACE_FOCUSED, 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, 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, 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, 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()}; m_icons = iconset_t{new iconset()};

View File

@ -22,11 +22,11 @@ namespace modules {
m_formatter->add(DEFAULT_FORMAT, TAG_LABEL, {TAG_LABEL, TAG_BAR_USED, TAG_BAR_FREE}); m_formatter->add(DEFAULT_FORMAT, TAG_LABEL, {TAG_LABEL, TAG_BAR_USED, TAG_BAR_FREE});
if (m_formatter->has(TAG_BAR_USED)) 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)) 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)) 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() { bool update() {
@ -93,9 +93,9 @@ namespace modules {
} }
bool build(builder* builder, string tag) const { 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))); 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))); builder->node(m_bars.at(memtype::FREE)->output(m_perc.at(memtype::FREE)));
else if (tag == TAG_LABEL) else if (tag == TAG_LABEL)
builder->node(m_label); builder->node(m_label);

View File

@ -25,11 +25,11 @@ namespace modules {
m_formatter->add(DEFAULT_FORMAT, default_format, {TAG_LABEL_TOGGLE, TAG_MENU}); m_formatter->add(DEFAULT_FORMAT, default_format, {TAG_LABEL_TOGGLE, TAG_MENU});
if (m_formatter->has(TAG_LABEL_TOGGLE)) { if (m_formatter->has(TAG_LABEL_TOGGLE)) {
m_labelopen = get_config_label(m_conf, name(), "label-open"); m_labelopen = load_label(m_conf, name(), "label-open");
m_labelclose = get_optional_config_label(m_conf, name(), "label-close", "x"); 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)) if (!m_formatter->has(TAG_MENU))
return; return;
@ -51,7 +51,7 @@ namespace modules {
m_log.trace("%s: Creating menu level item %i", name(), m_levels.back()->items.size()); m_log.trace("%s: Creating menu level item %i", name(), m_levels.back()->items.size());
auto item = make_unique<menu_tree_item>(); auto item = make_unique<menu_tree_item>();
item->label = get_config_label(m_conf, name(), item_param); item->label = load_label(m_conf, name(), item_param);
item->exec = m_conf.get<string>(name(), item_param + "-exec", EVENT_MENU_CLOSE); item->exec = m_conf.get<string>(name(), item_param + "-exec", EVENT_MENU_CLOSE);
m_levels.back()->items.emplace_back(std::move(item)); m_levels.back()->items.emplace_back(std::move(item));
} }

View File

@ -34,44 +34,39 @@ namespace modules {
m_icons = iconset_t{new iconset()}; m_icons = iconset_t{new iconset()};
if (m_formatter->has(TAG_ICON_PLAY) || m_formatter->has(TAG_TOGGLE)) 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)) 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)) 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)) 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)) 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)) 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)) 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)) 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)) 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)) 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)) { if (m_formatter->has(TAG_LABEL_SONG))
m_label_song = m_label_song = load_optional_label(m_conf, name(), TAG_LABEL_SONG, "%artist% - %title%");
get_optional_config_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_LABEL_TIME)) {
m_label_time =
get_optional_config_label(m_conf, name(), TAG_LABEL_TIME, "%elapsed% / %total%");
}
if (m_formatter->has(TAG_ICON_RANDOM) || m_formatter->has(TAG_ICON_REPEAT) || if (m_formatter->has(TAG_ICON_RANDOM) || m_formatter->has(TAG_ICON_REPEAT) ||
m_formatter->has(TAG_ICON_REPEAT_ONE)) { m_formatter->has(TAG_ICON_REPEAT_ONE)) {
m_toggle_on_color = m_conf.get<string>(name(), "toggle-on-foreground", ""); m_toggle_on_color = m_conf.get<string>(name(), "toggle-on-foreground", "");
m_toggle_off_color = m_conf.get<string>(name(), "toggle-off-foreground", ""); m_toggle_off_color = m_conf.get<string>(name(), "toggle-off-foreground", "");
} }
if (m_formatter->has(TAG_LABEL_OFFLINE, FORMAT_OFFLINE)) if (m_formatter->has(TAG_LABEL_OFFLINE, FORMAT_OFFLINE))
m_label_offline = get_config_label(m_conf, name(), TAG_LABEL_OFFLINE); m_label_offline = load_label(m_conf, name(), TAG_LABEL_OFFLINE);
if (m_formatter->has(TAG_BAR_PROGRESS)) { if (m_formatter->has(TAG_BAR_PROGRESS))
m_bar_progress = get_config_bar(m_bar, m_conf, name(), 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) { if (m_label_song) {
m_label_song->reset_tokens(); m_label_song->reset_tokens();
m_label_song->replace_token( m_label_song->replace_token("%artist%", !artist.empty() ? artist : "untitled artist");
"%artist%", !artist.empty() ? artist : "untitled artist");
m_label_song->replace_token("%album%", !album.empty() ? album : "untitled album"); m_label_song->replace_token("%album%", !album.empty() ? album : "untitled album");
m_label_song->replace_token("%title%", !title.empty() ? title : "untitled track"); m_label_song->replace_token("%title%", !title.empty() ? title : "untitled track");
} }

View File

@ -32,18 +32,18 @@ namespace modules {
// Create elements for format-connected // Create elements for format-connected
if (m_formatter->has(TAG_RAMP_SIGNAL, 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)) 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)) { if (m_formatter->has(TAG_LABEL_CONNECTED, FORMAT_CONNECTED)) {
m_label[connection_state::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 // Create elements for format-disconnected
if (m_formatter->has(TAG_LABEL_DISCONNECTED, FORMAT_DISCONNECTED)) { if (m_formatter->has(TAG_LABEL_DISCONNECTED, FORMAT_DISCONNECTED)) {
m_label[connection_state::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]->reset_tokens();
m_label[connection_state::DISCONNECTED]->replace_token("%ifname%", m_interface); 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)) { if (m_formatter->has(TAG_LABEL_PACKETLOSS, FORMAT_PACKETLOSS)) {
m_label[connection_state::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)) 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 // Get an intstance of the network interface

View File

@ -87,18 +87,17 @@ namespace modules {
FORMAT_MUTED, TAG_LABEL_MUTED, {TAG_RAMP_VOLUME, TAG_LABEL_MUTED, TAG_BAR_VOLUME}); FORMAT_MUTED, TAG_LABEL_MUTED, {TAG_RAMP_VOLUME, TAG_LABEL_MUTED, TAG_BAR_VOLUME});
if (m_formatter->has(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)) { if (m_formatter->has(TAG_RAMP_VOLUME)) {
m_ramp_volume = get_config_ramp(m_conf, name(), TAG_RAMP_VOLUME); m_ramp_volume = load_ramp(m_conf, name(), TAG_RAMP_VOLUME);
m_ramp_headphones = get_config_ramp(m_conf, name(), TAG_RAMP_HEADPHONES, false); m_ramp_headphones = load_ramp(m_conf, name(), TAG_RAMP_HEADPHONES, false);
} }
if (m_formatter->has(TAG_LABEL_VOLUME, FORMAT_VOLUME)) { if (m_formatter->has(TAG_LABEL_VOLUME, FORMAT_VOLUME)) {
m_label_volume = m_label_volume = load_optional_label(m_conf, name(), TAG_LABEL_VOLUME, "%percentage%");
get_optional_config_label(m_conf, name(), TAG_LABEL_VOLUME, "%percentage%");
} }
if (m_formatter->has(TAG_LABEL_MUTED, FORMAT_MUTED)) { 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%");
} }
// }}} // }}}

View File

@ -76,11 +76,11 @@ namespace modules {
m_formatter->add(DEFAULT_FORMAT, TAG_LABEL, {TAG_LABEL, TAG_BAR, TAG_RAMP}); m_formatter->add(DEFAULT_FORMAT, TAG_LABEL, {TAG_LABEL, TAG_BAR, TAG_RAMP});
if (m_formatter->has(TAG_LABEL)) 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)) 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)) 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 // Trigger the initial draw event
update(); update();