From 01373710b76f6c71c03e90302b35c0e3ccc67910 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Mon, 7 Apr 2025 15:23:02 +0200 Subject: [PATCH] gwin: Prevent multiple redraws See https://community.ugfx.io/topic/4782-the-screen-is-redrawn-more-than-once/#comment-13706 --- changelog.txt | 1 + src/gwin/gwin_wm.c | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/changelog.txt b/changelog.txt index 8e1cf78b..70f54cb5 100644 --- a/changelog.txt +++ b/changelog.txt @@ -34,6 +34,7 @@ FEATURE: LGDP4532 driver improvements. FIX: Win32 Keyboard driver now retrieves lock key states on window activate FEATURE: Add SSD1312 GDISP driver FEATURE: Add CH1115 GDISP driver +FIX: Fix multiple redraws of windows (thanks to Sergey Kushnir) *** Release 2.9 *** diff --git a/src/gwin/gwin_wm.c b/src/gwin/gwin_wm.c index a1cd8ea8..1b09bd37 100644 --- a/src/gwin/gwin_wm.c +++ b/src/gwin/gwin_wm.c @@ -749,6 +749,7 @@ static void WM_Delete(GHandle gh) { static void WM_Redraw(GHandle gh) { gU32 flags; + gU32 parents = 0; // Used to indicate whether the window (gh) has parent(s). flags = gh->flags; gh->flags &= ~(GWIN_FLG_NEEDREDRAW|GWIN_FLG_BGREDRAW|GWIN_FLG_PARENTREVEAL); @@ -790,6 +791,8 @@ static void WM_Redraw(GHandle gh) { if (gh->parent) { // Child redraw is done + parents++; + // Get the parent to redraw the area gh = gh->parent; @@ -806,6 +809,11 @@ static void WM_Redraw(GHandle gh) { // Clear the area to the background color gdispGFillArea(gh->display, gh->x, gh->y, gh->width, gh->height, gwinGetDefaultBgColor()); + #if GWIN_NEED_CONTAINERS + if (!parents) + return; + #endif + // Now loop over all windows looking for overlaps. Redraw them if they overlap the newly exposed area. for(gx = gwinGetNextWindow(0); gx; gx = gwinGetNextWindow(gx)) { if ((gx->flags & GWIN_FLG_SYSVISIBLE)