From 41b1934824518b154ee2c3f0e303431e07574d27 Mon Sep 17 00:00:00 2001
From: Olivier Fourdan <fourdan.olivier@wanadoo.fr>
Date: Thu, 15 Mar 2007 22:28:43 +0000
Subject: [PATCH] Check only visible windows to see if client is on top of
 stack (bug #2960)

(Old svn revision: 25174)
---
 src/stacking.c   | 21 +++++++++++----------
 src/workspaces.c |  2 +-
 2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/src/stacking.c b/src/stacking.c
index b7d201bb8..195c63798 100644
--- a/src/stacking.c
+++ b/src/stacking.c
@@ -156,7 +156,8 @@ gboolean
 clientIsTopMost (Client *c)
 {
     ScreenInfo *screen_info;
-    GList *index;
+    GList *index, *index2;
+    Client *c2;
 
     g_return_val_if_fail (c != NULL, FALSE);
     TRACE ("entering clientIsTopMost");
@@ -166,18 +167,18 @@ clientIsTopMost (Client *c)
     index = g_list_find (screen_info->windows_stack, (gconstpointer) c);
     if (index)
     {
-        GList *index2 = g_list_next (index);
-        if (index2)
-        {
-            Client *c2 = (Client *) index2->data;
-            return (c2->win_layer > c->win_layer);
-        }
-        else
+        index2 = g_list_next (index);
+        while (index2)
         {
-            return TRUE;
+            c2 = (Client *) index2->data;
+            if (FLAG_TEST (c2->xfwm_flags, XFWM_FLAG_VISIBLE) && (c2->win_layer == c->win_layer))
+            {
+                return FALSE;
+            }
+            index2 = g_list_next (index2);
         }
     }
-    return FALSE;
+    return TRUE;
 }
 
 Client *
diff --git a/src/workspaces.c b/src/workspaces.c
index 910223118..3668e2528 100644
--- a/src/workspaces.c
+++ b/src/workspaces.c
@@ -385,7 +385,7 @@ workspaceSwitch (ScreenInfo *screen_info, int new_ws, Client * c2, gboolean upda
         {
             if ((screen_info->params->click_to_focus) && (screen_info->params->raise_on_click))
             {
-                if (!clientIsTopMost (new_focus))
+                if (!(screen_info->params->raise_on_focus) && !clientIsTopMost (new_focus))
                 {
                     clientRaise (new_focus, None);
                 }
-- 
GitLab