From 464bedb33ce90dd335c7e737f5601f773b087fa6 Mon Sep 17 00:00:00 2001
From: patrick96
Date: Sun, 10 Jan 2021 23:05:48 +0100
Subject: [PATCH] Store all action info in action_context
The renderer is responsible for setting the start and end positions
while dispatch does the rest
---
include/components/renderer.hpp | 8 +---
include/components/renderer_interface.hpp | 12 ++++-
include/components/types.hpp | 15 -------
include/tags/context.hpp | 40 ++++++++++++-----
src/components/bar.cpp | 8 ++--
src/components/renderer.cpp | 53 +++++------------------
src/tags/context.cpp | 37 ++++++++++++++++
7 files changed, 93 insertions(+), 80 deletions(-)
diff --git a/include/components/renderer.hpp b/include/components/renderer.hpp
index 70bf1009..133ad6c7 100644
--- a/include/components/renderer.hpp
+++ b/include/components/renderer.hpp
@@ -36,10 +36,10 @@ class renderer : public renderer_interface,
public signal_receiver {
public:
using make_type = unique_ptr;
- static make_type make(const bar_settings& bar);
+ static make_type make(const bar_settings& bar, tags::action_context& action_ctxt);
explicit renderer(connection& conn, signal_emitter& sig, const config&, const logger& logger, const bar_settings& bar,
- background_manager& background_manager);
+ background_manager& background_manager, tags::action_context& action_ctxt);
~renderer();
xcb_window_t window() const;
@@ -56,9 +56,6 @@ class renderer : public renderer_interface,
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);
@@ -114,7 +111,6 @@ class renderer : public renderer_interface,
bool m_pseudo_transparency{false};
alignment m_align;
- 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 32e9dbcc..07ce7895 100644
--- a/include/components/renderer_interface.hpp
+++ b/include/components/renderer_interface.hpp
@@ -7,6 +7,8 @@ POLYBAR_NS
class renderer_interface {
public:
+ renderer_interface(tags::action_context& action_ctxt) : m_action_ctxt(action_ctxt){};
+
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;
@@ -14,8 +16,14 @@ class renderer_interface {
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 std::map get_actions(int x) = 0;
- virtual tags::action_t get_action(mousebtn btn, int x) = 0;
+ protected:
+ /**
+ * Stores information about actions in the current action cycle.
+ *
+ * The renderer is only responsible for updating the start and end positions
+ * of each action block.
+ */
+ tags::action_context& m_action_ctxt;
};
POLYBAR_NS_END
diff --git a/include/components/types.hpp b/include/components/types.hpp
index dd8cae46..0ec11440 100644
--- a/include/components/types.hpp
+++ b/include/components/types.hpp
@@ -109,21 +109,6 @@ struct action {
string command{};
};
-struct action_block {
- mousebtn button{mousebtn::NONE};
- alignment align{alignment::NONE};
- double start_x{0.0};
- double end_x{0.0};
-
- unsigned int width() const {
- return static_cast(end_x - start_x + 0.5);
- }
-
- bool test(int point) const {
- return static_cast(start_x) <= point && static_cast(end_x) > point;
- }
-};
-
struct bar_settings {
explicit bar_settings() = default;
bar_settings(const bar_settings& other) = default;
diff --git a/include/tags/context.hpp b/include/tags/context.hpp
index 590a85e4..4c292874 100644
--- a/include/tags/context.hpp
+++ b/include/tags/context.hpp
@@ -1,5 +1,7 @@
#pragma once
+#include