mirror of https://github.com/polybar/polybar.git
refactor(renderer): Separate methods
This commit is contained in:
parent
b14e55f729
commit
4794ef653c
|
@ -23,8 +23,10 @@ class renderer {
|
|||
|
||||
void reserve_space(edge side, uint16_t w);
|
||||
|
||||
void set_background(const gc gcontext, const uint32_t color);
|
||||
void set_foreground(const gc gcontext, const uint32_t color);
|
||||
void set_background(const uint32_t color);
|
||||
void set_foreground(const uint32_t color);
|
||||
void set_underline(const uint32_t color);
|
||||
void set_overline(const uint32_t color);
|
||||
void set_fontindex(const uint8_t font);
|
||||
void set_alignment(const alignment align);
|
||||
void set_attribute(const attribute attr, const bool state);
|
||||
|
@ -73,8 +75,8 @@ class renderer {
|
|||
|
||||
uint32_t m_background{0};
|
||||
uint32_t m_foreground{0};
|
||||
gc m_background_gc{gc::NONE};
|
||||
gc m_foreground_gc{gc::NONE};
|
||||
uint32_t m_underline{0};
|
||||
uint32_t m_overline{0};
|
||||
|
||||
edge m_reserve_at{edge::NONE};
|
||||
uint16_t m_reserve;
|
||||
|
|
|
@ -171,7 +171,14 @@ void bar::bootstrap(bool nodraw) {
|
|||
m_renderer->end_action(btn);
|
||||
};
|
||||
g_signals::parser::color_change= [this](const gc gcontext, const uint32_t color) {
|
||||
m_renderer->set_foreground(gcontext, color);
|
||||
if (gcontext == gc::BG)
|
||||
m_renderer->set_background(color);
|
||||
else if (gcontext == gc::FG)
|
||||
m_renderer->set_foreground(color);
|
||||
else if (gcontext == gc::UL)
|
||||
m_renderer->set_underline(color);
|
||||
else if (gcontext == gc::OL)
|
||||
m_renderer->set_overline(color);
|
||||
};
|
||||
g_signals::parser::font_change = [this](const int8_t font) {
|
||||
m_renderer->set_fontindex(font);
|
||||
|
|
|
@ -180,26 +180,38 @@ void renderer::reserve_space(edge side, uint16_t w) {
|
|||
m_reserve_at = side;
|
||||
}
|
||||
|
||||
void renderer::set_background(const gc gcontext, const uint32_t color) {
|
||||
if (color == m_background && gcontext == m_background_gc)
|
||||
void renderer::set_background(const uint32_t color) {
|
||||
if (color == m_background)
|
||||
return;
|
||||
m_log.trace_x("renderer: set_background(%i, #%08x)", static_cast<uint8_t>(gcontext), color);
|
||||
m_connection.change_gc(m_gcontexts.at(gcontext), XCB_GC_BACKGROUND, &color);
|
||||
m_log.trace_x("renderer: set_background(#%08x)", color);
|
||||
m_connection.change_gc(m_gcontexts.at(gc::BG), XCB_GC_FOREGROUND, &color);
|
||||
m_background = color;
|
||||
m_background_gc = gcontext;
|
||||
shift_content(0);
|
||||
}
|
||||
|
||||
void renderer::set_foreground(const gc gcontext, const uint32_t color) {
|
||||
if (color == m_foreground && gcontext == m_foreground_gc)
|
||||
void renderer::set_foreground(const uint32_t color) {
|
||||
if (color == m_foreground)
|
||||
return;
|
||||
m_log.trace_x("renderer: set_foreground(%i, #%08x)", static_cast<uint8_t>(gcontext), color);
|
||||
m_connection.change_gc(m_gcontexts.at(gcontext), XCB_GC_FOREGROUND, &color);
|
||||
if (gcontext == gc::FG)
|
||||
m_fontmanager->allocate_color(color);
|
||||
else if (gcontext == gc::BG)
|
||||
shift_content(0);
|
||||
m_log.trace_x("renderer: set_foreground(#%08x)", color);
|
||||
m_connection.change_gc(m_gcontexts.at(gc::FG), XCB_GC_FOREGROUND, &color);
|
||||
m_fontmanager->allocate_color(color);
|
||||
m_foreground = color;
|
||||
m_foreground_gc = gcontext;
|
||||
}
|
||||
|
||||
void renderer::set_underline(const uint32_t color) {
|
||||
if (color == m_foreground)
|
||||
return;
|
||||
m_log.trace_x("renderer: set_underline(#%08x)", color);
|
||||
m_connection.change_gc(m_gcontexts.at(gc::UL), XCB_GC_FOREGROUND, &color);
|
||||
m_underline = color;
|
||||
}
|
||||
|
||||
void renderer::set_overline(const uint32_t color) {
|
||||
if (color == m_foreground)
|
||||
return;
|
||||
m_log.trace_x("renderer: set_overline(#%08x)", color);
|
||||
m_connection.change_gc(m_gcontexts.at(gc::OL), XCB_GC_FOREGROUND, &color);
|
||||
m_overline = color;
|
||||
}
|
||||
|
||||
void renderer::set_fontindex(const uint8_t font) {
|
||||
|
|
Loading…
Reference in New Issue