From b6c6f1e78cda6c7c4fbfd898441acba908b06c53 Mon Sep 17 00:00:00 2001 From: hippoz <10706925-hippoz@users.noreply.gitlab.com> Date: Tue, 26 Jul 2022 04:47:17 +0300 Subject: [PATCH] fix batch system --- src/Window.cpp | 41 ++++++++++++++++++++++------------------- src/Window.hpp | 4 ++-- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/Window.cpp b/src/Window.cpp index 888b6df..794509d 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -73,10 +73,8 @@ bool Window::dispatch_to_main_widget(Event &event) { void Window::repaint(Box geometry) { m_did_repaint_during_batch = true; - - if (m_is_batching) { + if (m_batches) return; - } auto event = RepaintRectEvent(true, geometry); dispatch_to_main_widget(event); @@ -92,10 +90,8 @@ void Window::repaint() { void Window::relayout(Widget *target) { m_did_relayout_during_batch = true; - - if (m_is_batching) { + if (m_batches) return; - } auto event = RelayoutSubtreeEvent(); target->dispatch_event(event); @@ -103,10 +99,8 @@ void Window::relayout(Widget *target) { void Window::relayout() { m_did_relayout_during_batch = true; - - if (m_is_batching) { + if (m_batches) return; - } auto event = RelayoutSubtreeEvent(); dispatch_to_main_widget(event); @@ -118,20 +112,29 @@ void Window::reflow() { } void Window::start_batch() { - m_is_batching = true; - m_did_relayout_during_batch = false; - m_did_repaint_during_batch = false; + m_batches++; } void Window::end_batch() { - if (m_is_batching) { - m_is_batching = false; - if (m_did_relayout_during_batch) { - reflow(); - } else if (m_did_repaint_during_batch) { - repaint(); - } + if (m_batches < 1) + return; + + // we are only interested in performing batch operations for the last batch + if (m_batches > 1) { + m_batches--; + return; } + + m_batches = 0; + + if (m_did_relayout_during_batch) { + reflow(); + } else if (m_did_repaint_during_batch) { + repaint(); + } + + m_did_relayout_during_batch = false; + m_did_repaint_during_batch = false; } void Window::run(bool block) { diff --git a/src/Window.hpp b/src/Window.hpp index e3e457a..74084b5 100644 --- a/src/Window.hpp +++ b/src/Window.hpp @@ -56,9 +56,9 @@ private: Box m_rect { 0, 0, 800, 600 }; Painter m_painter {}; Cairo::RefPtr m_xlib_surface { nullptr }; - bool m_is_batching { true }; - bool m_did_relayout_during_batch { true }; + int m_batches { 1 }; bool m_did_repaint_during_batch { false }; + bool m_did_relayout_during_batch { false }; Display *m_x_display { nullptr };