From 5283fbff01906e19eac2b8ec09c6a7c972f3f8e0 Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Thu, 26 Jan 2017 01:53:24 +0100 Subject: [PATCH] fix(renderer): Fill background to the sub blocks Paint the background on each sub block instead of the base surface. Fixes the compositing ops. --- include/cairo/context.hpp | 4 +--- src/components/bar.cpp | 1 + src/components/renderer.cpp | 35 +++++++++++++++++++++++++++-------- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/include/cairo/context.hpp b/include/cairo/context.hpp index 87b222e1..82409e53 100644 --- a/include/cairo/context.hpp +++ b/include/cairo/context.hpp @@ -312,9 +312,7 @@ namespace cairo { context& clip(const rect& r) { *this << r; - cairo_clip(m_c); - cairo_new_path(m_c); - return *this; + return clip(); } context& reset_clip() { diff --git a/src/components/bar.cpp b/src/components/bar.cpp index 4d8dcb96..ddbd7783 100644 --- a/src/components/bar.cpp +++ b/src/components/bar.cpp @@ -665,6 +665,7 @@ bool bar::on(const signals::eventqueue::start&) { m_log.trace("bar: Draw empty bar"); m_renderer->begin(m_opts.inner_area()); + m_renderer->fill_background(); m_renderer->end(); m_sig.emit(signals::ui::ready{}); diff --git a/src/components/renderer.cpp b/src/components/renderer.cpp index 02e74c64..3dac2043 100644 --- a/src/components/renderer.cpp +++ b/src/components/renderer.cpp @@ -241,8 +241,6 @@ void renderer::begin(xcb_rectangle_t rect) { static_cast(m_rect.width), static_cast(m_rect.height)}); // clang-format on - - fill_background(); } /** @@ -260,11 +258,28 @@ void renderer::end() { m_log.trace_x("renderer: pop(%i)", static_cast(m_align)); m_context->pop(&m_blocks[m_align].pattern); + // Capture the concatenated block contents + // so that it can be masked with the corner pattern + if (m_cornermask != nullptr) { + m_context->push(); + } + for (auto&& b : m_blocks) { if (block_w(b.first) && b.second.pattern != nullptr) { flush(b.first); } } + + if (m_cornermask != nullptr) { + cairo_pattern_t* pattern{nullptr}; + m_context->pop(&pattern); + m_context->save(); + { + *m_context << pattern; + m_context->mask(m_cornermask); + } + m_context->restore(); + } } m_context->restore(); @@ -292,6 +307,13 @@ void renderer::flush(alignment a) { { *m_context << cairo::abspos{0.0, 0.0}; *m_context << cairo::rect{m_rect.x + x, m_rect.y + y, w, h}; + + m_context->clip(); + *m_context << CAIRO_OPERATOR_CLEAR; + m_context->paint(); + m_context->reset_clip(); + *m_context << CAIRO_OPERATOR_OVER; + *m_context << cairo::translate{x, 0.0}; *m_context << m_blocks[a].pattern; @@ -454,12 +476,7 @@ void renderer::fill_background() { *m_context << m_bar.background; } - if (m_cornermask != nullptr) { - m_context->mask(m_cornermask); - } else { - m_context->paint(); - } - + m_context->paint(); m_context->restore(); } @@ -672,6 +689,8 @@ bool renderer::on(const signals::parser::change_alignment& evt) { m_blocks[m_align].y = 0.0; m_context->push(); m_log.trace_x("renderer: push(%i)", static_cast(m_align)); + + fill_background(); } return true; }