From f359540b5db62e435e51d90858ad57634f844776 Mon Sep 17 00:00:00 2001 From: patrick96 Date: Sun, 10 Jan 2021 21:30:10 +0100 Subject: [PATCH] renderer: Move change_alignment into interface --- include/components/renderer.hpp | 8 ++-- include/components/renderer_interface.hpp | 1 + include/events/signal.hpp | 6 --- include/events/signal_fwd.hpp | 3 -- include/tags/dispatch.hpp | 3 +- src/components/renderer.cpp | 47 +++++++++++------------ src/tags/dispatch.cpp | 14 +++---- 7 files changed, 34 insertions(+), 48 deletions(-) diff --git a/include/components/renderer.hpp b/include/components/renderer.hpp index 9c6b099c..70bf1009 100644 --- a/include/components/renderer.hpp +++ b/include/components/renderer.hpp @@ -32,9 +32,8 @@ struct alignment_block { double y; }; -class renderer - : public renderer_interface, - public signal_receiver { +class renderer : public renderer_interface, + public signal_receiver { public: using make_type = unique_ptr; static make_type make(const bar_settings& bar); @@ -52,6 +51,8 @@ class renderer void render_offset(const tags::context& ctxt, int pixels) override; void render_text(const tags::context& ctxt, const string&&) override; + void change_alignment(const tags::context& ctxt) override; + void action_open(const tags::context& ctxt, mousebtn btn, tags::action_t id) override; void action_close(const tags::context& ctxt, tags::action_t id) override; @@ -73,7 +74,6 @@ class renderer void highlight_clickable_areas(); bool on(const signals::ui::request_snapshot& evt) override; - bool on(const signals::parser::change_alignment& evt) override; protected: struct reserve_area { diff --git a/include/components/renderer_interface.hpp b/include/components/renderer_interface.hpp index 5f2cb107..32e9dbcc 100644 --- a/include/components/renderer_interface.hpp +++ b/include/components/renderer_interface.hpp @@ -9,6 +9,7 @@ class renderer_interface { public: virtual void render_offset(const tags::context& ctxt, int pixels) = 0; virtual void render_text(const tags::context& ctxt, const string&& str) = 0; + virtual void change_alignment(const tags::context& ctxt) = 0; virtual void action_open(const tags::context& ctxt, mousebtn btn, tags::action_t id) = 0; virtual void action_close(const tags::context& ctxt, tags::action_t id) = 0; diff --git a/include/events/signal.hpp b/include/events/signal.hpp index e3df96c7..a220be4d 100644 --- a/include/events/signal.hpp +++ b/include/events/signal.hpp @@ -130,12 +130,6 @@ namespace signals { using base_type::base_type; }; } // namespace ui_tray - - namespace parser { - struct change_alignment : public detail::value_signal { - using base_type::base_type; - }; - } // namespace parser } // namespace signals POLYBAR_NS_END diff --git a/include/events/signal_fwd.hpp b/include/events/signal_fwd.hpp index f3700322..bedf0312 100644 --- a/include/events/signal_fwd.hpp +++ b/include/events/signal_fwd.hpp @@ -44,9 +44,6 @@ namespace signals { namespace ui_tray { struct mapped_clients; } - namespace parser { - struct change_alignment; - } // namespace parser } // namespace signals POLYBAR_NS_END diff --git a/include/tags/dispatch.hpp b/include/tags/dispatch.hpp index 2dc5f224..2fb44877 100644 --- a/include/tags/dispatch.hpp +++ b/include/tags/dispatch.hpp @@ -25,7 +25,7 @@ namespace tags { using make_type = unique_ptr; static make_type make(action_context& action_ctxt); - explicit dispatch(signal_emitter& emitter, const logger& logger, action_context& action_ctxt); + explicit dispatch(const logger& logger, action_context& action_ctxt); void parse(const bar_settings& bar, renderer_interface&, const string&& data); protected: @@ -34,7 +34,6 @@ namespace tags { void handle_control(controltag ctrl); private: - signal_emitter& m_sig; vector m_actions; const logger& m_log; diff --git a/src/components/renderer.cpp b/src/components/renderer.cpp index b8429eb8..b3cd6744 100644 --- a/src/components/renderer.cpp +++ b/src/components/renderer.cpp @@ -678,10 +678,30 @@ void renderer::render_offset(const tags::context&, int pixels) { m_blocks[m_align].x += pixels; } -void renderer::action_open(const tags::context& ctxt, mousebtn btn, tags::action_t id) { +void renderer::change_alignment(const tags::context& ctxt) { + auto align = ctxt.get_alignment(); + if (align != m_align) { + m_log.trace_x("renderer: change_alignment(%i)", static_cast(align)); + + if (m_align != alignment::NONE) { + m_log.trace_x("renderer: pop(%i)", static_cast(m_align)); + m_context->pop(&m_blocks[m_align].pattern); + } + + m_align = align; + m_blocks[m_align].x = 0.0; + m_blocks[m_align].y = 0.0; + m_context->push(); + m_log.trace_x("renderer: push(%i)", static_cast(m_align)); + + fill_background(); + } +} + +void renderer::action_open(const tags::context&, mousebtn btn, tags::action_t id) { assert(btn != mousebtn::NONE); action_block block; - block.align = ctxt.get_alignment(); + block.align = m_align; block.button = btn; block.start_x = m_blocks.at(block.align).x; m_actions[id] = block; @@ -734,7 +754,7 @@ void renderer::highlight_clickable_areas() { double h = m_rect.height; m_context->save(); - *m_context << CAIRO_OPERATOR_DIFFERENCE << (n % 2 ? rgba{0xFF00FF00} :rgba{0xFFFF0000}); + *m_context << CAIRO_OPERATOR_DIFFERENCE << (n % 2 ? rgba{0xFF00FF00} : rgba{0xFFFF0000}); *m_context << cairo::rect{x, y, w, h}; m_context->fill(); m_context->restore(); @@ -748,25 +768,4 @@ bool renderer::on(const signals::ui::request_snapshot& evt) { return true; } -bool renderer::on(const signals::parser::change_alignment& evt) { - auto align = static_cast(evt.cast()); - if (align != m_align) { - m_log.trace_x("renderer: change_alignment(%i)", static_cast(align)); - - if (m_align != alignment::NONE) { - m_log.trace_x("renderer: pop(%i)", static_cast(m_align)); - m_context->pop(&m_blocks[m_align].pattern); - } - - m_align = align; - m_blocks[m_align].x = 0.0; - 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; -} - POLYBAR_NS_END diff --git a/src/tags/dispatch.cpp b/src/tags/dispatch.cpp index 38088841..465c80e3 100644 --- a/src/tags/dispatch.cpp +++ b/src/tags/dispatch.cpp @@ -11,21 +11,18 @@ POLYBAR_NS -using namespace signals::parser; - namespace tags { /** * Create instance */ dispatch::make_type dispatch::make(action_context& action_ctxt) { - return factory_util::unique(signal_emitter::make(), logger::make(), action_ctxt); + return factory_util::unique(logger::make(), action_ctxt); } /** * Construct parser instance */ - dispatch::dispatch(signal_emitter& emitter, const logger& logger, action_context& action_ctxt) - : m_sig(emitter), m_log(logger), m_action_ctxt(action_ctxt) {} + dispatch::dispatch(const logger& logger, action_context& action_ctxt) : m_log(logger), m_action_ctxt(action_ctxt) {} /** * Process input string @@ -79,15 +76,15 @@ namespace tags { break; case tags::syntaxtag::l: m_ctxt->apply_alignment(alignment::LEFT); - m_sig.emit(change_alignment{alignment::LEFT}); + renderer.change_alignment(*m_ctxt); break; case tags::syntaxtag::r: m_ctxt->apply_alignment(alignment::RIGHT); - m_sig.emit(change_alignment{alignment::RIGHT}); + renderer.change_alignment(*m_ctxt); break; case tags::syntaxtag::c: m_ctxt->apply_alignment(alignment::CENTER); - m_sig.emit(change_alignment{alignment::CENTER}); + renderer.change_alignment(*m_ctxt); break; default: throw runtime_error( @@ -129,7 +126,6 @@ namespace tags { std::tie(id, btn) = m_action_ctxt.action_close(btn, m_ctxt->get_alignment()); renderer.action_close(*m_ctxt, id); } else { - string tmp = cmd; action_t id = m_action_ctxt.action_open(btn, std::move(cmd), m_ctxt->get_alignment()); renderer.action_open(*m_ctxt, btn, id); }