From 95b94a2b841b624be8c0c99730f7011aa56a6a60 Mon Sep 17 00:00:00 2001 From: Tom Anderson 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 Reviewed-by: Scott Violet Commit-Queue: Scott Violet Cr-Original-Commit-Position: refs/heads/main@{#993220} Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3669471 Commit-Queue: Thomas Anderson 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