From 2bae8905a97aa8a29826c78311c826d61f075e0e Mon Sep 17 00:00:00 2001
From: David Robillard <d@drobilla.net>
Date: Tue, 18 Feb 2020 10:00:27 +0100
Subject: Remove immediate dispatch of exposed rects

This was a hack to support only exposing the rects that were explicitly exposed
with puglPostRedisplayRect(), but it caused flaky drawing issues because it
circumvented the deferral of exposure until the end of the loop.  Instead,
simply expand the pending expose to be dispatched later as usual.

This means that only the union will be exposed in the end, so more area might
be drawn than necessary, but this is probably good enough.  If not, we will
have to maintain a set of rects and be more clever about combining them.
---
 pugl/detail/x11.c | 32 ++------------------------------
 1 file changed, 2 insertions(+), 30 deletions(-)

diff --git a/pugl/detail/x11.c b/pugl/detail/x11.c
index c1189a5..b62e62d 100644
--- a/pugl/detail/x11.c
+++ b/pugl/detail/x11.c
@@ -593,15 +593,6 @@ puglWaitForEvent(PuglView* view)
 	return PUGL_SUCCESS;
 }
 
-static bool
-exposeEventsIntersect(const PuglEvent* a, const PuglEvent* b)
-{
-	return !(a->expose.x + a->expose.width < b->expose.x ||
-	         b->expose.x + b->expose.width < a->expose.x ||
-	         a->expose.y + a->expose.height < b->expose.y ||
-	         b->expose.y + b->expose.height < a->expose.y);
-}
-
 static void
 mergeExposeEvents(PuglEvent* dst, const PuglEvent* src)
 {
@@ -621,25 +612,6 @@ mergeExposeEvents(PuglEvent* dst, const PuglEvent* src)
 	}
 }
 
-static void
-addPendingExpose(PuglView* view, const PuglEvent* expose)
-{
-	if (view->impl->pendingConfigure.type ||
-	    (view->impl->pendingExpose.type &&
-	     exposeEventsIntersect(&view->impl->pendingExpose, expose))) {
-		// Pending configure or an intersecting expose, expand it
-		mergeExposeEvents(&view->impl->pendingExpose, expose);
-	} else {
-		if (view->impl->pendingExpose.type) {
-			// Pending non-intersecting expose, dispatch it now
-			// This isn't ideal, but avoids needing to maintain an expose list
-			puglDispatchEvent(view, &view->impl->pendingExpose);
-		}
-
-		view->impl->pendingExpose = *expose;
-	}
-}
-
 static void
 flushPendingConfigure(PuglView* view)
 {
@@ -755,7 +727,7 @@ puglDispatchEvents(PuglWorld* world)
 
 		if (event.type == PUGL_EXPOSE) {
 			// Expand expose event to be dispatched after loop
-			addPendingExpose(view, &event);
+			mergeExposeEvents(&view->impl->pendingExpose, &event);
 		} else if (event.type == PUGL_CONFIGURE) {
 			// Expand configure event to be dispatched after loop
 			view->impl->pendingConfigure = event;
@@ -823,7 +795,7 @@ puglPostRedisplayRect(PuglView* view, PuglRect rect)
 			PUGL_EXPOSE, 0, rect.x, rect.y, rect.width, rect.height, 0
 		};
 
-		addPendingExpose(view, (const PuglEvent*)&event);
+		mergeExposeEvents(&view->impl->pendingExpose, (const PuglEvent*)&event);
 	} else if (view->visible) {
 		// Not dispatching events, send an X expose so we wake up next time
 		const int x = (int)floor(rect.x);
-- 
cgit v1.2.1