From 96239597ed3271097bef09316bd9f6e8214e2d0e Mon Sep 17 00:00:00 2001
From: patrick96
Date: Sun, 10 Jan 2021 20:49:50 +0100
Subject: [PATCH] Move most action state out of renderer
The renderer now only stores the positions of the actions because that
is specific to the renderer and because the actual position can only be
finalized after all the rendering is done because intitially the
positions are relative to the alignment and not the bar.
---
include/components/bar.hpp | 5 +-
include/components/renderer.hpp | 28 ++---
include/components/renderer_interface.hpp | 8 ++
include/components/types.hpp | 4 +-
include/events/signal.hpp | 6 -
include/events/signal_fwd.hpp | 2 -
include/tags/context.hpp | 49 +++++++-
include/tags/dispatch.hpp | 15 ++-
src/components/bar.cpp | 78 +++++++-----
src/components/renderer.cpp | 142 +++++++++-------------
src/tags/context.cpp | 59 ++++++++-
src/tags/dispatch.cpp | 87 ++++++-------
12 files changed, 275 insertions(+), 208 deletions(-)
diff --git a/include/components/bar.hpp b/include/components/bar.hpp
index 0c554678..8afbe6ea 100644
--- a/include/components/bar.hpp
+++ b/include/components/bar.hpp
@@ -10,6 +10,7 @@
#include "events/signal_fwd.hpp"
#include "events/signal_receiver.hpp"
#include "settings.hpp"
+#include "tags/context.hpp"
#include "utils/math.hpp"
#include "x11/types.hpp"
#include "x11/window.hpp"
@@ -66,7 +67,8 @@ class bar : public xpp::event::sink&&,
- unique_ptr&&, unique_ptr&&, unique_ptr&&, bool only_initialize_values);
+ unique_ptr&&, unique_ptr&&, unique_ptr&&,
+ unique_ptr&&, bool only_initialize_values);
~bar();
const bar_settings settings() const;
@@ -114,6 +116,7 @@ class bar : public xpp::event::sink m_tray;
unique_ptr m_renderer;
unique_ptr m_dispatch;
+ unique_ptr m_action_ctxt;
unique_ptr m_taskqueue;
bar_settings m_opts{};
diff --git a/include/components/renderer.hpp b/include/components/renderer.hpp
index a6c8f0ec..9c6b099c 100644
--- a/include/components/renderer.hpp
+++ b/include/components/renderer.hpp
@@ -32,9 +32,9 @@ 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);
@@ -44,24 +44,26 @@ class renderer : public renderer_interface,
~renderer();
xcb_window_t window() const;
- const vector actions() const;
void begin(xcb_rectangle_t rect);
void end();
void flush();
-#if 0
- void reserve_space(edge side, unsigned int w);
-#endif
+ void render_offset(const tags::context& ctxt, int pixels) override;
+ void render_text(const tags::context& ctxt, const string&&) 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;
+
+ std::map get_actions(int x) override;
+ tags::action_t get_action(mousebtn btn, int x) override;
+
+ protected:
void fill_background();
void fill_overline(rgba color, double x, double w);
void fill_underline(rgba color, double x, double w);
void fill_borders();
- void render_offset(const tags::context& ctxt, int pixels) override;
- void render_text(const tags::context& ctxt, const string&&) override;
-
- protected:
double block_x(alignment a) const;
double block_y(alignment a) const;
double block_w(alignment a) const;
@@ -72,8 +74,6 @@ class renderer : public renderer_interface,
bool on(const signals::ui::request_snapshot& evt) override;
bool on(const signals::parser::change_alignment& evt) override;
- bool on(const signals::parser::action_begin& evt) override;
- bool on(const signals::parser::action_end& evt) override;
protected:
struct reserve_area {
@@ -114,7 +114,7 @@ class renderer : public renderer_interface,
bool m_pseudo_transparency{false};
alignment m_align;
- vector m_actions;
+ std::unordered_map m_actions;
bool m_fixedcenter;
string m_snapshot_dst;
diff --git a/include/components/renderer_interface.hpp b/include/components/renderer_interface.hpp
index d94042f9..5f2cb107 100644
--- a/include/components/renderer_interface.hpp
+++ b/include/components/renderer_interface.hpp
@@ -1,4 +1,6 @@
#pragma once
+#include