From d846400279a1831d3d29a4dd179fbf799b4ee541 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 10 Apr 2018 20:35:23 +1000 Subject: [PATCH] Redraw window when the face definition changed Hash the current face state and store that hash to check for changes. --- src/face.hh | 5 +++++ src/face_registry.hh | 15 +++++++-------- src/window.cc | 12 +++++++++++- src/window.hh | 1 + 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/face.hh b/src/face.hh index dc38192c..098664d7 100644 --- a/src/face.hh +++ b/src/face.hh @@ -44,6 +44,11 @@ constexpr bool operator!=(const Face& lhs, const Face& rhs) return not (lhs == rhs); } +constexpr size_t hash_value(const Face& val) +{ + return hash_values(val.fg, val.bg, val.attributes); +} + constexpr Face merge_faces(const Face& base, const Face& face) { return face.attributes & Attribute::Exclusive ? diff --git a/src/face_registry.hh b/src/face_registry.hh index 049227eb..1182a9d3 100644 --- a/src/face_registry.hh +++ b/src/face_registry.hh @@ -20,6 +20,13 @@ public: void add_face(StringView name, StringView facedesc, bool override = false); void remove_face(StringView name); + struct FaceOrAlias + { + Face face = {}; + String alias = {}; + }; + using FaceMap = HashMap; + auto flatten_faces() const { auto merge = [](auto&& first, const FaceMap& second) { @@ -33,19 +40,11 @@ public: return merge(merge(grand_parent, parent), m_faces); } - struct FaceOrAlias - { - Face face = {}; - String alias = {}; - }; - private: friend class Scope; FaceRegistry(); SafePtr m_parent; - - using FaceMap = HashMap; FaceMap m_faces; }; diff --git a/src/window.cc b/src/window.cc index db7caebb..6919a5d7 100644 --- a/src/window.cc +++ b/src/window.cc @@ -75,6 +75,14 @@ void Window::center_column(ColumnCount buffer_column) display_column_at(buffer_column, m_dimensions.column/2_col); } +static uint32_t compute_faces_hash(const FaceRegistry& faces) +{ + uint32_t hash = 0; + for (auto&& face : faces.flatten_faces() | transform(&FaceRegistry::FaceMap::Item::value)) + hash = combine_hash(hash, face.alias.empty() ? hash_value(face.face) : hash_value(face.alias)); + return hash; +} + Window::Setup Window::build_setup(const Context& context) const { Vector selections; @@ -83,6 +91,7 @@ Window::Setup Window::build_setup(const Context& context) const return { m_position, m_dimensions, context.buffer().timestamp(), + compute_faces_hash(context.faces()), context.selections().main_index(), std::move(selections) }; } @@ -95,7 +104,8 @@ bool Window::needs_redraw(const Context& context) const m_dimensions != m_last_setup.dimensions or context.buffer().timestamp() != m_last_setup.timestamp or selections.main_index() != m_last_setup.main_selection or - selections.size() != m_last_setup.selections.size()) + selections.size() != m_last_setup.selections.size() or + compute_faces_hash(context.faces()) != m_last_setup.faces_hash) return true; for (int i = 0; i < selections.size(); ++i) diff --git a/src/window.hh b/src/window.hh index 832a25b6..94989046 100644 --- a/src/window.hh +++ b/src/window.hh @@ -72,6 +72,7 @@ private: DisplayCoord position; DisplayCoord dimensions; size_t timestamp; + size_t faces_hash; size_t main_selection; Vector selections; };