renderer: Move change_alignment into interface
This commit is contained in:
parent
f0ee5ab8cd
commit
f359540b5d
@ -32,9 +32,8 @@ struct alignment_block {
|
|||||||
double y;
|
double y;
|
||||||
};
|
};
|
||||||
|
|
||||||
class renderer
|
class renderer : public renderer_interface,
|
||||||
: public renderer_interface,
|
public signal_receiver<SIGN_PRIORITY_RENDERER, signals::ui::request_snapshot> {
|
||||||
public signal_receiver<SIGN_PRIORITY_RENDERER, signals::ui::request_snapshot, signals::parser::change_alignment> {
|
|
||||||
public:
|
public:
|
||||||
using make_type = unique_ptr<renderer>;
|
using make_type = unique_ptr<renderer>;
|
||||||
static make_type make(const bar_settings& bar);
|
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_offset(const tags::context& ctxt, int pixels) override;
|
||||||
void render_text(const tags::context& ctxt, const string&&) 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_open(const tags::context& ctxt, mousebtn btn, tags::action_t id) override;
|
||||||
void action_close(const tags::context& ctxt, 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();
|
void highlight_clickable_areas();
|
||||||
|
|
||||||
bool on(const signals::ui::request_snapshot& evt) override;
|
bool on(const signals::ui::request_snapshot& evt) override;
|
||||||
bool on(const signals::parser::change_alignment& evt) override;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
struct reserve_area {
|
struct reserve_area {
|
||||||
|
@ -9,6 +9,7 @@ class renderer_interface {
|
|||||||
public:
|
public:
|
||||||
virtual void render_offset(const tags::context& ctxt, int pixels) = 0;
|
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 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_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;
|
virtual void action_close(const tags::context& ctxt, tags::action_t id) = 0;
|
||||||
|
@ -130,12 +130,6 @@ namespace signals {
|
|||||||
using base_type::base_type;
|
using base_type::base_type;
|
||||||
};
|
};
|
||||||
} // namespace ui_tray
|
} // namespace ui_tray
|
||||||
|
|
||||||
namespace parser {
|
|
||||||
struct change_alignment : public detail::value_signal<change_alignment, alignment> {
|
|
||||||
using base_type::base_type;
|
|
||||||
};
|
|
||||||
} // namespace parser
|
|
||||||
} // namespace signals
|
} // namespace signals
|
||||||
|
|
||||||
POLYBAR_NS_END
|
POLYBAR_NS_END
|
||||||
|
@ -44,9 +44,6 @@ namespace signals {
|
|||||||
namespace ui_tray {
|
namespace ui_tray {
|
||||||
struct mapped_clients;
|
struct mapped_clients;
|
||||||
}
|
}
|
||||||
namespace parser {
|
|
||||||
struct change_alignment;
|
|
||||||
} // namespace parser
|
|
||||||
} // namespace signals
|
} // namespace signals
|
||||||
|
|
||||||
POLYBAR_NS_END
|
POLYBAR_NS_END
|
||||||
|
@ -25,7 +25,7 @@ namespace tags {
|
|||||||
using make_type = unique_ptr<dispatch>;
|
using make_type = unique_ptr<dispatch>;
|
||||||
static make_type make(action_context& action_ctxt);
|
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);
|
void parse(const bar_settings& bar, renderer_interface&, const string&& data);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -34,7 +34,6 @@ namespace tags {
|
|||||||
void handle_control(controltag ctrl);
|
void handle_control(controltag ctrl);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
signal_emitter& m_sig;
|
|
||||||
vector<mousebtn> m_actions;
|
vector<mousebtn> m_actions;
|
||||||
const logger& m_log;
|
const logger& m_log;
|
||||||
|
|
||||||
|
@ -678,10 +678,30 @@ void renderer::render_offset(const tags::context&, int pixels) {
|
|||||||
m_blocks[m_align].x += 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<int>(align));
|
||||||
|
|
||||||
|
if (m_align != alignment::NONE) {
|
||||||
|
m_log.trace_x("renderer: pop(%i)", static_cast<int>(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<int>(m_align));
|
||||||
|
|
||||||
|
fill_background();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void renderer::action_open(const tags::context&, mousebtn btn, tags::action_t id) {
|
||||||
assert(btn != mousebtn::NONE);
|
assert(btn != mousebtn::NONE);
|
||||||
action_block block;
|
action_block block;
|
||||||
block.align = ctxt.get_alignment();
|
block.align = m_align;
|
||||||
block.button = btn;
|
block.button = btn;
|
||||||
block.start_x = m_blocks.at(block.align).x;
|
block.start_x = m_blocks.at(block.align).x;
|
||||||
m_actions[id] = block;
|
m_actions[id] = block;
|
||||||
@ -734,7 +754,7 @@ void renderer::highlight_clickable_areas() {
|
|||||||
double h = m_rect.height;
|
double h = m_rect.height;
|
||||||
|
|
||||||
m_context->save();
|
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 << cairo::rect{x, y, w, h};
|
||||||
m_context->fill();
|
m_context->fill();
|
||||||
m_context->restore();
|
m_context->restore();
|
||||||
@ -748,25 +768,4 @@ bool renderer::on(const signals::ui::request_snapshot& evt) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool renderer::on(const signals::parser::change_alignment& evt) {
|
|
||||||
auto align = static_cast<const alignment&>(evt.cast());
|
|
||||||
if (align != m_align) {
|
|
||||||
m_log.trace_x("renderer: change_alignment(%i)", static_cast<int>(align));
|
|
||||||
|
|
||||||
if (m_align != alignment::NONE) {
|
|
||||||
m_log.trace_x("renderer: pop(%i)", static_cast<int>(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<int>(m_align));
|
|
||||||
|
|
||||||
fill_background();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
POLYBAR_NS_END
|
POLYBAR_NS_END
|
||||||
|
@ -11,21 +11,18 @@
|
|||||||
|
|
||||||
POLYBAR_NS
|
POLYBAR_NS
|
||||||
|
|
||||||
using namespace signals::parser;
|
|
||||||
|
|
||||||
namespace tags {
|
namespace tags {
|
||||||
/**
|
/**
|
||||||
* Create instance
|
* Create instance
|
||||||
*/
|
*/
|
||||||
dispatch::make_type dispatch::make(action_context& action_ctxt) {
|
dispatch::make_type dispatch::make(action_context& action_ctxt) {
|
||||||
return factory_util::unique<dispatch>(signal_emitter::make(), logger::make(), action_ctxt);
|
return factory_util::unique<dispatch>(logger::make(), action_ctxt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct parser instance
|
* Construct parser instance
|
||||||
*/
|
*/
|
||||||
dispatch::dispatch(signal_emitter& emitter, const logger& logger, action_context& action_ctxt)
|
dispatch::dispatch(const logger& logger, action_context& action_ctxt) : m_log(logger), m_action_ctxt(action_ctxt) {}
|
||||||
: m_sig(emitter), m_log(logger), m_action_ctxt(action_ctxt) {}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process input string
|
* Process input string
|
||||||
@ -79,15 +76,15 @@ namespace tags {
|
|||||||
break;
|
break;
|
||||||
case tags::syntaxtag::l:
|
case tags::syntaxtag::l:
|
||||||
m_ctxt->apply_alignment(alignment::LEFT);
|
m_ctxt->apply_alignment(alignment::LEFT);
|
||||||
m_sig.emit(change_alignment{alignment::LEFT});
|
renderer.change_alignment(*m_ctxt);
|
||||||
break;
|
break;
|
||||||
case tags::syntaxtag::r:
|
case tags::syntaxtag::r:
|
||||||
m_ctxt->apply_alignment(alignment::RIGHT);
|
m_ctxt->apply_alignment(alignment::RIGHT);
|
||||||
m_sig.emit(change_alignment{alignment::RIGHT});
|
renderer.change_alignment(*m_ctxt);
|
||||||
break;
|
break;
|
||||||
case tags::syntaxtag::c:
|
case tags::syntaxtag::c:
|
||||||
m_ctxt->apply_alignment(alignment::CENTER);
|
m_ctxt->apply_alignment(alignment::CENTER);
|
||||||
m_sig.emit(change_alignment{alignment::CENTER});
|
renderer.change_alignment(*m_ctxt);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw runtime_error(
|
throw runtime_error(
|
||||||
@ -129,7 +126,6 @@ namespace tags {
|
|||||||
std::tie(id, btn) = m_action_ctxt.action_close(btn, m_ctxt->get_alignment());
|
std::tie(id, btn) = m_action_ctxt.action_close(btn, m_ctxt->get_alignment());
|
||||||
renderer.action_close(*m_ctxt, id);
|
renderer.action_close(*m_ctxt, id);
|
||||||
} else {
|
} else {
|
||||||
string tmp = cmd;
|
|
||||||
action_t id = m_action_ctxt.action_open(btn, std::move(cmd), m_ctxt->get_alignment());
|
action_t id = m_action_ctxt.action_open(btn, std::move(cmd), m_ctxt->get_alignment());
|
||||||
renderer.action_open(*m_ctxt, btn, id);
|
renderer.action_open(*m_ctxt, btn, id);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user