diff --git a/include/components/renderer.hpp b/include/components/renderer.hpp index 69268d30..77e20837 100644 --- a/include/components/renderer.hpp +++ b/include/components/renderer.hpp @@ -7,6 +7,7 @@ #include "cairo/fwd.hpp" #include "common.hpp" +#include "components/renderer_interface.hpp" #include "components/types.hpp" #include "events/signal_fwd.hpp" #include "events/signal_receiver.hpp" @@ -32,12 +33,12 @@ struct alignment_block { }; class renderer - : public signal_receiver { + signals::parser::attribute_set, signals::parser::attribute_unset, signals::parser::attribute_toggle, + signals::parser::action_begin, signals::parser::action_end, signals::parser::text, signals::parser::control> { public: using make_type = unique_ptr; static make_type make(const bar_settings& bar); @@ -62,6 +63,8 @@ class renderer void fill_borders(); void draw_text(const string& contents); + void render_offset(const tags::context& ctxt, int pixels) override; + protected: double block_x(alignment a) const; double block_y(alignment a) const; @@ -79,7 +82,6 @@ class renderer bool on(const signals::parser::change_font& evt) override; bool on(const signals::parser::change_alignment& evt) override; bool on(const signals::parser::reverse_colors&) override; - bool on(const signals::parser::offset_pixel& evt) override; bool on(const signals::parser::attribute_set& evt) override; bool on(const signals::parser::attribute_unset& evt) override; bool on(const signals::parser::attribute_toggle& evt) override; diff --git a/include/components/renderer_interface.hpp b/include/components/renderer_interface.hpp new file mode 100644 index 00000000..8adf94d7 --- /dev/null +++ b/include/components/renderer_interface.hpp @@ -0,0 +1,11 @@ +#pragma once +#include "common.hpp" +#include "tags/context.hpp" +POLYBAR_NS + +class renderer_interface { + public: + virtual void render_offset(const tags::context& ctxt, int pixels) = 0; +}; + +POLYBAR_NS_END diff --git a/include/events/signal.hpp b/include/events/signal.hpp index 45c34f05..7cc09691 100644 --- a/include/events/signal.hpp +++ b/include/events/signal.hpp @@ -153,9 +153,6 @@ namespace signals { struct reverse_colors : public detail::base_signal { using base_type::base_type; }; - struct offset_pixel : public detail::value_signal { - using base_type::base_type; - }; struct attribute_set : public detail::value_signal { using base_type::base_type; }; diff --git a/include/events/signal_fwd.hpp b/include/events/signal_fwd.hpp index f2efba98..790625a4 100644 --- a/include/events/signal_fwd.hpp +++ b/include/events/signal_fwd.hpp @@ -52,7 +52,6 @@ namespace signals { struct change_font; struct change_alignment; struct reverse_colors; - struct offset_pixel; struct attribute_set; struct attribute_unset; struct attribute_toggle; diff --git a/include/tags/context.hpp b/include/tags/context.hpp new file mode 100644 index 00000000..174ffe88 --- /dev/null +++ b/include/tags/context.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include "common.hpp" + +POLYBAR_NS + +namespace tags { + class context {}; +} // namespace tags + +POLYBAR_NS_END diff --git a/include/tags/dispatch.hpp b/include/tags/dispatch.hpp index fc0fc7a7..7a022abb 100644 --- a/include/tags/dispatch.hpp +++ b/include/tags/dispatch.hpp @@ -1,6 +1,7 @@ #pragma once #include "common.hpp" +#include "components/renderer_interface.hpp" #include "errors.hpp" POLYBAR_NS @@ -25,7 +26,7 @@ namespace tags { static make_type make(); explicit dispatch(signal_emitter& emitter, const logger& logger); - void parse(const bar_settings& bar, string data); + void parse(const bar_settings& bar, renderer_interface&, string data); protected: void text(string&& data); diff --git a/src/components/bar.cpp b/src/components/bar.cpp index ed3c4c59..9224f6f2 100644 --- a/src/components/bar.cpp +++ b/src/components/bar.cpp @@ -361,7 +361,7 @@ void bar::parse(string&& data, bool force) { m_renderer->begin(rect); try { - m_dispatch->parse(settings(), data); + m_dispatch->parse(settings(), *m_renderer, data); } catch (const exception& err) { m_log.err("Failed to parse contents (reason: %s)", err.what()); } diff --git a/src/components/renderer.cpp b/src/components/renderer.cpp index 394e644f..c6b84540 100644 --- a/src/components/renderer.cpp +++ b/src/components/renderer.cpp @@ -711,6 +711,11 @@ void renderer::draw_text(const string& contents) { } } +void renderer::render_offset(const tags::context&, int pixels) { + m_log.trace_x("renderer: offset_pixel(%f)", pixels); + m_blocks[m_align].x += pixels; +} + /** * Colorize the bounding box of created action blocks */ @@ -813,12 +818,6 @@ bool renderer::on(const signals::parser::reverse_colors&) { return true; } -bool renderer::on(const signals::parser::offset_pixel& evt) { - m_log.trace_x("renderer: offset_pixel(%f)", evt.cast()); - m_blocks[m_align].x += evt.cast(); - return true; -} - bool renderer::on(const signals::parser::attribute_set& evt) { m_log.trace_x("renderer: attribute_set(%i)", static_cast(evt.cast())); m_attr.set(static_cast(evt.cast()), true); diff --git a/src/tags/dispatch.cpp b/src/tags/dispatch.cpp index 82f49ca3..514fa492 100644 --- a/src/tags/dispatch.cpp +++ b/src/tags/dispatch.cpp @@ -37,7 +37,7 @@ namespace tags { /** * Process input string */ - void dispatch::parse(const bar_settings& bar, string data) { + void dispatch::parse(const bar_settings& bar, renderer_interface& renderer, string data) { tags::parser p; p.set(std::move(data)); @@ -67,7 +67,7 @@ namespace tags { m_sig.emit(change_font{el.tag_data.font}); break; case tags::syntaxtag::O: - m_sig.emit(offset_pixel{el.tag_data.offset}); + renderer.render_offset(tags::context{}, el.tag_data.offset); break; case tags::syntaxtag::R: m_sig.emit(reverse_colors{});