From 4f41469637dc1eedee504ba1167ddc8e064838d9 Mon Sep 17 00:00:00 2001
From: Olivier Fourdan <fourdan.olivier@wanadoo.fr>
Date: Wed, 12 Dec 2007 22:33:56 +0000
Subject: [PATCH] Rework the windows unredirection to take advantage of the new
 overlay support

(Old svn revision: 26463)
---
 src/compositor.c | 56 ++++++++++++++++++++++++------------------------
 src/screen.h     |  2 +-
 2 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/src/compositor.c b/src/compositor.c
index a75fde11c..9a5cb4497 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -1089,7 +1089,7 @@ unredirect_win (CWindow *cw)
         XCompositeUnredirectWindow (display_info->dpy, cw->id, display_info->composite_mode);
         XSync (display_info->dpy, FALSE);
 
-        TRACE ("Window 0x%lx unredirected, overlays is %i", cw->id, screen_info->overlays);
+        TRACE ("Window 0x%lx unredirected, wins_unredirected is %i", cw->id, screen_info->wins_unredirected);
     }
 }
 
@@ -1772,24 +1772,28 @@ map_win (CWindow *cw)
 
     if (!WIN_IS_REDIRECTED(cw))
     {
-        screen_info->overlays++;
+        /* To be safe, we count only the fullscreen overlays */
+        if (WIN_IS_FULLSCREEN(cw))
+        {
+            screen_info->wins_unredirected++;
+        }
 #if HAVE_OVERLAYS
-        if ((screen_info->overlays == 1) && (display_info->have_overlays))
+        if ((screen_info->wins_unredirected == 1) && (display_info->have_overlays))
         {
             XUnmapWindow (myScreenGetXDisplay (screen_info), screen_info->overlay);
         }
 #endif /* HAVE_OVERLAYS */
-        TRACE ("Mapping unredirected window 0x%lx, overlays increased to %i", cw->id, screen_info->overlays);
+        TRACE ("Mapping unredirected window 0x%lx, wins_unredirected increased to %i", cw->id, screen_info->wins_unredirected);
         return;
     }
     if (!screen_info->params->unredirect_overlays)
     {
-        TRACE ("Not unredirecting overlays");
+        TRACE ("Not unredirecting wins_unredirected");
         return;
     }
 
     /* Check for new windows to un-redirect. */
-    if (WIN_IS_FULLSCREEN(cw) && WIN_HAS_DAMAGE(cw) && WIN_IS_OVERRIDE(cw) &&
+    if ((WIN_IS_FULLSCREEN(cw) || (screen_info->wins_unredirected > 0)) && WIN_HAS_DAMAGE(cw) && WIN_IS_OVERRIDE(cw) &&
         WIN_IS_NATIVE_OPAQUE(cw) && WIN_IS_REDIRECTED(cw) && !WIN_IS_SHAPED(cw))
     {
         CWindow *top;
@@ -1818,32 +1822,28 @@ unmap_win (CWindow *cw)
     screen_info = cw->screen_info;
     display_info = screen_info->display_info;
 
-    if (!WIN_IS_REDIRECTED(cw) && (screen_info->overlays > 0))
+    if (!WIN_IS_REDIRECTED(cw) && WIN_IS_FULLSCREEN(cw) && (screen_info->wins_unredirected > 0))
     {
-        screen_info->overlays--;
-        TRACE ("Unmapped window 0x%lx, overlays decreased to %i", cw->id, screen_info->overlays);
-#if HAVE_OVERLAYS
-        if ((screen_info->overlays == 0) && (display_info->have_overlays))
+        screen_info->wins_unredirected--;
+        TRACE ("Unmapped window 0x%lx, wins_unredirected decreased to %i", cw->id, screen_info->wins_unredirected);
+        if (!screen_info->wins_unredirected)
         {
-            XMapWindow (myScreenGetXDisplay (screen_info), screen_info->overlay);
-        }
+            /* Restore the overlay if that was the last unredirected window */
+#if HAVE_OVERLAYS
+            if (display_info->have_overlays)
+            {
+                XMapWindow (myScreenGetXDisplay (screen_info), screen_info->overlay);
+            }
 #endif /* HAVE_OVERLAYS */
-    }
-
-    if (!screen_info->overlays)
-    {
-        /* Repaint immediately if that was the last unredirected window */
-
-        if (!WIN_IS_REDIRECTED(cw))
-        {
             damage_screen (screen_info);
             repair_screen (screen_info);
-        }
-        else if (WIN_IS_VISIBLE(cw))
-        {
-            damage_win (cw);
-        }
+       }
     }
+    else if (WIN_IS_VISIBLE(cw))
+    {
+        damage_win (cw);
+    }
+
     cw->viewable = FALSE;
     cw->damaged = FALSE;
     free_win_data (cw, FALSE);
@@ -2879,7 +2879,7 @@ compositorManageScreen (ScreenInfo *screen_info)
     screen_info->allDamage = None;
     screen_info->cwindows = NULL;
     screen_info->compositor_active = TRUE;
-    screen_info->overlays = 0;
+    screen_info->wins_unredirected = 0;
 
     XClearArea (display_info->dpy, screen_info->output, 0, 0, 0, 0, TRUE);
     compositorSetCMSelection (screen_info, screen_info->xfwm4_win);
@@ -2967,7 +2967,7 @@ compositorUnmanageScreen (ScreenInfo *screen_info)
     }
 
     screen_info->gaussianSize = -1;
-    screen_info->overlays = 0;
+    screen_info->wins_unredirected = 0;
 
     XCompositeUnredirectSubwindows (display_info->dpy, screen_info->xroot,
                                     display_info->composite_mode);
diff --git a/src/screen.h b/src/screen.h
index 11c7c2c99..01a54de42 100644
--- a/src/screen.h
+++ b/src/screen.h
@@ -152,7 +152,7 @@ struct _ScreenInfo
     Picture rootTile;
     XserverRegion allDamage;
 
-    guint overlays;
+    guint wins_unredirected;
     gboolean compositor_active;
     gboolean clipChanged;
 #endif /* HAVE_COMPOSITOR */
-- 
GitLab