@@ -151,6 +151,25 @@ static void twin_screen_span_pixmap(twin_screen_t maybe_unused *screen,
151151 op32 (dst , src , p_right - p_left );
152152}
153153
154+ static twin_pixmap_t * twin_active_pixmap (twin_screen_t * screen ,
155+ twin_pixmap_t * * active_pix )
156+ {
157+ twin_pixmap_t * p = NULL , * prev_active_pix = NULL ;
158+ /*
159+ * Identify the previously active pixel map and the currently active pixel
160+ * map, which is on the topmost layer.
161+ */
162+ for (p = screen -> bottom ; p ; p = p -> up ) {
163+ if (p -> window -> active == true) {
164+ prev_active_pix = p ;
165+ prev_active_pix -> window -> active = false;
166+ }
167+ (* active_pix ) = p ;
168+ }
169+ (* active_pix )-> window -> active = true;
170+ return prev_active_pix ;
171+ }
172+
154173void twin_screen_update (twin_screen_t * screen )
155174{
156175 twin_coord_t left = screen -> damage .left ;
@@ -170,7 +189,7 @@ void twin_screen_update(twin_screen_t *screen)
170189
171190 if (!screen -> disable && left < right && top < bottom ) {
172191 twin_argb32_t * span ;
173- twin_pixmap_t * p ;
192+ twin_pixmap_t * p , * active_pix = NULL , * prev_active_pix = NULL ;
174193 twin_coord_t y ;
175194 twin_coord_t width = right - left ;
176195
@@ -183,6 +202,24 @@ void twin_screen_update(twin_screen_t *screen)
183202
184203 if (screen -> put_begin )
185204 (* screen -> put_begin )(left , top , right , bottom , screen -> closure );
205+
206+ prev_active_pix = twin_active_pixmap (screen , & active_pix );
207+
208+ /*
209+ * Mark the previously active pixel map as damaged to update its
210+ * changes.
211+ */
212+ if (prev_active_pix && active_pix != prev_active_pix ) {
213+ twin_pixmap_damage (prev_active_pix , 0 , 0 , prev_active_pix -> width ,
214+ prev_active_pix -> height );
215+ twin_window_draw (prev_active_pix -> window );
216+ }
217+
218+ /* Mark the active pixel map as damaged to update its changes. */
219+ twin_pixmap_damage (active_pix , 0 , 0 , active_pix -> width ,
220+ active_pix -> height );
221+ twin_window_draw (active_pix -> window );
222+
186223 for (y = top ; y < bottom ; y ++ ) {
187224 if (screen -> background ) {
188225 twin_pointer_t dst ;
0 commit comments