summaryrefslogtreecommitdiff
blob: 3a6046b690a986cd3ed9b2b13ad97b798b3c44a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
From 95b94a2b841b624be8c0c99730f7011aa56a6a60 Mon Sep 17 00:00:00 2001
From: Tom Anderson <thomasanderson@chromium.org>
Date: Thu, 26 May 2022 21:04:21 +0000
Subject: [PATCH] Fix x11::WindowCache::GetWindowAtPoint() in i3

In i3, container windows have a WM_NAME, but we're interested in the
named content window.  This CL changes the DFS search order to check
child windows before checking parent windows.

R=​sky

(cherry picked from commit 57032db2a7adea88585b1bb00a3cd6542d04285c)

Fixed: 1316735
Change-Id: I8049552f1c0faa7dcbc3bb6b25df2324ee9bbf7a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3588704
Auto-Submit: Thomas Anderson <thomasanderson@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Commit-Queue: Scott Violet <sky@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#993220}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3669471
Commit-Queue: Thomas Anderson <thomasanderson@chromium.org>
Cr-Commit-Position: refs/branch-heads/5005@{#1031}
Cr-Branched-From: 5b4d9450fee01f821b6400e947b3839727643a71-refs/heads/main@{#992738}
---

diff --git a/ui/gfx/x/window_cache.cc b/ui/gfx/x/window_cache.cc
index 0f1fa29..c12bea05 100644
--- a/ui/gfx/x/window_cache.cc
+++ b/ui/gfx/x/window_cache.cc
@@ -152,13 +152,13 @@
     }
   }
 
-  if (info->has_wm_name)
-    return window;
   for (Window child : base::Reversed(info->children)) {
     Window ret = GetWindowAtPoint(point_px, child, ignore);
     if (ret != Window::None)
       return ret;
   }
+  if (info->has_wm_name)
+    return window;
   return Window::None;
 }
 
diff --git a/ui/gfx/x/window_cache_unittest.cc b/ui/gfx/x/window_cache_unittest.cc
index a4c2378..c88dbfd5 100644
--- a/ui/gfx/x/window_cache_unittest.cc
+++ b/ui/gfx/x/window_cache_unittest.cc
@@ -418,4 +418,19 @@
   EXPECT_EQ(cache()->GetWindowAtPoint({150, 150}, root()), c);
 }
 
+// Regression test for https://crbug.com/1316735
+// If both a parent and child window have a WM_NAME, the child window
+// should be returned by GetWindowAtPoint().
+TEST_F(WindowCacheTest, NestedWmName) {
+  connection()->MapWindow(root());
+  SetStringProperty(root(), Atom::WM_NAME, Atom::STRING, "root");
+
+  Window a = CreateWindow(root());
+  connection()->MapWindow(a);
+  SetStringProperty(a, Atom::WM_NAME, Atom::STRING, "a");
+
+  cache()->SyncForTest();
+  EXPECT_EQ(cache()->GetWindowAtPoint({100, 100}, root()), a);
+}
+
 }  // namespace x11