From d7105b23e6f17827406a4c6dac23f8a0c30e44d1 Mon Sep 17 00:00:00 2001
From: Olivier Fourdan <fourdan.olivier@wanadoo.fr>
Date: Wed, 15 Dec 2004 21:52:04 +0000
Subject: [PATCH] Don't restack if the sibling is unknown.

(Old svn revision: 12212)
---
 po/xfwm4.pot     |  2 +-
 src/compositor.c | 60 +++++++++++++++++++++++++++++-------------------
 2 files changed, 37 insertions(+), 25 deletions(-)

diff --git a/po/xfwm4.pot b/po/xfwm4.pot
index 395a74f9e..d459b3b92 100644
--- a/po/xfwm4.pot
+++ b/po/xfwm4.pot
@@ -8,7 +8,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2004-12-13 22:44+0100\n"
+"POT-Creation-Date: 2004-12-14 20:31+0100\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
diff --git a/src/compositor.c b/src/compositor.c
index dc794780b..883f9168d 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -1490,9 +1490,9 @@ void
 restack_win (CWindow *cw, Window above)
 {
     ScreenInfo *screen_info = NULL;
+    Window previous_above = None;
     GList *sibling;
     GList *next;
-    GList *index;
 
     g_return_if_fail (cw != NULL);
     TRACE ("entering restack_win");
@@ -1500,32 +1500,46 @@ restack_win (CWindow *cw, Window above)
     screen_info = cw->screen_info;
     sibling = g_list_find (screen_info->cwindows, (gconstpointer) cw);
     next = g_list_next (sibling);
-    screen_info->cwindows = g_list_delete_link (screen_info->cwindows, sibling);
 
-    for (index = screen_info->cwindows; index; index = g_list_next (index))
+    if (next)
     {
-        CWindow *cw2 = (CWindow *) index->data;
-        if (cw2->id == above)
-        {
-            break;
-        }
+        CWindow *ncw = (CWindow *) next;
+        previous_above = ncw->id;
     }
 
-    if (index != NULL)
-    {
-        screen_info->cwindows =  g_list_insert_before (screen_info->cwindows, index, cw);
-    }
-    else if (above == None)
-    {
-        /* Insert at bottom of window stack */
-        screen_info->cwindows =  g_list_append (screen_info->cwindows, cw);
-    }
-    else
+    if (previous_above != above)
     {
-        /* Insert at top of window stack */
-        g_warning ("The window 0x%lx has been placed on top of stack\n"
-        "because the specified sibling 0x%lx was not found in our stack", cw->id, above);
-        screen_info->cwindows =  g_list_prepend (screen_info->cwindows, cw);
+        GList *index;
+
+        for (index = screen_info->cwindows; index; index = g_list_next (index))
+        {
+            CWindow *cw2 = (CWindow *) index->data;
+            if (cw2->id == above)
+            {
+                break;
+            }
+        }
+
+        if (index != NULL)
+        {
+            screen_info->cwindows = g_list_delete_link (screen_info->cwindows, sibling);
+            screen_info->cwindows = g_list_insert_before (screen_info->cwindows, index, cw);
+        }
+        else if (above == None)
+        {
+            /* Insert at bottom of window stack */
+            screen_info->cwindows = g_list_delete_link (screen_info->cwindows, sibling);
+            screen_info->cwindows = g_list_append (screen_info->cwindows, cw);
+        }
+#ifdef DEBUG
+        else
+        {
+            /* Don't know what to do */
+            g_warning ("The window 0x%lx has not been restacked\n"
+                       "because the specified sibling 0x%lx was\n"
+                       "not found in our stack", cw->id, above);
+        }
+#endif
     }
 }
 
@@ -1839,8 +1853,6 @@ compositorHandleCirculateNotify (DisplayInfo *display_info, XCirculateEvent *ev)
 static void
 compositorHandleCreateNotify (DisplayInfo *display_info, XCreateWindowEvent *ev)
 {
-    CWindow *cw;
-
     g_return_if_fail (display_info != NULL);
     g_return_if_fail (ev != NULL);
     TRACE ("entering compositorHandleCreateNotify for 0x%lx", ev->window);
-- 
GitLab