Load rgba from config instead of strings.
This commit is contained in:
parent
8e10c046fa
commit
c9efd09f71
@ -33,20 +33,19 @@ class builder {
|
|||||||
void remove_trailing_space();
|
void remove_trailing_space();
|
||||||
void font(int index);
|
void font(int index);
|
||||||
void font_close();
|
void font_close();
|
||||||
void background(string color);
|
void background(rgba color);
|
||||||
void background_close();
|
void background_close();
|
||||||
void color(string color);
|
void color(rgba color);
|
||||||
void color_alpha(string alpha);
|
|
||||||
void color_close();
|
void color_close();
|
||||||
void line_color(const string& color);
|
void line_color(const rgba& color);
|
||||||
void line_color_close();
|
void line_color_close();
|
||||||
void overline_color(string color);
|
void overline_color(rgba color);
|
||||||
void overline_color_close();
|
void overline_color_close();
|
||||||
void underline_color(string color);
|
void underline_color(rgba color);
|
||||||
void underline_color_close();
|
void underline_color_close();
|
||||||
void overline(const string& color = "");
|
void overline(const rgba& color = rgba{});
|
||||||
void overline_close();
|
void overline_close();
|
||||||
void underline(const string& color = "");
|
void underline(const rgba& color = rgba{});
|
||||||
void underline_close();
|
void underline_close();
|
||||||
void control(controltag tag);
|
void control(controltag tag);
|
||||||
void action(mousebtn index, string action);
|
void action(mousebtn index, string action);
|
||||||
@ -56,8 +55,6 @@ class builder {
|
|||||||
void action_close();
|
void action_close();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
string background_hex();
|
|
||||||
string foreground_hex();
|
|
||||||
|
|
||||||
void tag_open(syntaxtag tag, const string& value);
|
void tag_open(syntaxtag tag, const string& value);
|
||||||
void tag_open(attribute attr);
|
void tag_open(attribute attr);
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
#include "common.hpp"
|
#include "common.hpp"
|
||||||
|
#include "utils/color.hpp"
|
||||||
|
|
||||||
POLYBAR_NS
|
POLYBAR_NS
|
||||||
|
|
||||||
@ -106,12 +107,12 @@ struct radius {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct border_settings {
|
struct border_settings {
|
||||||
unsigned int color{0xFF000000};
|
rgba color{0xFF000000};
|
||||||
unsigned int size{0U};
|
unsigned int size{0U};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct line_settings {
|
struct line_settings {
|
||||||
unsigned int color{0xFF000000};
|
rgba color{0xFF000000};
|
||||||
unsigned int size{0U};
|
unsigned int size{0U};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -154,9 +155,9 @@ struct bar_settings {
|
|||||||
side_values module_margin{0U, 0U};
|
side_values module_margin{0U, 0U};
|
||||||
edge_values strut{0U, 0U, 0U, 0U};
|
edge_values strut{0U, 0U, 0U, 0U};
|
||||||
|
|
||||||
unsigned int background{0xFF000000};
|
rgba background{0xFF000000};
|
||||||
unsigned int foreground{0xFFFFFFFF};
|
rgba foreground{0xFFFFFFFF};
|
||||||
vector<unsigned int> background_steps;
|
vector<rgba> background_steps;
|
||||||
|
|
||||||
line_settings underline{};
|
line_settings underline{};
|
||||||
line_settings overline{};
|
line_settings overline{};
|
||||||
|
@ -20,10 +20,10 @@ namespace drawtypes {
|
|||||||
|
|
||||||
class label : public non_copyable_mixin<label> {
|
class label : public non_copyable_mixin<label> {
|
||||||
public:
|
public:
|
||||||
string m_foreground{};
|
rgba m_foreground{};
|
||||||
string m_background{};
|
rgba m_background{};
|
||||||
string m_underline{};
|
rgba m_underline{};
|
||||||
string m_overline{};
|
rgba m_overline{};
|
||||||
int m_font{0};
|
int m_font{0};
|
||||||
side_values m_padding{0U, 0U};
|
side_values m_padding{0U, 0U};
|
||||||
side_values m_margin{0U, 0U};
|
side_values m_margin{0U, 0U};
|
||||||
@ -41,8 +41,8 @@ namespace drawtypes {
|
|||||||
bool m_ellipsis{true};
|
bool m_ellipsis{true};
|
||||||
|
|
||||||
explicit label(string text, int font) : m_font(font), m_text(text), m_tokenized(m_text) {}
|
explicit label(string text, int font) : m_font(font), m_text(text), m_tokenized(m_text) {}
|
||||||
explicit label(string text, string foreground = ""s, string background = ""s, string underline = ""s,
|
explicit label(string text, rgba foreground = rgba{}, rgba background = rgba{}, rgba underline = rgba{},
|
||||||
string overline = ""s, int font = 0, struct side_values padding = {0U, 0U},
|
rgba overline = rgba{}, int font = 0, struct side_values padding = {0U, 0U},
|
||||||
struct side_values margin = {0U, 0U}, int minlen = 0, size_t maxlen = 0_z,
|
struct side_values margin = {0U, 0U}, int minlen = 0, size_t maxlen = 0_z,
|
||||||
alignment label_alignment = alignment::LEFT, bool ellipsis = true, vector<token>&& tokens = {})
|
alignment label_alignment = alignment::LEFT, bool ellipsis = true, vector<token>&& tokens = {})
|
||||||
: m_foreground(foreground)
|
: m_foreground(foreground)
|
||||||
|
@ -17,7 +17,7 @@ namespace drawtypes {
|
|||||||
void set_empty(label_t&& empty);
|
void set_empty(label_t&& empty);
|
||||||
void set_indicator(label_t&& indicator);
|
void set_indicator(label_t&& indicator);
|
||||||
void set_gradient(bool mode);
|
void set_gradient(bool mode);
|
||||||
void set_colors(vector<string>&& colors);
|
void set_colors(vector<rgba>&& colors);
|
||||||
|
|
||||||
string output(float percentage);
|
string output(float percentage);
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ namespace drawtypes {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
unique_ptr<builder> m_builder;
|
unique_ptr<builder> m_builder;
|
||||||
vector<string> m_colors;
|
vector<rgba> m_colors;
|
||||||
string m_format;
|
string m_format;
|
||||||
unsigned int m_width;
|
unsigned int m_width;
|
||||||
unsigned int m_colorstep = 1;
|
unsigned int m_colorstep = 1;
|
||||||
@ -40,6 +40,6 @@ namespace drawtypes {
|
|||||||
using progressbar_t = shared_ptr<progressbar>;
|
using progressbar_t = shared_ptr<progressbar>;
|
||||||
|
|
||||||
progressbar_t load_progressbar(const bar_settings& bar, const config& conf, const string& section, string name);
|
progressbar_t load_progressbar(const bar_settings& bar, const config& conf, const string& section, string name);
|
||||||
}
|
} // namespace drawtypes
|
||||||
|
|
||||||
POLYBAR_NS_END
|
POLYBAR_NS_END
|
||||||
|
@ -58,10 +58,10 @@ namespace modules {
|
|||||||
vector<string> tags{};
|
vector<string> tags{};
|
||||||
label_t prefix{};
|
label_t prefix{};
|
||||||
label_t suffix{};
|
label_t suffix{};
|
||||||
string fg{};
|
rgba fg{};
|
||||||
string bg{};
|
rgba bg{};
|
||||||
string ul{};
|
rgba ul{};
|
||||||
string ol{};
|
rgba ol{};
|
||||||
size_t ulsize{0};
|
size_t ulsize{0};
|
||||||
size_t olsize{0};
|
size_t olsize{0};
|
||||||
size_t spacing{0};
|
size_t spacing{0};
|
||||||
|
@ -102,8 +102,8 @@ namespace modules {
|
|||||||
label_t m_label_time;
|
label_t m_label_time;
|
||||||
label_t m_label_offline;
|
label_t m_label_offline;
|
||||||
|
|
||||||
string m_toggle_on_color;
|
rgba m_toggle_on_color;
|
||||||
string m_toggle_off_color;
|
rgba m_toggle_off_color;
|
||||||
};
|
};
|
||||||
} // namespace modules
|
} // namespace modules
|
||||||
|
|
||||||
|
@ -197,9 +197,9 @@ bar::bar(connection& conn, signal_emitter& emitter, const config& config, const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto parse_or_throw = [&](string key, unsigned int def) -> unsigned int {
|
const auto parse_or_throw_color = [&](string key, rgba def) -> rgba {
|
||||||
try {
|
try {
|
||||||
return m_conf.get(bs, key, rgba{def});
|
return m_conf.get(bs, key, def);
|
||||||
} catch (const exception& err) {
|
} catch (const exception& err) {
|
||||||
throw application_error(sstream() << "Failed to set " << key << " (reason: " << err.what() << ")");
|
throw application_error(sstream() << "Failed to set " << key << " (reason: " << err.what() << ")");
|
||||||
}
|
}
|
||||||
@ -217,20 +217,20 @@ bar::bar(connection& conn, signal_emitter& emitter, const config& config, const
|
|||||||
m_log.warn("Ignoring `%s.background` (overridden by gradient background)", bs);
|
m_log.warn("Ignoring `%s.background` (overridden by gradient background)", bs);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
m_opts.background = parse_or_throw("background", m_opts.background);
|
m_opts.background = parse_or_throw_color("background", m_opts.background);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load foreground
|
// Load foreground
|
||||||
m_opts.foreground = parse_or_throw("foreground", m_opts.foreground);
|
m_opts.foreground = parse_or_throw_color("foreground", m_opts.foreground);
|
||||||
|
|
||||||
// Load over-/underline
|
// Load over-/underline
|
||||||
auto line_color = m_conf.get(bs, "line-color", rgba{0xFFFF0000});
|
auto line_color = m_conf.get(bs, "line-color", rgba{0xFFFF0000});
|
||||||
auto line_size = m_conf.get(bs, "line-size", 0);
|
auto line_size = m_conf.get(bs, "line-size", 0);
|
||||||
|
|
||||||
m_opts.overline.size = m_conf.get(bs, "overline-size", line_size);
|
m_opts.overline.size = m_conf.get(bs, "overline-size", line_size);
|
||||||
m_opts.overline.color = parse_or_throw("overline-color", line_color);
|
m_opts.overline.color = parse_or_throw_color("overline-color", line_color);
|
||||||
m_opts.underline.size = m_conf.get(bs, "underline-size", line_size);
|
m_opts.underline.size = m_conf.get(bs, "underline-size", line_size);
|
||||||
m_opts.underline.color = parse_or_throw("underline-color", line_color);
|
m_opts.underline.color = parse_or_throw_color("underline-color", line_color);
|
||||||
|
|
||||||
// Load border settings
|
// Load border settings
|
||||||
auto border_color = m_conf.get(bs, "border-color", rgba{0x00000000});
|
auto border_color = m_conf.get(bs, "border-color", rgba{0x00000000});
|
||||||
@ -242,16 +242,16 @@ bar::bar(connection& conn, signal_emitter& emitter, const config& config, const
|
|||||||
|
|
||||||
m_opts.borders.emplace(edge::TOP, border_settings{});
|
m_opts.borders.emplace(edge::TOP, border_settings{});
|
||||||
m_opts.borders[edge::TOP].size = geom_format_to_pixels(border_top, m_opts.monitor->h);
|
m_opts.borders[edge::TOP].size = geom_format_to_pixels(border_top, m_opts.monitor->h);
|
||||||
m_opts.borders[edge::TOP].color = parse_or_throw("border-top-color", border_color);
|
m_opts.borders[edge::TOP].color = parse_or_throw_color("border-top-color", border_color);
|
||||||
m_opts.borders.emplace(edge::BOTTOM, border_settings{});
|
m_opts.borders.emplace(edge::BOTTOM, border_settings{});
|
||||||
m_opts.borders[edge::BOTTOM].size = geom_format_to_pixels(border_bottom, m_opts.monitor->h);
|
m_opts.borders[edge::BOTTOM].size = geom_format_to_pixels(border_bottom, m_opts.monitor->h);
|
||||||
m_opts.borders[edge::BOTTOM].color = parse_or_throw("border-bottom-color", border_color);
|
m_opts.borders[edge::BOTTOM].color = parse_or_throw_color("border-bottom-color", border_color);
|
||||||
m_opts.borders.emplace(edge::LEFT, border_settings{});
|
m_opts.borders.emplace(edge::LEFT, border_settings{});
|
||||||
m_opts.borders[edge::LEFT].size = geom_format_to_pixels(border_left, m_opts.monitor->w);
|
m_opts.borders[edge::LEFT].size = geom_format_to_pixels(border_left, m_opts.monitor->w);
|
||||||
m_opts.borders[edge::LEFT].color = parse_or_throw("border-left-color", border_color);
|
m_opts.borders[edge::LEFT].color = parse_or_throw_color("border-left-color", border_color);
|
||||||
m_opts.borders.emplace(edge::RIGHT, border_settings{});
|
m_opts.borders.emplace(edge::RIGHT, border_settings{});
|
||||||
m_opts.borders[edge::RIGHT].size = geom_format_to_pixels(border_right, m_opts.monitor->w);
|
m_opts.borders[edge::RIGHT].size = geom_format_to_pixels(border_right, m_opts.monitor->w);
|
||||||
m_opts.borders[edge::RIGHT].color = parse_or_throw("border-right-color", border_color);
|
m_opts.borders[edge::RIGHT].color = parse_or_throw_color("border-right-color", border_color);
|
||||||
|
|
||||||
// Load geometry values
|
// Load geometry values
|
||||||
auto w = m_conf.get(m_conf.section(), "width", "100%"s);
|
auto w = m_conf.get(m_conf.section(), "width", "100%"s);
|
||||||
|
@ -128,17 +128,17 @@ void builder::node(const label_t& label) {
|
|||||||
space(label->m_margin.left);
|
space(label->m_margin.left);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!label->m_overline.empty()) {
|
if (label->m_overline.has_color()) {
|
||||||
overline(label->m_overline);
|
overline(label->m_overline);
|
||||||
}
|
}
|
||||||
if (!label->m_underline.empty()) {
|
if (label->m_underline.has_color()) {
|
||||||
underline(label->m_underline);
|
underline(label->m_underline);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!label->m_background.empty()) {
|
if (label->m_background.has_color()) {
|
||||||
background(label->m_background);
|
background(label->m_background);
|
||||||
}
|
}
|
||||||
if (!label->m_foreground.empty()) {
|
if (label->m_foreground.has_color()) {
|
||||||
color(label->m_foreground);
|
color(label->m_foreground);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,17 +152,17 @@ void builder::node(const label_t& label) {
|
|||||||
space(label->m_padding.right);
|
space(label->m_padding.right);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!label->m_background.empty()) {
|
if (label->m_background.has_color()) {
|
||||||
background_close();
|
background_close();
|
||||||
}
|
}
|
||||||
if (!label->m_foreground.empty()) {
|
if (label->m_foreground.has_color()) {
|
||||||
color_close();
|
color_close();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!label->m_underline.empty()) {
|
if (label->m_underline.has_color()) {
|
||||||
underline_close();
|
underline_close();
|
||||||
}
|
}
|
||||||
if (!label->m_overline.empty()) {
|
if (label->m_overline.has_color()) {
|
||||||
overline_close();
|
overline_close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,16 +258,15 @@ void builder::font_close() {
|
|||||||
/**
|
/**
|
||||||
* Insert tag to alter the current background color
|
* Insert tag to alter the current background color
|
||||||
*/
|
*/
|
||||||
void builder::background(string color) {
|
void builder::background(rgba color) {
|
||||||
if (color.length() == 2 || (color.find('#') == 0 && color.length() == 3)) {
|
if (color.m_type == color.ALPHA_ONLY) {
|
||||||
string bg{background_hex()};
|
rgba bg = m_bar.background;
|
||||||
color = "#" + color.substr(color.length() - 2);
|
color.m_value |= bg;
|
||||||
color += bg.substr(bg.length() - (bg.length() < 6 ? 3 : 6));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
color = color_util::simplify_hex(color);
|
auto hex = color_util::simplify_hex(color);
|
||||||
m_colors[syntaxtag::B] = color;
|
m_colors[syntaxtag::B] = hex;
|
||||||
tag_open(syntaxtag::B, color);
|
tag_open(syntaxtag::B, hex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -281,36 +280,15 @@ void builder::background_close() {
|
|||||||
/**
|
/**
|
||||||
* Insert tag to alter the current foreground color
|
* Insert tag to alter the current foreground color
|
||||||
*/
|
*/
|
||||||
void builder::color(string color) {
|
void builder::color(rgba color) {
|
||||||
if (color.length() == 2 || (color[0] == '#' && color.length() == 3)) {
|
if (color.m_type == color.ALPHA_ONLY) {
|
||||||
string fg{foreground_hex()};
|
rgba bg = m_bar.foreground;
|
||||||
if (!fg.empty()) {
|
color.m_value |= bg;
|
||||||
color = "#" + color.substr(color.length() - 2);
|
|
||||||
color += fg.substr(fg.length() - (fg.length() < 6 ? 3 : 6));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
color = color_util::simplify_hex(color);
|
auto hex = color_util::simplify_hex(color);
|
||||||
m_colors[syntaxtag::F] = color;
|
m_colors[syntaxtag::F] = hex;
|
||||||
tag_open(syntaxtag::F, color);
|
tag_open(syntaxtag::F, hex);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Insert tag to alter the alpha value of the default foreground color
|
|
||||||
*/
|
|
||||||
void builder::color_alpha(string alpha) {
|
|
||||||
if (alpha.find('#') == string::npos) {
|
|
||||||
alpha = "#" + alpha;
|
|
||||||
}
|
|
||||||
if (alpha.size() == 4) {
|
|
||||||
color(alpha);
|
|
||||||
} else {
|
|
||||||
string val{foreground_hex()};
|
|
||||||
if (val.size() < 6 && val.size() > 2) {
|
|
||||||
val.append(val.substr(val.size() - 3));
|
|
||||||
}
|
|
||||||
color((alpha.substr(0, 3) + val.substr(val.size() - 6)).substr(0, 9));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -324,7 +302,7 @@ void builder::color_close() {
|
|||||||
/**
|
/**
|
||||||
* Insert tag to alter the current overline/underline color
|
* Insert tag to alter the current overline/underline color
|
||||||
*/
|
*/
|
||||||
void builder::line_color(const string& color) {
|
void builder::line_color(const rgba& color) {
|
||||||
overline_color(color);
|
overline_color(color);
|
||||||
underline_color(color);
|
underline_color(color);
|
||||||
}
|
}
|
||||||
@ -340,10 +318,10 @@ void builder::line_color_close() {
|
|||||||
/**
|
/**
|
||||||
* Insert tag to alter the current overline color
|
* Insert tag to alter the current overline color
|
||||||
*/
|
*/
|
||||||
void builder::overline_color(string color) {
|
void builder::overline_color(rgba color) {
|
||||||
color = color_util::simplify_hex(color);
|
auto hex = color_util::simplify_hex(color);
|
||||||
m_colors[syntaxtag::o] = color;
|
m_colors[syntaxtag::o] = hex;
|
||||||
tag_open(syntaxtag::o, color);
|
tag_open(syntaxtag::o, hex);
|
||||||
tag_open(attribute::OVERLINE);
|
tag_open(attribute::OVERLINE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -358,10 +336,10 @@ void builder::overline_color_close() {
|
|||||||
/**
|
/**
|
||||||
* Insert tag to alter the current underline color
|
* Insert tag to alter the current underline color
|
||||||
*/
|
*/
|
||||||
void builder::underline_color(string color) {
|
void builder::underline_color(rgba color) {
|
||||||
color = color_util::simplify_hex(color);
|
auto hex = color_util::simplify_hex(color);
|
||||||
m_colors[syntaxtag::u] = color;
|
m_colors[syntaxtag::u] = hex;
|
||||||
tag_open(syntaxtag::u, color);
|
tag_open(syntaxtag::u, hex);
|
||||||
tag_open(attribute::UNDERLINE);
|
tag_open(attribute::UNDERLINE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -376,8 +354,8 @@ void builder::underline_color_close() {
|
|||||||
/**
|
/**
|
||||||
* Insert tag to enable the overline attribute
|
* Insert tag to enable the overline attribute
|
||||||
*/
|
*/
|
||||||
void builder::overline(const string& color) {
|
void builder::overline(const rgba& color) {
|
||||||
if (!color.empty()) {
|
if (color.has_color()) {
|
||||||
overline_color(color);
|
overline_color(color);
|
||||||
} else {
|
} else {
|
||||||
tag_open(attribute::OVERLINE);
|
tag_open(attribute::OVERLINE);
|
||||||
@ -394,8 +372,8 @@ void builder::overline_close() {
|
|||||||
/**
|
/**
|
||||||
* Insert tag to enable the underline attribute
|
* Insert tag to enable the underline attribute
|
||||||
*/
|
*/
|
||||||
void builder::underline(const string& color) {
|
void builder::underline(const rgba& color) {
|
||||||
if (!color.empty()) {
|
if (color.has_color()) {
|
||||||
underline_color(color);
|
underline_color(color);
|
||||||
} else {
|
} else {
|
||||||
tag_open(attribute::UNDERLINE);
|
tag_open(attribute::UNDERLINE);
|
||||||
@ -472,26 +450,6 @@ void builder::action_close() {
|
|||||||
tag_close(syntaxtag::A);
|
tag_close(syntaxtag::A);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get default background hex string
|
|
||||||
*/
|
|
||||||
string builder::background_hex() {
|
|
||||||
if (m_background.empty()) {
|
|
||||||
m_background = color_util::hex<unsigned short int>(m_bar.background);
|
|
||||||
}
|
|
||||||
return m_background;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get default foreground hex string
|
|
||||||
*/
|
|
||||||
string builder::foreground_hex() {
|
|
||||||
if (m_foreground.empty()) {
|
|
||||||
m_foreground = color_util::hex<unsigned short int>(m_bar.foreground);
|
|
||||||
}
|
|
||||||
return m_foreground;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Insert directive to change value of given tag
|
* Insert directive to change value of given tag
|
||||||
*/
|
*/
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
|
#include "components/config.hpp"
|
||||||
|
|
||||||
#include <climits>
|
#include <climits>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
#include "cairo/utils.hpp"
|
#include "cairo/utils.hpp"
|
||||||
#include "components/config.hpp"
|
|
||||||
#include "utils/color.hpp"
|
#include "utils/color.hpp"
|
||||||
#include "utils/env.hpp"
|
#include "utils/env.hpp"
|
||||||
#include "utils/factory.hpp"
|
#include "utils/factory.hpp"
|
||||||
@ -10,6 +11,8 @@
|
|||||||
|
|
||||||
POLYBAR_NS
|
POLYBAR_NS
|
||||||
|
|
||||||
|
namespace chrono = std::chrono;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create instance
|
* Create instance
|
||||||
*/
|
*/
|
||||||
@ -198,7 +201,7 @@ chrono::duration<double> config::convert(string&& value) const {
|
|||||||
|
|
||||||
template <>
|
template <>
|
||||||
rgba config::convert(string&& value) const {
|
rgba config::convert(string&& value) const {
|
||||||
return rgba{color_util::parse(value, 0)};
|
return rgba{value};
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
|
@ -99,16 +99,16 @@ namespace drawtypes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void label::replace_defined_values(const label_t& label) {
|
void label::replace_defined_values(const label_t& label) {
|
||||||
if (!label->m_foreground.empty()) {
|
if (label->m_foreground.has_color()) {
|
||||||
m_foreground = label->m_foreground;
|
m_foreground = label->m_foreground;
|
||||||
}
|
}
|
||||||
if (!label->m_background.empty()) {
|
if (label->m_background.has_color()) {
|
||||||
m_background = label->m_background;
|
m_background = label->m_background;
|
||||||
}
|
}
|
||||||
if (!label->m_underline.empty()) {
|
if (label->m_underline.has_color()) {
|
||||||
m_underline = label->m_underline;
|
m_underline = label->m_underline;
|
||||||
}
|
}
|
||||||
if (!label->m_overline.empty()) {
|
if (label->m_overline.has_color()) {
|
||||||
m_overline = label->m_overline;
|
m_overline = label->m_overline;
|
||||||
}
|
}
|
||||||
if (label->m_font != 0) {
|
if (label->m_font != 0) {
|
||||||
@ -133,16 +133,16 @@ namespace drawtypes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void label::copy_undefined(const label_t& label) {
|
void label::copy_undefined(const label_t& label) {
|
||||||
if (m_foreground.empty() && !label->m_foreground.empty()) {
|
if (!m_foreground.has_color() && label->m_foreground.has_color()) {
|
||||||
m_foreground = label->m_foreground;
|
m_foreground = label->m_foreground;
|
||||||
}
|
}
|
||||||
if (m_background.empty() && !label->m_background.empty()) {
|
if (!m_background.has_color() && label->m_background.has_color()) {
|
||||||
m_background = label->m_background;
|
m_background = label->m_background;
|
||||||
}
|
}
|
||||||
if (m_underline.empty() && !label->m_underline.empty()) {
|
if (!m_underline.has_color() && label->m_underline.has_color()) {
|
||||||
m_underline = label->m_underline;
|
m_underline = label->m_underline;
|
||||||
}
|
}
|
||||||
if (m_overline.empty() && !label->m_overline.empty()) {
|
if (!m_overline.has_color() && label->m_overline.has_color()) {
|
||||||
m_overline = label->m_overline;
|
m_overline = label->m_overline;
|
||||||
}
|
}
|
||||||
if (m_font == 0 && label->m_font != 0) {
|
if (m_font == 0 && label->m_font != 0) {
|
||||||
@ -279,10 +279,10 @@ namespace drawtypes {
|
|||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
return factory_util::shared<label>(text,
|
return factory_util::shared<label>(text,
|
||||||
conf.get(section, name + "-foreground", ""s),
|
conf.get(section, name + "-foreground", rgba{}),
|
||||||
conf.get(section, name + "-background", ""s),
|
conf.get(section, name + "-background", rgba{}),
|
||||||
conf.get(section, name + "-underline", ""s),
|
conf.get(section, name + "-underline", rgba{}),
|
||||||
conf.get(section, name + "-overline", ""s),
|
conf.get(section, name + "-overline", rgba{}),
|
||||||
conf.get(section, name + "-font", 0),
|
conf.get(section, name + "-font", 0),
|
||||||
padding,
|
padding,
|
||||||
margin,
|
margin,
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
|
#include "drawtypes/progressbar.hpp"
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "drawtypes/label.hpp"
|
#include "drawtypes/label.hpp"
|
||||||
#include "drawtypes/progressbar.hpp"
|
|
||||||
#include "utils/color.hpp"
|
#include "utils/color.hpp"
|
||||||
#include "utils/factory.hpp"
|
#include "utils/factory.hpp"
|
||||||
#include "utils/math.hpp"
|
#include "utils/math.hpp"
|
||||||
@ -31,7 +32,7 @@ namespace drawtypes {
|
|||||||
m_gradient = mode;
|
m_gradient = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void progressbar::set_colors(vector<string>&& colors) {
|
void progressbar::set_colors(vector<rgba>&& colors) {
|
||||||
m_colors = forward<decltype(colors)>(colors);
|
m_colors = forward<decltype(colors)>(colors);
|
||||||
|
|
||||||
m_colorstep = m_colors.empty() ? 1 : m_width / m_colors.size();
|
m_colorstep = m_colors.empty() ? 1 : m_width / m_colors.size();
|
||||||
@ -98,7 +99,7 @@ namespace drawtypes {
|
|||||||
|
|
||||||
auto pbar = factory_util::shared<progressbar>(bar, width, format);
|
auto pbar = factory_util::shared<progressbar>(bar, width, format);
|
||||||
pbar->set_gradient(conf.get(section, name + "-gradient", true));
|
pbar->set_gradient(conf.get(section, name + "-gradient", true));
|
||||||
pbar->set_colors(conf.get_list(section, name + "-foreground", {}));
|
pbar->set_colors(conf.get_list(section, name + "-foreground", vector<rgba>{}));
|
||||||
|
|
||||||
label_t icon_empty;
|
label_t icon_empty;
|
||||||
label_t icon_fill;
|
label_t icon_fill;
|
||||||
@ -118,11 +119,11 @@ namespace drawtypes {
|
|||||||
// but not for the empty icon we use the bar's default colors to
|
// but not for the empty icon we use the bar's default colors to
|
||||||
// avoid color bleed
|
// avoid color bleed
|
||||||
if (icon_empty && icon_indicator) {
|
if (icon_empty && icon_indicator) {
|
||||||
if (!icon_indicator->m_background.empty() && icon_empty->m_background.empty()) {
|
if (icon_indicator->m_background.has_color() && !icon_empty->m_background.has_color()) {
|
||||||
icon_empty->m_background = color_util::hex<unsigned short int>(bar.background);
|
icon_empty->m_background = bar.background;
|
||||||
}
|
}
|
||||||
if (!icon_indicator->m_foreground.empty() && icon_empty->m_foreground.empty()) {
|
if (icon_indicator->m_foreground.has_color() && !icon_empty->m_foreground.has_color()) {
|
||||||
icon_empty->m_foreground = color_util::hex<unsigned short int>(bar.foreground);
|
icon_empty->m_foreground = bar.foreground;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,6 +133,6 @@ namespace drawtypes {
|
|||||||
|
|
||||||
return pbar;
|
return pbar;
|
||||||
}
|
}
|
||||||
}
|
} // namespace drawtypes
|
||||||
|
|
||||||
POLYBAR_NS_END
|
POLYBAR_NS_END
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
|
#include "modules/meta/base.hpp"
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "components/builder.hpp"
|
#include "components/builder.hpp"
|
||||||
#include "drawtypes/label.hpp"
|
#include "drawtypes/label.hpp"
|
||||||
#include "modules/meta/base.hpp"
|
|
||||||
|
|
||||||
POLYBAR_NS
|
POLYBAR_NS
|
||||||
|
|
||||||
@ -20,19 +21,19 @@ namespace modules {
|
|||||||
if (margin > 0) {
|
if (margin > 0) {
|
||||||
builder->space(margin);
|
builder->space(margin);
|
||||||
}
|
}
|
||||||
if (!bg.empty()) {
|
if (bg.has_color()) {
|
||||||
builder->background(bg);
|
builder->background(bg);
|
||||||
}
|
}
|
||||||
if (!fg.empty()) {
|
if (fg.has_color()) {
|
||||||
builder->color(fg);
|
builder->color(fg);
|
||||||
}
|
}
|
||||||
if (!ul.empty()) {
|
if (ul.has_color()) {
|
||||||
builder->underline(ul);
|
builder->underline(ul);
|
||||||
}
|
}
|
||||||
if (!ol.empty()) {
|
if (ol.has_color()) {
|
||||||
builder->overline(ol);
|
builder->overline(ol);
|
||||||
}
|
}
|
||||||
if(font > 0) {
|
if (font > 0) {
|
||||||
builder->font(font);
|
builder->font(font);
|
||||||
}
|
}
|
||||||
if (padding > 0) {
|
if (padding > 0) {
|
||||||
@ -41,16 +42,16 @@ namespace modules {
|
|||||||
|
|
||||||
builder->node(prefix);
|
builder->node(prefix);
|
||||||
|
|
||||||
if (!bg.empty()) {
|
if (bg.has_color()) {
|
||||||
builder->background(bg);
|
builder->background(bg);
|
||||||
}
|
}
|
||||||
if (!fg.empty()) {
|
if (fg.has_color()) {
|
||||||
builder->color(fg);
|
builder->color(fg);
|
||||||
}
|
}
|
||||||
if (!ul.empty()) {
|
if (ul.has_color()) {
|
||||||
builder->underline(ul);
|
builder->underline(ul);
|
||||||
}
|
}
|
||||||
if (!ol.empty()) {
|
if (ol.has_color()) {
|
||||||
builder->overline(ol);
|
builder->overline(ol);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,19 +61,19 @@ namespace modules {
|
|||||||
if (padding > 0) {
|
if (padding > 0) {
|
||||||
builder->space(padding);
|
builder->space(padding);
|
||||||
}
|
}
|
||||||
if(font > 0) {
|
if (font > 0) {
|
||||||
builder->font_close();
|
builder->font_close();
|
||||||
}
|
}
|
||||||
if (!ol.empty()) {
|
if (ol.has_color()) {
|
||||||
builder->overline_close();
|
builder->overline_close();
|
||||||
}
|
}
|
||||||
if (!ul.empty()) {
|
if (ul.has_color()) {
|
||||||
builder->underline_close();
|
builder->underline_close();
|
||||||
}
|
}
|
||||||
if (!fg.empty()) {
|
if (fg.has_color()) {
|
||||||
builder->color_close();
|
builder->color_close();
|
||||||
}
|
}
|
||||||
if (!bg.empty()) {
|
if (bg.has_color()) {
|
||||||
builder->background_close();
|
builder->background_close();
|
||||||
}
|
}
|
||||||
if (margin > 0) {
|
if (margin > 0) {
|
||||||
@ -86,8 +87,9 @@ namespace modules {
|
|||||||
// module_formatter {{{
|
// module_formatter {{{
|
||||||
|
|
||||||
void module_formatter::add(string name, string fallback, vector<string>&& tags, vector<string>&& whitelist) {
|
void module_formatter::add(string name, string fallback, vector<string>&& tags, vector<string>&& whitelist) {
|
||||||
const auto formatdef = [&](
|
const auto formatdef = [&](const string& param, const auto& fallback) {
|
||||||
const string& param, const auto& fallback) { return m_conf.get("settings", "format-" + param, fallback); };
|
return m_conf.get("settings", "format-" + param, fallback);
|
||||||
|
};
|
||||||
|
|
||||||
auto format = make_unique<module_format>();
|
auto format = make_unique<module_format>();
|
||||||
format->value = m_conf.get(m_modname, name, move(fallback));
|
format->value = m_conf.get(m_modname, name, move(fallback));
|
||||||
@ -165,6 +167,6 @@ namespace modules {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
}
|
} // namespace modules
|
||||||
|
|
||||||
POLYBAR_NS_END
|
POLYBAR_NS_END
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
|
#include "modules/mpd.hpp"
|
||||||
|
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
|
|
||||||
#include "drawtypes/iconset.hpp"
|
#include "drawtypes/iconset.hpp"
|
||||||
#include "drawtypes/label.hpp"
|
#include "drawtypes/label.hpp"
|
||||||
#include "drawtypes/progressbar.hpp"
|
#include "drawtypes/progressbar.hpp"
|
||||||
#include "modules/mpd.hpp"
|
|
||||||
#include "utils/factory.hpp"
|
|
||||||
|
|
||||||
#include "modules/meta/base.inl"
|
#include "modules/meta/base.inl"
|
||||||
|
#include "utils/factory.hpp"
|
||||||
|
|
||||||
POLYBAR_NS
|
POLYBAR_NS
|
||||||
|
|
||||||
@ -24,8 +24,8 @@ namespace modules {
|
|||||||
for (auto&& format : {FORMAT_PLAYING, FORMAT_PAUSED, FORMAT_STOPPED}) {
|
for (auto&& format : {FORMAT_PLAYING, FORMAT_PAUSED, FORMAT_STOPPED}) {
|
||||||
m_formatter->add(format, format_online,
|
m_formatter->add(format, format_online,
|
||||||
{TAG_BAR_PROGRESS, TAG_TOGGLE, TAG_TOGGLE_STOP, TAG_LABEL_SONG, TAG_LABEL_TIME, TAG_ICON_RANDOM,
|
{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_SINGLE, TAG_ICON_PREV, TAG_ICON_STOP, TAG_ICON_PLAY, TAG_ICON_PAUSE,
|
TAG_ICON_REPEAT, TAG_ICON_REPEAT_ONE, TAG_ICON_SINGLE, TAG_ICON_PREV, TAG_ICON_STOP, TAG_ICON_PLAY,
|
||||||
TAG_ICON_NEXT, TAG_ICON_SEEKB, TAG_ICON_SEEKF, TAG_ICON_CONSUME});
|
TAG_ICON_PAUSE, TAG_ICON_NEXT, TAG_ICON_SEEKB, TAG_ICON_SEEKF, TAG_ICON_CONSUME});
|
||||||
|
|
||||||
auto mod_format = m_formatter->get(format);
|
auto mod_format = m_formatter->get(format);
|
||||||
|
|
||||||
@ -88,9 +88,7 @@ namespace modules {
|
|||||||
|
|
||||||
if (m_formatter->has(TAG_ICON_SINGLE)) {
|
if (m_formatter->has(TAG_ICON_SINGLE)) {
|
||||||
m_icons->add("single", load_label(m_conf, name(), TAG_ICON_SINGLE));
|
m_icons->add("single", load_label(m_conf, name(), TAG_ICON_SINGLE));
|
||||||
}
|
} else if (m_formatter->has(TAG_ICON_REPEAT_ONE)) {
|
||||||
else if(m_formatter->has(TAG_ICON_REPEAT_ONE)){
|
|
||||||
|
|
||||||
m_conf.warn_deprecated(name(), "icon-repeatone", "icon-single");
|
m_conf.warn_deprecated(name(), "icon-repeatone", "icon-single");
|
||||||
|
|
||||||
m_icons->add("single", load_label(m_conf, name(), TAG_ICON_REPEAT_ONE));
|
m_icons->add("single", load_label(m_conf, name(), TAG_ICON_REPEAT_ONE));
|
||||||
@ -109,8 +107,8 @@ namespace modules {
|
|||||||
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_SINGLE) ||
|
m_formatter->has(TAG_ICON_REPEAT_ONE) || m_formatter->has(TAG_ICON_SINGLE) ||
|
||||||
m_formatter->has(TAG_ICON_CONSUME)) {
|
m_formatter->has(TAG_ICON_CONSUME)) {
|
||||||
m_toggle_on_color = m_conf.get(name(), "toggle-on-foreground", ""s);
|
m_toggle_on_color = m_conf.get(name(), "toggle-on-foreground", rgba{});
|
||||||
m_toggle_off_color = m_conf.get(name(), "toggle-off-foreground", ""s);
|
m_toggle_off_color = m_conf.get(name(), "toggle-off-foreground", rgba{});
|
||||||
}
|
}
|
||||||
if (m_formatter->has(TAG_LABEL_OFFLINE, FORMAT_OFFLINE)) {
|
if (m_formatter->has(TAG_LABEL_OFFLINE, FORMAT_OFFLINE)) {
|
||||||
m_label_offline = load_label(m_conf, name(), TAG_LABEL_OFFLINE);
|
m_label_offline = load_label(m_conf, name(), TAG_LABEL_OFFLINE);
|
||||||
@ -280,8 +278,7 @@ namespace modules {
|
|||||||
m_icons->get("repeat")->m_foreground = m_status && m_status->repeat() ? m_toggle_on_color : m_toggle_off_color;
|
m_icons->get("repeat")->m_foreground = m_status && m_status->repeat() ? m_toggle_on_color : m_toggle_off_color;
|
||||||
}
|
}
|
||||||
if (m_icons->has("single")) {
|
if (m_icons->has("single")) {
|
||||||
m_icons->get("single")->m_foreground =
|
m_icons->get("single")->m_foreground = m_status && m_status->single() ? m_toggle_on_color : m_toggle_off_color;
|
||||||
m_status && m_status->single() ? m_toggle_on_color : m_toggle_off_color;
|
|
||||||
}
|
}
|
||||||
if (m_icons->has("consume")) {
|
if (m_icons->has("consume")) {
|
||||||
m_icons->get("consume")->m_foreground = m_status && m_status->consume() ? m_toggle_on_color : m_toggle_off_color;
|
m_icons->get("consume")->m_foreground = m_status && m_status->consume() ? m_toggle_on_color : m_toggle_off_color;
|
||||||
@ -406,6 +403,6 @@ namespace modules {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
} // namespace modules
|
||||||
|
|
||||||
POLYBAR_NS_END
|
POLYBAR_NS_END
|
||||||
|
Loading…
Reference in New Issue
Block a user