Blob Blame History Raw
From 245a3c2e12b4aad2e752675f82be9517235d5498 Mon Sep 17 00:00:00 2001
From: Rui Matos <tiagomatos@gmail.com>
Date: Fri, 19 May 2017 17:11:19 +0200
Subject: [PATCH] stack-tracker: Keep override redirect windows on top

Since commit 6b5cf2e, we keep override redirect windows on a layer
above regular windows in the clutter actor scene graph. In the X
server, and thus for input purposes, these windows might end up being
stacked below regular windows though, e.g. because a new regular
window is mapped after an OR window.

Fix this disconnect by re-stacking OR windows on top when syncing the
window stack with the compositor.

https://bugzilla.gnome.org/show_bug.cgi?id=780485
---
 src/core/stack-tracker.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/src/core/stack-tracker.c b/src/core/stack-tracker.c
index a76b42cbf..82afd644a 100644
--- a/src/core/stack-tracker.c
+++ b/src/core/stack-tracker.c
@@ -168,6 +168,9 @@ struct _MetaStackTracker
   guint sync_stack_later;
 };
 
+static void
+meta_stack_tracker_keep_override_redirect_on_top (MetaStackTracker *tracker);
+
 static inline const char *
 get_window_desc (MetaStackTracker *tracker,
                  guint64           window)
@@ -835,6 +838,8 @@ meta_stack_tracker_sync_stack (MetaStackTracker *tracker)
       tracker->sync_stack_later = 0;
     }
 
+  meta_stack_tracker_keep_override_redirect_on_top (tracker);
+
   meta_stack_tracker_get_stack (tracker, &windows, &n_windows);
 
   meta_windows = NULL;
@@ -1040,6 +1045,37 @@ meta_stack_tracker_lower (MetaStackTracker *tracker,
   meta_stack_tracker_raise_above (tracker, window, None);
 }
 
+static void
+meta_stack_tracker_keep_override_redirect_on_top (MetaStackTracker *tracker)
+{
+  MetaWindow *window;
+  guint64 *stack;
+  int n_windows, i;
+  int topmost_non_or;
+
+  meta_stack_tracker_get_stack (tracker, &stack, &n_windows);
+
+  for (i = n_windows - 1; i >= 0; i--)
+    {
+      window = meta_display_lookup_stack_id (tracker->screen->display, stack[i]);
+      if (window && window->layer != META_LAYER_OVERRIDE_REDIRECT)
+        break;
+    }
+
+  topmost_non_or = i;
+
+  for (i -= 1; i >= 0; i--)
+    {
+      window = meta_display_lookup_stack_id (tracker->screen->display, stack[i]);
+      if (window && window->layer == META_LAYER_OVERRIDE_REDIRECT)
+        {
+          meta_stack_tracker_raise_above (tracker, stack[i], stack[topmost_non_or]);
+          meta_stack_tracker_get_stack (tracker, &stack, &n_windows);
+          topmost_non_or -= 1;
+        }
+    }
+}
+
 void
 meta_stack_tracker_restack_managed (MetaStackTracker *tracker,
                                     const guint64    *managed,
-- 
2.13.0